This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: dynamic sections attached to first object file
- From: Alan Modra <amodra at gmail dot com>
- To: binutils at sourceware dot org
- Date: Mon, 2 Jul 2012 12:34:01 +0930
- Subject: Re: dynamic sections attached to first object file
- References: <20120629144732.GE3203@bubble.grove.modra.org>
I missed a few places where dynamic sections should be created with
the "anyway" variant of bfd_make_section, and retrieved with
bfd_get_linker_section. MIPS maintainers, I'm making a guess as to
correct linker behaviour on finding an existing .rtproc section. Old
behaviour was to overwrite an input section called .rtproc with the
linker section. New behaviour with this patch is to link a user
.rtproc like any other non-special section, and create a separate
input section for the linker .rtproc. I think that is correct when
the first input object file is a shared lib and has a .rtproc section
(which is dropped from linker output like all other shared lib
sections). I'm guessing that you shouldn't drop the linker created
.rtproc in this case.
sunos.c also uses a couple of sections, .need and .rules, that are
attached to dynobj but don't set SEC_LINKER_CREATED. They probably
ought to, but that will mean other code changes to write them out, so
I left them alone.
* 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.
Index: bfd/elf32-m32c.c
===================================================================
RCS file: /cvs/src/src/bfd/elf32-m32c.c,v
retrieving revision 1.27
diff -u -p -r1.27 elf32-m32c.c
--- bfd/elf32-m32c.c 29 Jun 2012 14:45:59 -0000 1.27
+++ bfd/elf32-m32c.c 1 Jul 2012 05:26:28 -0000
@@ -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_
}
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;
Index: bfd/elfxx-mips.c
===================================================================
RCS file: /cvs/src/src/bfd/elfxx-mips.c,v
retrieving revision 1.306
diff -u -p -r1.306 elfxx-mips.c
--- bfd/elfxx-mips.c 29 Jun 2012 14:46:03 -0000 1.306
+++ bfd/elfxx-mips.c 30 Jun 2012 14:57:44 -0000
@@ -4874,7 +4874,7 @@ mips_elf_create_got_section (bfd *abfd,
/* 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,
|= 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, str
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;
Index: bfd/sunos.c
===================================================================
RCS file: /cvs/src/src/bfd/sunos.c,v
retrieving revision 1.27
diff -u -p -r1.27 sunos.c
--- bfd/sunos.c 16 May 2012 14:26:46 -0000 1.27
+++ bfd/sunos.c 30 Jun 2012 14:57:46 -0000
@@ -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_i
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_i
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_i
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_i
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_
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_
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 *ou
++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 *ou
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 *ou
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 *ou
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 *ou
/* 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 *ou
/* 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 *ou
}
}
- 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 *ou
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_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_
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_li
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_li
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_li
/* 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_li
/* 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, st
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, st
/* 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, st
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, st
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);
--
Alan Modra
Australia Development Lab, IBM