From: Alan Modra Date: Mon, 2 Jul 2012 03:02:45 +0000 (+0000) Subject: * elf32-m32c.c (m32c_elf_check_relocs): Use bfd_make_section X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=87e0a731c84e58c8a6f63b38baacbc066a70ab28;p=binutils-gdb.git * elf32-m32c.c (m32c_elf_check_relocs): Use bfd_make_section "anyway" variant when creating .plt. (m32c_elf_relax_plt_section): Remove redundant test and unused param. (m32c_elf_relax_section): Test SEC_LINKER_CREATED before calling m32c_elf_relax_plt_section. * elfxx-mips.c (mips_elf_create_got_section): Use make anyway variant when creating .got and .got.plt. (_bfd_mips_elf_final_link): Likewise for .rtproc, and use bfd_get_linker_section. * sunos.c: Similarly throughout. --- diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 6083702f022..b594c66c0a7 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,16 @@ +2012-07-02 Alan Modra + + * elf32-m32c.c (m32c_elf_check_relocs): Use bfd_make_section + "anyway" variant when creating .plt. + (m32c_elf_relax_plt_section): Remove redundant test and unused param. + (m32c_elf_relax_section): Test SEC_LINKER_CREATED before calling + m32c_elf_relax_plt_section. + * elfxx-mips.c (mips_elf_create_got_section): Use make anyway variant + when creating .got and .got.plt. + (_bfd_mips_elf_final_link): Likewise for .rtproc, and use + bfd_get_linker_section. + * sunos.c: Similarly throughout. + 2012-07-01 Andreas Schwab * elf.c (_bfd_elf_make_section_from_shdr): Fix typo in error diff --git a/bfd/elf32-m32c.c b/bfd/elf32-m32c.c index 6c4352d7e1e..667a4828d27 100644 --- a/bfd/elf32-m32c.c +++ b/bfd/elf32-m32c.c @@ -639,7 +639,8 @@ m32c_elf_check_relocs flagword flags = (SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED | SEC_READONLY | SEC_CODE); - splt = bfd_make_section_with_flags (dynobj, ".plt", flags); + splt = bfd_make_section_anyway_with_flags (dynobj, ".plt", + flags); if (splt == NULL || ! bfd_set_section_alignment (dynobj, splt, 1)) return FALSE; @@ -1031,8 +1032,7 @@ m32c_relax_plt_realloc (struct elf_link_hash_entry *h, } static bfd_boolean -m32c_elf_relax_plt_section (bfd *dynobj, - asection *splt, +m32c_elf_relax_plt_section (asection *splt, struct bfd_link_info *info, bfd_boolean *again) { @@ -1045,11 +1045,6 @@ m32c_elf_relax_plt_section (bfd *dynobj, if (info->relocatable) return TRUE; - /* We only relax the .plt section at the moment. */ - if (dynobj != elf_hash_table (info)->dynobj - || strcmp (splt->name, ".plt") != 0) - return TRUE; - /* Quick check for an empty plt. */ if (splt->size == 0) return TRUE; @@ -1337,8 +1332,9 @@ m32c_elf_relax_section int machine; if (abfd == elf_hash_table (link_info)->dynobj + && (sec->flags & SEC_LINKER_CREATED) != 0 && strcmp (sec->name, ".plt") == 0) - return m32c_elf_relax_plt_section (abfd, sec, link_info, again); + return m32c_elf_relax_plt_section (sec, link_info, again); /* Assume nothing changes. */ *again = FALSE; diff --git a/bfd/elfxx-mips.c b/bfd/elfxx-mips.c index de5e9c6674a..4440170e6e6 100644 --- a/bfd/elfxx-mips.c +++ b/bfd/elfxx-mips.c @@ -4874,7 +4874,7 @@ mips_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) /* We have to use an alignment of 2**4 here because this is hardcoded in the function stub generation and in the linker script. */ - s = bfd_make_section_with_flags (abfd, ".got", flags); + s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 4)) return FALSE; @@ -4926,9 +4926,11 @@ mips_elf_create_got_section (bfd *abfd, struct bfd_link_info *info) |= SHF_ALLOC | SHF_WRITE | SHF_MIPS_GPREL; /* We also need a .got.plt section when generating PLTs. */ - s = bfd_make_section_with_flags (abfd, ".got.plt", - SEC_ALLOC | SEC_LOAD | SEC_HAS_CONTENTS - | SEC_IN_MEMORY | SEC_LINKER_CREATED); + s = bfd_make_section_anyway_with_flags (abfd, ".got.plt", + SEC_ALLOC | SEC_LOAD + | SEC_HAS_CONTENTS + | SEC_IN_MEMORY + | SEC_LINKER_CREATED); if (s == NULL) return FALSE; htab->sgotplt = s; @@ -13309,15 +13311,15 @@ _bfd_mips_elf_final_link (bfd *abfd, struct bfd_link_info *info) if (SGI_COMPAT (abfd) && info->shared) { /* Create .rtproc section. */ - rtproc_sec = bfd_get_section_by_name (abfd, ".rtproc"); + rtproc_sec = bfd_get_linker_section (abfd, ".rtproc"); if (rtproc_sec == NULL) { flagword flags = (SEC_HAS_CONTENTS | SEC_IN_MEMORY | SEC_LINKER_CREATED | SEC_READONLY); - rtproc_sec = bfd_make_section_with_flags (abfd, - ".rtproc", - flags); + rtproc_sec = bfd_make_section_anyway_with_flags (abfd, + ".rtproc", + flags); if (rtproc_sec == NULL || ! bfd_set_section_alignment (abfd, rtproc_sec, 4)) return FALSE; diff --git a/bfd/sunos.c b/bfd/sunos.c index bd140015eb7..028fb280e3b 100644 --- a/bfd/sunos.c +++ b/bfd/sunos.c @@ -748,49 +748,53 @@ sunos_create_dynamic_sections (bfd *abfd, /* The .dynamic section holds the basic dynamic information: the sun4_dynamic structure, the dynamic debugger information, and the sun4_dynamic_link structure. */ - s = bfd_make_section_with_flags (abfd, ".dynamic", flags); + s = bfd_make_section_anyway_with_flags (abfd, ".dynamic", flags); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .got section holds the global offset table. The address is put in the ld_got field. */ - s = bfd_make_section_with_flags (abfd, ".got", flags); + s = bfd_make_section_anyway_with_flags (abfd, ".got", flags); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .plt section holds the procedure linkage table. The address is put in the ld_plt field. */ - s = bfd_make_section_with_flags (abfd, ".plt", flags | SEC_CODE); + s = bfd_make_section_anyway_with_flags (abfd, ".plt", flags | SEC_CODE); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .dynrel section holds the dynamic relocs. The address is put in the ld_rel field. */ - s = bfd_make_section_with_flags (abfd, ".dynrel", flags | SEC_READONLY); + s = bfd_make_section_anyway_with_flags (abfd, ".dynrel", + flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .hash section holds the dynamic hash table. The address is put in the ld_hash field. */ - s = bfd_make_section_with_flags (abfd, ".hash", flags | SEC_READONLY); + s = bfd_make_section_anyway_with_flags (abfd, ".hash", + flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .dynsym section holds the dynamic symbols. The address is put in the ld_stab field. */ - s = bfd_make_section_with_flags (abfd, ".dynsym", flags | SEC_READONLY); + s = bfd_make_section_anyway_with_flags (abfd, ".dynsym", + flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; /* The .dynstr section holds the dynamic symbol string table. The address is put in the ld_symbols field. */ - s = bfd_make_section_with_flags (abfd, ".dynstr", flags | SEC_READONLY); + s = bfd_make_section_anyway_with_flags (abfd, ".dynstr", + flags | SEC_READONLY); if (s == NULL || ! bfd_set_section_alignment (abfd, s, 2)) return FALSE; @@ -805,7 +809,7 @@ sunos_create_dynamic_sections (bfd *abfd, dynobj = sunos_hash_table (info)->dynobj; - s = bfd_get_section_by_name (dynobj, ".got"); + s = bfd_get_linker_section (dynobj, ".got"); if (s->size == 0) s->size = BYTES_IN_WORD; @@ -1325,11 +1329,11 @@ sunos_scan_std_relocs (struct bfd_link_info *info, if (! sunos_create_dynamic_sections (abfd, info, FALSE)) return FALSE; dynobj = sunos_hash_table (info)->dynobj; - splt = bfd_get_section_by_name (dynobj, ".plt"); - srel = bfd_get_section_by_name (dynobj, ".dynrel"); + splt = bfd_get_linker_section (dynobj, ".plt"); + srel = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (splt != NULL && srel != NULL); - sgot = bfd_get_section_by_name (dynobj, ".got"); + sgot = bfd_get_linker_section (dynobj, ".got"); BFD_ASSERT (sgot != NULL); if (sgot->size == 0) sgot->size = BYTES_IN_WORD; @@ -1475,9 +1479,9 @@ sunos_scan_ext_relocs (struct bfd_link_info *info, if (! sunos_create_dynamic_sections (abfd, info, FALSE)) return FALSE; dynobj = sunos_hash_table (info)->dynobj; - splt = bfd_get_section_by_name (dynobj, ".plt"); - sgot = bfd_get_section_by_name (dynobj, ".got"); - srel = bfd_get_section_by_name (dynobj, ".dynrel"); + splt = bfd_get_linker_section (dynobj, ".plt"); + sgot = bfd_get_linker_section (dynobj, ".got"); + srel = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); /* Make sure we have an initial entry in the .got table. */ @@ -1543,9 +1547,9 @@ sunos_scan_ext_relocs (struct bfd_link_info *info, if (! sunos_create_dynamic_sections (abfd, info, TRUE)) return FALSE; dynobj = sunos_hash_table (info)->dynobj; - splt = bfd_get_section_by_name (dynobj, ".plt"); - sgot = bfd_get_section_by_name (dynobj, ".got"); - srel = bfd_get_section_by_name (dynobj, ".dynrel"); + splt = bfd_get_linker_section (dynobj, ".plt"); + sgot = bfd_get_linker_section (dynobj, ".got"); + srel = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); } @@ -1590,9 +1594,9 @@ sunos_scan_ext_relocs (struct bfd_link_info *info, if (! sunos_create_dynamic_sections (abfd, info, FALSE)) return FALSE; dynobj = sunos_hash_table (info)->dynobj; - splt = bfd_get_section_by_name (dynobj, ".plt"); - sgot = bfd_get_section_by_name (dynobj, ".got"); - srel = bfd_get_section_by_name (dynobj, ".dynrel"); + splt = bfd_get_linker_section (dynobj, ".plt"); + sgot = bfd_get_linker_section (dynobj, ".got"); + srel = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (splt != NULL && sgot != NULL && srel != NULL); /* Make sure we have an initial entry in the .got table. */ @@ -1815,7 +1819,7 @@ sunos_scan_dynamic_symbol (struct sunos_link_hash_entry *h, void * data) regular symbols includes the debugging symbols, which have long names and are often duplicated in several object files. There are no debugging symbols in the dynamic symbols. */ - s = bfd_get_section_by_name (dynobj, ".dynstr"); + s = bfd_get_linker_section (dynobj, ".dynstr"); BFD_ASSERT (s != NULL); contents = bfd_realloc (s->contents, s->size + len + 1); if (contents == NULL) @@ -1834,7 +1838,7 @@ sunos_scan_dynamic_symbol (struct sunos_link_hash_entry *h, void * data) hash &= 0x7fffffff; hash %= sunos_hash_table (info)->bucketcount; - s = bfd_get_section_by_name (dynobj, ".hash"); + s = bfd_get_linker_section (dynobj, ".hash"); BFD_ASSERT (s != NULL); if (GET_SWORD (dynobj, s->contents + hash * HASH_ENTRY_SIZE) == -1) @@ -1931,14 +1935,14 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, ++sunos_hash_table (info)->dynsymcount; h->dynindx = -2; } + s = bfd_get_linker_section (dynobj, ".got"); + BFD_ASSERT (s != NULL); h->root.root.type = bfd_link_hash_defined; - h->root.root.u.def.section = bfd_get_section_by_name (dynobj, ".got"); + h->root.root.u.def.section = s; /* If the .got section is more than 0x1000 bytes, we set __GLOBAL_OFFSET_TABLE_ to be 0x1000 bytes into the section, so that 13 bit relocations have a greater chance of working. */ - s = bfd_get_section_by_name (dynobj, ".got"); - BFD_ASSERT (s != NULL); if (s->size >= 0x1000) h->root.root.u.def.value = 0x1000; else @@ -1951,7 +1955,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, up the dynamic linking information. */ if (sunos_hash_table (info)->dynamic_sections_needed) { - *sdynptr = bfd_get_section_by_name (dynobj, ".dynamic"); + *sdynptr = bfd_get_linker_section (dynobj, ".dynamic"); /* The .dynamic section is always the same size. */ s = *sdynptr; @@ -1968,7 +1972,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, symbols. We build the dynamic symbol string table (.dynstr) in a traversal of the symbol table using sunos_scan_dynamic_symbol. */ - s = bfd_get_section_by_name (dynobj, ".dynsym"); + s = bfd_get_linker_section (dynobj, ".dynsym"); BFD_ASSERT (s != NULL); s->size = dynsymcount * sizeof (struct external_nlist); s->contents = bfd_alloc (output_bfd, s->size); @@ -1989,7 +1993,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, bucketcount = dynsymcount; else bucketcount = 1; - s = bfd_get_section_by_name (dynobj, ".hash"); + s = bfd_get_linker_section (dynobj, ".hash"); BFD_ASSERT (s != NULL); hashalloc = (dynsymcount + bucketcount - 1) * HASH_ENTRY_SIZE; s->contents = bfd_zalloc (dynobj, hashalloc); @@ -2013,7 +2017,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, /* The SunOS native linker seems to align the total size of the symbol strings to a multiple of 8. I don't know if this is important, but it can't hurt much. */ - s = bfd_get_section_by_name (dynobj, ".dynstr"); + s = bfd_get_linker_section (dynobj, ".dynstr"); BFD_ASSERT (s != NULL); if ((s->size & 7) != 0) { @@ -2032,7 +2036,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, /* Now that we have worked out the sizes of the procedure linkage table and the dynamic relocs, allocate storage for them. */ - s = bfd_get_section_by_name (dynobj, ".plt"); + s = bfd_get_linker_section (dynobj, ".plt"); BFD_ASSERT (s != NULL); if (s->size != 0) { @@ -2056,7 +2060,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, } } - s = bfd_get_section_by_name (dynobj, ".dynrel"); + s = bfd_get_linker_section (dynobj, ".dynrel"); if (s->size != 0) { s->contents = bfd_alloc (dynobj, s->size); @@ -2068,7 +2072,7 @@ bfd_sunos_size_dynamic_sections (bfd *output_bfd, s->reloc_count = 0; /* Make space for the global offset table. */ - s = bfd_get_section_by_name (dynobj, ".got"); + s = bfd_get_linker_section (dynobj, ".got"); s->contents = bfd_alloc (dynobj, s->size); if (s->contents == NULL) return FALSE; @@ -2114,10 +2118,10 @@ sunos_write_dynamic_symbol (bfd *output_bfd, bfd_vma r_address; dynobj = sunos_hash_table (info)->dynobj; - splt = bfd_get_section_by_name (dynobj, ".plt"); + splt = bfd_get_linker_section (dynobj, ".plt"); p = splt->contents + h->plt_offset; - s = bfd_get_section_by_name (dynobj, ".dynrel"); + s = bfd_get_linker_section (dynobj, ".dynrel"); r_address = (splt->output_section->vma + splt->output_offset @@ -2301,7 +2305,7 @@ sunos_write_dynamic_symbol (bfd *output_bfd, return TRUE; } - s = bfd_get_section_by_name (sunos_hash_table (info)->dynobj, ".dynsym"); + s = bfd_get_linker_section (sunos_hash_table (info)->dynobj, ".dynsym"); BFD_ASSERT (s != NULL); outsym = ((struct external_nlist *) (s->contents + h->dynindx * EXTERNAL_NLIST_SIZE)); @@ -2356,7 +2360,7 @@ sunos_check_dynamic_reloc (struct bfd_link_info *info, asection *splt; /* Redirect the relocation to the PLT entry. */ - splt = bfd_get_section_by_name (dynobj, ".plt"); + splt = bfd_get_linker_section (dynobj, ".plt"); *relocationp = (splt->output_section->vma + splt->output_offset + h->plt_offset); @@ -2451,7 +2455,7 @@ sunos_check_dynamic_reloc (struct bfd_link_info *info, BFD_ASSERT (got_offsetp != NULL && *got_offsetp != 0); - sgot = bfd_get_section_by_name (dynobj, ".got"); + sgot = bfd_get_linker_section (dynobj, ".got"); /* We set the least significant bit to indicate whether we have already initialized the GOT entry. */ @@ -2473,7 +2477,7 @@ sunos_check_dynamic_reloc (struct bfd_link_info *info, /* We need to create a GLOB_DAT or 32 reloc to tell the dynamic linker to fill in this entry in the table. */ - s = bfd_get_section_by_name (dynobj, ".dynrel"); + s = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (s != NULL); BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size); @@ -2603,7 +2607,7 @@ sunos_check_dynamic_reloc (struct bfd_link_info *info, /* It looks like this is a reloc we are supposed to copy. */ - s = bfd_get_section_by_name (dynobj, ".dynrel"); + s = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (s != NULL); BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) < s->size); @@ -2701,7 +2705,7 @@ sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info) dynobj = sunos_hash_table (info)->dynobj; - sdyn = bfd_get_section_by_name (dynobj, ".dynamic"); + sdyn = bfd_get_linker_section (dynobj, ".dynamic"); BFD_ASSERT (sdyn != NULL); /* Finish up the .need section. The linker emulation code filled it @@ -2731,7 +2735,7 @@ sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info) /* The first entry in the .got section is the address of the dynamic information, unless this is a shared library. */ - s = bfd_get_section_by_name (dynobj, ".got"); + s = bfd_get_linker_section (dynobj, ".got"); BFD_ASSERT (s != NULL); if (info->shared || sdyn->size == 0) PUT_WORD (dynobj, 0, s->contents); @@ -2793,30 +2797,30 @@ sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info) PUT_WORD (dynobj, s->output_section->filepos + s->output_offset, esdl.ld_rules); - s = bfd_get_section_by_name (dynobj, ".got"); + s = bfd_get_linker_section (dynobj, ".got"); BFD_ASSERT (s != NULL); PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_got); - s = bfd_get_section_by_name (dynobj, ".plt"); + s = bfd_get_linker_section (dynobj, ".plt"); BFD_ASSERT (s != NULL); PUT_WORD (dynobj, s->output_section->vma + s->output_offset, esdl.ld_plt); PUT_WORD (dynobj, s->size, esdl.ld_plt_sz); - s = bfd_get_section_by_name (dynobj, ".dynrel"); + s = bfd_get_linker_section (dynobj, ".dynrel"); BFD_ASSERT (s != NULL); BFD_ASSERT (s->reloc_count * obj_reloc_entry_size (dynobj) == s->size); PUT_WORD (dynobj, s->output_section->filepos + s->output_offset, esdl.ld_rel); - s = bfd_get_section_by_name (dynobj, ".hash"); + s = bfd_get_linker_section (dynobj, ".hash"); BFD_ASSERT (s != NULL); PUT_WORD (dynobj, s->output_section->filepos + s->output_offset, esdl.ld_hash); - s = bfd_get_section_by_name (dynobj, ".dynsym"); + s = bfd_get_linker_section (dynobj, ".dynsym"); BFD_ASSERT (s != NULL); PUT_WORD (dynobj, s->output_section->filepos + s->output_offset, esdl.ld_stab); @@ -2826,7 +2830,7 @@ sunos_finish_dynamic_link (bfd *abfd, struct bfd_link_info *info) PUT_WORD (dynobj, (bfd_vma) sunos_hash_table (info)->bucketcount, esdl.ld_buckets); - s = bfd_get_section_by_name (dynobj, ".dynstr"); + s = bfd_get_linker_section (dynobj, ".dynstr"); BFD_ASSERT (s != NULL); PUT_WORD (dynobj, s->output_section->filepos + s->output_offset, esdl.ld_symbols);