aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2023-12-05 09:23:41 +1030
committerAlan Modra <amodra@gmail.com>2023-12-06 12:23:05 +1030
commit3c8852fcc806915fdeab8b3d6f49be7347160527 (patch)
tree0738b9341e04fae97c7cc25efa39f86e054e99ca /binutils
parent9d498f4286d7058f448cf78214c0bc6cdf8dad31 (diff)
downloadgdb-3c8852fcc806915fdeab8b3d6f49be7347160527.zip
gdb-3c8852fcc806915fdeab8b3d6f49be7347160527.tar.gz
gdb-3c8852fcc806915fdeab8b3d6f49be7347160527.tar.bz2
PR31096, nm shows 32bit addresses as 64bit addresses
Prior to commit 0e3c1eebb2 nm output depended on the host unsigned long when printing "negative" symbol values for 32-bit targets. Commit 0e3c1eebb22 made the output match that seen with a 64-bit host unsigned long. The fact that nm output changed depending on host is of course a bug, but it is reasonable to expect 32-bit target output is only 32 bits. So this patch makes 32-bit target output the same as it was on 32-bit hosts prior to 0e3c1eebb2. PR 31096 * nm.c (print_format_string): Make it a static buffer. (get_print_format): Merge into.. (set_print_format): ..this, renamed from set_print_width. When print_width is 32, set up print_format_string for an int32_t value. Don't malloc print_format_string. Adjust calls. (print_value): Correct printing of 32-bit values.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/nm.c79
1 files changed, 44 insertions, 35 deletions
diff --git a/binutils/nm.c b/binutils/nm.c
index 54ee818..bfab620 100644
--- a/binutils/nm.c
+++ b/binutils/nm.c
@@ -169,7 +169,7 @@ static const struct output_fns formats[FORMAT_MAX] =
/* The output format to use. */
static const struct output_fns *format = &formats[FORMAT_DEFAULT];
static unsigned int print_format = FORMAT_DEFAULT;
-static const char *print_format_string = NULL;
+static char print_format_string[10];
/* Command options. */
@@ -1512,37 +1512,8 @@ display_rel_file (bfd *abfd, bfd *archive_bfd)
/* Construct a formatting string for printing symbol values. */
-static const char *
-get_print_format (void)
-{
- const char * padding;
- if (print_format == FORMAT_POSIX || print_format == FORMAT_JUST_SYMBOLS)
- {
- /* POSIX compatible output does not have any padding. */
- padding = "";
- }
- else if (print_width == 32)
- {
- padding ="08";
- }
- else /* print_width == 64 */
- {
- padding = "016";
- }
-
- const char * radix = NULL;
- switch (print_radix)
- {
- case 8: radix = PRIo64; break;
- case 10: radix = PRId64; break;
- case 16: radix = PRIx64; break;
- }
-
- return concat ("%", padding, radix, NULL);
-}
-
static void
-set_print_width (bfd *file)
+set_print_format (bfd *file)
{
print_width = bfd_get_arch_size (file);
@@ -1559,8 +1530,43 @@ set_print_width (bfd *file)
else
print_width = 32;
}
- free ((char *) print_format_string);
- print_format_string = get_print_format ();
+
+ char *p = print_format_string;
+ *p++ = '%';
+ if (print_format == FORMAT_POSIX || print_format == FORMAT_JUST_SYMBOLS)
+ {
+ /* POSIX compatible output does not have any padding. */
+ }
+ else if (print_width == 32)
+ {
+ *p++ = '0';
+ *p++ = '8';
+ }
+ else /* print_width == 64. */
+ {
+ *p++ = '0';
+ *p++ = '1';
+ *p++ = '6';
+ }
+
+ if (print_width == 32)
+ {
+ switch (print_radix)
+ {
+ case 8: strcpy (p, PRIo32); break;
+ case 10: strcpy (p, PRId32); break;
+ case 16: strcpy (p, PRIx32); break;
+ }
+ }
+ else
+ {
+ switch (print_radix)
+ {
+ case 8: strcpy (p, PRIo64); break;
+ case 10: strcpy (p, PRId64); break;
+ case 16: strcpy (p, PRIx64); break;
+ }
+ }
}
static void
@@ -1588,7 +1594,7 @@ display_archive (bfd *file)
if (bfd_check_format_matches (arfile, bfd_object, &matching))
{
- set_print_width (arfile);
+ set_print_format (arfile);
format->print_archive_member (bfd_get_filename (file),
bfd_get_filename (arfile));
display_rel_file (arfile, file);
@@ -1644,7 +1650,7 @@ display_file (char *filename)
}
else if (bfd_check_format_matches (file, bfd_object, &matching))
{
- set_print_width (file);
+ set_print_format (file);
format->print_object_filename (filename);
display_rel_file (file, NULL);
}
@@ -1821,6 +1827,9 @@ print_value (bfd *abfd ATTRIBUTE_UNUSED, bfd_vma val)
switch (print_width)
{
case 32:
+ printf (print_format_string, (uint32_t) val);
+ break;
+
case 64:
printf (print_format_string, (uint64_t) val);
break;