[PATCH] nm: Enforce 32-bit width limit when printing 32-bit values

Nicolas Schier n.schier@avm.de
Mon Dec 4 12:03:29 GMT 2023


Enforce printing only lower-half of 64-bit values if 32-bit print width
is requested.

Printing 32-bit values >= 0x80000000 on MIPS32 causes effective output
of a sign-extended 64-bit value since commit 0e3c1eebb22 ("Remove use of
bfd_uint64_t and similar", 2022-05-27).  While this might be considered
appropriate for a "signed address-space", the output differs from other
tools from binutils, e.g. objdump, which always prints 32-bit values as
32-bit values.

Bug: https://sourceware.org/bugzilla/show_bug.cgi?id=31096
Fixes: 0e3c1eebb22e ("Remove use of bfd_uint64_t and similar")
Signed-off-by: Nicolas Schier <n.schier@avm.de>
---
 binutils/nm.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/binutils/nm.c b/binutils/nm.c
index e4c8036df1b..7e42ce8f469 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -1821,6 +1821,9 @@ print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val)
   switch (print_width)
     {
     case 32:
+      printf (print_format_string, 0xffffffff & (uint64_t) val);
+      break;
+
     case 64:
       printf (print_format_string, (uint64_t) val);
       break;
-- 
2.40.1



More information about the Binutils mailing list