X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf64-x86-64.c;h=9c5a1ea5b95d2d38d19182777a01f1de6837b416;hb=6f2f2c9d168d475a9c77fc2a8e4a5bc73ce31b6e;hp=dc627fb6c42f605994a3be7f03dc244de2498043;hpb=ae9a127f867f404d20b8010b401ca9aaae9018d9;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf64-x86-64.c b/bfd/elf64-x86-64.c index dc627fb6c4..9c5a1ea5b9 100644 --- a/bfd/elf64-x86-64.c +++ b/bfd/elf64-x86-64.c @@ -150,72 +150,14 @@ static const struct elf_reloc_map x86_64_reloc_map[] = { BFD_RELOC_VTABLE_ENTRY, R_X86_64_GNU_VTENTRY, }, }; -static reloc_howto_type *elf64_x86_64_reloc_type_lookup - PARAMS ((bfd *, bfd_reloc_code_real_type)); -static void elf64_x86_64_info_to_howto - PARAMS ((bfd *, arelent *, Elf_Internal_Rela *)); -static bfd_boolean elf64_x86_64_grok_prstatus - PARAMS ((bfd *, Elf_Internal_Note *)); -static bfd_boolean elf64_x86_64_grok_psinfo - PARAMS ((bfd *, Elf_Internal_Note *)); -static struct bfd_link_hash_table *elf64_x86_64_link_hash_table_create - PARAMS ((bfd *)); -static int elf64_x86_64_tls_transition - PARAMS ((struct bfd_link_info *, int, int)); -static bfd_boolean elf64_x86_64_mkobject - PARAMS((bfd *)); -static bfd_boolean elf64_x86_64_elf_object_p PARAMS ((bfd *abfd)); -static bfd_boolean create_got_section - PARAMS((bfd *, struct bfd_link_info *)); -static bfd_boolean elf64_x86_64_create_dynamic_sections - PARAMS((bfd *, struct bfd_link_info *)); -static void elf64_x86_64_copy_indirect_symbol - PARAMS ((struct elf_backend_data *, struct elf_link_hash_entry *, - struct elf_link_hash_entry *)); -static bfd_boolean elf64_x86_64_check_relocs - PARAMS ((bfd *, struct bfd_link_info *, asection *sec, - const Elf_Internal_Rela *)); -static asection *elf64_x86_64_gc_mark_hook - PARAMS ((asection *, struct bfd_link_info *, Elf_Internal_Rela *, - struct elf_link_hash_entry *, Elf_Internal_Sym *)); - -static bfd_boolean elf64_x86_64_gc_sweep_hook - PARAMS ((bfd *, struct bfd_link_info *, asection *, - const Elf_Internal_Rela *)); - -static struct bfd_hash_entry *link_hash_newfunc - PARAMS ((struct bfd_hash_entry *, struct bfd_hash_table *, const char *)); -static bfd_boolean elf64_x86_64_adjust_dynamic_symbol - PARAMS ((struct bfd_link_info *, struct elf_link_hash_entry *)); - -static bfd_boolean allocate_dynrelocs - PARAMS ((struct elf_link_hash_entry *, PTR)); -static bfd_boolean readonly_dynrelocs - PARAMS ((struct elf_link_hash_entry *, PTR)); -static bfd_boolean elf64_x86_64_size_dynamic_sections - PARAMS ((bfd *, struct bfd_link_info *)); -static bfd_vma dtpoff_base - PARAMS ((struct bfd_link_info *)); -static bfd_vma tpoff - PARAMS ((struct bfd_link_info *, bfd_vma)); -static bfd_boolean elf64_x86_64_relocate_section - PARAMS ((bfd *, struct bfd_link_info *, bfd *, asection *, bfd_byte *, - Elf_Internal_Rela *, Elf_Internal_Sym *, asection **)); -static bfd_boolean elf64_x86_64_finish_dynamic_symbol - PARAMS ((bfd *, struct bfd_link_info *, struct elf_link_hash_entry *, - Elf_Internal_Sym *sym)); -static bfd_boolean elf64_x86_64_finish_dynamic_sections - PARAMS ((bfd *, struct bfd_link_info *)); -static enum elf_reloc_type_class elf64_x86_64_reloc_type_class - PARAMS ((const Elf_Internal_Rela *)); /* Given a BFD reloc type, return a HOWTO structure. */ static reloc_howto_type * -elf64_x86_64_reloc_type_lookup (abfd, code) - bfd *abfd ATTRIBUTE_UNUSED; - bfd_reloc_code_real_type code; +elf64_x86_64_reloc_type_lookup (bfd *abfd ATTRIBUTE_UNUSED, + bfd_reloc_code_real_type code) { unsigned int i; + for (i = 0; i < sizeof (x86_64_reloc_map) / sizeof (struct elf_reloc_map); i++) { @@ -228,10 +170,8 @@ elf64_x86_64_reloc_type_lookup (abfd, code) /* Given an x86_64 ELF reloc type, fill in an arelent structure. */ static void -elf64_x86_64_info_to_howto (abfd, cache_ptr, dst) - bfd *abfd ATTRIBUTE_UNUSED; - arelent *cache_ptr; - Elf_Internal_Rela *dst; +elf64_x86_64_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, arelent *cache_ptr, + Elf_Internal_Rela *dst) { unsigned r_type, i; @@ -252,9 +192,7 @@ elf64_x86_64_info_to_howto (abfd, cache_ptr, dst) /* Support for core dump NOTE sections. */ static bfd_boolean -elf64_x86_64_grok_prstatus (abfd, note) - bfd *abfd; - Elf_Internal_Note *note; +elf64_x86_64_grok_prstatus (bfd *abfd, Elf_Internal_Note *note) { int offset; size_t raw_size; @@ -286,9 +224,7 @@ elf64_x86_64_grok_prstatus (abfd, note) } static bfd_boolean -elf64_x86_64_grok_psinfo (abfd, note) - bfd *abfd; - Elf_Internal_Note *note; +elf64_x86_64_grok_psinfo (bfd *abfd, Elf_Internal_Note *note) { switch (note->descsz) { @@ -324,6 +260,12 @@ elf64_x86_64_grok_psinfo (abfd, note) #define ELF_DYNAMIC_INTERPRETER "/lib/ld64.so.1" +/* If ELIMINATE_COPY_RELOCS is non-zero, the linker will try to avoid + copying dynamic variables from a shared lib into an app's dynbss + section, and instead use a dynamic relocation to point into the + shared lib. */ +#define ELIMINATE_COPY_RELOCS 1 + /* The size in bytes of an entry in the global offset table. */ #define GOT_ENTRY_SIZE 8 @@ -441,10 +383,8 @@ struct elf64_x86_64_link_hash_table /* Create an entry in an x86-64 ELF linker hash table. */ static struct bfd_hash_entry * -link_hash_newfunc (entry, table, string) - struct bfd_hash_entry *entry; - struct bfd_hash_table *table; - const char *string; +link_hash_newfunc (struct bfd_hash_entry *entry, struct bfd_hash_table *table, + const char *string) { /* Allocate the structure if it has not already been allocated by a subclass. */ @@ -473,8 +413,7 @@ link_hash_newfunc (entry, table, string) /* Create an X86-64 ELF linker hash table. */ static struct bfd_link_hash_table * -elf64_x86_64_link_hash_table_create (abfd) - bfd *abfd; +elf64_x86_64_link_hash_table_create (bfd *abfd) { struct elf64_x86_64_link_hash_table *ret; bfd_size_type amt = sizeof (struct elf64_x86_64_link_hash_table); @@ -506,9 +445,7 @@ elf64_x86_64_link_hash_table_create (abfd) shortcuts to them in our hash table. */ static bfd_boolean -create_got_section (dynobj, info) - bfd *dynobj; - struct bfd_link_info *info; +create_got_section (bfd *dynobj, struct bfd_link_info *info) { struct elf64_x86_64_link_hash_table *htab; @@ -537,9 +474,7 @@ create_got_section (dynobj, info) hash table. */ static bfd_boolean -elf64_x86_64_create_dynamic_sections (dynobj, info) - bfd *dynobj; - struct bfd_link_info *info; +elf64_x86_64_create_dynamic_sections (bfd *dynobj, struct bfd_link_info *info) { struct elf64_x86_64_link_hash_table *htab; @@ -566,9 +501,9 @@ elf64_x86_64_create_dynamic_sections (dynobj, info) /* Copy the extra info we tack onto an elf_link_hash_entry. */ static void -elf64_x86_64_copy_indirect_symbol (bed, dir, ind) - struct elf_backend_data *bed; - struct elf_link_hash_entry *dir, *ind; +elf64_x86_64_copy_indirect_symbol (const struct elf_backend_data *bed, + struct elf_link_hash_entry *dir, + struct elf_link_hash_entry *ind) { struct elf64_x86_64_link_hash_entry *edir, *eind; @@ -616,12 +551,22 @@ elf64_x86_64_copy_indirect_symbol (bed, dir, ind) eind->tls_type = GOT_UNKNOWN; } - _bfd_elf_link_hash_copy_indirect (bed, dir, ind); + if (ELIMINATE_COPY_RELOCS + && ind->root.type != bfd_link_hash_indirect + && (dir->elf_link_hash_flags & ELF_LINK_HASH_DYNAMIC_ADJUSTED) != 0) + /* If called to transfer flags for a weakdef during processing + of elf_adjust_dynamic_symbol, don't copy ELF_LINK_NON_GOT_REF. + We clear it ourselves for ELIMINATE_COPY_RELOCS. */ + dir->elf_link_hash_flags |= + (ind->elf_link_hash_flags & (ELF_LINK_HASH_REF_DYNAMIC + | ELF_LINK_HASH_REF_REGULAR + | ELF_LINK_HASH_REF_REGULAR_NONWEAK)); + else + _bfd_elf_link_hash_copy_indirect (bed, dir, ind); } static bfd_boolean -elf64_x86_64_mkobject (abfd) - bfd *abfd; +elf64_x86_64_mkobject (bfd *abfd) { bfd_size_type amt = sizeof (struct elf64_x86_64_obj_tdata); abfd->tdata.any = bfd_zalloc (abfd, amt); @@ -631,8 +576,7 @@ elf64_x86_64_mkobject (abfd) } static bfd_boolean -elf64_x86_64_elf_object_p (abfd) - bfd *abfd; +elf64_x86_64_elf_object_p (bfd *abfd) { /* Allocate our special target data. */ struct elf64_x86_64_obj_tdata *new_tdata; @@ -648,10 +592,7 @@ elf64_x86_64_elf_object_p (abfd) } static int -elf64_x86_64_tls_transition (info, r_type, is_local) - struct bfd_link_info *info; - int r_type; - int is_local; +elf64_x86_64_tls_transition (struct bfd_link_info *info, int r_type, int is_local) { if (info->shared) return r_type; @@ -675,11 +616,8 @@ elf64_x86_64_tls_transition (info, r_type, is_local) linkage table, and dynamic reloc sections. */ static bfd_boolean -elf64_x86_64_check_relocs (abfd, info, sec, relocs) - bfd *abfd; - struct bfd_link_info *info; - asection *sec; - const Elf_Internal_Rela *relocs; +elf64_x86_64_check_relocs (bfd *abfd, struct bfd_link_info *info, asection *sec, + const Elf_Internal_Rela *relocs) { struct elf64_x86_64_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; @@ -688,7 +626,7 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs) const Elf_Internal_Rela *rel_end; asection *sreloc; - if (info->relocateable) + if (info->relocatable) return TRUE; htab = elf64_x86_64_hash_table (info); @@ -914,7 +852,8 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs) || h->root.type == bfd_link_hash_defweak || (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) == 0)))) - || (!info->shared + || (ELIMINATE_COPY_RELOCS + && !info->shared && (sec->flags & SEC_ALLOC) != 0 && h != NULL && (h->root.type == bfd_link_hash_defweak @@ -1042,12 +981,11 @@ elf64_x86_64_check_relocs (abfd, info, sec, relocs) relocation. */ static asection * -elf64_x86_64_gc_mark_hook (sec, info, rel, h, sym) - asection *sec; - struct bfd_link_info *info ATTRIBUTE_UNUSED; - Elf_Internal_Rela *rel; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; +elf64_x86_64_gc_mark_hook (asection *sec, + struct bfd_link_info *info ATTRIBUTE_UNUSED, + Elf_Internal_Rela *rel, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) { if (h != NULL) { @@ -1081,19 +1019,13 @@ elf64_x86_64_gc_mark_hook (sec, info, rel, h, sym) /* Update the got entry reference counts for the section being removed. */ static bfd_boolean -elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs) - bfd *abfd; - struct bfd_link_info *info; - asection *sec; - const Elf_Internal_Rela *relocs; +elf64_x86_64_gc_sweep_hook (bfd *abfd, struct bfd_link_info *info, + asection *sec, const Elf_Internal_Rela *relocs) { Elf_Internal_Shdr *symtab_hdr; struct elf_link_hash_entry **sym_hashes; bfd_signed_vma *local_got_refcounts; const Elf_Internal_Rela *rel, *relend; - unsigned long r_symndx; - int r_type; - struct elf_link_hash_entry *h; elf_section_data (sec)->local_dynrel = NULL; @@ -1103,85 +1035,79 @@ elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs) relend = relocs + sec->reloc_count; for (rel = relocs; rel < relend; rel++) - switch ((r_type = elf64_x86_64_tls_transition (info, - ELF64_R_TYPE (rel->r_info), - ELF64_R_SYM (rel->r_info) - >= symtab_hdr->sh_info))) - { - case R_X86_64_TLSLD: - if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0) - elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1; - break; - - case R_X86_64_TLSGD: - case R_X86_64_GOTTPOFF: - case R_X86_64_GOT32: - case R_X86_64_GOTPCREL: - r_symndx = ELF64_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - if (h->got.refcount > 0) - h->got.refcount -= 1; - } - else if (local_got_refcounts != NULL) - { - if (local_got_refcounts[r_symndx] > 0) - local_got_refcounts[r_symndx] -= 1; - } - break; + { + unsigned long r_symndx; + unsigned int r_type; + struct elf_link_hash_entry *h = NULL; - case R_X86_64_8: - case R_X86_64_16: - case R_X86_64_32: - case R_X86_64_64: - case R_X86_64_32S: - case R_X86_64_PC8: - case R_X86_64_PC16: - case R_X86_64_PC32: - r_symndx = ELF64_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - struct elf64_x86_64_link_hash_entry *eh; - struct elf64_x86_64_dyn_relocs **pp; - struct elf64_x86_64_dyn_relocs *p; + r_symndx = ELF64_R_SYM (rel->r_info); + if (r_symndx >= symtab_hdr->sh_info) + { + struct elf64_x86_64_link_hash_entry *eh; + struct elf64_x86_64_dyn_relocs **pp; + struct elf64_x86_64_dyn_relocs *p; - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + h = sym_hashes[r_symndx - symtab_hdr->sh_info]; + eh = (struct elf64_x86_64_link_hash_entry *) h; - if (!info->shared && h->plt.refcount > 0) - h->plt.refcount -= 1; + for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) + if (p->sec == sec) + { + /* Everything must go for SEC. */ + *pp = p->next; + break; + } + } - eh = (struct elf64_x86_64_link_hash_entry *) h; + r_type = ELF64_R_TYPE (rel->r_info); + r_type = elf64_x86_64_tls_transition (info, r_type, h != NULL); + switch (r_type) + { + case R_X86_64_TLSLD: + if (elf64_x86_64_hash_table (info)->tls_ld_got.refcount > 0) + elf64_x86_64_hash_table (info)->tls_ld_got.refcount -= 1; + break; - for (pp = &eh->dyn_relocs; (p = *pp) != NULL; pp = &p->next) - if (p->sec == sec) - { - if (ELF64_R_TYPE (rel->r_info) == R_X86_64_PC8 - || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC16 - || ELF64_R_TYPE (rel->r_info) == R_X86_64_PC32) - p->pc_count -= 1; - p->count -= 1; - if (p->count == 0) - *pp = p->next; - break; - } - } - break; + case R_X86_64_TLSGD: + case R_X86_64_GOTTPOFF: + case R_X86_64_GOT32: + case R_X86_64_GOTPCREL: + if (h != NULL) + { + if (h->got.refcount > 0) + h->got.refcount -= 1; + } + else if (local_got_refcounts != NULL) + { + if (local_got_refcounts[r_symndx] > 0) + local_got_refcounts[r_symndx] -= 1; + } + break; + case R_X86_64_8: + case R_X86_64_16: + case R_X86_64_32: + case R_X86_64_64: + case R_X86_64_32S: + case R_X86_64_PC8: + case R_X86_64_PC16: + case R_X86_64_PC32: + if (info->shared) + break; + /* Fall thru */ - case R_X86_64_PLT32: - r_symndx = ELF64_R_SYM (rel->r_info); - if (r_symndx >= symtab_hdr->sh_info) - { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - if (h->plt.refcount > 0) - h->plt.refcount -= 1; - } - break; + case R_X86_64_PLT32: + if (h != NULL) + { + if (h->plt.refcount > 0) + h->plt.refcount -= 1; + } + break; - default: - break; - } + default: + break; + } + } return TRUE; } @@ -1193,13 +1119,10 @@ elf64_x86_64_gc_sweep_hook (abfd, info, sec, relocs) understand. */ static bfd_boolean -elf64_x86_64_adjust_dynamic_symbol (info, h) - struct bfd_link_info *info; - struct elf_link_hash_entry *h; +elf64_x86_64_adjust_dynamic_symbol (struct bfd_link_info *info, + struct elf_link_hash_entry *h) { struct elf64_x86_64_link_hash_table *htab; - struct elf64_x86_64_link_hash_entry * eh; - struct elf64_x86_64_dyn_relocs *p; asection *s; unsigned int power_of_two; @@ -1210,11 +1133,9 @@ elf64_x86_64_adjust_dynamic_symbol (info, h) || (h->elf_link_hash_flags & ELF_LINK_HASH_NEEDS_PLT) != 0) { if (h->plt.refcount <= 0 - || (! info->shared - && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_DYNAMIC) == 0 - && (h->elf_link_hash_flags & ELF_LINK_HASH_REF_DYNAMIC) == 0 - && h->root.type != bfd_link_hash_undefweak - && h->root.type != bfd_link_hash_undefined)) + || SYMBOL_CALLS_LOCAL (info, h) + || (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + && h->root.type == bfd_link_hash_undefweak)) { /* This case can occur if we saw a PLT32 reloc in an input file, but the symbol was never referred to by a dynamic @@ -1244,6 +1165,10 @@ elf64_x86_64_adjust_dynamic_symbol (info, h) || h->weakdef->root.type == bfd_link_hash_defweak); h->root.u.def.section = h->weakdef->root.u.def.section; h->root.u.def.value = h->weakdef->root.u.def.value; + if (ELIMINATE_COPY_RELOCS || info->nocopyreloc) + h->elf_link_hash_flags + = ((h->elf_link_hash_flags & ~ELF_LINK_NON_GOT_REF) + | (h->weakdef->elf_link_hash_flags & ELF_LINK_NON_GOT_REF)); return TRUE; } @@ -1269,20 +1194,26 @@ elf64_x86_64_adjust_dynamic_symbol (info, h) return TRUE; } - eh = (struct elf64_x86_64_link_hash_entry *) h; - for (p = eh->dyn_relocs; p != NULL; p = p->next) + if (ELIMINATE_COPY_RELOCS) { - s = p->sec->output_section; - if (s != NULL && (s->flags & SEC_READONLY) != 0) - break; - } + struct elf64_x86_64_link_hash_entry * eh; + struct elf64_x86_64_dyn_relocs *p; - /* If we didn't find any dynamic relocs in read-only sections, then - we'll be keeping the dynamic relocs and avoiding the copy reloc. */ - if (p == NULL) - { - h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; - return TRUE; + eh = (struct elf64_x86_64_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) != 0) + break; + } + + /* If we didn't find any dynamic relocs in read-only sections, then + we'll be keeping the dynamic relocs and avoiding the copy reloc. */ + if (p == NULL) + { + h->elf_link_hash_flags &= ~ELF_LINK_NON_GOT_REF; + return TRUE; + } } /* We must allocate the symbol in our .dynbss section, which will @@ -1338,9 +1269,9 @@ elf64_x86_64_adjust_dynamic_symbol (info, h) will be called from elflink.h. If elflink.h doesn't call our finish_dynamic_symbol routine, we'll need to do something about initializing any .plt and .got entries in elf64_x86_64_relocate_section. */ -#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, INFO, H) \ +#define WILL_CALL_FINISH_DYNAMIC_SYMBOL(DYN, SHARED, H) \ ((DYN) \ - && ((INFO)->shared \ + && ((SHARED) \ || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) == 0) \ && ((H)->dynindx != -1 \ || ((H)->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0)) @@ -1349,9 +1280,7 @@ elf64_x86_64_adjust_dynamic_symbol (info, h) dynamic relocs. */ static bfd_boolean -allocate_dynrelocs (h, inf) - struct elf_link_hash_entry *h; - PTR inf; +allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) { struct bfd_link_info *info; struct elf64_x86_64_link_hash_table *htab; @@ -1379,7 +1308,8 @@ allocate_dynrelocs (h, inf) return FALSE; } - if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, info, h)) + if (info->shared + || WILL_CALL_FINISH_DYNAMIC_SYMBOL (1, 0, h)) { asection *s = htab->splt; @@ -1461,7 +1391,10 @@ allocate_dynrelocs (h, inf) htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); else if (tls_type == GOT_TLS_GD) htab->srelgot->_raw_size += 2 * sizeof (Elf64_External_Rela); - else if (WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h)) + else if ((ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak) + && (info->shared + || WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, 0, h))) htab->srelgot->_raw_size += sizeof (Elf64_External_Rela); } else @@ -1479,9 +1412,13 @@ allocate_dynrelocs (h, inf) if (info->shared) { - if ((h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR) != 0 - && ((h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL) != 0 - || info->symbolic)) + /* Relocs that use pc_count are those that appear on a call + insn, or certain REL relocs that can generated via assembly. + We want calls to protected symbols to resolve directly to the + function rather than going via the plt. If people want + function pointer comparisons to work as expected then they + should avoid writing weird assembly. */ + if (SYMBOL_CALLS_LOCAL (info, h)) { struct elf64_x86_64_dyn_relocs **pp; @@ -1495,8 +1432,14 @@ allocate_dynrelocs (h, inf) pp = &p->next; } } + + /* Also discard relocs on undefined weak syms with non-default + visibility. */ + if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT + && h->root.type == bfd_link_hash_undefweak) + eh->dyn_relocs = NULL; } - else + else if (ELIMINATE_COPY_RELOCS) { /* For the non-shared case, discard space for relocs against symbols which turn out to need copy relocs or are not @@ -1542,9 +1485,7 @@ allocate_dynrelocs (h, inf) /* Find any dynamic relocs that apply to read-only sections. */ static bfd_boolean -readonly_dynrelocs (h, inf) - struct elf_link_hash_entry *h; - PTR inf; +readonly_dynrelocs (struct elf_link_hash_entry *h, void * inf) { struct elf64_x86_64_link_hash_entry *eh; struct elf64_x86_64_dyn_relocs *p; @@ -1573,9 +1514,8 @@ readonly_dynrelocs (h, inf) /* Set the sizes of the dynamic sections. */ static bfd_boolean -elf64_x86_64_size_dynamic_sections (output_bfd, info) - bfd *output_bfd ATTRIBUTE_UNUSED; - struct bfd_link_info *info; +elf64_x86_64_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, + struct bfd_link_info *info) { struct elf64_x86_64_link_hash_table *htab; bfd *dynobj; @@ -1591,7 +1531,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info) if (htab->elf.dynamic_sections_created) { /* Set the contents of the .interp section to the interpreter. */ - if (! info->shared) + if (info->executable) { s = bfd_get_section_by_name (dynobj, ".interp"); if (s == NULL) @@ -1752,7 +1692,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info) #define add_dynamic_entry(TAG, VAL) \ bfd_elf64_add_dynamic_entry (info, (bfd_vma) (TAG), (bfd_vma) (VAL)) - if (! info->shared) + if (info->executable) { if (!add_dynamic_entry (DT_DEBUG, 0)) return FALSE; @@ -1797,8 +1737,7 @@ elf64_x86_64_size_dynamic_sections (output_bfd, info) This is PT_TLS segment p_vaddr. */ static bfd_vma -dtpoff_base (info) - struct bfd_link_info *info; +dtpoff_base (struct bfd_link_info *info) { /* If tls_segment is NULL, we should have signalled an error already. */ if (elf_hash_table (info)->tls_segment == NULL) @@ -1810,9 +1749,7 @@ dtpoff_base (info) if STT_TLS virtual address is ADDRESS. */ static bfd_vma -tpoff (info, address) - struct bfd_link_info *info; - bfd_vma address; +tpoff (struct bfd_link_info *info, bfd_vma address) { struct elf_link_tls_segment *tls_segment = elf_hash_table (info)->tls_segment; @@ -1827,16 +1764,11 @@ tpoff (info, address) /* Relocate an x86_64 ELF section. */ static bfd_boolean -elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, - contents, relocs, local_syms, local_sections) - bfd *output_bfd; - struct bfd_link_info *info; - bfd *input_bfd; - asection *input_section; - bfd_byte *contents; - Elf_Internal_Rela *relocs; - Elf_Internal_Sym *local_syms; - asection **local_sections; +elf64_x86_64_relocate_section (bfd *output_bfd, struct bfd_link_info *info, + bfd *input_bfd, asection *input_section, + bfd_byte *contents, Elf_Internal_Rela *relocs, + Elf_Internal_Sym *local_syms, + asection **local_sections) { struct elf64_x86_64_link_hash_table *htab; Elf_Internal_Shdr *symtab_hdr; @@ -1845,7 +1777,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, Elf_Internal_Rela *rel; Elf_Internal_Rela *relend; - if (info->relocateable) + if (info->relocatable) return TRUE; htab = elf64_x86_64_hash_table (info); @@ -1895,45 +1827,12 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, } else { - h = sym_hashes[r_symndx - symtab_hdr->sh_info]; - while (h->root.type == bfd_link_hash_indirect - || h->root.type == bfd_link_hash_warning) - h = (struct elf_link_hash_entry *) h->root.u.i.link; + bfd_boolean warned; - if (h->root.type == bfd_link_hash_defined - || h->root.type == bfd_link_hash_defweak) - { - sec = h->root.u.def.section; - if (sec->output_section == NULL) - { - /* Set a flag that will be cleared later if we find a - relocation value for this symbol. output_section - is typically NULL for symbols satisfied by a shared - library. */ - unresolved_reloc = TRUE; - relocation = 0; - } - else - relocation = (h->root.u.def.value - + sec->output_section->vma - + sec->output_offset); - } - else if (h->root.type == bfd_link_hash_undefweak) - relocation = 0; - else if (info->shared - && !info->no_undefined - && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) - relocation = 0; - else - { - if (! ((*info->callbacks->undefined_symbol) - (info, h->root.root.string, input_bfd, - input_section, rel->r_offset, - (!info->shared || info->no_undefined - || ELF_ST_VISIBILITY (h->other))))) - return FALSE; - relocation = 0; - } + RELOC_FOR_GLOBAL_SYMBOL (h, sym_hashes, r_symndx, + symtab_hdr, relocation, sec, + unresolved_reloc, info, + warned); } /* When generating a shared object, the relocations handled here are copied into the output file to be resolved at run time. */ @@ -1954,12 +1853,11 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, off = h->got.offset; dyn = htab->elf.dynamic_sections_created; - if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info, h) + if (! WILL_CALL_FINISH_DYNAMIC_SYMBOL (dyn, info->shared, h) || (info->shared - && (info->symbolic - || h->dynindx == -1 - || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) - && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR))) + && SYMBOL_REFERENCES_LOCAL (info, h)) + || (ELF_ST_VISIBILITY (h->other) + && h->root.type == bfd_link_hash_undefweak)) { /* This is actually a static link, or it is a -Bsymbolic link and the symbol is defined locally, or the symbol @@ -2078,15 +1976,15 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, break; if ((info->shared + && (h == NULL + || ELF_ST_VISIBILITY (h->other) == STV_DEFAULT + || h->root.type != bfd_link_hash_undefweak) && ((r_type != R_X86_64_PC8 && r_type != R_X86_64_PC16 && r_type != R_X86_64_PC32) - || (h != NULL - && h->dynindx != -1 - && (! info->symbolic - || (h->elf_link_hash_flags - & ELF_LINK_HASH_DEF_REGULAR) == 0)))) - || (!info->shared + || !SYMBOL_CALLS_LOCAL (info, h))) + || (ELIMINATE_COPY_RELOCS + && !info->shared && h != NULL && h->dynindx != -1 && (h->elf_link_hash_flags & ELF_LINK_NON_GOT_REF) == 0 @@ -2328,7 +2226,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, if ((off & 1) != 0) off &= ~1; - else + else { Elf_Internal_Rela outrel; bfd_byte *loc; @@ -2360,7 +2258,7 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, { if (indx == 0) { - BFD_ASSERT (! unresolved_reloc); + BFD_ASSERT (! unresolved_reloc); bfd_put_64 (output_bfd, relocation - dtpoff_base (info), htab->sgot->contents + off + GOT_ENTRY_SIZE); @@ -2406,12 +2304,12 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, addq foo@gottpoff(%rip), %rax */ BFD_ASSERT (rel->r_offset >= 4); for (i = 0; i < 4; i++) - BFD_ASSERT (bfd_get_8 (input_bfd, + BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset - 4 + i) == tlsgd[i]); BFD_ASSERT (rel->r_offset + 12 <= input_section->_raw_size); for (i = 0; i < 4; i++) - BFD_ASSERT (bfd_get_8 (input_bfd, + BFD_ASSERT (bfd_get_8 (input_bfd, contents + rel->r_offset + 4 + i) == tlsgd[i+4]); BFD_ASSERT (rel + 1 < relend); @@ -2571,11 +2469,10 @@ elf64_x86_64_relocate_section (output_bfd, info, input_bfd, input_section, dynamic sections here. */ static bfd_boolean -elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym) - bfd *output_bfd; - struct bfd_link_info *info; - struct elf_link_hash_entry *h; - Elf_Internal_Sym *sym; +elf64_x86_64_finish_dynamic_symbol (bfd *output_bfd, + struct bfd_link_info *info, + struct elf_link_hash_entry *h, + Elf_Internal_Sym *sym) { struct elf64_x86_64_link_hash_table *htab; @@ -2681,10 +2578,7 @@ elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym) The entry in the global offset table will already have been initialized in the relocate_section function. */ if (info->shared - && (info->symbolic - || h->dynindx == -1 - || (h->elf_link_hash_flags & ELF_LINK_FORCED_LOCAL)) - && (h->elf_link_hash_flags & ELF_LINK_HASH_DEF_REGULAR)) + && SYMBOL_REFERENCES_LOCAL (info, h)) { BFD_ASSERT((h->got.offset & 1) != 0); rela.r_info = ELF64_R_INFO (0, R_X86_64_RELATIVE); @@ -2741,8 +2635,7 @@ elf64_x86_64_finish_dynamic_symbol (output_bfd, info, h, sym) dynamic linker, before writing them out. */ static enum elf_reloc_type_class -elf64_x86_64_reloc_type_class (rela) - const Elf_Internal_Rela *rela; +elf64_x86_64_reloc_type_class (const Elf_Internal_Rela *rela) { switch ((int) ELF64_R_TYPE (rela->r_info)) { @@ -2760,9 +2653,7 @@ elf64_x86_64_reloc_type_class (rela) /* Finish up the dynamic sections. */ static bfd_boolean -elf64_x86_64_finish_dynamic_sections (output_bfd, info) - bfd *output_bfd; - struct bfd_link_info *info; +elf64_x86_64_finish_dynamic_sections (bfd *output_bfd, struct bfd_link_info *info) { struct elf64_x86_64_link_hash_table *htab; bfd *dynobj; @@ -2901,7 +2792,6 @@ elf64_x86_64_finish_dynamic_sections (output_bfd, info) #define elf_backend_plt_readonly 1 #define elf_backend_want_plt_sym 0 #define elf_backend_got_header_size (GOT_ENTRY_SIZE*3) -#define elf_backend_plt_header_size PLT_ENTRY_SIZE #define elf_backend_rela_normal 1 #define elf_info_to_howto elf64_x86_64_info_to_howto