diff options
author | Alan Modra <amodra@gmail.com> | 2022-08-01 11:33:46 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2022-08-01 13:52:18 +0930 |
commit | f493c2174ef99a43c0a5d89179122f857955d738 (patch) | |
tree | 62cc84715e6a801434dce9cd6cb7760e94110d74 /bfd | |
parent | 48ca1b26b99c8fd5bc21f5c69b6b666d9b6b9726 (diff) |
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 'bfd')
-rw-r--r-- | bfd/bfd-in.h | 7 | ||||
-rw-r--r-- | bfd/bfd-in2.h | 7 | ||||
-rw-r--r-- | bfd/bfd.c | 12 | ||||
-rw-r--r-- | bfd/coff-rs6000.c | 27 | ||||
-rw-r--r-- | bfd/cofflink.c | 12 | ||||
-rw-r--r-- | bfd/ecoff.c | 6 | ||||
-rw-r--r-- | bfd/elf32-xtensa.c | 7 | ||||
-rw-r--r-- | bfd/mmo.c | 11 | ||||
-rw-r--r-- | bfd/pei-x86_64.c | 52 | ||||
-rw-r--r-- | bfd/som.c | 5 | ||||
-rw-r--r-- | bfd/srec.c | 21 |
11 files changed, 54 insertions, 113 deletions
diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 9d0738a232..5ae7e48214 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -115,9 +115,6 @@ typedef uint64_t symvalue; #define BFD_VMA_FMT @BFD_INT64_FMT@ -#define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x) -#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x) - #else /* not BFD64 */ typedef unsigned long bfd_vma; @@ -127,9 +124,6 @@ typedef unsigned long bfd_size_type; #define BFD_VMA_FMT "l" -#define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x) -#define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x) - #endif /* not BFD64 */ #define HALF_BFD_SIZE_TYPE \ @@ -143,7 +137,6 @@ typedef @bfd_ufile_ptr@ ufile_ptr; extern void bfd_sprintf_vma (bfd *, char *, bfd_vma); extern void bfd_fprintf_vma (bfd *, void *, bfd_vma); -#define printf_vma(x) fprintf_vma(stdout,x) #define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x) typedef unsigned int flagword; /* 32 bits of flags */ diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index bbe1928852..91ada0e3a9 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -122,9 +122,6 @@ typedef uint64_t symvalue; #define BFD_VMA_FMT @BFD_INT64_FMT@ -#define fprintf_vma(f,x) fprintf (f, "%016" BFD_VMA_FMT "x", x) -#define sprintf_vma(s,x) sprintf (s, "%016" BFD_VMA_FMT "x", x) - #else /* not BFD64 */ typedef unsigned long bfd_vma; @@ -134,9 +131,6 @@ typedef unsigned long bfd_size_type; #define BFD_VMA_FMT "l" -#define fprintf_vma(s,x) fprintf (s, "%08" BFD_VMA_FMT "x", x) -#define sprintf_vma(s,x) sprintf (s, "%08" BFD_VMA_FMT "x", x) - #endif /* not BFD64 */ #define HALF_BFD_SIZE_TYPE \ @@ -150,7 +144,6 @@ typedef @bfd_ufile_ptr@ ufile_ptr; extern void bfd_sprintf_vma (bfd *, char *, bfd_vma); extern void bfd_fprintf_vma (bfd *, void *, bfd_vma); -#define printf_vma(x) fprintf_vma(stdout,x) #define bfd_printf_vma(abfd,x) bfd_fprintf_vma (abfd,stdout,x) typedef unsigned int flagword; /* 32 bits of flags */ @@ -2236,26 +2236,26 @@ void bfd_sprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, char *buf, bfd_vma value) { #ifdef BFD64 - if (is32bit (abfd)) + if (!is32bit (abfd)) { - sprintf (buf, "%08lx", (unsigned long) value & 0xffffffff); + sprintf (buf, "%016" PRIx64, (uint64_t) value); return; } #endif - sprintf_vma (buf, value); + sprintf (buf, "%08lx", (unsigned long) value & 0xffffffff); } void bfd_fprintf_vma (bfd *abfd ATTRIBUTE_UNUSED, void *stream, bfd_vma value) { #ifdef BFD64 - if (is32bit (abfd)) + if (!is32bit (abfd)) { - fprintf ((FILE *) stream, "%08lx", (unsigned long) value & 0xffffffff); + fprintf ((FILE *) stream, "%016" PRIx64, (uint64_t) value); return; } #endif - fprintf_vma ((FILE *) stream, value); + fprintf ((FILE *) stream, "%08lx", (unsigned long) value & 0xffffffff); } /* diff --git a/bfd/coff-rs6000.c b/bfd/coff-rs6000.c index 6ad77ba77c..3f0753e5bf 100644 --- a/bfd/coff-rs6000.c +++ b/bfd/coff-rs6000.c @@ -3280,12 +3280,9 @@ xcoff_reloc_type_tls (bfd *input_bfd ATTRIBUTE_UNUSED, /* TLS relocations must target a TLS symbol. */ if (h->smclas != XMC_TL && h->smclas != XMC_UL) { - char vaddr_buf[128]; - - sprintf_vma (vaddr_buf, rel->r_vaddr); _bfd_error_handler - (_("%pB: TLS relocation at 0x%s over non-TLS symbol %s (0x%x)\n"), - input_bfd, vaddr_buf, h->root.root.string, h->smclas); + (_("%pB: TLS relocation at 0x%" PRIx64 " over non-TLS symbol %s (0x%x)\n"), + input_bfd, (uint64_t) rel->r_vaddr, h->root.root.string, h->smclas); return false; } @@ -3296,12 +3293,9 @@ xcoff_reloc_type_tls (bfd *input_bfd ATTRIBUTE_UNUSED, && (h->flags & XCOFF_DEF_DYNAMIC) != 0) || (h->flags & XCOFF_IMPORT) != 0)) { - char vaddr_buf[128]; - - sprintf_vma (vaddr_buf, rel->r_vaddr); _bfd_error_handler - (_("%pB: TLS local relocation at 0x%s over imported symbol %s\n"), - input_bfd, vaddr_buf, h->root.root.string); + (_("%pB: TLS local relocation at 0x%" PRIx64 " over imported symbol %s\n"), + input_bfd, (uint64_t) rel->r_vaddr, h->root.root.string); return false; } @@ -3705,15 +3699,10 @@ xcoff_ppc_relocate_section (bfd *output_bfd, break; default: - { - char vaddr_buf[128]; - - sprintf_vma (vaddr_buf, rel->r_vaddr); - _bfd_error_handler - (_("%pB: relocation (%d) at 0x%s has wrong r_rsize (0x%x)\n"), - input_bfd, rel->r_type, vaddr_buf, rel->r_size); - return false; - } + _bfd_error_handler + (_("%pB: relocation (%d) at 0x%" PRIx64 " has wrong r_rsize (0x%x)\n"), + input_bfd, rel->r_type, (uint64_t) rel->r_vaddr, rel->r_size); + return false; } } diff --git a/bfd/cofflink.c b/bfd/cofflink.c index 92e780733f..a5b936fd7c 100644 --- a/bfd/cofflink.c +++ b/bfd/cofflink.c @@ -2562,14 +2562,10 @@ _bfd_coff_write_global_sym (struct bfd_hash_entry *bh, void *data) if (isym.n_value > (bfd_vma) 0xffffffff) { if (! h->root.linker_def) - { - char value_buf[128]; - - sprintf_vma (value_buf, isym.n_value); - _bfd_error_handler - (_("%pB: stripping non-representable symbol '%s' (value 0x%s)"), - output_bfd, h->root.root.string, value_buf); - } + _bfd_error_handler + (_("%pB: stripping non-representable symbol '%s' " + "(value 0x%" PRIx64 ")"), + output_bfd, h->root.root.string, isym.n_value); return true; } #endif diff --git a/bfd/ecoff.c b/bfd/ecoff.c index 511d88b533..a4edf7a2e6 100644 --- a/bfd/ecoff.c +++ b/bfd/ecoff.c @@ -1389,7 +1389,7 @@ _bfd_ecoff_print_symbol (bfd *abfd, (*debug_swap->swap_sym_in) (abfd, ecoffsymbol (symbol)->native, &ecoff_sym); fprintf (file, "ecoff local "); - fprintf_vma (file, (bfd_vma) ecoff_sym.value); + bfd_fprintf_vma (abfd, file, ecoff_sym.value); fprintf (file, " %x %x", (unsigned) ecoff_sym.st, (unsigned) ecoff_sym.sc); } @@ -1400,7 +1400,7 @@ _bfd_ecoff_print_symbol (bfd *abfd, (*debug_swap->swap_ext_in) (abfd, ecoffsymbol (symbol)->native, &ecoff_ext); fprintf (file, "ecoff extern "); - fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value); + bfd_fprintf_vma (abfd, file, ecoff_ext.asym.value); fprintf (file, " %x %x", (unsigned) ecoff_ext.asym.st, (unsigned) ecoff_ext.asym.sc); } @@ -1443,7 +1443,7 @@ _bfd_ecoff_print_symbol (bfd *abfd, fprintf (file, "[%3d] %c ", pos, type); - fprintf_vma (file, (bfd_vma) ecoff_ext.asym.value); + bfd_fprintf_vma (abfd, file, ecoff_ext.asym.value); fprintf (file, " st %x sc %x indx %x %c%c%c %s", (unsigned) ecoff_ext.asym.st, (unsigned) ecoff_ext.asym.sc, diff --git a/bfd/elf32-xtensa.c b/bfd/elf32-xtensa.c index ce3c46f69e..bf72c85ca4 100644 --- a/bfd/elf32-xtensa.c +++ b/bfd/elf32-xtensa.c @@ -5054,12 +5054,9 @@ print_r_reloc (FILE *fp, const r_reloc *r_rel) else fprintf (fp, " ?? + "); - fprintf_vma (fp, r_rel->target_offset); + fprintf (fp, "%" PRIx64, (uint64_t) r_rel->target_offset); if (r_rel->virtual_offset) - { - fprintf (fp, " + "); - fprintf_vma (fp, r_rel->virtual_offset); - } + fprintf (fp, " + %" PRIx64, (uint64_t) r_rel->virtual_offset); fprintf (fp, ")"); } @@ -3010,18 +3010,13 @@ mmo_write_symbols_and_terminator (bfd *abfd) { /* Arbitrary buffer to hold the printable representation of a vma. */ - char vmas_main[40]; - char vmas_start[40]; bfd_vma vma_start = bfd_get_start_address (abfd); - sprintf_vma (vmas_main, mainvalue); - sprintf_vma (vmas_start, vma_start); - _bfd_error_handler /* xgettext:c-format */ - (_("%pB: bad symbol definition: `Main' set to %s rather" - " than the start address %s\n"), - abfd, vmas_main, vmas_start); + (_("%pB: bad symbol definition: `Main' set to %" PRIx64 " rather" + " than the start address %" PRIx64 "\n"), + abfd, mainvalue, vma_start); bfd_set_error (bfd_error_bad_value); return false; } diff --git a/bfd/pei-x86_64.c b/bfd/pei-x86_64.c index 90ee530ea2..7d8fc8f072 100644 --- a/bfd/pei-x86_64.c +++ b/bfd/pei-x86_64.c @@ -498,19 +498,14 @@ pex64_dump_xdata (FILE *file, bfd *abfd, case UNW_FLAG_EHANDLER: case UNW_FLAG_UHANDLER: case UNW_FLAG_FHANDLER: - fprintf (file, "\tHandler: "); - fprintf_vma (file, (ui.rva_ExceptionHandler - + pe_data (abfd)->pe_opthdr.ImageBase)); - fprintf (file, ".\n"); + fprintf (file, "\tHandler: %016" PRIx64 ".\n", + ui.rva_ExceptionHandler + pe_data (abfd)->pe_opthdr.ImageBase); break; case UNW_FLAG_CHAININFO: - fprintf (file, "\tChain: start: "); - fprintf_vma (file, ui.rva_BeginAddress); - fprintf (file, ", end: "); - fprintf_vma (file, ui.rva_EndAddress); - fprintf (file, "\n\t unwind data: "); - fprintf_vma (file, ui.rva_UnwindData); - fprintf (file, ".\n"); + fprintf (file, "\tChain: start: %016" PRIx64 ", end: %016" PRIx64, + ui.rva_BeginAddress, ui.rva_EndAddress); + fprintf (file, "\n\t unwind data: %016" PRIx64 ".\n", + ui.rva_UnwindData); break; } @@ -640,15 +635,10 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section) && rf.rva_UnwindData == 0) /* We are probably into the padding of the section now. */ break; - fputc (' ', file); - fprintf_vma (file, i + pdata_section->vma); - fprintf (file, ":\t"); - fprintf_vma (file, imagebase + rf.rva_BeginAddress); - fprintf (file, " "); - fprintf_vma (file, imagebase + rf.rva_EndAddress); - fprintf (file, " "); - fprintf_vma (file, imagebase + rf.rva_UnwindData); - fprintf (file, "\n"); + fprintf (file, " %016" PRIx64, i + pdata_section->vma); + fprintf (file, ":\t%016" PRIx64, imagebase + rf.rva_BeginAddress); + fprintf (file, " %016" PRIx64, imagebase + rf.rva_EndAddress); + fprintf (file, " %016" PRIx64 "\n", imagebase + rf.rva_UnwindData); if (i != 0 && rf.rva_BeginAddress <= prev_beginaddress) { seen_error = 1; @@ -744,26 +734,22 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section) if (i == 0) fprintf (file, _("\nDump of %s\n"), xdata_section->name); - fputc (' ', file); - fprintf_vma (file, rf.rva_UnwindData + imagebase); + fprintf (file, " %016" PRIx64, rf.rva_UnwindData + imagebase); if (prev_unwinddata_rva == rf.rva_UnwindData) { /* Do not dump again the xdata for the same entry. */ - fprintf (file, " also used for function at "); - fprintf_vma (file, rf.rva_BeginAddress + imagebase); - fputc ('\n', file); + fprintf (file, " also used for function at %016" PRIx64 "\n", + rf.rva_BeginAddress + imagebase); continue; } else prev_unwinddata_rva = rf.rva_UnwindData; - fprintf (file, " (rva: %08x): ", - (unsigned int) rf.rva_UnwindData); - fprintf_vma (file, rf.rva_BeginAddress + imagebase); - fprintf (file, " - "); - fprintf_vma (file, rf.rva_EndAddress + imagebase); - fputc ('\n', file); + fprintf (file, " (rva: %08x): %016" PRIx64 " - %016" PRIx64 "\n", + (unsigned int) rf.rva_UnwindData, + rf.rva_BeginAddress + imagebase, + rf.rva_EndAddress + imagebase); if (rf.rva_UnwindData != 0 || virt_size_is_zero) { @@ -781,8 +767,8 @@ pex64_bfd_print_pdata_section (bfd *abfd, void *vfile, asection *pdata_section) { pex64_get_runtime_function (abfd, &arf, &pdata[altent - pdata_vma]); - fprintf (file, "pdata element at 0x"); - fprintf_vma (file, arf.rva_UnwindData); + fprintf (file, "pdata element at 0x%016" PRIx64, + arf.rva_UnwindData); } else fprintf (file, "unknown pdata element"); @@ -4897,9 +4897,8 @@ som_print_symbol (bfd *abfd, fprintf (file, "%s", symbol->name); break; case bfd_print_symbol_more: - fprintf (file, "som "); - fprintf_vma (file, symbol->value); - fprintf (file, " %lx", (long) symbol->flags); + fprintf (file, "som %08" PRIx64 " %x", + (uint64_t) symbol->value, symbol->flags); break; case bfd_print_symbol_all: { diff --git a/bfd/srec.c b/bfd/srec.c index 5f8c8c1808..abe36bbdbd 100644 --- a/bfd/srec.c +++ b/bfd/srec.c @@ -1096,26 +1096,19 @@ srec_write_symbols (bfd *abfd) && s->section->output_section != NULL) { /* Just dump out non debug symbols. */ - char buf[43], *p; + char buf[43]; len = strlen (s->name); if (bfd_bwrite (" ", (bfd_size_type) 2, abfd) != 2 || bfd_bwrite (s->name, len, abfd) != len) return false; - sprintf_vma (buf + 2, (s->value - + s->section->output_section->lma - + s->section->output_offset)); - p = buf + 2; - while (p[0] == '0' && p[1] != 0) - p++; - len = strlen (p); - p[len] = '\r'; - p[len + 1] = '\n'; - *--p = '$'; - *--p = ' '; - len += 4; - if (bfd_bwrite (p, len, abfd) != len) + sprintf (buf, " $%" PRIx64 "\r\n", + (uint64_t) (s->value + + s->section->output_section->lma + + s->section->output_offset)); + len = strlen (buf); + if (bfd_bwrite (buf, len, abfd) != len) return false; } } |