Skip to contentSkip to conversation

objtool: Print bfd_vma as unsigned long long on ia32-x86_64 cross build

PATCH Applied Dmitry Safonov 4 participants 4 messages Jan 26 – Jan 28 objtool

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 objtool: Print bfd_vma as unsigned long long on ia32-x86_64 cross build

When objtool is cross-compiled in ia32 container for x86_64 target it fails with the following errors:

Quoted 6 lines

disas.c: In function 'disas_print_addr_sym':
disas.c:173:38: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'bfd_vma' {aka 'long long unsigned int'} [-Werror=format=]

  173 |                 DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
      |                                      ^~~~~~~~~~~~  ~~~~
      |                                                    |
      |                                                    bfd_vma {aka long long unsigned int}

Provide a correct printf-fmt depending on sizeof(bfd_vma).

Cc Alexandre Chartre <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Fixes 5d859dff266f ("objtool: Print symbol during disassembly")
---
 tools/objtool/disas.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/objtool/disas.c +8 -6
index 2b5059f55e40..26f08d41f2b1 100644
@@ -108,6 +108,8 @@ static int sprint_name(char *str, const char *name, unsigned long offset)
 
 #define DINFO_FPRINTF(dinfo, ...)	\
 	((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__))
+#define bfd_vma_fmt			\
+	__builtin_choose_expr(sizeof(bfd_vma) == sizeof(unsigned long), "%#lx <%s>", "%#llx <%s>")
 
 static int disas_result_fprintf(struct disas_context *dctx,
 				const char *fmt, va_list ap)
@@ -170,10 +172,10 @@ static void disas_print_addr_sym(struct section *sec, struct symbol *sym,
 
 	if (sym) {
 		sprint_name(symstr, sym->name, addr - sym->offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
 	} else {
 		str = offstr(sec, addr);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
 		free(str);
 	}
 }
@@ -252,7 +254,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
 		 * example: "lea 0x0(%rip),%rdi". The kernel can reference
 		 * the next IP with _THIS_IP_ macro.
 		 */
-		DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, "_THIS_IP_");
 		return;
 	}
 
@@ -264,11 +266,11 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
 	 */
 	if (reloc->sym->type == STT_SECTION) {
 		str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
 		free(str);
 	} else {
 		sprint_name(symstr, reloc->sym->name, offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
 	}
 }
 
@@ -311,7 +313,7 @@ static void disas_print_address(bfd_vma addr, struct disassemble_info *dinfo)
 	 */
 	sym = insn_call_dest(insn);
 	if (sym && (sym->offset == addr || (sym->offset == 0 && is_reloc))) {
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, sym->name);
 		return;
 	}
 

---
base-commit: ca3a02fda4da8e2c1cb6baee5d72352e9e2cfaea
change-id: 20260126-objtool-ia32-84f2ba28de2a

Best regards,

Signature · 1 line
Dmitry Safonov <[email protected]>
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 10 lines · Dmitry Safonov

When objtool is cross-compiled in ia32 container for x86_64 target it fails with the following errors:

Quoted 6 lines

disas.c: In function 'disas_print_addr_sym':
disas.c:173:38: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'bfd_vma' {aka 'long long unsigned int'} [-Werror=format=]

  173 |                 DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
      |                                      ^~~~~~~~~~~~  ~~~~
      |                                                    |
      |                                                    bfd_vma {aka long long unsigned int}
Quoted 7 lines

Provide a correct printf-fmt depending on sizeof(bfd_vma).

Cc Alexandre Chartre <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Fixes 5d859dff266f ("objtool: Print symbol during disassembly")

Thanks!

Signature · 1 line
Josh
Reviewed-by on v1 1/1
#2 lore raw
In reply to Dmitry Safonov
Quoted 14 lines · On 1/26/26 05:57, Dmitry Safonov via B4 Relay wrote:

From: Dmitry Safonov <[email protected]>

When objtool is cross-compiled in ia32 container for x86_64 target it fails with the following errors:

Quoted 6 lines

disas.c: In function 'disas_print_addr_sym':
disas.c:173:38: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'bfd_vma' {aka 'long long unsigned int'} [-Werror=format=]

   173 |                 DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
       |                                      ^~~~~~~~~~~~  ~~~~
       |                                                    |
       |                                                    bfd_vma {aka long long unsigned int}

