aboutsummaryrefslogtreecommitdiff
path: root/bfd
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2017-03-22 17:27:49 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2017-06-06 09:53:38 +0100
commit7bdf4127c38081c7764c0bf1db55d0b2e56391dc (patch)
tree099667b65c51c4ba0289abadb4cf363f63fcf3b8 /bfd
parent458ad2b83ecf4d764703767bccf19723ca741f00 (diff)
downloadgdb-7bdf4127c38081c7764c0bf1db55d0b2e56391dc.zip
gdb-7bdf4127c38081c7764c0bf1db55d0b2e56391dc.tar.gz
gdb-7bdf4127c38081c7764c0bf1db55d0b2e56391dc.tar.bz2
ld: Allow section groups to be resolved as part of a relocatable link
This commit adds a new linker feature: the ability to resolve section groups as part of a relocatable link. Currently section groups are automatically resolved when performing a final link, and are carried through when performing a relocatable link. By carried through this means that one copy of each section group (from all the copies that might be found in all the input files) is placed into the output file. Sections that are part of a section group will not match input section specifiers within a linker script and are forcibly kept as separate sections. There is a slight resemblance between section groups and common section. Like section groups, common sections are carried through when performing a relocatable link, and resolved (allocated actual space) only at final link time. However, with common sections there is an ability to force the linker to allocate space for the common sections when performing a relocatable link, there's currently no such ability for section groups. This commit adds such a mechanism. This new facility can be accessed in two ways, first there's a command line switch --force-group-allocation, second, there's a new linker script command FORCE_GROUP_ALLOCATION. If one of these is used when performing a relocatable link then the linker will resolve the section groups as though it were performing a final link, the section group will be deleted, and the members of the group will be placed like normal input sections. If there are multiple copies of the group (from multiple input files) then only one copy of the group members will be placed, the duplicate copies will be discarded. Unlike common sections that have the --no-define-common command line flag, and INHIBIT_COMMON_ALLOCATION linker script command there is no way to prevent group resolution during a final link, this is because the ELF gABI specifically prohibits the presence of SHT_GROUP sections in a fully linked executable. However, the code as written should make adding such a feature trivial, setting the new resolve_section_groups flag to false during a final link should work as you'd expect. bfd/ChangeLog: * elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark SEC_GROUP sections as SEC_EXCLUDE. (bfd_elf_set_group_contents): Replace use of abort with an assert. (assign_section_numbers): Use resolve_section_groups flag instead of relocatable link type. (_bfd_elf_init_private_section_data): Use resolve_section_groups flag instead of checking the final_link flag for part of the checks in here. Fix white space as a result. * elflink.c (elf_link_input_bfd): Use resolve_section_groups flag instead of relocatable link type. (bfd_elf_final_link): Likewise. include/ChangeLog: * bfdlink.h (struct bfd_link_info): Add new resolve_section_groups flag. ld/ChangeLog: * ld.h (struct args_type): Add force_group_allocation field. * ldgram.y: Add support for FORCE_GROUP_ALLOCATION. * ldlex.h: Likewise. * ldlex.l: Likewise. * lexsup.c: Likewise. * ldlang.c (unique_section_p): Check resolve_section_groups flag not the relaxable link flag. (lang_add_section): Discard section groups when we're resolving groups. Clear the SEC_LINK_ONCE flag if we're resolving section groups. * ldmain.c (main): Initialise resolve_section_groups flag in link_info based on command line flags. * testsuite/ld-elf/group11.d: New file. * testsuite/ld-elf/group12.d: New file. * testsuite/ld-elf/group12.ld: New file. * NEWS: Mention new features. * ld.texinfo (Options): Document --force-group-allocation. (Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION.
Diffstat (limited to 'bfd')
-rw-r--r--bfd/ChangeLog14
-rw-r--r--bfd/elf.c35
-rw-r--r--bfd/elflink.c6
3 files changed, 35 insertions, 20 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 7dfc62f..99329c8 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,3 +1,17 @@
+2017-06-06 Andrew Burgess <andrew.burgess@embecosm.com>
+
+ * elf.c (_bfd_elf_make_section_from_shdr): Don't initially mark
+ SEC_GROUP sections as SEC_EXCLUDE.
+ (bfd_elf_set_group_contents): Replace use of abort with an assert.
+ (assign_section_numbers): Use resolve_section_groups flag instead
+ of relocatable link type.
+ (_bfd_elf_init_private_section_data): Use resolve_section_groups
+ flag instead of checking the final_link flag for part of the
+ checks in here. Fix white space as a result.
+ * elflink.c (elf_link_input_bfd): Use resolve_section_groups flag
+ instead of relocatable link type.
+ (bfd_elf_final_link): Likewise.
+
2017-06-06 Jose E. Marchesi <jose.marchesi@oracle.com>
* elfxx-mips.c (_bfd_mips_elf_relocate_section): Remove unused
diff --git a/bfd/elf.c b/bfd/elf.c
index b0da500..bab1e16 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -983,7 +983,7 @@ _bfd_elf_make_section_from_shdr (bfd *abfd,
if (hdr->sh_type != SHT_NOBITS)
flags |= SEC_HAS_CONTENTS;
if (hdr->sh_type == SHT_GROUP)
- flags |= SEC_GROUP | SEC_EXCLUDE;
+ flags |= SEC_GROUP;
if ((hdr->sh_flags & SHF_ALLOC) != 0)
{
flags |= SEC_ALLOC;
@@ -3533,8 +3533,8 @@ bfd_elf_set_group_contents (bfd *abfd, asection *sec, void *failedptrarg)
break;
}
- if ((loc -= 4) != sec->contents)
- abort ();
+ loc -= 4;
+ BFD_ASSERT (loc == sec->contents);
H_PUT_32 (abfd, sec->flags & SEC_LINK_ONCE ? GRP_COMDAT : 0, loc);
}
@@ -3609,7 +3609,7 @@ assign_section_numbers (bfd *abfd, struct bfd_link_info *link_info)
_bfd_elf_strtab_clear_all_refs (elf_shstrtab (abfd));
/* SHT_GROUP sections are in relocatable files only. */
- if (link_info == NULL || bfd_link_relocatable (link_info))
+ if (link_info == NULL || !link_info->resolve_section_groups)
{
size_t reloc_count = 0;
@@ -7445,23 +7445,22 @@ _bfd_elf_init_private_section_data (bfd *ibfd,
SHT_GROUP section will have its elf_next_in_group pointing back
to the input group members. Ignore linker created group section.
See elfNN_ia64_object_p in elfxx-ia64.c. */
- if (!final_link)
+ if ((link_info == NULL
+ || !link_info->resolve_section_groups)
+ && (elf_sec_group (isec) == NULL
+ || (elf_sec_group (isec)->flags & SEC_LINKER_CREATED) == 0))
{
- if (elf_sec_group (isec) == NULL
- || (elf_sec_group (isec)->flags & SEC_LINKER_CREATED) == 0)
- {
- if (elf_section_flags (isec) & SHF_GROUP)
- elf_section_flags (osec) |= SHF_GROUP;
- elf_next_in_group (osec) = elf_next_in_group (isec);
- elf_section_data (osec)->group = elf_section_data (isec)->group;
- }
-
- /* If not decompress, preserve SHF_COMPRESSED. */
- if ((ibfd->flags & BFD_DECOMPRESS) == 0)
- elf_section_flags (osec) |= (elf_section_flags (isec)
- & SHF_COMPRESSED);
+ if (elf_section_flags (isec) & SHF_GROUP)
+ elf_section_flags (osec) |= SHF_GROUP;
+ elf_next_in_group (osec) = elf_next_in_group (isec);
+ elf_section_data (osec)->group = elf_section_data (isec)->group;
}
+ /* If not decompress, preserve SHF_COMPRESSED. */
+ if (!final_link && (ibfd->flags & BFD_DECOMPRESS) == 0)
+ elf_section_flags (osec) |= (elf_section_flags (isec)
+ & SHF_COMPRESSED);
+
ihdr = &elf_section_data (isec)->this_hdr;
/* We need to handle elf_linked_to_section for SHF_LINK_ORDER. We
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 7b001b7..1b447bb 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10277,7 +10277,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
continue;
}
- if (bfd_link_relocatable (flinfo->info)
+ if (!flinfo->info->resolve_section_groups
&& (o->flags & (SEC_LINKER_CREATED | SEC_GROUP)) == SEC_GROUP)
{
/* Deal with the group signature symbol. */
@@ -10285,6 +10285,7 @@ elf_link_input_bfd (struct elf_final_link_info *flinfo, bfd *input_bfd)
unsigned long symndx = sec_data->this_hdr.sh_info;
asection *osec = o->output_section;
+ BFD_ASSERT (bfd_link_relocatable (flinfo->info));
if (symndx >= locsymcount
|| (elf_bad_symtab (input_bfd)
&& flinfo->sections[symndx] == NULL))
@@ -12463,10 +12464,11 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
}
}
- if (bfd_link_relocatable (info))
+ if (!info->resolve_section_groups)
{
bfd_boolean failed = FALSE;
+ BFD_ASSERT (bfd_link_relocatable (info));
bfd_map_over_sections (abfd, bfd_elf_set_group_contents, &failed);
if (failed)
goto error_return;