mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-20 01:50:24 +08:00
Support %Lx, %Lu, %Ld in _bfd_error_handler format
One way to print 64-bit bfd_vma or bfd_size_type values on 32-bit hosts is to cast the value to long long and use the 'll' modifier in printf format strings. However, that's awkward because we also support the Microsoft C library printf that uses 'I64' as a modifier instead, and having variants of translated strings would not endear us to the translation project. So, rewrite the 'll' modifier in _doprint for Microsoft. Even with that capability it's not so nice for 32-bit code to need casts to long long, so this patch makes 'L' a modifier for bfd_vma rather than an alias for 'll'. I've then used the new 'L' modifier to fix selected format strings. * bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for __MSVCRT__. Support "L" modifier for bfd_vma. Formatting. * elf.c (setup_group): Use "Lx" to print sh_size. (_bfd_elf_setup_sections): Remove unnecessary cast and print unknown section type in hex. (copy_special_section_fields): Style fix. (bfd_section_from_shdr): Correct format for sh_link. Use a common error message for all the variants of unrecognized section types. (assign_file_positions_for_load_sections): Use "Lx" for lma adjust error message. (assign_file_positions_for_non_load_sections): Formatting. (rewrite_elf_program_header): Formatting. Use "Lx" for bfd_vma values in error messages. * elfcode.h (elf_slurp_reloc_table_from_section): Cast ELF_R_SYM value to type expected by format. * elflink.c (elf_link_read_relocs_from_section): Use "Lx" in error messages. (elf_link_add_object_symbols): Use "Lu" for symbol sizes. (elf_link_input_bfd): Use "Lx" for r_info. (bfd_elf_gc_record_vtinherit): Use "Lx" for offset.
This commit is contained in:
@ -1,3 +1,27 @@
|
|||||||
|
2017-07-03 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
|
* bfd.c (_doprnt): Rewrite "ll" and "L" modifiers to "I64" for
|
||||||
|
__MSVCRT__. Support "L" modifier for bfd_vma. Formatting.
|
||||||
|
* elf.c (setup_group): Use "Lx" to print sh_size.
|
||||||
|
(_bfd_elf_setup_sections): Remove unnecessary cast and print
|
||||||
|
unknown section type in hex.
|
||||||
|
(copy_special_section_fields): Style fix.
|
||||||
|
(bfd_section_from_shdr): Correct format for sh_link. Use a
|
||||||
|
common error message for all the variants of unrecognized
|
||||||
|
section types.
|
||||||
|
(assign_file_positions_for_load_sections): Use "Lx" for lma
|
||||||
|
adjust error message.
|
||||||
|
(assign_file_positions_for_non_load_sections): Formatting.
|
||||||
|
(rewrite_elf_program_header): Formatting. Use "Lx" for
|
||||||
|
bfd_vma values in error messages.
|
||||||
|
* elfcode.h (elf_slurp_reloc_table_from_section): Cast
|
||||||
|
ELF_R_SYM value to type expected by format.
|
||||||
|
* elflink.c (elf_link_read_relocs_from_section): Use "Lx"
|
||||||
|
in error messages.
|
||||||
|
(elf_link_add_object_symbols): Use "Lu" for symbol sizes.
|
||||||
|
(elf_link_input_bfd): Use "Lx" for r_info.
|
||||||
|
(bfd_elf_gc_record_vtinherit): Use "Lx" for offset.
|
||||||
|
|
||||||
2017-07-03 Alan Modra <amodra@gmail.com>
|
2017-07-03 Alan Modra <amodra@gmail.com>
|
||||||
|
|
||||||
* bfd.c (bfd_scan_vma): Don't use long long unless HAVE_LONG_LONG.
|
* bfd.c (bfd_scan_vma): Don't use long long unless HAVE_LONG_LONG.
|
||||||
|
24
bfd/bfd.c
24
bfd/bfd.c
@ -612,7 +612,9 @@ CODE_FRAGMENT
|
|||||||
static const char *_bfd_error_program_name;
|
static const char *_bfd_error_program_name;
|
||||||
|
|
||||||
/* This macro and _doprnt taken from libiberty _doprnt.c, tidied a
|
/* This macro and _doprnt taken from libiberty _doprnt.c, tidied a
|
||||||
little and extended to handle '%A' and '%B'. */
|
little and extended to handle '%A' and '%B'. 'L' as a modifer for
|
||||||
|
integer formats is used for bfd_vma and bfd_size_type args, which
|
||||||
|
vary in size depending on BFD configuration. */
|
||||||
|
|
||||||
#define PRINT_TYPE(TYPE) \
|
#define PRINT_TYPE(TYPE) \
|
||||||
do \
|
do \
|
||||||
@ -721,6 +723,12 @@ _doprnt (FILE *stream, const char *format, va_list ap)
|
|||||||
PRINT_TYPE (int);
|
PRINT_TYPE (int);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
/* L modifier for bfd_vma or bfd_size_type may be
|
||||||
|
either long long or long. */
|
||||||
|
if ((BFD_ARCH_SIZE < 64 || BFD_HOST_64BIT_LONG)
|
||||||
|
&& sptr[-2] == 'L')
|
||||||
|
wide_width = 1;
|
||||||
|
|
||||||
switch (wide_width)
|
switch (wide_width)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
@ -731,7 +739,17 @@ _doprnt (FILE *stream, const char *format, va_list ap)
|
|||||||
break;
|
break;
|
||||||
case 2:
|
case 2:
|
||||||
default:
|
default:
|
||||||
#if defined(__GNUC__) || defined(HAVE_LONG_LONG)
|
#if defined (__GNUC__) || defined (HAVE_LONG_LONG)
|
||||||
|
# if defined (__MSVCRT__)
|
||||||
|
sptr--;
|
||||||
|
while (sptr[-1] == 'L' || sptr[-1] == 'l')
|
||||||
|
sptr--;
|
||||||
|
*sptr++ = 'I';
|
||||||
|
*sptr++ = '6';
|
||||||
|
*sptr++ = '4';
|
||||||
|
*sptr++ = ptr[-1];
|
||||||
|
*sptr = '\0';
|
||||||
|
# endif
|
||||||
PRINT_TYPE (long long);
|
PRINT_TYPE (long long);
|
||||||
#else
|
#else
|
||||||
/* Fake it and hope for the best. */
|
/* Fake it and hope for the best. */
|
||||||
@ -752,7 +770,7 @@ _doprnt (FILE *stream, const char *format, va_list ap)
|
|||||||
PRINT_TYPE (double);
|
PRINT_TYPE (double);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
#if defined(__GNUC__) || defined(HAVE_LONG_DOUBLE)
|
#if defined (__GNUC__) || defined (HAVE_LONG_DOUBLE)
|
||||||
PRINT_TYPE (long double);
|
PRINT_TYPE (long double);
|
||||||
#else
|
#else
|
||||||
/* Fake it and hope for the best. */
|
/* Fake it and hope for the best. */
|
||||||
|
54
bfd/elf.c
54
bfd/elf.c
@ -658,7 +658,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
|
|||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: corrupt size field in group section"
|
(_("%B: corrupt size field in group section"
|
||||||
" header: 0x%lx"), abfd, shdr->sh_size);
|
" header: %#Lx"), abfd, shdr->sh_size);
|
||||||
bfd_set_error (bfd_error_bad_value);
|
bfd_set_error (bfd_error_bad_value);
|
||||||
-- num_group;
|
-- num_group;
|
||||||
continue;
|
continue;
|
||||||
@ -673,7 +673,7 @@ setup_group (bfd *abfd, Elf_Internal_Shdr *hdr, asection *newsect)
|
|||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: invalid size field in group section"
|
(_("%B: invalid size field in group section"
|
||||||
" header: 0x%lx"), abfd, shdr->sh_size);
|
" header: %#Lx"), abfd, shdr->sh_size);
|
||||||
bfd_set_error (bfd_error_bad_value);
|
bfd_set_error (bfd_error_bad_value);
|
||||||
-- num_group;
|
-- num_group;
|
||||||
/* PR 17510: If the group contents are even
|
/* PR 17510: If the group contents are even
|
||||||
@ -911,9 +911,9 @@ _bfd_elf_setup_sections (bfd *abfd)
|
|||||||
/* There are some unknown sections in the group. */
|
/* There are some unknown sections in the group. */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: unknown [%d] section `%s' in group [%A]"),
|
(_("%B: unknown type [%#x] section `%s' in group [%A]"),
|
||||||
abfd,
|
abfd,
|
||||||
(unsigned int) idx->shdr->sh_type,
|
idx->shdr->sh_type,
|
||||||
bfd_elf_string_from_elf_section (abfd,
|
bfd_elf_string_from_elf_section (abfd,
|
||||||
(elf_elfheader (abfd)
|
(elf_elfheader (abfd)
|
||||||
->e_shstrndx),
|
->e_shstrndx),
|
||||||
@ -1368,7 +1368,7 @@ copy_special_section_fields (const bfd *ibfd,
|
|||||||
/* See PR 20931 for a reproducer. */
|
/* See PR 20931 for a reproducer. */
|
||||||
if (iheader->sh_link >= elf_numsections (ibfd))
|
if (iheader->sh_link >= elf_numsections (ibfd))
|
||||||
{
|
{
|
||||||
(* _bfd_error_handler)
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: Invalid sh_link field (%d) in section number %d"),
|
(_("%B: Invalid sh_link field (%d) in section number %d"),
|
||||||
ibfd, iheader->sh_link, secnum);
|
ibfd, iheader->sh_link, secnum);
|
||||||
@ -1384,7 +1384,7 @@ copy_special_section_fields (const bfd *ibfd,
|
|||||||
else
|
else
|
||||||
/* FIXME: Should we install iheader->sh_link
|
/* FIXME: Should we install iheader->sh_link
|
||||||
if we could not find a match ? */
|
if we could not find a match ? */
|
||||||
(* _bfd_error_handler)
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: Failed to find link section for section %d"), obfd, secnum);
|
(_("%B: Failed to find link section for section %d"), obfd, secnum);
|
||||||
}
|
}
|
||||||
@ -1411,7 +1411,7 @@ copy_special_section_fields (const bfd *ibfd,
|
|||||||
changed = TRUE;
|
changed = TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
(* _bfd_error_handler)
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: Failed to find info section for section %d"), obfd, secnum);
|
(_("%B: Failed to find info section for section %d"), obfd, secnum);
|
||||||
}
|
}
|
||||||
@ -2301,7 +2301,7 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
|
|||||||
{
|
{
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: invalid link %lu for reloc section %s (index %u)"),
|
(_("%B: invalid link %u for reloc section %s (index %u)"),
|
||||||
abfd, hdr->sh_link, name, shindex);
|
abfd, hdr->sh_link, name, shindex);
|
||||||
ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
|
ret = _bfd_elf_make_section_from_shdr (abfd, hdr, name,
|
||||||
shindex);
|
shindex);
|
||||||
@ -2460,9 +2460,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
|
|||||||
for applications? */
|
for applications? */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: don't know how to handle allocated, application "
|
(_("%B: unknown type [%#x] section `%s'"),
|
||||||
"specific section `%s' [0x%8x]"),
|
abfd, hdr->sh_type, name);
|
||||||
abfd, name, hdr->sh_type);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Allow sections reserved for applications. */
|
/* Allow sections reserved for applications. */
|
||||||
@ -2476,9 +2475,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
|
|||||||
/* FIXME: We should handle this section. */
|
/* FIXME: We should handle this section. */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: don't know how to handle processor specific section "
|
(_("%B: unknown type [%#x] section `%s'"),
|
||||||
"`%s' [0x%8x]"),
|
abfd, hdr->sh_type, name);
|
||||||
abfd, name, hdr->sh_type);
|
|
||||||
else if (hdr->sh_type >= SHT_LOOS && hdr->sh_type <= SHT_HIOS)
|
else if (hdr->sh_type >= SHT_LOOS && hdr->sh_type <= SHT_HIOS)
|
||||||
{
|
{
|
||||||
/* Unrecognised OS-specific sections. */
|
/* Unrecognised OS-specific sections. */
|
||||||
@ -2488,9 +2486,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
|
|||||||
be rejected with an error message. */
|
be rejected with an error message. */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: don't know how to handle OS specific section "
|
(_("%B: unknown type [%#x] section `%s'"),
|
||||||
"`%s' [0x%8x]"),
|
abfd, hdr->sh_type, name);
|
||||||
abfd, name, hdr->sh_type);
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
/* Otherwise it should be processed. */
|
/* Otherwise it should be processed. */
|
||||||
@ -2502,8 +2499,8 @@ bfd_section_from_shdr (bfd *abfd, unsigned int shindex)
|
|||||||
/* FIXME: We should handle this section. */
|
/* FIXME: We should handle this section. */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: don't know how to handle section `%s' [0x%8x]"),
|
(_("%B: unknown type [%#x] section `%s'"),
|
||||||
abfd, name, hdr->sh_type);
|
abfd, hdr->sh_type, name);
|
||||||
|
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -5514,8 +5511,8 @@ assign_file_positions_for_load_sections (bfd *abfd,
|
|||||||
{
|
{
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: section %A lma %#lx adjusted to %#lx"), abfd, sec,
|
(_("%B: section %A lma %#Lx adjusted to %#Lx"),
|
||||||
(unsigned long) s_start, (unsigned long) p_end);
|
abfd, sec, s_start, p_end);
|
||||||
adjust = 0;
|
adjust = 0;
|
||||||
sec->lma = p_end;
|
sec->lma = p_end;
|
||||||
}
|
}
|
||||||
@ -5897,8 +5894,9 @@ assign_file_positions_for_non_load_sections (bfd *abfd,
|
|||||||
{
|
{
|
||||||
/* PR 17512: file: 2195325e. */
|
/* PR 17512: file: 2195325e. */
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
(_("%B: error: non-load segment %d includes file header and/or program header"),
|
(_("%B: error: non-load segment %d includes file header "
|
||||||
abfd, (int)(p - phdrs));
|
"and/or program header"),
|
||||||
|
abfd, (int) (p - phdrs));
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -6760,8 +6758,8 @@ rewrite_elf_program_header (bfd *ibfd, bfd *obfd)
|
|||||||
if (segment->p_type == PT_LOAD
|
if (segment->p_type == PT_LOAD
|
||||||
&& (segment->p_filesz > 0 || segment->p_memsz == 0))
|
&& (segment->p_filesz > 0 || segment->p_memsz == 0))
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
_bfd_error_handler (_("\
|
_bfd_error_handler (_("%B: warning: Empty loadable segment detected"
|
||||||
%B: warning: Empty loadable segment detected at vaddr=0x%.8x, is this intentional ?"),
|
" at vaddr=%#Lx, is this intentional?"),
|
||||||
ibfd, segment->p_vaddr);
|
ibfd, segment->p_vaddr);
|
||||||
|
|
||||||
map->count = 0;
|
map->count = 0;
|
||||||
@ -7374,9 +7372,9 @@ rewrite:
|
|||||||
/* PR 17512: file: f17299af. */
|
/* PR 17512: file: f17299af. */
|
||||||
if (segment->p_align > (bfd_vma) 1 << ((sizeof (bfd_vma) * 8) - 2))
|
if (segment->p_align > (bfd_vma) 1 << ((sizeof (bfd_vma) * 8) - 2))
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
_bfd_error_handler (_("\
|
_bfd_error_handler (_("%B: warning: segment alignment of %#Lx"
|
||||||
%B: warning: segment alignment of 0x%llx is too large"),
|
" is too large"),
|
||||||
ibfd, (long long) segment->p_align);
|
ibfd, segment->p_align);
|
||||||
else
|
else
|
||||||
maxpagesize = segment->p_align;
|
maxpagesize = segment->p_align;
|
||||||
}
|
}
|
||||||
|
@ -1446,7 +1446,7 @@ elf_slurp_reloc_table_from_section (bfd *abfd,
|
|||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B(%A): relocation %d has invalid symbol index %ld"),
|
(_("%B(%A): relocation %d has invalid symbol index %ld"),
|
||||||
abfd, asect, i, ELF_R_SYM (rela.r_info));
|
abfd, asect, i, (long) ELF_R_SYM (rela.r_info));
|
||||||
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
relent->sym_ptr_ptr = bfd_abs_section_ptr->symbol_ptr_ptr;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -2394,8 +2394,8 @@ elf_link_read_relocs_from_section (bfd *abfd,
|
|||||||
{
|
{
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: bad reloc symbol index (0x%lx >= 0x%lx)"
|
(_("%B: bad reloc symbol index (%#lx >= %#lx)"
|
||||||
" for offset 0x%lx in section `%A'"),
|
" for offset %#Lx in section `%A'"),
|
||||||
abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
|
abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
|
||||||
irela->r_offset, sec);
|
irela->r_offset, sec);
|
||||||
bfd_set_error (bfd_error_bad_value);
|
bfd_set_error (bfd_error_bad_value);
|
||||||
@ -2406,8 +2406,8 @@ elf_link_read_relocs_from_section (bfd *abfd,
|
|||||||
{
|
{
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("%B: non-zero symbol index (0x%lx)"
|
(_("%B: non-zero symbol index (%#lx)"
|
||||||
" for offset 0x%lx in section `%A'"
|
" for offset %#Lx in section `%A'"
|
||||||
" when the object file has no symbol table"),
|
" when the object file has no symbol table"),
|
||||||
abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
|
abfd, (unsigned long) r_symndx, (unsigned long) nsyms,
|
||||||
irela->r_offset, sec);
|
irela->r_offset, sec);
|
||||||
@ -4752,9 +4752,8 @@ error_free_dyn:
|
|||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("Warning: size of symbol `%s' changed"
|
(_("Warning: size of symbol `%s' changed"
|
||||||
" from %lu in %B to %lu in %B"),
|
" from %Lu in %B to %Lu in %B"),
|
||||||
name, (unsigned long) h->size, old_bfd,
|
name, h->size, old_bfd, isym->st_size, abfd);
|
||||||
(unsigned long) isym->st_size, abfd);
|
|
||||||
|
|
||||||
h->size = isym->st_size;
|
h->size = isym->st_size;
|
||||||
}
|
}
|
||||||
@ -10477,14 +10476,11 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
|
|||||||
we do not seg fault. */
|
we do not seg fault. */
|
||||||
if (h == NULL)
|
if (h == NULL)
|
||||||
{
|
{
|
||||||
char buffer [32];
|
|
||||||
|
|
||||||
sprintf_vma (buffer, rel->r_info);
|
|
||||||
_bfd_error_handler
|
_bfd_error_handler
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
(_("error: %B contains a reloc (0x%s) for section %A "
|
(_("error: %B contains a reloc (%#Lx) for section %A "
|
||||||
"that references a non-existent global symbol"),
|
"that references a non-existent global symbol"),
|
||||||
input_bfd, buffer, o);
|
input_bfd, rel->r_info, o);
|
||||||
bfd_set_error (bfd_error_bad_value);
|
bfd_set_error (bfd_error_bad_value);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
@ -13422,8 +13418,8 @@ bfd_elf_gc_record_vtinherit (bfd *abfd,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* xgettext:c-format */
|
/* xgettext:c-format */
|
||||||
_bfd_error_handler (_("%B: %A+%lu: No symbol found for INHERIT"),
|
_bfd_error_handler (_("%B: %A+%#Lx: No symbol found for INHERIT"),
|
||||||
abfd, sec, (unsigned long) offset);
|
abfd, sec, offset);
|
||||||
bfd_set_error (bfd_error_invalid_operation);
|
bfd_set_error (bfd_error_invalid_operation);
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user