diff options
author | Alan Modra <amodra@gmail.com> | 2017-12-05 10:03:03 +1030 |
---|---|---|
committer | Alan Modra <amodra@gmail.com> | 2017-12-06 14:21:45 +1030 |
commit | 3bf083ed23b1337341129b810ed5da29ba8207f9 (patch) | |
tree | f20359c17a9b7b8804fe7a84208dd6f76cde43f1 /bfd/elf32-sh.c | |
parent | dce2246a6c934bf35157e8970d0da5a11aefb282 (diff) | |
download | gdb-3bf083ed23b1337341129b810ed5da29ba8207f9.zip gdb-3bf083ed23b1337341129b810ed5da29ba8207f9.tar.gz gdb-3bf083ed23b1337341129b810ed5da29ba8207f9.tar.bz2 |
dyn_relocs tidy
Many targets define their own dyn_relocs struct when they could use
struct elf_dyn_relocs. This patch tidies that, and uses
readonly_dynrelocs in a few more places.
The SH adjust_dynamic_symbol had some really weird code dating back to
2002 that looked over dynamic relocations for any in SEC_HAS_CONTENTS
or SEC_READONLY sections, rather than just the usual SEC_READONLY
sections. So basically any dynamic relocation. What's more, the SH
relocate_section has no support for emitting dynamic relocations in
non-PIC. In other words, SH has no support for avoiding copy relocs
in non-PIC. I've made that more obvious by using "if (0 && ..)" in
asjust_dynamic_symbol.
Unfortunately, LM32, M32R, NDS32, and OR1K copied the bogus SH
adjust_dynamic_symbol code. So none of those targets would have
avoided copy relocs. LM32, M32R, NDS32 get the "if (0)" treatment
too. (LM32 is even more broken in that non_got_ref is never set.)
OR1K relocate_section looks like it might support dynamic relocs in
non-PIC, so I've enabled the copy reloc avoidance code for that
target.
* elf32-hppa.c (struct elf32_hppa_dyn_reloc_entry): Delete. Use
struct elf_dyn_relocs throughout file instead.
(elf32_hppa_adjust_dynamic_symbol): Comment tidy.
* elf32-lm32.c (struct elf_lm32_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(lm32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-m32r.c (struct elf_m32r_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(m32r_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-metag.c (struct elf_metag_dyn_reloc_entry): Delete. Use
struct elf_dyn_relocs throughout file instead.
(elf_metag_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-microblaze.c (struct elf32_mb_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(readonly_dynrelocs): New function.
(microblaze_elf_adjust_dynamic_symbol): Use it.
* elf32-nds32.c (struct elf_nds32_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(nds32_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-nios2.c (struct elf32_nios2_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
* elf32-or1k.c (struct elf_or1k_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(or1k_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-sh.c (struct elf_sh_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(sh_elf_adjust_dynamic_symbol): Use readonly_dynrelocs, but disable.
Disable -z no-copyreloc too.
* elf32-tilepro.c (struct tilepro_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(tilepro_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfnn-riscv.c (struct riscv_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(riscv_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfxx-sparc.c (struct _bfd_sparc_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(_bfd_sparc_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elfxx-tilegx.c (struct tilegx_elf_dyn_relocs): Delete. Use
struct elf_dyn_relocs throughout file instead.
(tilegx_elf_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf32-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
* elf64-s390.c (elf_s390_adjust_dynamic_symbol): Use readonly_dynrelocs.
Diffstat (limited to 'bfd/elf32-sh.c')
-rw-r--r-- | bfd/elf32-sh.c | 65 |
1 files changed, 17 insertions, 48 deletions
diff --git a/bfd/elf32-sh.c b/bfd/elf32-sh.c index 0ff6a1b..420931b 100644 --- a/bfd/elf32-sh.c +++ b/bfd/elf32-sh.c @@ -2367,26 +2367,6 @@ get_plt_offset (const struct elf_sh_plt_info *info, bfd_vma plt_index) + (plt_index * info->symbol_entry_size)); } -/* The sh linker needs to keep track of the number of relocs that it - decides to copy as dynamic relocs in check_relocs for each symbol. - This is so that it can later discard them if they are found to be - unnecessary. We store the information in a field extending the - regular ELF linker hash table. */ - -struct elf_sh_dyn_relocs -{ - struct elf_sh_dyn_relocs *next; - - /* The input section of the reloc. */ - asection *sec; - - /* Total number of relocs copied for the input section. */ - bfd_size_type count; - - /* Number of pc-relative relocs copied for the input section. */ - bfd_size_type pc_count; -}; - union gotref { bfd_signed_vma refcount; @@ -2408,7 +2388,7 @@ struct elf_sh_link_hash_entry #endif /* Track dynamic relocs copied for this symbol. */ - struct elf_sh_dyn_relocs *dyn_relocs; + struct elf_dyn_relocs *dyn_relocs; bfd_signed_vma gotplt_refcount; @@ -2800,7 +2780,7 @@ sh_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) static asection * readonly_dynrelocs (struct elf_link_hash_entry *h) { - struct elf_sh_dyn_relocs *p; + struct elf_dyn_relocs *p; for (p = sh_elf_hash_entry (h)->dyn_relocs; p != NULL; p = p->next) { @@ -2823,8 +2803,6 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info, struct elf_link_hash_entry *h) { struct elf_sh_link_hash_table *htab; - struct elf_sh_link_hash_entry *eh; - struct elf_sh_dyn_relocs *p; asection *s; htab = sh_elf_hash_table (info); @@ -2894,24 +2872,15 @@ sh_elf_adjust_dynamic_symbol (struct bfd_link_info *info, return TRUE; /* If -z nocopyreloc was given, we won't generate them either. */ - if (info->nocopyreloc) + if (0 && info->nocopyreloc) { h->non_got_ref = 0; return TRUE; } - eh = (struct elf_sh_link_hash_entry *) h; - for (p = eh->dyn_relocs; p != NULL; p = p->next) - { - s = p->sec->output_section; - if (s != NULL && (s->flags & (SEC_READONLY | SEC_HAS_CONTENTS)) != 0) - break; - } - - /* If we didn't find any dynamic relocs in sections which needs the - copy reloc, then we'll be keeping the dynamic relocs and avoiding - the copy reloc. */ - if (p == NULL) + /* If we don't find any dynamic relocs in read-only sections, then + we'll be keeping the dynamic relocs and avoiding the copy reloc. */ + if (0 && !readonly_dynrelocs (h)) { h->non_got_ref = 0; return TRUE; @@ -2956,7 +2925,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) struct bfd_link_info *info; struct elf_sh_link_hash_table *htab; struct elf_sh_link_hash_entry *eh; - struct elf_sh_dyn_relocs *p; + struct elf_dyn_relocs *p; if (h->root.type == bfd_link_hash_indirect) return TRUE; @@ -3207,7 +3176,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) { if (SYMBOL_CALLS_LOCAL (info, h)) { - struct elf_sh_dyn_relocs **pp; + struct elf_dyn_relocs **pp; for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) { @@ -3222,7 +3191,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void *inf) if (htab->vxworks_p) { - struct elf_sh_dyn_relocs **pp; + struct elf_dyn_relocs **pp; for (pp = &eh->dyn_relocs; (p = *pp) != NULL; ) { @@ -3391,9 +3360,9 @@ sh_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, for (s = ibfd->sections; s != NULL; s = s->next) { - struct elf_sh_dyn_relocs *p; + struct elf_dyn_relocs *p; - for (p = ((struct elf_sh_dyn_relocs *) + for (p = ((struct elf_dyn_relocs *) elf_section_data (s)->local_dynrel); p != NULL; p = p->next) @@ -5710,14 +5679,14 @@ sh_elf_copy_indirect_symbol (struct bfd_link_info *info, { if (edir->dyn_relocs != NULL) { - struct elf_sh_dyn_relocs **pp; - struct elf_sh_dyn_relocs *p; + struct elf_dyn_relocs **pp; + struct elf_dyn_relocs *p; /* Add reloc counts against the indirect sym to the direct sym list. Merge any entries against the same section. */ for (pp = &eind->dyn_relocs; (p = *pp) != NULL; ) { - struct elf_sh_dyn_relocs *q; + struct elf_dyn_relocs *q; for (q = edir->dyn_relocs; q != NULL; q = q->next) if (q->sec == p->sec) @@ -6259,8 +6228,8 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, && (h->root.type == bfd_link_hash_defweak || !h->def_regular))) { - struct elf_sh_dyn_relocs *p; - struct elf_sh_dyn_relocs **head; + struct elf_dyn_relocs *p; + struct elf_dyn_relocs **head; if (htab->root.dynobj == NULL) htab->root.dynobj = abfd; @@ -6298,7 +6267,7 @@ sh_elf_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, s = sec; vpp = &elf_section_data (s)->local_dynrel; - head = (struct elf_sh_dyn_relocs **) vpp; + head = (struct elf_dyn_relocs **) vpp; } p = *head; |