summaryrefslogtreecommitdiff
path: root/opcodes
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 /opcodes
parent48ca1b26b99c8fd5bc21f5c69b6b666d9b6b9726 (diff)
downloadbinutils-gdb-f493c2174ef99a43c0a5d89179122f857955d738.tar.gz
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 'opcodes')
-rw-r--r--opcodes/dis-buf.c11
-rw-r--r--opcodes/i386-dis.c21
-rw-r--r--opcodes/ia64-gen.c20
-rw-r--r--opcodes/m68k-dis.c10
-rw-r--r--opcodes/ns32k-dis.c5
5 files changed, 17 insertions, 50 deletions
diff --git a/opcodes/dis-buf.c b/opcodes/dis-buf.c
index 3bd078f54dc..56a57f9639f 100644
--- a/opcodes/dis-buf.c
+++ b/opcodes/dis-buf.c
@@ -61,13 +61,11 @@ perror_memory (int status,
info->fprintf_func (info->stream, _("Unknown error %d\n"), status);
else
{
- char buf[30];
-
/* Actually, address between memaddr and memaddr + len was
out of bounds. */
- sprintf_vma (buf, memaddr);
info->fprintf_func (info->stream,
- _("Address 0x%s is out of bounds.\n"), buf);
+ _("Address 0x%" PRIx64 " is out of bounds.\n"),
+ (uint64_t) memaddr);
}
}
@@ -81,10 +79,7 @@ perror_memory (int status,
void
generic_print_address (bfd_vma addr, struct disassemble_info *info)
{
- char buf[30];
-
- sprintf_vma (buf, addr);
- (*info->fprintf_func) (info->stream, "0x%s", buf);
+ (*info->fprintf_func) (info->stream, "0x%08" PRIx64, (uint64_t) addr);
}
/* Just return NULL. */
diff --git a/opcodes/i386-dis.c b/opcodes/i386-dis.c
index de9793690a5..1761df583da 100644
--- a/opcodes/i386-dis.c
+++ b/opcodes/i386-dis.c
@@ -10973,18 +10973,12 @@ print_operand_value (instr_info *ins, bfd_vma disp,
enum disassembler_style style)
{
char tmp[30];
- unsigned int i = 0;
if (ins->address_mode == mode_64bit)
- {
- oappend_with_style (ins, "0x", style);
- sprintf_vma (tmp, disp);
- while (tmp[i] == '0' && tmp[i + 1])
- ++i;
- }
+ sprintf (tmp, "0x%" PRIx64, (uint64_t) disp);
else
sprintf (tmp, "0x%x", (unsigned int) disp);
- oappend_with_style (ins, tmp + i, style);
+ oappend_with_style (ins, tmp, style);
}
/* Like oappend, but called for immediate operands. */
@@ -11004,7 +10998,6 @@ print_displacement (instr_info *ins, bfd_vma disp)
{
bfd_signed_vma val = disp;
char tmp[30];
- unsigned int i;
if (val < 0)
{
@@ -11033,14 +11026,8 @@ print_displacement (instr_info *ins, bfd_vma disp)
}
}
- oappend_with_style (ins, "0x", dis_style_address_offset);
-
- sprintf_vma (tmp, (bfd_vma) val);
- for (i = 0; tmp[i] == '0'; i++)
- continue;
- if (tmp[i] == '\0')
- i--;
- oappend_with_style (ins, tmp + i, dis_style_address_offset);
+ sprintf (tmp, "0x%" PRIx64, (int64_t) val);
+ oappend_with_style (ins, tmp, dis_style_address_offset);
}
static void
diff --git a/opcodes/ia64-gen.c b/opcodes/ia64-gen.c
index a996bcd1c21..9acb078264b 100644
--- a/opcodes/ia64-gen.c
+++ b/opcodes/ia64-gen.c
@@ -53,15 +53,6 @@
#include <libintl.h>
#define _(String) gettext (String)
-/* This is a copy of fprintf_vma from bfd/bfd-in2.h. We have to use this
- always, because we might be compiled without BFD64 defined, if configured
- for a 32-bit target and --enable-targets=all is used. This will work for
- both 32-bit and 64-bit hosts. */
-#define _opcode_int64_low(x) ((unsigned long) (((x) & 0xffffffff)))
-#define _opcode_int64_high(x) ((unsigned long) (((x) >> 32) & 0xffffffff))
-#define opcode_fprintf_vma(s,x) \
- fprintf ((s), "%08lx%08lx", _opcode_int64_high (x), _opcode_int64_low (x))
-
const char * program_name = NULL;
int debug = 0;
@@ -2711,14 +2702,13 @@ print_main_table (void)
printf ("static const struct ia64_main_table\nmain_table[] = {\n");
while (ptr != NULL)
{
- printf (" { %d, %d, %d, 0x",
+ printf (" { %d, %d, %d, 0x%016" PRIx64 "ull, 0x%016" PRIx64
+ "ull, { %d, %d, %d, %d, %d }, 0x%x, %d, },\n",
ptr->name->num,
ptr->opcode->type,
- ptr->opcode->num_outputs);
- opcode_fprintf_vma (stdout, ptr->opcode->opcode);
- printf ("ull, 0x");
- opcode_fprintf_vma (stdout, ptr->opcode->mask);
- printf ("ull, { %d, %d, %d, %d, %d }, 0x%x, %d, },\n",
+ ptr->opcode->num_outputs,
+ ptr->opcode->opcode,
+ ptr->opcode->mask,
ptr->opcode->operands[0],
ptr->opcode->operands[1],
ptr->opcode->operands[2],
diff --git a/opcodes/m68k-dis.c b/opcodes/m68k-dis.c
index 963e1bf94a2..55038d4207a 100644
--- a/opcodes/m68k-dis.c
+++ b/opcodes/m68k-dis.c
@@ -515,17 +515,13 @@ print_base (int regno, bfd_vma disp, disassemble_info *info)
}
else
{
- char buf[50];
-
if (regno == -2)
(*info->fprintf_func) (info->stream, "@(");
else if (regno == -3)
(*info->fprintf_func) (info->stream, "%%zpc@(");
else
(*info->fprintf_func) (info->stream, "%s@(", reg_names[regno]);
-
- sprintf_vma (buf, disp);
- (*info->fprintf_func) (info->stream, "%s", buf);
+ (*info->fprintf_func) (info->stream, "%" PRIx64, (uint64_t) disp);
}
}
@@ -545,7 +541,6 @@ print_indexed (int basereg,
bfd_vma base_disp;
bfd_vma outer_disp;
char buf[40];
- char vmabuf[50];
NEXTWORD (p, word, NULL);
@@ -620,8 +615,7 @@ print_indexed (int basereg,
(*info->fprintf_func) (info->stream, ",%s", buf);
buf[0] = '\0';
}
- sprintf_vma (vmabuf, outer_disp);
- (*info->fprintf_func) (info->stream, ")@(%s", vmabuf);
+ (*info->fprintf_func) (info->stream, ")@(%" PRIx64, (uint64_t) outer_disp);
if (buf[0] != '\0')
(*info->fprintf_func) (info->stream, ",%s", buf);
(*info->fprintf_func) (info->stream, ")");
diff --git a/opcodes/ns32k-dis.c b/opcodes/ns32k-dis.c
index a8509abb5cd..46e467da849 100644
--- a/opcodes/ns32k-dis.c
+++ b/opcodes/ns32k-dis.c
@@ -606,7 +606,7 @@ print_insn_arg (int d,
/* Memory space disp(PC). */
disp1 = get_displacement (buffer, aoffsetp);
*result++ = NEXT_IS_ADDR;
- sprintf_vma (result, addr + disp1);
+ sprintf (result, "%" PRIx64, (uint64_t) (addr + disp1));
result += strlen (result);
*result++ = NEXT_IS_ADDR;
*result = '\0';
@@ -665,7 +665,8 @@ print_insn_arg (int d,
break;
case 'p':
*result++ = NEXT_IS_ADDR;
- sprintf_vma (result, addr + get_displacement (buffer, aoffsetp));
+ sprintf (result, "%" PRIx64,
+ (uint64_t) (addr + get_displacement (buffer, aoffsetp)));
result += strlen (result);
*result++ = NEXT_IS_ADDR;
*result = '\0';