X-Git-Url: http://drtracing.org/?a=blobdiff_plain;f=bfd%2Felf32-m32r.c;h=740be9338295f29aa8db8d10a15ce78499fbff9b;hb=14962256b310efddf677ff4f5c9fa41047f48c39;hp=94a4bc9dffbedefe4ea4d5a16b5737326a8c03fa;hpb=f3185997ac0951edac802e29df03dfc0844fda34;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf32-m32r.c b/bfd/elf32-m32r.c index 94a4bc9dff..740be93382 100644 --- a/bfd/elf32-m32r.c +++ b/bfd/elf32-m32r.c @@ -1,5 +1,5 @@ /* M32R-specific support for 32-bit ELF. - Copyright (C) 1996-2018 Free Software Foundation, Inc. + Copyright (C) 1996-2020 Free Software Foundation, Inc. This file is part of BFD, the Binary File Descriptor library. @@ -1310,7 +1310,7 @@ m32r_info_to_howto (bfd *abfd ATTRIBUTE_UNUSED, /* xgettext:c-format */ _bfd_error_handler (_("%pB: unsupported relocation type %#x"), abfd, r_type); bfd_set_error (bfd_error_bad_value); - return FALSE; + return FALSE; } @@ -1322,7 +1322,7 @@ _bfd_m32r_elf_section_from_bfd_section (bfd *abfd ATTRIBUTE_UNUSED, asection *sec, int *retval) { - if (strcmp (bfd_get_section_name (abfd, sec), ".scommon") == 0) + if (strcmp (bfd_section_name (sec), ".scommon") == 0) { *retval = SHN_M32R_SCOMMON; return TRUE; @@ -1407,7 +1407,7 @@ m32r_elf_add_symbol_hook (bfd *abfd, flags); if (s == NULL) return FALSE; - if (! bfd_set_section_alignment (abfd, s, 2)) + if (!bfd_set_section_alignment (s, 2)) return FALSE; } @@ -1498,16 +1498,6 @@ struct elf_m32r_pcrel_relocs_copied bfd_size_type count; }; -/* m32r ELF linker hash entry. */ - -struct elf_m32r_link_hash_entry -{ - struct elf_link_hash_entry root; - - /* Track dynamic relocs copied for this symbol. */ - struct elf_dyn_relocs *dyn_relocs; -}; - /* m32r ELF linker hash table. */ struct elf_m32r_link_hash_table @@ -1536,54 +1526,21 @@ struct elf_m32r_link_hash_table (elf_hash_table_id ((struct elf_link_hash_table *) ((p)->hash)) \ == M32R_ELF_DATA ? ((struct elf_m32r_link_hash_table *) ((p)->hash)) : NULL) -/* Create an entry in an m32r ELF linker hash table. */ - -static struct bfd_hash_entry * -m32r_elf_link_hash_newfunc (struct bfd_hash_entry *entry, - struct bfd_hash_table *table, - const char *string) -{ - struct elf_m32r_link_hash_entry *ret = - (struct elf_m32r_link_hash_entry *) entry; - - /* Allocate the structure if it has not already been allocated by a - subclass. */ - if (ret == NULL) - ret = bfd_hash_allocate (table, - sizeof (struct elf_m32r_link_hash_entry)); - if (ret == NULL) - return NULL; - - /* Call the allocation method of the superclass. */ - ret = ((struct elf_m32r_link_hash_entry *) - _bfd_elf_link_hash_newfunc ((struct bfd_hash_entry *) ret, - table, string)); - if (ret != NULL) - { - struct elf_m32r_link_hash_entry *eh; - - eh = (struct elf_m32r_link_hash_entry *) ret; - eh->dyn_relocs = NULL; - } - - return (struct bfd_hash_entry *) ret; -} - /* Create an m32r ELF linker hash table. */ static struct bfd_link_hash_table * m32r_elf_link_hash_table_create (bfd *abfd) { struct elf_m32r_link_hash_table *ret; - bfd_size_type amt = sizeof (struct elf_m32r_link_hash_table); + size_t amt = sizeof (struct elf_m32r_link_hash_table); ret = bfd_zmalloc (amt); if (ret == NULL) return NULL; if (!_bfd_elf_link_hash_table_init (&ret->root, abfd, - m32r_elf_link_hash_newfunc, - sizeof (struct elf_m32r_link_hash_entry), + _bfd_elf_link_hash_newfunc, + sizeof (struct elf_link_hash_entry), M32R_ELF_DATA)) { free (ret); @@ -1623,7 +1580,7 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) s = bfd_make_section_anyway_with_flags (abfd, ".plt", pltflags); htab->root.splt = s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, bed->plt_alignment)) + || !bfd_set_section_alignment (s, bed->plt_alignment)) return FALSE; if (bed->want_plt_sym) @@ -1654,7 +1611,7 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) flags | SEC_READONLY); htab->root.srelplt = s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; if (htab->root.sgot == NULL @@ -1693,7 +1650,7 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) flags | SEC_READONLY); htab->srelbss = s; if (s == NULL - || ! bfd_set_section_alignment (abfd, s, ptralign)) + || !bfd_set_section_alignment (s, ptralign)) return FALSE; } } @@ -1701,72 +1658,7 @@ m32r_elf_create_dynamic_sections (bfd *abfd, struct bfd_link_info *info) return TRUE; } -/* Copy the extra info we tack onto an elf_link_hash_entry. */ - -static void -m32r_elf_copy_indirect_symbol (struct bfd_link_info *info, - struct elf_link_hash_entry *dir, - struct elf_link_hash_entry *ind) -{ - struct elf_m32r_link_hash_entry * edir; - struct elf_m32r_link_hash_entry * eind; - - edir = (struct elf_m32r_link_hash_entry *) dir; - eind = (struct elf_m32r_link_hash_entry *) ind; - - if (eind->dyn_relocs != NULL) - { - if (edir->dyn_relocs != NULL) - { - 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_dyn_relocs *q; - - for (q = edir->dyn_relocs; q != NULL; q = q->next) - if (q->sec == p->sec) - { - q->pc_count += p->pc_count; - q->count += p->count; - *pp = p->next; - break; - } - if (q == NULL) - pp = &p->next; - } - *pp = edir->dyn_relocs; - } - - edir->dyn_relocs = eind->dyn_relocs; - eind->dyn_relocs = NULL; - } - - _bfd_elf_link_hash_copy_indirect (info, dir, ind); -} - -/* Find dynamic relocs for H that apply to read-only sections. */ - -static asection * -readonly_dynrelocs (struct elf_link_hash_entry *h) -{ - struct elf_dyn_relocs *p; - struct elf_m32r_link_hash_entry *eh = (struct elf_m32r_link_hash_entry *) h; - - for (p = eh->dyn_relocs; p != NULL; p = p->next) - { - asection *s = p->sec->output_section; - - if (s != NULL && (s->flags & SEC_READONLY) != 0) - return p->sec; - } - return NULL; -} - /* Adjust a symbol defined by a dynamic object and referenced by a regular object. The current definition is in some section of the dynamic object, but we're not including those sections. We have to @@ -1857,7 +1749,7 @@ m32r_elf_adjust_dynamic_symbol (struct bfd_link_info *info, /* 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)) + if (0 && !_bfd_elf_readonly_dynrelocs (h)) { h->non_got_ref = 0; return TRUE; @@ -1905,7 +1797,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) { struct bfd_link_info *info; struct elf_m32r_link_hash_table *htab; - struct elf_m32r_link_hash_entry *eh; struct elf_dyn_relocs *p; if (h->root.type == bfd_link_hash_indirect) @@ -1916,8 +1807,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) if (htab == NULL) return FALSE; - eh = (struct elf_m32r_link_hash_entry *) h; - if (htab->root.dynamic_sections_created && h->plt.refcount > 0) { @@ -2000,7 +1889,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) else h->got.offset = (bfd_vma) -1; - if (eh->dyn_relocs == NULL) + if (h->dyn_relocs == NULL) return TRUE; /* In the shared -Bsymbolic case, discard space allocated for @@ -2017,7 +1906,7 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) { struct elf_dyn_relocs **pp; - for (pp = &eh->dyn_relocs; (p = *pp) != NULL;) + for (pp = &h->dyn_relocs; (p = *pp) != NULL;) { p->count -= p->pc_count; p->pc_count = 0; @@ -2030,11 +1919,11 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) /* Also discard relocs on undefined weak syms with non-default visibility. */ - if (eh->dyn_relocs != NULL + if (h->dyn_relocs != NULL && h->root.type == bfd_link_hash_undefweak) { if (ELF_ST_VISIBILITY (h->other) != STV_DEFAULT) - eh->dyn_relocs = NULL; + h->dyn_relocs = NULL; /* Make sure undefined weak symbols are output as a dynamic symbol in PIEs. */ @@ -2074,13 +1963,13 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) goto keep; } - eh->dyn_relocs = NULL; + h->dyn_relocs = NULL; keep: ; } /* Finally, allocate space. */ - for (p = eh->dyn_relocs; p != NULL; p = p->next) + for (p = h->dyn_relocs; p != NULL; p = p->next) { asection *sreloc = elf_section_data (p->sec)->sreloc; sreloc->size += p->count * sizeof (Elf32_External_Rela); @@ -2089,33 +1978,6 @@ allocate_dynrelocs (struct elf_link_hash_entry *h, void * inf) return TRUE; } -/* Set DF_TEXTREL if we find any dynamic relocs that apply to - read-only sections. */ - -static bfd_boolean -maybe_set_textrel (struct elf_link_hash_entry *h, void *info_p) -{ - asection *sec; - - if (h->root.type == bfd_link_hash_indirect) - return TRUE; - - sec = readonly_dynrelocs (h); - if (sec != NULL) - { - struct bfd_link_info *info = (struct bfd_link_info *) info_p; - - info->flags |= DF_TEXTREL; - info->callbacks->minfo - (_("%pB: dynamic relocation against `%pT' in read-only section `%pA'\n"), - sec->owner, h->root.root.string, sec); - - /* Not an error, just cut short the traversal. */ - return FALSE; - } - return TRUE; -} - /* Set the sizes of the dynamic sections. */ static bfd_boolean @@ -2234,7 +2096,7 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* Strip this section if we don't need it; see the comment below. */ } - else if (CONST_STRNEQ (bfd_get_section_name (dynobj, s), ".rela")) + else if (CONST_STRNEQ (bfd_section_name (s), ".rela")) { if (s->size != 0 && s != htab->root.srelplt) relocs = TRUE; @@ -2311,7 +2173,8 @@ m32r_elf_size_dynamic_sections (bfd *output_bfd ATTRIBUTE_UNUSED, /* If any dynamic relocs apply to a read-only section, then we need a DT_TEXTREL entry. */ if ((info->flags & DF_TEXTREL) == 0) - elf_link_hash_traverse (&htab->root, maybe_set_textrel, info); + elf_link_hash_traverse (&htab->root, + _bfd_elf_maybe_set_textrel, info); if ((info->flags & DF_TEXTREL) != 0) { @@ -2551,12 +2414,12 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, && ELF_ST_VISIBILITY (h->other) == STV_DEFAULT) ; else if (!bfd_link_relocatable (info)) - (*info->callbacks->undefined_symbol) - (info, h->root.root.string, input_bfd, - input_section, offset, - (info->unresolved_syms_in_objects == RM_GENERATE_ERROR - || ELF_ST_VISIBILITY (h->other))); - } + info->callbacks->undefined_symbol + (info, h->root.root.string, input_bfd, input_section, offset, + (info->unresolved_syms_in_objects == RM_DIAGNOSE + && !info->warn_unresolved_syms) + || ELF_ST_VISIBILITY (h->other)); + } if (sec != NULL && discarded_section (sec)) RELOC_AGAINST_DISCARDED_SECTION (info, input_bfd, input_section, @@ -2954,7 +2817,7 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, const char *name; BFD_ASSERT (sec != NULL); - name = bfd_get_section_name (sec->owner, sec); + name = bfd_section_name (sec); if ( strcmp (name, ".sdata") == 0 || strcmp (name, ".sbss") == 0 @@ -3022,7 +2885,7 @@ m32r_elf_relocate_section (bfd *output_bfd ATTRIBUTE_UNUSED, name = (bfd_elf_string_from_elf_section (input_bfd, symtab_hdr->sh_link, sym->st_name)); if (name == NULL || *name == '\0') - name = bfd_section_name (input_bfd, sec); + name = bfd_section_name (sec); } if (errmsg != NULL) @@ -3403,9 +3266,8 @@ m32r_elf_object_p (bfd *abfd) /* Store the machine number in the flags field. */ -static void -m32r_elf_final_write_processing (bfd *abfd, - bfd_boolean linker ATTRIBUTE_UNUSED) +static bfd_boolean +m32r_elf_final_write_processing (bfd *abfd) { unsigned long val; @@ -3419,6 +3281,7 @@ m32r_elf_final_write_processing (bfd *abfd, elf_elfheader (abfd)->e_flags &=~ EF_M32R_ARCH; elf_elfheader (abfd)->e_flags |= val; + return _bfd_elf_final_write_processing (abfd); } /* Function to keep M32R specific file flags. */ @@ -3561,15 +3424,6 @@ m32r_elf_check_relocs (bfd *abfd, if (bfd_link_relocatable (info)) return TRUE; - /* Don't do anything special with non-loaded, non-alloced sections. - In particular, any relocs in such sections should not affect GOT - and PLT reference counting (ie. we don't allow them to create GOT - or PLT entries), there's no possibility or desire to optimize TLS - relocs, and there's not much point in propagating relocs to shared - libs that the dynamic linker won't relocate. */ - if ((sec->flags & SEC_ALLOC) == 0) - return TRUE; - sreloc = NULL; symtab_hdr = &elf_tdata (abfd)->symtab_hdr; sym_hashes = elf_sym_hashes (abfd); @@ -3751,7 +3605,7 @@ m32r_elf_check_relocs (bfd *abfd, /* If this is a global symbol, we count the number of relocations we need for this symbol. */ if (h != NULL) - head = &((struct elf_m32r_link_hash_entry *) h)->dyn_relocs; + head = &h->dyn_relocs; else { /* Track dynamic relocs needed for local syms too. */ @@ -3775,7 +3629,7 @@ m32r_elf_check_relocs (bfd *abfd, p = *head; if (p == NULL || p->sec != sec) { - bfd_size_type amt = sizeof (*p); + size_t amt = sizeof (*p); p = bfd_alloc (dynobj, amt); if (p == NULL) @@ -3807,15 +3661,11 @@ m32r_elf_check_relocs (bfd *abfd, /* This relocation describes which C++ vtable entries are actually used. Record for later use during GC. */ case R_M32R_GNU_VTENTRY: - BFD_ASSERT (h != NULL); - if (h != NULL - && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) + if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_offset)) return FALSE; break; case R_M32R_RELA_GNU_VTENTRY: - BFD_ASSERT (h != NULL); - if (h != NULL - && !bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) + if (!bfd_elf_gc_record_vtentry (abfd, sec, h, rel->r_addend)) return FALSE; break; } @@ -3831,6 +3681,18 @@ static const struct bfd_elf_special_section m32r_elf_special_sections[] = { NULL, 0, 0, 0, 0 } }; +static bfd_boolean +m32r_elf_section_flags (const Elf_Internal_Shdr *hdr) +{ + const char *name = hdr->bfd_section->name; + + if (strncmp (name, ".sbss", 5) == 0 + || strncmp (name, ".sdata", 6) == 0) + hdr->bfd_section->flags |= SEC_SMALL_DATA; + + return TRUE; +} + static enum elf_reloc_type_class m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, const asection *rel_sec ATTRIBUTE_UNUSED, @@ -3873,7 +3735,6 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, #define elf_backend_adjust_dynamic_symbol m32r_elf_adjust_dynamic_symbol #define elf_backend_finish_dynamic_symbol m32r_elf_finish_dynamic_symbol #define elf_backend_reloc_type_class m32r_elf_reloc_type_class -#define elf_backend_copy_indirect_symbol m32r_elf_copy_indirect_symbol #define elf_backend_can_gc_sections 1 /*#if !USE_REL @@ -3901,6 +3762,7 @@ m32r_elf_reloc_type_class (const struct bfd_link_info *info ATTRIBUTE_UNUSED, #define bfd_elf32_bfd_set_private_flags m32r_elf_set_private_flags #define bfd_elf32_bfd_print_private_bfd_data m32r_elf_print_private_bfd_data #define elf_backend_special_sections m32r_elf_special_sections +#define elf_backend_section_flags m32r_elf_section_flags #define elf_backend_linux_prpsinfo32_ugid16 TRUE