diff options
author | Nick Clifton <nickc@redhat.com> | 2017-06-13 14:03:16 +0100 |
---|---|---|
committer | Nick Clifton <nickc@redhat.com> | 2017-06-13 14:03:16 +0100 |
commit | 10bbbc1d790836122c417fe4fef7233604bb3982 (patch) | |
tree | a1c0fcdb39e20868e0fbfb9fe2f8d98f68b37f31 /bfd/elflink.c | |
parent | 032bb6eae8a0166f9b5d2eac6960383c532ef6d1 (diff) | |
download | gdb-10bbbc1d790836122c417fe4fef7233604bb3982.zip gdb-10bbbc1d790836122c417fe4fef7233604bb3982.tar.gz gdb-10bbbc1d790836122c417fe4fef7233604bb3982.tar.bz2 |
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.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r-- | bfd/elflink.c | 23 |
1 files changed, 19 insertions, 4 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c index 1b447bb..f0ca33f 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -8547,7 +8547,8 @@ static bfd_boolean elf_link_adjust_relocs (bfd *abfd, asection *sec, struct bfd_elf_section_reloc_data *reldata, - bfd_boolean sort) + bfd_boolean sort, + struct bfd_link_info *info) { unsigned int i; 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) 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); (*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. */ BFD_ASSERT (rh->indx < 0); rh->indx = -2; - *rel_hash = rh; 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); bfd_boolean sort; + if ((o->flags & SEC_RELOC) == 0) continue; sort = bed->sort_relocs_p == NULL || (*bed->sort_relocs_p) (o); 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; 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; /* Set the reloc_count field to 0 to prevent write_relocs from |