Provide a correct printf-fmt depending on sizeof(bfd_vma).

Quoted 9 lines
Cc Alexandre Chartre <[email protected]>
Cc Peter Zijlstra (Intel) <[email protected]>
Cc Josh Poimboeuf <[email protected]>
Fixes 5d859dff266f ("objtool: Print symbol during disassembly")
---
  tools/objtool/disas.c | 14 ++++++++------
  1 file changed, 8 insertions(+), 6 deletions(-)

Thanks,

alex.

merge bot Applied
#3 lore raw
In reply to Dmitry Safonov
The following commit has been merged into the objtool/urgent branch of tip:

The following commit has been merged into the objtool/urgent branch of tip:

Commit-ID:     fd4eeb30b9e30ca1118a618be0755287bcbb2da9
Gitweb:        https://git.kernel.org/tip/fd4eeb30b9e30ca1118a618be0755287bcbb2da9
Author:        Dmitry Safonov <[email protected]>
AuthorDate:    Mon, 26 Jan 2026 04:57:35 
Committer:     Josh Poimboeuf <[email protected]>
CommitterDate: Tue, 27 Jan 2026 08:19:35 -08:00

objtool: Print bfd_vma as unsigned long long on ia32-x86_64 cross build

When objtool is cross-compiled in ia32 container for x86_64 target it fails with the following errors:

Quoted 6 lines

disas.c: In function 'disas_print_addr_sym':
disas.c:173:38: error: format '%lx' expects argument of type 'long unsigned int', but argument 3 has type 'bfd_vma' {aka 'long long unsigned int'} [-Werror=format=]

  173 |                 DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
      |                                      ^~~~~~~~~~~~  ~~~~
      |                                                    |
      |                                                    bfd_vma {aka long long unsigned int}

Provide a correct printf-fmt depending on sizeof(bfd_vma).

Fixes 5d859dff266f ("objtool: Print symbol during disassembly")
---
 tools/objtool/disas.c | 14 ++++++++------
 1 file changed, 8 insertions(+), 6 deletions(-)
tools/objtool/disas.c +8 -6
index 2b5059f..26f08d4 100644
@@ -108,6 +108,8 @@ static int sprint_name(char *str, const char *name, unsigned long offset)
 
 #define DINFO_FPRINTF(dinfo, ...)	\
 	((*(dinfo)->fprintf_func)((dinfo)->stream, __VA_ARGS__))
+#define bfd_vma_fmt			\
+	__builtin_choose_expr(sizeof(bfd_vma) == sizeof(unsigned long), "%#lx <%s>", "%#llx <%s>")
 
 static int disas_result_fprintf(struct disas_context *dctx,
 				const char *fmt, va_list ap)
@@ -170,10 +172,10 @@ static void disas_print_addr_sym(struct section *sec, struct symbol *sym,
 
 	if (sym) {
 		sprint_name(symstr, sym->name, addr - sym->offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
 	} else {
 		str = offstr(sec, addr);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
 		free(str);
 	}
 }
@@ -252,7 +254,7 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
 		 * example: "lea 0x0(%rip),%rdi". The kernel can reference
 		 * the next IP with _THIS_IP_ macro.
 		 */
-		DINFO_FPRINTF(dinfo, "0x%lx <_THIS_IP_>", addr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, "_THIS_IP_");
 		return;
 	}
 
@@ -264,11 +266,11 @@ static void disas_print_addr_reloc(bfd_vma addr, struct disassemble_info *dinfo)
 	 */
 	if (reloc->sym->type == STT_SECTION) {
 		str = offstr(reloc->sym->sec, reloc->sym->offset + offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, str);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, str);
 		free(str);
 	} else {
 		sprint_name(symstr, reloc->sym->name, offset);
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, symstr);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, symstr);
 	}
 }
 
@@ -311,7 +313,7 @@ static void disas_print_address(bfd_vma addr, struct disassemble_info *dinfo)
 	 */
 	sym = insn_call_dest(insn);
 	if (sym && (sym->offset == addr || (sym->offset == 0 && is_reloc))) {
-		DINFO_FPRINTF(dinfo, "0x%lx <%s>", addr, sym->name);
+		DINFO_FPRINTF(dinfo, bfd_vma_fmt, addr, sym->name);
 		return;
 	}