mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-03 05:12:28 +08:00
Re: Get rid of fprintf_vma and sprintf_vma
Commit f493c2174e messed the formatting in linker map files, particularly for 32-bit builds where a number of tests using map files regressed. I should have noticed the BFD64 conditional printing of spaces to line up output due to the original %V printing hex vmas with 16 digits when BFD64 and 8 digits when not. Besides that, it is nicer to print 32-bit vmas for 32-bit targets. So change %V back to be target dependent, now using bfd_sprintf_vma. Since minfo doesn't return the number of chars printed, that means some places that currently use %V must instead sprintf to a buffer in order to find the length printed. * ldmisc.h (print_spaces): Declare. (print_space): Change to a macro. * ldmisc.c (vfinfo): Use bfd_sprintf_vma for %V. Tidy %W case. (print_space): Delete. (print_spaces): New function. * emultempl/aix.em (print_symbol): Use print_spaces. * ldctor.c (ldctor_build_sets): Likewise. * ldmain.c (add_archive_element): Likewise. * ldlang.c (print_one_symbol, lang_print_asneeded): Likewise. (print_output_section_statement, print_data_statement): Likewise. (print_reloc_statement, print_padding_statement): Likewise. (print_assignment): Likewise. Also replace %V printing of vmas with printing to a buffer in order to properly format output. (print_input_section, lang_one_common): Likewise.
This commit is contained in:
@ -1772,11 +1772,9 @@ gld${EMULATION_NAME}_print_symbol (struct bfd_link_hash_entry *hash_entry,
|
|||||||
|| hash_entry->type == bfd_link_hash_defweak)
|
|| hash_entry->type == bfd_link_hash_defweak)
|
||||||
&& sec == hash_entry->u.def.section)
|
&& sec == hash_entry->u.def.section)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
struct xcoff_link_hash_entry *h;
|
struct xcoff_link_hash_entry *h;
|
||||||
|
|
||||||
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
|
print_spaces (SECTION_NAME_MAP_LENGTH);
|
||||||
print_space ();
|
|
||||||
minfo ("0x%V ",
|
minfo ("0x%V ",
|
||||||
(hash_entry->u.def.value
|
(hash_entry->u.def.value
|
||||||
+ hash_entry->u.def.section->output_offset
|
+ hash_entry->u.def.section->output_offset
|
||||||
|
@ -352,11 +352,7 @@ ldctor_build_sets (void)
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < 20)
|
print_spaces (20 - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (e->name != NULL)
|
if (e->name != NULL)
|
||||||
minfo ("%pT\n", e->name);
|
minfo ("%pT\n", e->name);
|
||||||
|
124
ld/ldlang.c
124
ld/ldlang.c
@ -2221,7 +2221,7 @@ lang_print_asneeded (void)
|
|||||||
|
|
||||||
for (m = asneeded_list_head; m != NULL; m = m->next)
|
for (m = asneeded_list_head; m != NULL; m = m->next)
|
||||||
{
|
{
|
||||||
size_t len;
|
int len;
|
||||||
|
|
||||||
minfo ("%s", m->soname);
|
minfo ("%s", m->soname);
|
||||||
len = strlen (m->soname);
|
len = strlen (m->soname);
|
||||||
@ -2231,11 +2231,7 @@ lang_print_asneeded (void)
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < 30)
|
print_spaces (30 - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (m->ref != NULL)
|
if (m->ref != NULL)
|
||||||
minfo ("%pB ", m->ref);
|
minfo ("%pB ", m->ref);
|
||||||
@ -2298,26 +2294,22 @@ lang_map (void)
|
|||||||
|
|
||||||
for (m = lang_memory_region_list; m != NULL; m = m->next)
|
for (m = lang_memory_region_list; m != NULL; m = m->next)
|
||||||
{
|
{
|
||||||
fprintf (config.map_file, "%-16s ", m->name_list.name);
|
fprintf (config.map_file, "%-16s", m->name_list.name);
|
||||||
|
|
||||||
minfo ("0x%V 0x%V", m->origin, m->length);
|
char buf[32];
|
||||||
if (m->flags || m->not_flags)
|
bfd_sprintf_vma (link_info.output_bfd, buf, m->origin);
|
||||||
{
|
fprintf (config.map_file, " 0x%-16s", buf);
|
||||||
#ifndef BFD64
|
bfd_sprintf_vma (link_info.output_bfd, buf, m->length);
|
||||||
minfo (" ");
|
fprintf (config.map_file,
|
||||||
#endif
|
" 0x%*s", m->flags || m->not_flags ? -17 : 0, buf);
|
||||||
if (m->flags)
|
if (m->flags)
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
lang_map_flags (m->flags);
|
lang_map_flags (m->flags);
|
||||||
}
|
|
||||||
|
|
||||||
if (m->not_flags)
|
if (m->not_flags)
|
||||||
{
|
{
|
||||||
minfo (" !");
|
minfo ("!");
|
||||||
lang_map_flags (m->not_flags);
|
lang_map_flags (m->not_flags);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
print_nl ();
|
print_nl ();
|
||||||
}
|
}
|
||||||
@ -4668,11 +4660,7 @@ print_output_section_statement
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < SECTION_NAME_MAP_LENGTH)
|
print_spaces (SECTION_NAME_MAP_LENGTH - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
minfo ("0x%V %W", section->vma, TO_ADDR (section->size));
|
minfo ("0x%V %W", section->vma, TO_ADDR (section->size));
|
||||||
|
|
||||||
@ -4695,13 +4683,11 @@ static void
|
|||||||
print_assignment (lang_assignment_statement_type *assignment,
|
print_assignment (lang_assignment_statement_type *assignment,
|
||||||
lang_output_section_statement_type *output_section)
|
lang_output_section_statement_type *output_section)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
|
||||||
bool is_dot;
|
bool is_dot;
|
||||||
etree_type *tree;
|
etree_type *tree;
|
||||||
asection *osec;
|
asection *osec;
|
||||||
|
|
||||||
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
|
print_spaces (SECTION_NAME_MAP_LENGTH);
|
||||||
print_space ();
|
|
||||||
|
|
||||||
if (assignment->exp->type.node_class == etree_assert)
|
if (assignment->exp->type.node_class == etree_assert)
|
||||||
{
|
{
|
||||||
@ -4725,6 +4711,8 @@ print_assignment (lang_assignment_statement_type *assignment,
|
|||||||
else
|
else
|
||||||
expld.result.valid_p = false;
|
expld.result.valid_p = false;
|
||||||
|
|
||||||
|
char buf[32];
|
||||||
|
const char *str = buf;
|
||||||
if (expld.result.valid_p)
|
if (expld.result.valid_p)
|
||||||
{
|
{
|
||||||
bfd_vma value;
|
bfd_vma value;
|
||||||
@ -4738,7 +4726,9 @@ print_assignment (lang_assignment_statement_type *assignment,
|
|||||||
if (expld.result.section != NULL)
|
if (expld.result.section != NULL)
|
||||||
value += expld.result.section->vma;
|
value += expld.result.section->vma;
|
||||||
|
|
||||||
minfo ("0x%V", value);
|
buf[0] = '0';
|
||||||
|
buf[1] = 'x';
|
||||||
|
bfd_sprintf_vma (link_info.output_bfd, buf + 2, value);
|
||||||
if (is_dot)
|
if (is_dot)
|
||||||
print_dot = value;
|
print_dot = value;
|
||||||
}
|
}
|
||||||
@ -4756,25 +4746,26 @@ print_assignment (lang_assignment_statement_type *assignment,
|
|||||||
value += h->u.def.section->output_section->vma;
|
value += h->u.def.section->output_section->vma;
|
||||||
value += h->u.def.section->output_offset;
|
value += h->u.def.section->output_offset;
|
||||||
|
|
||||||
minfo ("[0x%V]", value);
|
buf[0] = '[';
|
||||||
|
buf[1] = '0';
|
||||||
|
buf[2] = 'x';
|
||||||
|
bfd_sprintf_vma (link_info.output_bfd, buf + 3, value);
|
||||||
|
strcat (buf, "]");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
minfo ("[unresolved]");
|
str = "[unresolved]";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (assignment->exp->type.node_class == etree_provide)
|
if (assignment->exp->type.node_class == etree_provide)
|
||||||
minfo ("[!provide]");
|
str = "[!provide]";
|
||||||
else
|
else
|
||||||
minfo ("*undef* ");
|
str = "*undef*";
|
||||||
#ifdef BFD64
|
|
||||||
minfo (" ");
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
expld.assign_name = NULL;
|
expld.assign_name = NULL;
|
||||||
|
|
||||||
minfo (" ");
|
fprintf (config.map_file, "%-34s", str);
|
||||||
exp_print_tree (assignment->exp);
|
exp_print_tree (assignment->exp);
|
||||||
print_nl ();
|
print_nl ();
|
||||||
}
|
}
|
||||||
@ -4798,10 +4789,7 @@ print_one_symbol (struct bfd_link_hash_entry *hash_entry, void *ptr)
|
|||||||
|| hash_entry->type == bfd_link_hash_defweak)
|
|| hash_entry->type == bfd_link_hash_defweak)
|
||||||
&& sec == hash_entry->u.def.section)
|
&& sec == hash_entry->u.def.section)
|
||||||
{
|
{
|
||||||
int i;
|
print_spaces (SECTION_NAME_MAP_LENGTH);
|
||||||
|
|
||||||
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
|
|
||||||
print_space ();
|
|
||||||
minfo ("0x%V ",
|
minfo ("0x%V ",
|
||||||
(hash_entry->u.def.value
|
(hash_entry->u.def.value
|
||||||
+ hash_entry->u.def.section->output_offset
|
+ hash_entry->u.def.section->output_offset
|
||||||
@ -4869,8 +4857,7 @@ print_input_section (asection *i, bool is_discarded)
|
|||||||
|
|
||||||
init_opb (i);
|
init_opb (i);
|
||||||
|
|
||||||
print_space ();
|
minfo (" %s", i->name);
|
||||||
minfo ("%s", i->name);
|
|
||||||
|
|
||||||
len = 1 + strlen (i->name);
|
len = 1 + strlen (i->name);
|
||||||
if (len >= SECTION_NAME_MAP_LENGTH - 1)
|
if (len >= SECTION_NAME_MAP_LENGTH - 1)
|
||||||
@ -4878,11 +4865,7 @@ print_input_section (asection *i, bool is_discarded)
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < SECTION_NAME_MAP_LENGTH)
|
print_spaces (SECTION_NAME_MAP_LENGTH - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i->output_section != NULL
|
if (i->output_section != NULL
|
||||||
&& i->output_section->owner == link_info.output_bfd)
|
&& i->output_section->owner == link_info.output_bfd)
|
||||||
@ -4894,22 +4877,14 @@ print_input_section (asection *i, bool is_discarded)
|
|||||||
size = 0;
|
size = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
minfo ("0x%V %W %pB\n", addr, TO_ADDR (size), i->owner);
|
char buf[32];
|
||||||
|
bfd_sprintf_vma (link_info.output_bfd, buf, addr);
|
||||||
|
minfo ("0x%s %W %pB\n", buf, TO_ADDR (size), i->owner);
|
||||||
|
|
||||||
if (size != i->rawsize && i->rawsize != 0)
|
if (size != i->rawsize && i->rawsize != 0)
|
||||||
{
|
{
|
||||||
len = SECTION_NAME_MAP_LENGTH + 3;
|
len = SECTION_NAME_MAP_LENGTH + 3 + strlen (buf);
|
||||||
#ifdef BFD64
|
print_spaces (len);
|
||||||
len += 16;
|
|
||||||
#else
|
|
||||||
len += 8;
|
|
||||||
#endif
|
|
||||||
while (len > 0)
|
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
--len;
|
|
||||||
}
|
|
||||||
|
|
||||||
minfo (_("%W (size before relaxing)\n"), TO_ADDR (i->rawsize));
|
minfo (_("%W (size before relaxing)\n"), TO_ADDR (i->rawsize));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4943,14 +4918,12 @@ print_fill_statement (lang_fill_statement_type *fill)
|
|||||||
static void
|
static void
|
||||||
print_data_statement (lang_data_statement_type *data)
|
print_data_statement (lang_data_statement_type *data)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
bfd_vma addr;
|
bfd_vma addr;
|
||||||
bfd_size_type size;
|
bfd_size_type size;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
init_opb (data->output_section);
|
init_opb (data->output_section);
|
||||||
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
|
print_spaces (SECTION_NAME_MAP_LENGTH);
|
||||||
print_space ();
|
|
||||||
|
|
||||||
addr = data->output_offset;
|
addr = data->output_offset;
|
||||||
if (data->output_section != NULL)
|
if (data->output_section != NULL)
|
||||||
@ -5013,13 +4986,11 @@ print_address_statement (lang_address_statement_type *address)
|
|||||||
static void
|
static void
|
||||||
print_reloc_statement (lang_reloc_statement_type *reloc)
|
print_reloc_statement (lang_reloc_statement_type *reloc)
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
bfd_vma addr;
|
bfd_vma addr;
|
||||||
bfd_size_type size;
|
bfd_size_type size;
|
||||||
|
|
||||||
init_opb (reloc->output_section);
|
init_opb (reloc->output_section);
|
||||||
for (i = 0; i < SECTION_NAME_MAP_LENGTH; i++)
|
print_spaces (SECTION_NAME_MAP_LENGTH);
|
||||||
print_space ();
|
|
||||||
|
|
||||||
addr = reloc->output_offset;
|
addr = reloc->output_offset;
|
||||||
if (reloc->output_section != NULL)
|
if (reloc->output_section != NULL)
|
||||||
@ -5051,11 +5022,7 @@ print_padding_statement (lang_padding_statement_type *s)
|
|||||||
minfo (" *fill*");
|
minfo (" *fill*");
|
||||||
|
|
||||||
len = sizeof " *fill*" - 1;
|
len = sizeof " *fill*" - 1;
|
||||||
while (len < SECTION_NAME_MAP_LENGTH)
|
print_spaces (SECTION_NAME_MAP_LENGTH - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
addr = s->output_offset;
|
addr = s->output_offset;
|
||||||
if (s->output_section != NULL)
|
if (s->output_section != NULL)
|
||||||
@ -7271,7 +7238,7 @@ lang_one_common (struct bfd_link_hash_entry *h, void *info)
|
|||||||
static bool header_printed;
|
static bool header_printed;
|
||||||
int len;
|
int len;
|
||||||
char *name;
|
char *name;
|
||||||
char buf[50];
|
char buf[32];
|
||||||
|
|
||||||
if (!header_printed)
|
if (!header_printed)
|
||||||
{
|
{
|
||||||
@ -7299,22 +7266,9 @@ lang_one_common (struct bfd_link_hash_entry *h, void *info)
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < 20)
|
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
minfo ("0x");
|
|
||||||
sprintf (buf, "%" PRIx64, (uint64_t) size);
|
sprintf (buf, "%" PRIx64, (uint64_t) size);
|
||||||
minfo ("%s", buf);
|
fprintf (config.map_file, "%*s0x%-16s", 20 - len, "", buf);
|
||||||
len = strlen (buf);
|
|
||||||
|
|
||||||
while (len < 16)
|
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
minfo ("%pB\n", section->owner);
|
minfo ("%pB\n", section->owner);
|
||||||
}
|
}
|
||||||
|
@ -990,11 +990,7 @@ add_archive_element (struct bfd_link_info *info,
|
|||||||
print_nl ();
|
print_nl ();
|
||||||
len = 0;
|
len = 0;
|
||||||
}
|
}
|
||||||
while (len < 30)
|
print_spaces (30 - len);
|
||||||
{
|
|
||||||
print_space ();
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (from != NULL)
|
if (from != NULL)
|
||||||
minfo ("%pB ", from);
|
minfo ("%pB ", from);
|
||||||
|
29
ld/ldmisc.c
29
ld/ldmisc.c
@ -47,7 +47,7 @@
|
|||||||
%H like %C but in addition emit section+offset
|
%H like %C but in addition emit section+offset
|
||||||
%P print program name
|
%P print program name
|
||||||
%V hex bfd_vma
|
%V hex bfd_vma
|
||||||
%W hex bfd_vma with 0x with no leading zeros taking up 8 spaces
|
%W hex bfd_vma with 0x with no leading zeros taking up 10 spaces
|
||||||
%X no object output, fail return
|
%X no object output, fail return
|
||||||
%d integer, like printf
|
%d integer, like printf
|
||||||
%ld long, like printf
|
%ld long, like printf
|
||||||
@ -241,9 +241,13 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
|
|||||||
case 'V':
|
case 'V':
|
||||||
/* hex bfd_vma */
|
/* hex bfd_vma */
|
||||||
{
|
{
|
||||||
uint64_t value = args[arg_no].v;
|
char buf[32];
|
||||||
|
bfd_vma value;
|
||||||
|
|
||||||
|
value = args[arg_no].v;
|
||||||
++arg_count;
|
++arg_count;
|
||||||
fprintf (fp, "%016" PRIx64, value);
|
bfd_sprintf_vma (link_info.output_bfd, buf, value);
|
||||||
|
fprintf (fp, "%s", buf);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -258,22 +262,15 @@ vfinfo (FILE *fp, const char *fmt, va_list ap, bool is_warning)
|
|||||||
|
|
||||||
case 'W':
|
case 'W':
|
||||||
/* hex bfd_vma with 0x with no leading zeroes taking up
|
/* hex bfd_vma with 0x with no leading zeroes taking up
|
||||||
8 spaces. */
|
10 spaces (including the 0x). */
|
||||||
{
|
{
|
||||||
char buf[100];
|
char buf[32];
|
||||||
uint64_t value;
|
uint64_t value;
|
||||||
int len;
|
|
||||||
|
|
||||||
value = args[arg_no].v;
|
value = args[arg_no].v;
|
||||||
++arg_count;
|
++arg_count;
|
||||||
sprintf (buf, "%" PRIx64, value);
|
sprintf (buf, "0x%" PRIx64, value);
|
||||||
len = strlen (buf);
|
fprintf (fp, "%10s", buf);
|
||||||
while (len < 8)
|
|
||||||
{
|
|
||||||
putc (' ', fp);
|
|
||||||
++len;
|
|
||||||
}
|
|
||||||
fprintf (fp, "0x%s", buf);
|
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -653,9 +650,9 @@ lfinfo (FILE *file, const char *fmt, ...)
|
|||||||
/* Functions to print the link map. */
|
/* Functions to print the link map. */
|
||||||
|
|
||||||
void
|
void
|
||||||
print_space (void)
|
print_spaces (int count)
|
||||||
{
|
{
|
||||||
fprintf (config.map_file, " ");
|
fprintf (config.map_file, "%*s", count, "");
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -38,7 +38,8 @@ do { if (!(x)) info_assert(__FILE__,__LINE__); } while (0)
|
|||||||
#define FAIL() \
|
#define FAIL() \
|
||||||
do { info_assert(__FILE__,__LINE__); } while (0)
|
do { info_assert(__FILE__,__LINE__); } while (0)
|
||||||
|
|
||||||
extern void print_space (void);
|
extern void print_spaces (int);
|
||||||
|
#define print_space() print_spaces (1)
|
||||||
extern void print_nl (void);
|
extern void print_nl (void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Reference in New Issue
Block a user