diff options
author | Alan Modra <amodra@gmail.com> | 2017-04-23 11:03:34 +0930 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2017-04-23 20:33:34 +0930 |
commit | bce964aa6c777d236fbd641f2bc7bb931cfe4bf3 (patch) | |
tree | 0766f8772604e3f7b4df1f2dffb9ee456b9fc6f9 /bfd/elf.c | |
parent | 97e83a100aa8250be783304bfe0429761c6e6b6b (diff) | |
download | gdb-bce964aa6c777d236fbd641f2bc7bb931cfe4bf3.zip gdb-bce964aa6c777d236fbd641f2bc7bb931cfe4bf3.tar.gz gdb-bce964aa6c777d236fbd641f2bc7bb931cfe4bf3.tar.bz2 |
PR 21412, get_reloc_section assumes .rel/.rela name for SHT_REL/RELA.
This patch fixes an assumption made by code that runs for objcopy and
strip, that SHT_REL/SHR_RELA sections are always named starting with a
.rel/.rela prefix. I'm also modifying the interface for
elf_backend_get_reloc_section, so any backend function just needs to
handle name mapping.
PR 21412
* elf-bfd.h (struct elf_backend_data <get_reloc_section>): Change
parameters and comment.
(_bfd_elf_get_reloc_section): Delete.
(_bfd_elf_plt_get_reloc_section): Declare.
* elf.c (_bfd_elf_plt_get_reloc_section, elf_get_reloc_section):
New functions. Don't blindly skip over assumed .rel/.rela prefix.
Extracted from..
(_bfd_elf_get_reloc_section): ..here. Delete.
(assign_section_numbers): Call elf_get_reloc_section.
* elf64-ppc.c (elf_backend_get_reloc_section): Define.
* elfxx-target.h (elf_backend_get_reloc_section): Update.
Diffstat (limited to 'bfd/elf.c')
-rw-r--r-- | bfd/elf.c | 61 |
1 files changed, 35 insertions, 26 deletions
@@ -3538,17 +3538,39 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg) H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc); } -/* Return the section which RELOC_SEC applies to. */ +/* Given NAME, the name of a relocation section stripped of its + .rel/.rela prefix, return the section in ABFD to which the + relocations apply. */ asection * -_bfd_elf_get_reloc_section (asection *reloc_sec) +_bfd_elf_plt_get_reloc_section (bfd *abfd, const char *name) +{ + /* If a target needs .got.plt section, relocations in rela.plt/rel.plt + section likely apply to .got.plt or .got section. */ + if (get_elf_backend_data (abfd)->want_got_plt + && strcmp (name, ".plt") == 0) + { + asection *sec; + + name = ".got.plt"; + sec = bfd_get_section_by_name (abfd, name); + if (sec != NULL) + return sec; + name = ".got"; + } + + return bfd_get_section_by_name (abfd, name); +} + +/* Return the section to which RELOC_SEC applies. */ + +static asection * +elf_get_reloc_section (asection *reloc_sec) { const char *name; unsigned int type; bfd *abfd; - - if (reloc_sec == NULL) - return NULL; + const struct elf_backend_data *bed; type = elf_section_data (reloc_sec)->this_hdr.sh_type; if (type != SHT_REL && type != SHT_RELA) @@ -3556,28 +3578,15 @@ _bfd_elf_get_reloc_section (asection *reloc_sec) /* We look up the section the relocs apply to by name. */ name = reloc_sec->name; - if (type == SHT_REL) - name += 4; - else - name += 5; + if (strncmp (name, ".rel", 4) != 0) + return NULL; + name += 4; + if (type == SHT_RELA && *name++ != 'a') + return NULL; - /* If a target needs .got.plt section, relocations in rela.plt/rel.plt - section apply to .got.plt section. */ abfd = reloc_sec->owner; - if (get_elf_backend_data (abfd)->want_got_plt - && strcmp (name, ".plt") == 0) - { - /* .got.plt is a linker created input section. It may be mapped - to some other output section. Try two likely sections. */ - name = ".got.plt"; - reloc_sec = bfd_get_section_by_name (abfd, name); - if (reloc_sec != NULL) - return reloc_sec; - name = ".got"; - } - - reloc_sec = bfd_get_section_by_name (abfd, name); - return reloc_sec; + bed = get_elf_backend_data (abfd); + return bed->get_reloc_section (abfd, name); } /* Assign all ELF section numbers. The dummy first section is handled here @@ -3841,7 +3850,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info) if (s != NULL) d->this_hdr.sh_link = elf_section_data (s)->this_idx; - s = get_elf_backend_data (abfd)->get_reloc_section (sec); + s = elf_get_reloc_section (sec); if (s != NULL) { d->this_hdr.sh_info = elf_section_data (s)->this_idx; |