[RFC PATCH v2 06/17] objtool: Improve offstr() output

Alexandre Chartre posted 17 patches 3 months, 3 weeks ago
[RFC PATCH v2 06/17] objtool: Improve offstr() output
Posted by Alexandre Chartre 3 months, 3 weeks ago
offset() formats a section offset into a "<symbol>+<offset>" string.
Improve the output to just "<symbol>" when the offset is zero.

Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
---
 tools/objtool/include/objtool/warn.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h
index 125093d568be..d89e6ae69143 100644
--- a/tools/objtool/include/objtool/warn.h
+++ b/tools/objtool/include/objtool/warn.h
@@ -43,12 +43,12 @@ static inline char *offstr(struct section *sec, unsigned long offset)
 
 	if (sym) {
 		str = malloc(strlen(sym->name) + strlen(sec->name) + 40);
-		len = sprintf(str, "%s+0x%lx", sym->name, offset - sym->offset);
+		len = sprint_name(str, sym->name, offset - sym->offset);
 		if (opts.sec_address)
 			sprintf(str+len, " (%s+0x%lx)", sec->name, offset);
 	} else {
 		str = malloc(strlen(sec->name) + 20);
-		sprintf(str, "%s+0x%lx", sec->name, offset);
+		sprint_name(str, sec->name, offset);
 	}
 
 	return str;
-- 
2.43.5
Re: [RFC PATCH v2 06/17] objtool: Improve offstr() output
Posted by Josh Poimboeuf 2 weeks, 1 day ago
On Thu, Jun 19, 2025 at 04:56:48PM +0200, Alexandre Chartre wrote:
> offset() formats a section offset into a "<symbol>+<offset>" string.
> Improve the output to just "<symbol>" when the offset is zero.
> 
> Signed-off-by: Alexandre Chartre <alexandre.chartre@oracle.com>
> ---
>  tools/objtool/include/objtool/warn.h | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/tools/objtool/include/objtool/warn.h b/tools/objtool/include/objtool/warn.h
> index 125093d568be..d89e6ae69143 100644
> --- a/tools/objtool/include/objtool/warn.h
> +++ b/tools/objtool/include/objtool/warn.h
> @@ -43,12 +43,12 @@ static inline char *offstr(struct section *sec, unsigned long offset)
>  
>  	if (sym) {
>  		str = malloc(strlen(sym->name) + strlen(sec->name) + 40);
> -		len = sprintf(str, "%s+0x%lx", sym->name, offset - sym->offset);
> +		len = sprint_name(str, sym->name, offset - sym->offset);
>  		if (opts.sec_address)
>  			sprintf(str+len, " (%s+0x%lx)", sec->name, offset);
>  	} else {
>  		str = malloc(strlen(sec->name) + 20);
> -		sprintf(str, "%s+0x%lx", sec->name, offset);
> +		sprint_name(str, sec->name, offset);

Maybe this makes sense for the disassembler, but I'm not sure we want to
remove the zero for the more general warning case, as the intent is
usually to point to a specific instruction.

-- 
Josh