mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-06-23 19:50:13 +08:00
Prevent a call to abort when a relocatable link encounters a relocation against a symbol in a section removed by garbage collection.
PR ld/21524 * elflink.c (elf_link_adjust_relocs): Generate an error when encountering a reloc against a symbol removed by garbage collection.
This commit is contained in:
@ -1,3 +1,10 @@
|
|||||||
|
2017-06-13 Nick Clifton <nickc@redhat.com>
|
||||||
|
|
||||||
|
PR ld/21524
|
||||||
|
* elflink.c (elf_link_adjust_relocs): Generate an error when
|
||||||
|
encountering a reloc against a symbol removed by garbage
|
||||||
|
collection.
|
||||||
|
|
||||||
2017-06-12 H.J. Lu <hongjiu.lu@intel.com>
|
2017-06-12 H.J. Lu <hongjiu.lu@intel.com>
|
||||||
|
|
||||||
* elf-bfd.h (elf_backend_data): Add struct bfd_link_info *
|
* elf-bfd.h (elf_backend_data): Add struct bfd_link_info *
|
||||||
|
@ -8547,7 +8547,8 @@ static bfd_boolean
|
|||||||
elf_link_adjust_relocs (bfd *abfd,
|
elf_link_adjust_relocs (bfd *abfd,
|
||||||
asection *sec,
|
asection *sec,
|
||||||
struct bfd_elf_section_reloc_data *reldata,
|
struct bfd_elf_section_reloc_data *reldata,
|
||||||
bfd_boolean sort)
|
bfd_boolean sort,
|
||||||
|
struct bfd_link_info *info)
|
||||||
{
|
{
|
||||||
unsigned int i;
|
unsigned int i;
|
||||||
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
|
const struct elf_backend_data *bed = get_elf_backend_data (abfd);
|
||||||
@ -8595,6 +8596,20 @@ elf_link_adjust_relocs (bfd *abfd,
|
|||||||
if (*rel_hash == NULL)
|
if (*rel_hash == NULL)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
|
if ((*rel_hash)->indx == -2
|
||||||
|
&& info->gc_sections
|
||||||
|
&& ! info->gc_keep_exported)
|
||||||
|
{
|
||||||
|
/* PR 21524: Let the user know if a symbol was removed by garbage collection. */
|
||||||
|
_bfd_error_handler (_("%B:%A: error: relocation references symbol %s which was removed by garbage collection."),
|
||||||
|
abfd, sec,
|
||||||
|
(*rel_hash)->root.root.string);
|
||||||
|
_bfd_error_handler (_("%B:%A: error: try relinking with --gc-keep-exported enabled."),
|
||||||
|
abfd, sec,
|
||||||
|
(*rel_hash)->root.root.string);
|
||||||
|
bfd_set_error (bfd_error_invalid_operation);
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
BFD_ASSERT ((*rel_hash)->indx >= 0);
|
BFD_ASSERT ((*rel_hash)->indx >= 0);
|
||||||
|
|
||||||
(*swap_in) (abfd, erela, irela);
|
(*swap_in) (abfd, erela, irela);
|
||||||
@ -10701,7 +10716,6 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
|
|||||||
used by a reloc. */
|
used by a reloc. */
|
||||||
BFD_ASSERT (rh->indx < 0);
|
BFD_ASSERT (rh->indx < 0);
|
||||||
rh->indx = -2;
|
rh->indx = -2;
|
||||||
|
|
||||||
*rel_hash = rh;
|
*rel_hash = rh;
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
@ -12168,15 +12182,16 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
|
|||||||
{
|
{
|
||||||
struct bfd_elf_section_data *esdo = elf_section_data (o);
|
struct bfd_elf_section_data *esdo = elf_section_data (o);
|
||||||
bfd_boolean sort;
|
bfd_boolean sort;
|
||||||
|
|
||||||
if ((o->flags & SEC_RELOC) == 0)
|
if ((o->flags & SEC_RELOC) == 0)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
sort = bed->sort_relocs_p == NULL || (*bed->sort_relocs_p) (o);
|
sort = bed->sort_relocs_p == NULL || (*bed->sort_relocs_p) (o);
|
||||||
if (esdo->rel.hdr != NULL
|
if (esdo->rel.hdr != NULL
|
||||||
&& !elf_link_adjust_relocs (abfd, o, &esdo->rel, sort))
|
&& !elf_link_adjust_relocs (abfd, o, &esdo->rel, sort, info))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
if (esdo->rela.hdr != NULL
|
if (esdo->rela.hdr != NULL
|
||||||
&& !elf_link_adjust_relocs (abfd, o, &esdo->rela, sort))
|
&& !elf_link_adjust_relocs (abfd, o, &esdo->rela, sort, info))
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
/* Set the reloc_count field to 0 to prevent write_relocs from
|
/* Set the reloc_count field to 0 to prevent write_relocs from
|
||||||
|
Reference in New Issue
Block a user