aboutsummaryrefslogtreecommitdiff
path: root/binutils
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2022-08-01 11:33:46 +0930
committerAlan Modra <amodra@gmail.com>2022-08-01 13:52:18 +0930
commitf493c2174ef99a43c0a5d89179122f857955d738 (patch)
tree62cc84715e6a801434dce9cd6cb7760e94110d74 /binutils
parent48ca1b26b99c8fd5bc21f5c69b6b666d9b6b9726 (diff)
downloadbinutils-f493c2174ef99a43c0a5d89179122f857955d738.zip
binutils-f493c2174ef99a43c0a5d89179122f857955d738.tar.gz
binutils-f493c2174ef99a43c0a5d89179122f857955d738.tar.bz2
Get rid of fprintf_vma and sprintf_vma
These two macros print either a 16 digit hex number or an 8 digit hex number. Unfortunately they depend on both target and host, which means that the output for 32-bit targets may be either 8 or 16 hex digits. Replace them in most cases with code that prints a bfd_vma using PRIx64. In some cases, deliberately lose the leading zeros. This change some output, notably in base/offset fields of m68k disassembly which I think looks better that way, and in error messages. I've kept leading zeros in symbol dumps (objdump -t) and in PE header dumps. bfd/ * bfd-in.h (fprintf_vma, sprintf_vma, printf_vma): Delete. * bfd-in2.h: Regenerate. * bfd.c (bfd_sprintf_vma): Don't use sprintf_vma. (bfd_fprintf_vma): Don't use fprintf_vma. * coff-rs6000.c (xcoff_reloc_type_tls): Don't use sprintf_vma. Instead use PRIx64 to print bfd_vma values. (xcoff_ppc_relocate_section): Likewise. * cofflink.c (_bfd_coff_write_global_sym): Likewise. * mmo.c (mmo_write_symbols_and_terminator): Likewise. * srec.c (srec_write_symbols): Likewise. * elf32-xtensa.c (print_r_reloc): Similarly for fprintf_vma. * pei-x86_64.c (pex64_dump_xdata): Likewise. (pex64_bfd_print_pdata_section): Likewise. * som.c (som_print_symbol): Likewise. * ecoff.c (_bfd_ecoff_print_symbol): Use bfd_fprintf_vma. opcodes/ * dis-buf.c (perror_memory, generic_print_address): Don't use sprintf_vma. Instead use PRIx64 to print bfd_vma values. * i386-dis.c (print_operand_value, print_displacement): Likewise. * m68k-dis.c (print_base, print_indexed): Likewise. * ns32k-dis.c (print_insn_arg): Likewise. * ia64-gen.c (_opcode_int64_low, _opcode_int64_high): Delete. (opcode_fprintf_vma): Delete. (print_main_table): Use PRIx64 to print opcode. binutils/ * od-macho.c: Replace all uses of printf_vma with bfd_printf_vma. * objcopy.c (copy_object): Don't use sprintf_vma. Instead use PRIx64 to print bfd_vma values. (copy_main): Likewise. * readelf.c (CHECK_ENTSIZE_VALUES): Likewise. (dynamic_section_mips_val): Likewise. (print_vma): Don't use printf_vma. Instead use PRIx64 to print bfd_vma values. (dump_ia64_vms_dynamic_fixups): Likewise. (process_version_sections): Likewise. * rddbg.c (stab_context): Likewise. gas/ * config/tc-i386.c (offset_in_range): Don't use sprintf_vma. Instead use PRIx64 to print bfd_vma values. (md_assemble): Likewise. * config/tc-mips.c (load_register, macro): Likewise. * messages.c (as_internal_value_out_of_range): Likewise. * read.c (emit_expr_with_reloc): Likewise. * config/tc-ia64.c (note_register_values): Don't use fprintf_vma. Instead use PRIx64 to print bfd_vma values. (print_dependency): Likewise. * listing.c (list_symbol_table): Use bfd_sprintf_vma. * symbols.c (print_symbol_value_1): Use %p to print pointers. (print_binary): Likewise. (print_expr_1): Use PRIx64 to print bfd_vma values. * write.c (print_fixup): Use %p to print pointers. Don't use fprintf_vma. * testsuite/gas/all/overflow.l: Update expected output. * testsuite/gas/m68k/mcf-mov3q.d: Likewise. * testsuite/gas/m68k/operands.d: Likewise. * testsuite/gas/s12z/truncated.d: Likewise. ld/ * deffilep.y (def_file_print): Don't use fprintf_vma. Instead use PRIx64 to print bfd_vma values. * emultempl/armelf.em (gld${EMULATION_NAME}_finish): Don't use sprintf_vma. Instead use PRIx64 to print bfd_vma values. * emultempl/pe.em (gld${EMULATION_NAME}_finish): Likewise. * ldlang.c (lang_map): Use %V to print region origin. (lang_one_common): Don't use sprintf_vma. * ldmisc.c (vfinfo): Don't use fprintf_vma or sprintf_vma. * pe-dll.c (pe_dll_generate_def_file): Likewise. gdb/ * remote.c (remote_target::trace_set_readonly_regions): Replace uses of sprintf_vma with bfd_sprintf_vma.
Diffstat (limited to 'binutils')
-rw-r--r--binutils/objcopy.c58
-rw-r--r--binutils/od-macho.c34
-rw-r--r--binutils/rddbg.c2
-rw-r--r--binutils/readelf.c41
4 files changed, 52 insertions, 83 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 3743573..21c3a71 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2792,13 +2792,10 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
if (pe_file_alignment > pe_section_alignment)
{
- char file_alignment[20], section_alignment[20];
-
- sprintf_vma (file_alignment, pe_file_alignment);
- sprintf_vma (section_alignment, pe_section_alignment);
- non_fatal (_("warning: file alignment (0x%s) > section alignment (0x%s)"),
-
- file_alignment, section_alignment);
+ non_fatal (_("warning: file alignment (0x%" PRIx64
+ ") > section alignment (0x%" PRIx64 ")"),
+ (uint64_t) pe_file_alignment,
+ (uint64_t) pe_section_alignment);
}
}
@@ -5495,14 +5492,9 @@ copy_main (int argc, char *argv[])
gap_fill_vma = parse_vma (optarg, "--gap-fill");
gap_fill = (bfd_byte) gap_fill_vma;
if ((bfd_vma) gap_fill != gap_fill_vma)
- {
- char buff[20];
-
- sprintf_vma (buff, gap_fill_vma);
-
- non_fatal (_("Warning: truncating gap-fill from 0x%s to 0x%x"),
- buff, gap_fill);
- }
+ non_fatal (_("Warning: truncating gap-fill from 0x%" PRIx64
+ " to 0x%x"),
+ (uint64_t) gap_fill_vma, gap_fill);
gap_fill_set = true;
}
break;
@@ -5968,32 +5960,20 @@ copy_main (int argc, char *argv[])
if (! p->used)
{
if (p->context & (SECTION_CONTEXT_SET_VMA | SECTION_CONTEXT_ALTER_VMA))
- {
- char buff [20];
-
- sprintf_vma (buff, p->vma_val);
-
- /* xgettext:c-format */
- non_fatal (_("%s %s%c0x%s never used"),
- "--change-section-vma",
- p->pattern,
- p->context & SECTION_CONTEXT_SET_VMA ? '=' : '+',
- buff);
- }
+ /* xgettext:c-format */
+ non_fatal (_("%s %s%c0x%" PRIx64 " never used"),
+ "--change-section-vma",
+ p->pattern,
+ p->context & SECTION_CONTEXT_SET_VMA ? '=' : '+',
+ (uint64_t) p->vma_val);
if (p->context & (SECTION_CONTEXT_SET_LMA | SECTION_CONTEXT_ALTER_LMA))
- {
- char buff [20];
-
- sprintf_vma (buff, p->lma_val);
-
- /* xgettext:c-format */
- non_fatal (_("%s %s%c0x%s never used"),
- "--change-section-lma",
- p->pattern,
- p->context & SECTION_CONTEXT_SET_LMA ? '=' : '+',
- buff);
- }
+ /* xgettext:c-format */
+ non_fatal (_("%s %s%c0x%" PRIx64 " never used"),
+ "--change-section-lma",
+ p->pattern,
+ p->context & SECTION_CONTEXT_SET_LMA ? '=' : '+',
+ (uint64_t) p->lma_val);
}
}
}
diff --git a/binutils/od-macho.c b/binutils/od-macho.c
index e91c87d..710dfc3 100644
--- a/binutils/od-macho.c
+++ b/binutils/od-macho.c
@@ -357,9 +357,9 @@ dump_section_map (bfd *abfd)
seg = &cmd->command.segment;
printf ("[Segment %-16s ", seg->segname);
- printf_vma (seg->vmaddr);
+ bfd_printf_vma (abfd, seg->vmaddr);
putchar ('-');
- printf_vma (seg->vmaddr + seg->vmsize - 1);
+ bfd_printf_vma (abfd, seg->vmaddr + seg->vmsize - 1);
putchar (' ');
disp_segment_prot (seg->initprot);
printf ("]\n");
@@ -368,29 +368,29 @@ dump_section_map (bfd *abfd)
{
printf ("%02u: %-16s %-16s ", ++sec_nbr,
sec->segname, sec->sectname);
- printf_vma (sec->addr);
+ bfd_printf_vma (abfd, sec->addr);
putchar (' ');
- printf_vma (sec->size);
+ bfd_printf_vma (abfd, sec->size);
printf (" %08lx\n", sec->flags);
}
}
}
static void
-dump_section_header (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_section *sec)
+dump_section_header (bfd *abfd, bfd_mach_o_section *sec)
{
printf (" Section: %-16s %-16s (bfdname: %s)\n",
sec->sectname, sec->segname, sec->bfdsection->name);
printf (" addr: ");
- printf_vma (sec->addr);
+ bfd_printf_vma (abfd, sec->addr);
printf (" size: ");
- printf_vma (sec->size);
+ bfd_printf_vma (abfd, sec->size);
printf (" offset: ");
- printf_vma (sec->offset);
+ bfd_printf_vma (abfd, sec->offset);
printf ("\n");
printf (" align: %ld", sec->align);
printf (" nreloc: %lu reloff: ", sec->nreloc);
- printf_vma (sec->reloff);
+ bfd_printf_vma (abfd, sec->reloff);
printf ("\n");
printf (" flags: %08lx (type: %s", sec->flags,
bfd_mach_o_get_name (bfd_mach_o_section_type_name,
@@ -425,7 +425,7 @@ dump_section_header (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_section *sec)
}
static void
-dump_segment (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_load_command *cmd)
+dump_segment (bfd *abfd, bfd_mach_o_load_command *cmd)
{
bfd_mach_o_segment_command *seg = &cmd->command.segment;
bfd_mach_o_section *sec;
@@ -439,16 +439,16 @@ dump_segment (bfd *abfd ATTRIBUTE_UNUSED, bfd_mach_o_load_command *cmd)
disp_segment_prot (seg->maxprot);
printf ("\n");
printf (" vmaddr: ");
- printf_vma (seg->vmaddr);
+ bfd_printf_vma (abfd, seg->vmaddr);
printf (" vmsize: ");
- printf_vma (seg->vmsize);
+ bfd_printf_vma (abfd, seg->vmsize);
printf ("\n");
printf (" fileoff: ");
- printf_vma (seg->fileoff);
+ bfd_printf_vma (abfd, seg->fileoff);
printf (" filesize: ");
- printf_vma ((bfd_vma)seg->filesize);
+ bfd_printf_vma (abfd, (bfd_vma) seg->filesize);
printf (" endoff: ");
- printf_vma ((bfd_vma)(seg->fileoff + seg->filesize));
+ bfd_printf_vma (abfd, (bfd_vma) (seg->fileoff + seg->filesize));
printf ("\n");
for (sec = seg->sect_head; sec != NULL; sec = sec->next)
dump_section_header (abfd, sec);
@@ -540,7 +540,7 @@ dump_dysymtab (bfd *abfd, bfd_mach_o_load_command *cmd, bool verbose)
printf (" term: idx: %8u num: %u\n",
module->iterm, module->nterm);
printf (" objc_module_info: addr: ");
- printf_vma (module->objc_module_info_addr);
+ bfd_printf_vma (abfd, module->objc_module_info_addr);
printf (" size: %lu\n", module->objc_module_info_size);
}
@@ -608,7 +608,7 @@ dump_dysymtab (bfd *abfd, bfd_mach_o_load_command *cmd, bool verbose)
unsigned int isym = dysymtab->indirect_syms[j];
printf (" ");
- printf_vma (addr);
+ bfd_printf_vma (abfd, addr);
printf (" %5u: 0x%08x", j, isym);
if (isym & BFD_MACH_O_INDIRECT_SYMBOL_LOCAL)
printf (" LOCAL");
diff --git a/binutils/rddbg.c b/binutils/rddbg.c
index 169c52f..9d69355 100644
--- a/binutils/rddbg.c
+++ b/binutils/rddbg.c
@@ -410,7 +410,7 @@ stab_context (void)
else
fprintf (stderr, "%-6d", stabp->type);
fprintf (stderr, " %-6d ", stabp->desc);
- fprintf_vma (stderr, stabp->value);
+ fprintf (stderr, "%08" PRIx64, (uint64_t) stabp->value);
if (stabp->type != 0)
fprintf (stderr, " %s", stabp->string);
fprintf (stderr, "\n");
diff --git a/binutils/readelf.c b/binutils/readelf.c
index 4a3e448..157f8d8 100644
--- a/binutils/readelf.c
+++ b/binutils/readelf.c
@@ -566,11 +566,10 @@ print_vma (bfd_vma vma, print_mode mode)
/* Fall through. */
case LONG_HEX:
#ifdef BFD64
- if (is_32bit_elf)
- return nc + printf ("%8.8" BFD_VMA_FMT "x", vma);
+ if (!is_32bit_elf)
+ return nc + printf ("%16.16" PRIx64, (uint64_t) vma);
#endif
- printf_vma (vma);
- return nc + 16;
+ return nc + printf ("%8.8" PRIx64, (uint64_t) vma);
case DEC_5:
if (vma <= 99999)
@@ -7193,13 +7192,10 @@ process_section_headers (Filedata * filedata)
bfd_size_type expected_entsize = is_32bit_elf ? size32 : size64; \
if (section->sh_entsize != expected_entsize) \
{ \
- char buf[40]; \
- sprintf_vma (buf, section->sh_entsize); \
- /* Note: coded this way so that there is a single string for \
- translation. */ \
- error (_("Section %d has invalid sh_entsize of %s\n"), i, buf); \
- error (_("(Using the expected size of %u for the rest of this dump)\n"), \
- (unsigned) expected_entsize); \
+ error (_("Section %d has invalid sh_entsize of %" PRIx64 "\n"), \
+ i, (uint64_t) section->sh_entsize); \
+ error (_("(Using the expected size of %" PRIx64 " for the rest of this dump)\n"), \
+ (uint64_t) expected_entsize); \
section->sh_entsize = expected_entsize; \
} \
} \
@@ -8184,13 +8180,13 @@ dump_ia64_vms_dynamic_fixups (Filedata * filedata,
const char *rtype;
printf ("%3u ", (unsigned) BYTE_GET (imfs [i].fixup_seg));
- printf_vma ((bfd_vma) BYTE_GET (imfs [i].fixup_offset));
+ printf ("%016" PRIx64 " ", (uint64_t) BYTE_GET (imfs [i].fixup_offset));
type = BYTE_GET (imfs [i].type);
rtype = elf_ia64_reloc_type (type);
if (rtype == NULL)
- printf (" 0x%08x ", type);
+ printf ("0x%08x ", type);
else
- printf (" %-32s ", rtype);
+ printf ("%-32s ", rtype);
printf ("%6u ", (unsigned) BYTE_GET (imfs [i].symvec_index));
printf ("0x%08x\n", (unsigned) BYTE_GET (imfs [i].data_type));
}
@@ -10596,12 +10592,8 @@ dynamic_section_mips_val (Filedata * filedata, Elf_Internal_Dyn * entry)
printf (_("Interface Version: %s"),
get_dynamic_name (filedata, entry->d_un.d_val));
else
- {
- char buf[40];
- sprintf_vma (buf, entry->d_un.d_ptr);
- /* Note: coded this way so that there is a single string for translation. */
- printf (_("<corrupt: %s>"), buf);
- }
+ printf (_("Interface Version: <corrupt: %" PRIx64 ">"),
+ (uint64_t) entry->d_un.d_ptr);
break;
case DT_MIPS_TIME_STAMP:
@@ -12087,8 +12079,7 @@ process_version_sections (Filedata * filedata)
printable_section_name (filedata, section),
section->sh_info);
- printf (_(" Addr: 0x"));
- printf_vma (section->sh_addr);
+ printf (_(" Addr: 0x%016" PRIx64), (uint64_t) section->sh_addr);
printf (_(" Offset: %#08lx Link: %u (%s)\n"),
(unsigned long) section->sh_offset, section->sh_link,
printable_section_name_from_index (filedata, section->sh_link));
@@ -12234,8 +12225,7 @@ process_version_sections (Filedata * filedata)
printable_section_name (filedata, section),
section->sh_info);
- printf (_(" Addr: 0x"));
- printf_vma (section->sh_addr);
+ printf (_(" Addr: 0x%016" PRIx64), (uint64_t) section->sh_addr);
printf (_(" Offset: %#08lx Link: %u (%s)\n"),
(unsigned long) section->sh_offset, section->sh_link,
printable_section_name_from_index (filedata, section->sh_link));
@@ -12400,8 +12390,7 @@ process_version_sections (Filedata * filedata)
printable_section_name (filedata, section),
(unsigned long) total);
- printf (_(" Addr: 0x"));
- printf_vma (section->sh_addr);
+ printf (_(" Addr: 0x%016" PRIx64), (uint64_t) section->sh_addr);
printf (_(" Offset: %#08lx Link: %u (%s)\n"),
(unsigned long) section->sh_offset, section->sh_link,
printable_section_name (filedata, link_section));