public inbox for binutils@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
@ 2017-03-24 15:11 Andrew Burgess
  2017-04-04 10:01 ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Burgess @ 2017-03-24 15:11 UTC (permalink / raw)
  To: binutils; +Cc: Andrew Burgess

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.

In the same way that common sections have the flag --no-define-common
this commit also adds --inhibit-group-allocation and
INHIBIT_GROUP_ALLOCATION.  These can be used when performing a final
link to prevent the linker from resolving section groups.  If one of
these options is used then after a final link then one copy of each
section group will be copied from the input files to the output file.
Section group members will not be placed like regular input sections,
but will remain as unique sections within the output file.

I've tested this patch against 245 different targets with no
regressions, but I'd welcome and encourage people to test this,
especially for non-elf targets.

Comments and feedback welcome,

thanks,
Andrew

---

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 (enum group_allocation): New enum.
	(struct args_type): Add group_allocation field.
	* ldgram.y: Add support for FORCE_GROUP_ALLOCATION and
	INHIBIT_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.
	* testsuite/ld-elf/group13.d: New file.
	* testsuite/ld-elf/group13.ld: New file.
	* testsuite/ld-elf/group14.d: New file.
	* NEWS: Mention new features.
	* ld.texinfo (Options): Document --force-group-allocation and
	--inhibit-group-allocation.
	(Miscellaneous Commands): Document FORCE_GROUP_ALLOCATION and
	INHIBIT_GROUP_ALLOCATION.
---
 bfd/ChangeLog                  | 14 ++++++++++++
 bfd/elf.c                      | 35 +++++++++++++++---------------
 bfd/elflink.c                  |  4 ++--
 include/ChangeLog              |  5 +++++
 include/bfdlink.h              |  3 +++
 ld/ChangeLog                   | 28 ++++++++++++++++++++++++
 ld/NEWS                        |  6 ++++++
 ld/ld.h                        | 13 ++++++++++++
 ld/ld.texinfo                  | 48 ++++++++++++++++++++++++++++++++++++++++++
 ld/ldgram.y                    |  7 +++++-
 ld/ldlang.c                    | 18 +++++++++++++---
 ld/ldlex.h                     |  2 ++
 ld/ldlex.l                     |  2 ++
 ld/ldmain.c                    |  7 ++++++
 ld/lexsup.c                    | 12 +++++++++++
 ld/testsuite/ld-elf/group11.d  |  6 ++++++
 ld/testsuite/ld-elf/group12.d  |  6 ++++++
 ld/testsuite/ld-elf/group12.ld | 14 ++++++++++++
 ld/testsuite/ld-elf/group13.d  | 10 +++++++++
 ld/testsuite/ld-elf/group13.ld | 14 ++++++++++++
 ld/testsuite/ld-elf/group14.d  | 10 +++++++++
 21 files changed, 240 insertions(+), 24 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/group11.d
 create mode 100644 ld/testsuite/ld-elf/group12.d
 create mode 100644 ld/testsuite/ld-elf/group12.ld
 create mode 100644 ld/testsuite/ld-elf/group13.d
 create mode 100644 ld/testsuite/ld-elf/group13.ld
 create mode 100644 ld/testsuite/ld-elf/group14.d

diff --git a/bfd/elf.c b/bfd/elf.c
index 9418e51..dcc580b 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -979,7 +979,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;
@@ -3526,8 +3526,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);
 }
@@ -3593,7 +3593,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;
 
@@ -7363,23 +7363,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 776357f..153dce0 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10206,7 +10206,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.  */
@@ -12387,7 +12387,7 @@ 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;
 
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 3835fcb..457cd19 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -344,6 +344,9 @@ struct bfd_link_info
   /* TRUE if all data symbols should be dynamic.  */
   unsigned int dynamic_data: 1;
 
+  /* TRUE if section groups should be resolved.  */
+  unsigned int resolve_section_groups: 1;
+
   /* Which symbols to strip.  */
   ENUM_BITFIELD (bfd_link_strip) strip : 2;
 
diff --git a/ld/NEWS b/ld/NEWS
index 972e7a8..877bdb2 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -11,6 +11,12 @@
 * Orphan sections placed after an empty section that has an AT(LMA) will now
   take an load memory address starting from LMA.
 
+* Section groups can now be resolved (the group deleted and the group members
+  placed like normal sections) at partial link time either using the new linker
+  option --force-group-allocation or by placing FORCE_GROUP_ALLOCATION into the
+  linker script.  There's also INHIBIT_GROUP_ALLOCATION that can be used at
+  final link time to prevent groups being resolved.
+
 Changes in 2.28:
 
 * The EXCLUDE_FILE linker script construct can now be applied outside of the
diff --git a/ld/ld.h b/ld/ld.h
index 104bb8e..46b4792 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -127,6 +127,13 @@ enum dynamic_list_enum
   dynamic_list
 };
 
+enum group_allocation
+{
+  group_allocation_unset = 0,
+  group_allocation_force,
+  group_allocation_inhibit
+};
+
 typedef struct
 {
   /* 1 => assign space to common symbols even if `relocatable_output'.  */
@@ -172,6 +179,12 @@ typedef struct
   /* If set, display the target memory usage (per memory region).  */
   bfd_boolean print_memory_usage;
 
+  /* How are sections within groups handled.  Controlled with
+     --force-group-allocation and --inhibit-group-allocation on the command
+     line, or FORCE_GROUP_ALLOCATION and INHIBIT_GROUP_ALLOCATION in the
+     linker script.  */
+  enum group_allocation group_allocation;
+
   /* Big or little endian as set on command line.  */
   enum endian_enum endian;
 
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 769725d..7e01e0a 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1472,6 +1472,31 @@
 duplicate when there are many dynamic modules with specialized search
 paths for runtime symbol resolution.
 
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+@kindex --force-group-allocation
+@item --force-group-allocation
+This option causes the linker to place section group members like
+normal input sections, and to delete the section groups.  This is the
+default behaviour for a final link but this option can be used to
+change the behaviour of a relocatable link (@samp{-r}).  The script
+command @code{FORCE_GROUP_ALLOCATION} has the same
+effect. @xref{Miscellaneous Commands}.
+
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+@kindex --inhibit-group-allocation
+@item --inhibit-group-allocation
+This option prevents the linker from resolving sections groups,
+sections that are part of a group remain group members in the output
+file and the section groups are retained.  This is the default
+behaviour for a relocatable link (@samp{-r}) but this option can be
+used to change the behaviour of a final link.  The script command
+@code{INHIBIT_GROUP_ALLOCATION} has the same
+effect. @xref{Miscellaneous Commands}.
+
 @cindex symbols, from command line
 @kindex --defsym=@var{symbol}=@var{exp}
 @item --defsym=@var{symbol}=@var{expression}
@@ -3695,6 +3720,29 @@
 command-line option: to make @code{ld} omit the assignment of addresses
 to common symbols even for a non-relocatable output file.
 
+@item FORCE_GROUP_ALLOCATION
+@kindex FORCE_GROUP_ALLOCATION
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+This command has the same effect as the
+@samp{--force-group-allocation} command-line option: to make
+@command{ld} place section group members like normal input sections,
+and to delete the section groups even if a relocatable output file is
+specified (@samp{-r}).
+
+@item INHIBIT_GROUP_ALLOCATION
+@kindex INHIBIT_GROUP_ALLOCATION
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+This command has the same effect as the
+@samp{--inhibit-group-allocation} command-line option: @command{ld}
+will preserve section groups in the output file even if a final link
+is performed.  Section group members will not be placed like normal
+input sections but will instead be left as unique sections in the
+output file.
+
 @item INSERT [ AFTER | BEFORE ] @var{output_section}
 @kindex INSERT
 @cindex insert user script into default script
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 849f272..7ceff24 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -131,7 +131,8 @@ static int error_index;
 %token SORT_BY_INIT_PRIORITY
 %token '{' '}'
 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
-%token INHIBIT_COMMON_ALLOCATION
+%token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
+%token INHIBIT_GROUP_ALLOCATION
 %token SEGMENT_START
 %token INCLUDE
 %token MEMORY
@@ -336,8 +337,12 @@ ifile_p1:
 		  { ldfile_set_output_arch ($3, bfd_arch_unknown); }
 	|	FORCE_COMMON_ALLOCATION
 		{ command_line.force_common_definition = TRUE ; }
+	|	FORCE_GROUP_ALLOCATION
+		{ command_line.group_allocation = group_allocation_force ; }
 	|	INHIBIT_COMMON_ALLOCATION
 		{ command_line.inhibit_common_definition = TRUE ; }
+	|	INHIBIT_GROUP_ALLOCATION
+		{command_line.group_allocation = group_allocation_inhibit ; }
 	|	INPUT '(' input_list ')'
 	|	GROUP
 		  { lang_enter_group (); }
diff --git a/ld/ldlang.c b/ld/ldlang.c
index 5a42659..0b37c71 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -207,7 +207,7 @@ unique_section_p (const asection *sec,
   struct unique_sections *unam;
   const char *secnam;
 
-  if (bfd_link_relocatable (&link_info)
+  if (!link_info.resolve_section_groups
       && sec->owner != NULL
       && bfd_is_group_section (sec->owner, sec))
     return !(os != NULL
@@ -2346,6 +2346,12 @@ lang_add_section (lang_statement_list_type *ptr,
   if (strcmp (output->name, DISCARD_SECTION_NAME) == 0)
     discard = TRUE;
 
+  /* Discard the group descriptor sections when we're finally placing the
+     sections from within the group.  */
+  if ((section->flags & SEC_GROUP) == SEC_GROUP
+      && link_info.resolve_section_groups)
+    discard = TRUE;
+
   /* Discard debugging sections if we are stripping debugging
      information.  */
   if ((link_info.strip == strip_debugger || link_info.strip == strip_all)
@@ -2386,8 +2392,14 @@ lang_add_section (lang_statement_list_type *ptr,
      already been processed.  One reason to do this is that on pe
      format targets, .text$foo sections go into .text and it's odd
      to see .text with SEC_LINK_ONCE set.  */
-
-  if (!bfd_link_relocatable (&link_info))
+  if ((flags & (SEC_LINK_ONCE | SEC_GROUP)) == (SEC_LINK_ONCE | SEC_GROUP))
+    {
+      if (link_info.resolve_section_groups)
+        flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC);
+      else
+        flags &= ~(SEC_LINK_DUPLICATES | SEC_RELOC);
+    }
+  else if (!bfd_link_relocatable (&link_info))
     flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC);
 
   switch (output->sectype)
diff --git a/ld/ldlex.h b/ld/ldlex.h
index dac152b..4f8bf70 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -146,6 +146,8 @@ enum option_values
   OPTION_PRINT_MEMORY_USAGE,
   OPTION_REQUIRE_DEFINED_SYMBOL,
   OPTION_ORPHAN_HANDLING,
+  OPTION_FORCE_GROUP_ALLOCATION,
+  OPTION_INHIBIT_GROUP_ALLOCATION,
 };
 
 /* The initial parser states.  */
diff --git a/ld/ldlex.l b/ld/ldlex.l
index fa9b924..f9f342c 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -274,7 +274,9 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"	{ RTOKEN(CREATE_OBJECT_SYMBOLS);}
 <BOTH,SCRIPT>"CONSTRUCTORS"		{ RTOKEN( CONSTRUCTORS);}
 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION"	{ RTOKEN(FORCE_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"FORCE_GROUP_ALLOCATION"	{ RTOKEN(FORCE_GROUP_ALLOCATION);}
 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"INHIBIT_GROUP_ALLOCATION" { RTOKEN(INHIBIT_GROUP_ALLOCATION);}
 <BOTH,SCRIPT>"SECTIONS"			{ RTOKEN(SECTIONS);}
 <BOTH,SCRIPT>"INSERT"			{ RTOKEN(INSERT_K);}
 <BOTH,SCRIPT>"AFTER"			{ RTOKEN(AFTER);}
diff --git a/ld/ldmain.c b/ld/ldmain.c
index e049de3..01f7184 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -383,6 +383,13 @@ main (int argc, char **argv)
       info_msg ("\n==================================================\n");
     }
 
+  if (command_line.group_allocation == group_allocation_force
+      || (command_line.group_allocation == group_allocation_unset
+	  && !bfd_link_relocatable (&link_info)))
+    link_info.resolve_section_groups = TRUE;
+  else
+    link_info.resolve_section_groups = FALSE;
+
   if (command_line.print_output_format)
     info_msg ("%s\n", lang_get_output_target ());
 
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 0b7d497..880b5de 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -112,6 +112,12 @@ static const struct ld_option ld_options[] =
     'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
   { {"dp", no_argument, NULL, 'd'},
     '\0', NULL, NULL, ONE_DASH },
+  { {"force-group-allocation", no_argument, NULL,
+     OPTION_FORCE_GROUP_ALLOCATION},
+    '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
+  { {"inhibit-group-allocation", no_argument, NULL,
+     OPTION_INHIBIT_GROUP_ALLOCATION},
+    '\0', NULL, N_("Prevent section groups from being resolved"), TWO_DASHES },
   { {"entry", required_argument, NULL, 'e'},
     'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
   { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
@@ -767,6 +773,12 @@ parse_args (unsigned argc, char **argv)
 	case 'd':
 	  command_line.force_common_definition = TRUE;
 	  break;
+        case OPTION_FORCE_GROUP_ALLOCATION:
+          command_line.group_allocation = group_allocation_force;
+          break;
+        case OPTION_INHIBIT_GROUP_ALLOCATION:
+          command_line.group_allocation = group_allocation_inhibit;
+          break;
 	case OPTION_DEFSYM:
 	  lex_string = optarg;
 	  lex_redirect (optarg, "--defsym", ++defsym_count);
diff --git a/ld/testsuite/ld-elf/group11.d b/ld/testsuite/ld-elf/group11.d
new file mode 100644
index 0000000..245cf440
--- /dev/null
+++ b/ld/testsuite/ld-elf/group11.d
@@ -0,0 +1,6 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -r --force-group-allocation
+#readelf: -g
+
+There are no section groups in this file.
diff --git a/ld/testsuite/ld-elf/group12.d b/ld/testsuite/ld-elf/group12.d
new file mode 100644
index 0000000..3fa7be8
--- /dev/null
+++ b/ld/testsuite/ld-elf/group12.d
@@ -0,0 +1,6 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -r -T group12.ld
+#readelf: -g
+
+There are no section groups in this file.
diff --git a/ld/testsuite/ld-elf/group12.ld b/ld/testsuite/ld-elf/group12.ld
new file mode 100644
index 0000000..4a36ee5
--- /dev/null
+++ b/ld/testsuite/ld-elf/group12.ld
@@ -0,0 +1,14 @@
+FORCE_GROUP_ALLOCATION
+
+PHDRS
+{
+  header PT_PHDR PHDRS ;
+  image  PT_LOAD PHDRS;
+}
+
+SECTIONS
+{
+  . = 0x1000;
+  .text : { *(.text) *(.rodata.brlt) } :image :header
+  /DISCARD/ : { *(.dropme) *(.reginfo) *(.MIPS.abiflags) }
+}
diff --git a/ld/testsuite/ld-elf/group13.d b/ld/testsuite/ld-elf/group13.d
new file mode 100644
index 0000000..bba9b08
--- /dev/null
+++ b/ld/testsuite/ld-elf/group13.d
@@ -0,0 +1,10 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -T group13.ld
+#readelf: -g
+#xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-*
+# generic linker targets don't comply with all symbol merging rules
+
+COMDAT group section \[ +[0-9]+\] `\.group' \[foo_group\] contains 1 sections:
+   \[Index\]    Name
+   \[ +[0-9]+\]   \.text
diff --git a/ld/testsuite/ld-elf/group13.ld b/ld/testsuite/ld-elf/group13.ld
new file mode 100644
index 0000000..dcbbd77
--- /dev/null
+++ b/ld/testsuite/ld-elf/group13.ld
@@ -0,0 +1,14 @@
+INHIBIT_GROUP_ALLOCATION
+
+PHDRS
+{
+  header PT_PHDR PHDRS ;
+  image  PT_LOAD PHDRS;
+}
+
+SECTIONS
+{
+  . = 0x1000;
+  .text : { *(.text) *(.rodata.brlt) } :image :header
+  /DISCARD/ : { *(.dropme) *(.reginfo) *(.MIPS.abiflags) }
+}
diff --git a/ld/testsuite/ld-elf/group14.d b/ld/testsuite/ld-elf/group14.d
new file mode 100644
index 0000000..bce6806
--- /dev/null
+++ b/ld/testsuite/ld-elf/group14.d
@@ -0,0 +1,10 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -T group.ld --inhibit-group-allocation
+#readelf: -g
+#xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-*
+# generic linker targets don't comply with all symbol merging rules
+
+COMDAT group section \[ +[0-9]+\] `\.group' \[foo_group\] contains 1 sections:
+   \[Index\]    Name
+   \[ +[0-9]+\]   \.text
-- 
2.6.4

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-03-24 15:11 [PATCH] ld: Allow section groups to be resolved as part of a relocatable link Andrew Burgess
@ 2017-04-04 10:01 ` Alan Modra
  2017-04-13 22:07   ` Andrew Burgess
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2017-04-04 10:01 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: binutils

On Fri, Mar 24, 2017 at 03:11:29PM +0000, Andrew Burgess wrote:
> This commit adds a new linker feature: the ability to resolve section
> groups as part of a relocatable link.

What happens with dwarf debug or .eh_frame info for discarded
sections?

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-04-04 10:01 ` Alan Modra
@ 2017-04-13 22:07   ` Andrew Burgess
  2017-05-09 17:29     ` Andrew Burgess
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Burgess @ 2017-04-13 22:07 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

* Alan Modra <amodra@gmail.com> [2017-04-04 19:31:21 +0930]:

> On Fri, Mar 24, 2017 at 03:11:29PM +0000, Andrew Burgess wrote:
> > This commit adds a new linker feature: the ability to resolve section
> > groups as part of a relocatable link.
> 
> What happens with dwarf debug or .eh_frame info for discarded
> sections?

Alan,

Thanks for the feedback, sorry for the slow reply.

I wasn't totally sure what you're asking for, as far as I'm aware
debug and eh_frame sections will work largely as before.  However,
given your question I suspect you've spotted something that I'm still
not getting.

Below I've written down how I _think_ things work.  I'm guessing that
there's more complexity in some aspect that I'm missing (and that
you've spotted).

Currently, if we do a relocatable link of object_a and object_b into
object_ab, then fully link this into exe_ab I believe that we expect
the following to happen:

 1. object_a and object_b contain section groups for some .text*
 sections.

 2. object_a and object_b contain .debug* that reference symbols in
 .text* sections, some these sections will be in section groups, and
 some will not.

 3. During the partial link we merge the section groups, discarding
 all but one copy of each.  References to symbols in discarded
 sections are updated to reference the symbols in the kept copy.

 4. During the final link the section group is discarded, and the
 members become "regular" sections, to be placed in the normal way.
 Symbol references in the .debug* are resolved to the single copy of
 each symbol we now have.

If the new feature I propose is not used (by the user) then I expect
nothing to change.

If the user requests that groups be resolve at partial link time then
I expect:

  1. As above.

  2. As above.

  3. During partial link we discard all section groups, and all but
  one copy of each member of the section groups.  The one remaining
  section group members become "regular" sections and are placed in
  the normal way.  References to symbols in the discarded section
  groups are updated to reference the symbols in the kept sections.

  4. During the final link there are now no section groups.  All
  sections are placed in the normal way and relocations are patched as
  normal.

If the user requests that groups NOT be resolved during the final link
then I expect to see this behaviour:

  1. As above.

  2. As above.

  3. Back to the original behaviour; During the partial link we merge
  the section groups, discarding all but one copy of each.  References
  to symbols in discarded sections are updated to reference the
  symbols in the kept copy.

  4. During final link section groups are merged.  All but one copy of
  each of the group members is discarded, references to symbols in
  discarded sections are updated to reference the symbols in the kept
  copy.  The group members will most likely be placed as orphan
  sections with the linker picking a location for the section to
  live.  As this is a final like relocations in the debug* sections
  will be resolved in the normal way.

I'd expect eh_frame sections to be handled in exactly the same way.

Any guidance you could offer would be gratefully received.


Thanks,
Andrew

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-04-13 22:07   ` Andrew Burgess
@ 2017-05-09 17:29     ` Andrew Burgess
  2017-05-10  2:46       ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Burgess @ 2017-05-09 17:29 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

Alan,

Any followup to the below?

Thanks,
Andrew

* Andrew Burgess <andrew.burgess@embecosm.com> [2017-04-13 23:07:13 +0100]:

> * Alan Modra <amodra@gmail.com> [2017-04-04 19:31:21 +0930]:
> 
> > On Fri, Mar 24, 2017 at 03:11:29PM +0000, Andrew Burgess wrote:
> > > This commit adds a new linker feature: the ability to resolve section
> > > groups as part of a relocatable link.
> > 
> > What happens with dwarf debug or .eh_frame info for discarded
> > sections?
> 
> Alan,
> 
> Thanks for the feedback, sorry for the slow reply.
> 
> I wasn't totally sure what you're asking for, as far as I'm aware
> debug and eh_frame sections will work largely as before.  However,
> given your question I suspect you've spotted something that I'm still
> not getting.
> 
> Below I've written down how I _think_ things work.  I'm guessing that
> there's more complexity in some aspect that I'm missing (and that
> you've spotted).
> 
> Currently, if we do a relocatable link of object_a and object_b into
> object_ab, then fully link this into exe_ab I believe that we expect
> the following to happen:
> 
>  1. object_a and object_b contain section groups for some .text*
>  sections.
> 
>  2. object_a and object_b contain .debug* that reference symbols in
>  .text* sections, some these sections will be in section groups, and
>  some will not.
> 
>  3. During the partial link we merge the section groups, discarding
>  all but one copy of each.  References to symbols in discarded
>  sections are updated to reference the symbols in the kept copy.
> 
>  4. During the final link the section group is discarded, and the
>  members become "regular" sections, to be placed in the normal way.
>  Symbol references in the .debug* are resolved to the single copy of
>  each symbol we now have.
> 
> If the new feature I propose is not used (by the user) then I expect
> nothing to change.
> 
> If the user requests that groups be resolve at partial link time then
> I expect:
> 
>   1. As above.
> 
>   2. As above.
> 
>   3. During partial link we discard all section groups, and all but
>   one copy of each member of the section groups.  The one remaining
>   section group members become "regular" sections and are placed in
>   the normal way.  References to symbols in the discarded section
>   groups are updated to reference the symbols in the kept sections.
> 
>   4. During the final link there are now no section groups.  All
>   sections are placed in the normal way and relocations are patched as
>   normal.
> 
> If the user requests that groups NOT be resolved during the final link
> then I expect to see this behaviour:
> 
>   1. As above.
> 
>   2. As above.
> 
>   3. Back to the original behaviour; During the partial link we merge
>   the section groups, discarding all but one copy of each.  References
>   to symbols in discarded sections are updated to reference the
>   symbols in the kept copy.
> 
>   4. During final link section groups are merged.  All but one copy of
>   each of the group members is discarded, references to symbols in
>   discarded sections are updated to reference the symbols in the kept
>   copy.  The group members will most likely be placed as orphan
>   sections with the linker picking a location for the section to
>   live.  As this is a final like relocations in the debug* sections
>   will be resolved in the normal way.
> 
> I'd expect eh_frame sections to be handled in exactly the same way.
> 
> Any guidance you could offer would be gratefully received.
> 
> 
> Thanks,
> Andrew

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-05-09 17:29     ` Andrew Burgess
@ 2017-05-10  2:46       ` Alan Modra
  2017-05-25 16:54         ` Andrew Burgess
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2017-05-10  2:46 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: binutils

On Tue, May 09, 2017 at 06:29:42PM +0100, Andrew Burgess wrote:
> Any followup to the below?

Sorry, I put this aside as being a little difficult, and it
disappeared among too many other emails.

> * Andrew Burgess <andrew.burgess@embecosm.com> [2017-04-13 23:07:13 +0100]:
> 
> > * Alan Modra <amodra@gmail.com> [2017-04-04 19:31:21 +0930]:
> > 
> > > On Fri, Mar 24, 2017 at 03:11:29PM +0000, Andrew Burgess wrote:
> > > > This commit adds a new linker feature: the ability to resolve section
> > > > groups as part of a relocatable link.
> > > 
> > > What happens with dwarf debug or .eh_frame info for discarded
> > > sections?
> > 
> > Alan,
> > 
> > Thanks for the feedback, sorry for the slow reply.
> > 
> > I wasn't totally sure what you're asking for, as far as I'm aware
> > debug and eh_frame sections will work largely as before.  However,
> > given your question I suspect you've spotted something that I'm still
> > not getting.

One of the "little difficulties" is admitting that when I wrote the
email, I was thinking that ld -r kept all the groups. ;-)  It doesn't,
so the change isn't as major as I was thinking.

> +@item --inhibit-group-allocation
> +This option prevents the linker from resolving sections groups,
> +sections that are part of a group remain group members in the output
> +file and the section groups are retained.  This is the default
> +behaviour for a relocatable link (@samp{-r}) but this option can be
> +used to change the behaviour of a final link.  The script command
> +@code{INHIBIT_GROUP_ALLOCATION} has the same
> +effect. @xref{Miscellaneous Commands}.

This part is a problem.  The ELF gABI says "Sections of type SHT_GROUP
may appear only in relocatable objects".  Did you add the option for
symmetry?  If so, let's drop this part.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-05-10  2:46       ` Alan Modra
@ 2017-05-25 16:54         ` Andrew Burgess
  2017-06-05  0:53           ` Alan Modra
  0 siblings, 1 reply; 8+ messages in thread
From: Andrew Burgess @ 2017-05-25 16:54 UTC (permalink / raw)
  To: Alan Modra; +Cc: binutils

* Alan Modra <amodra@gmail.com> [2017-05-10 12:15:31 +0930]:

> On Tue, May 09, 2017 at 06:29:42PM +0100, Andrew Burgess wrote:
> > Any followup to the below?
> 
> Sorry, I put this aside as being a little difficult, and it
> disappeared among too many other emails.

Thanks for the follow up.  It's taken me a while to find time for this
again, but hopefully this should be it now...

> 
> > * Andrew Burgess <andrew.burgess@embecosm.com> [2017-04-13 23:07:13 +0100]:
> > 
> > > * Alan Modra <amodra@gmail.com> [2017-04-04 19:31:21 +0930]:
> > > 
> > > > On Fri, Mar 24, 2017 at 03:11:29PM +0000, Andrew Burgess wrote:
> > > > > This commit adds a new linker feature: the ability to resolve section
> > > > > groups as part of a relocatable link.
> > > > 
> > > > What happens with dwarf debug or .eh_frame info for discarded
> > > > sections?
> > > 
> > > Alan,
> > > 
> > > Thanks for the feedback, sorry for the slow reply.
> > > 
> > > I wasn't totally sure what you're asking for, as far as I'm aware
> > > debug and eh_frame sections will work largely as before.  However,
> > > given your question I suspect you've spotted something that I'm still
> > > not getting.
> 
> One of the "little difficulties" is admitting that when I wrote the
> email, I was thinking that ld -r kept all the groups. ;-)  It doesn't,
> so the change isn't as major as I was thinking.
> 
> > +@item --inhibit-group-allocation
> > +This option prevents the linker from resolving sections groups,
> > +sections that are part of a group remain group members in the output
> > +file and the section groups are retained.  This is the default
> > +behaviour for a relocatable link (@samp{-r}) but this option can be
> > +used to change the behaviour of a final link.  The script command
> > +@code{INHIBIT_GROUP_ALLOCATION} has the same
> > +effect. @xref{Miscellaneous Commands}.
> 
> This part is a problem.  The ELF gABI says "Sections of type SHT_GROUP
> may appear only in relocatable objects".  Did you add the option for
> symmetry?  If so, let's drop this part.

Yes, as I took the treatment of common sections as my model I just
added a FORCE/INHIBIT mechanism, but it's really only the FORCE that I
care about.

I've updated the patch to remove all trace (I believe) of the INHIBIT
side of things.  The only _new_ code is a couple of asserts inside bfd
that if we're _not_ resolving, then we _must_ be doing a relocatable
link.

Would you be happy with this version?

Thanks,
Andrew

---

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.
---
 bfd/ChangeLog                  | 14 ++++++++++++++
 bfd/elf.c                      | 35 +++++++++++++++++------------------
 bfd/elflink.c                  |  6 ++++--
 include/ChangeLog              |  5 +++++
 include/bfdlink.h              |  3 +++
 ld/ChangeLog                   | 21 +++++++++++++++++++++
 ld/NEWS                        |  5 +++++
 ld/ld.h                        |  5 +++++
 ld/ld.texinfo                  | 23 +++++++++++++++++++++++
 ld/ldgram.y                    |  4 +++-
 ld/ldlang.c                    | 18 +++++++++++++++---
 ld/ldlex.h                     |  1 +
 ld/ldlex.l                     |  1 +
 ld/ldmain.c                    |  6 ++++++
 ld/lexsup.c                    |  6 ++++++
 ld/testsuite/ld-elf/group11.d  |  6 ++++++
 ld/testsuite/ld-elf/group12.d  |  6 ++++++
 ld/testsuite/ld-elf/group12.ld | 14 ++++++++++++++
 18 files changed, 155 insertions(+), 24 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/group11.d
 create mode 100644 ld/testsuite/ld-elf/group12.d
 create mode 100644 ld/testsuite/ld-elf/group12.ld

diff --git a/bfd/elf.c b/bfd/elf.c
index 863bd61..22e3cfe 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;
@@ -3532,8 +3532,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);
 }
@@ -3608,7 +3608,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;
 
@@ -7444,23 +7444,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 71da4c9..5e8b807 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -10278,7 +10278,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.  */
@@ -10286,6 +10286,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))
@@ -12464,10 +12465,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;
diff --git a/include/bfdlink.h b/include/bfdlink.h
index 371822c..2e3f0b1 100644
--- a/include/bfdlink.h
+++ b/include/bfdlink.h
@@ -348,6 +348,9 @@ struct bfd_link_info
   /* TRUE if all data symbols should be dynamic.  */
   unsigned int dynamic_data: 1;
 
+  /* TRUE if section groups should be resolved.  */
+  unsigned int resolve_section_groups: 1;
+
   /* Which symbols to strip.  */
   ENUM_BITFIELD (bfd_link_strip) strip : 2;
 
diff --git a/ld/NEWS b/ld/NEWS
index 52daa6b..98055b5 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -15,6 +15,11 @@
 * Orphan sections placed after an empty section that has an AT(LMA) will now
   take an load memory address starting from LMA.
 
+* Section groups can now be resolved (the group deleted and the group members
+  placed like normal sections) at partial link time either using the new linker
+  option --force-group-allocation or by placing FORCE_GROUP_ALLOCATION into the
+  linker script.
+
 Changes in 2.28:
 
 * The EXCLUDE_FILE linker script construct can now be applied outside of the
diff --git a/ld/ld.h b/ld/ld.h
index 104bb8e..d9bb653 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -172,6 +172,11 @@ typedef struct
   /* If set, display the target memory usage (per memory region).  */
   bfd_boolean print_memory_usage;
 
+  /* Shold we force section groups to be resolved?  Controlled with
+     --force-group-allocation on the command line or FORCE_GROUP_ALLOCATION
+     in the linker script.  */
+  bfd_boolean force_group_allocation;
+
   /* Big or little endian as set on command line.  */
   enum endian_enum endian;
 
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 9a72cb9..9da35a1 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1486,6 +1486,18 @@
 duplicate when there are many dynamic modules with specialized search
 paths for runtime symbol resolution.
 
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+@kindex --force-group-allocation
+@item --force-group-allocation
+This option causes the linker to place section group members like
+normal input sections, and to delete the section groups.  This is the
+default behaviour for a final link but this option can be used to
+change the behaviour of a relocatable link (@samp{-r}).  The script
+command @code{FORCE_GROUP_ALLOCATION} has the same
+effect. @xref{Miscellaneous Commands}.
+
 @cindex symbols, from command line
 @kindex --defsym=@var{symbol}=@var{exp}
 @item --defsym=@var{symbol}=@var{expression}
@@ -3728,6 +3740,17 @@
 command-line option: to make @code{ld} omit the assignment of addresses
 to common symbols even for a non-relocatable output file.
 
+@item FORCE_GROUP_ALLOCATION
+@kindex FORCE_GROUP_ALLOCATION
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+This command has the same effect as the
+@samp{--force-group-allocation} command-line option: to make
+@command{ld} place section group members like normal input sections,
+and to delete the section groups even if a relocatable output file is
+specified (@samp{-r}).
+
 @item INSERT [ AFTER | BEFORE ] @var{output_section}
 @kindex INSERT
 @cindex insert user script into default script
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 849f272..4c1efdc 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -131,7 +131,7 @@ static int error_index;
 %token SORT_BY_INIT_PRIORITY
 %token '{' '}'
 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
-%token INHIBIT_COMMON_ALLOCATION
+%token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
 %token SEGMENT_START
 %token INCLUDE
 %token MEMORY
@@ -336,6 +336,8 @@ ifile_p1:
 		  { ldfile_set_output_arch ($3, bfd_arch_unknown); }
 	|	FORCE_COMMON_ALLOCATION
 		{ command_line.force_common_definition = TRUE ; }
+	|	FORCE_GROUP_ALLOCATION
+		{ command_line.force_group_allocation = TRUE ; }
 	|	INHIBIT_COMMON_ALLOCATION
 		{ command_line.inhibit_common_definition = TRUE ; }
 	|	INPUT '(' input_list ')'
diff --git a/ld/ldlang.c b/ld/ldlang.c
index ed7e552..252400b 100644
--- a/ld/ldlang.c
+++ b/ld/ldlang.c
@@ -207,7 +207,7 @@ unique_section_p (const asection *sec,
   struct unique_sections *unam;
   const char *secnam;
 
-  if (bfd_link_relocatable (&link_info)
+  if (!link_info.resolve_section_groups
       && sec->owner != NULL
       && bfd_is_group_section (sec->owner, sec))
     return !(os != NULL
@@ -2349,6 +2349,12 @@ lang_add_section (lang_statement_list_type *ptr,
   if (strcmp (output->name, DISCARD_SECTION_NAME) == 0)
     discard = TRUE;
 
+  /* Discard the group descriptor sections when we're finally placing the
+     sections from within the group.  */
+  if ((section->flags & SEC_GROUP) == SEC_GROUP
+      && link_info.resolve_section_groups)
+    discard = TRUE;
+
   /* Discard debugging sections if we are stripping debugging
      information.  */
   if ((link_info.strip == strip_debugger || link_info.strip == strip_all)
@@ -2389,8 +2395,14 @@ lang_add_section (lang_statement_list_type *ptr,
      already been processed.  One reason to do this is that on pe
      format targets, .text$foo sections go into .text and it's odd
      to see .text with SEC_LINK_ONCE set.  */
-
-  if (!bfd_link_relocatable (&link_info))
+  if ((flags & (SEC_LINK_ONCE | SEC_GROUP)) == (SEC_LINK_ONCE | SEC_GROUP))
+    {
+      if (link_info.resolve_section_groups)
+        flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC);
+      else
+        flags &= ~(SEC_LINK_DUPLICATES | SEC_RELOC);
+    }
+  else if (!bfd_link_relocatable (&link_info))
     flags &= ~(SEC_LINK_ONCE | SEC_LINK_DUPLICATES | SEC_RELOC);
 
   switch (output->sectype)
diff --git a/ld/ldlex.h b/ld/ldlex.h
index dac152b..5aa7f6b 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -146,6 +146,7 @@ enum option_values
   OPTION_PRINT_MEMORY_USAGE,
   OPTION_REQUIRE_DEFINED_SYMBOL,
   OPTION_ORPHAN_HANDLING,
+  OPTION_FORCE_GROUP_ALLOCATION,
 };
 
 /* The initial parser states.  */
diff --git a/ld/ldlex.l b/ld/ldlex.l
index acba1a2..ba618ec 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -274,6 +274,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <BOTH,SCRIPT>"CREATE_OBJECT_SYMBOLS"	{ RTOKEN(CREATE_OBJECT_SYMBOLS);}
 <BOTH,SCRIPT>"CONSTRUCTORS"		{ RTOKEN( CONSTRUCTORS);}
 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION"	{ RTOKEN(FORCE_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"FORCE_GROUP_ALLOCATION"	{ RTOKEN(FORCE_GROUP_ALLOCATION);}
 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
 <BOTH,SCRIPT>"SECTIONS"			{ RTOKEN(SECTIONS);}
 <BOTH,SCRIPT>"INSERT"			{ RTOKEN(INSERT_K);}
diff --git a/ld/ldmain.c b/ld/ldmain.c
index e049de3..8aa308d 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -383,6 +383,12 @@ main (int argc, char **argv)
       info_msg ("\n==================================================\n");
     }
 
+  if (command_line.force_group_allocation
+      || !bfd_link_relocatable (&link_info))
+    link_info.resolve_section_groups = TRUE;
+  else
+    link_info.resolve_section_groups = FALSE;
+
   if (command_line.print_output_format)
     info_msg ("%s\n", lang_get_output_target ());
 
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 0b7d497..95c7e59 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -112,6 +112,9 @@ static const struct ld_option ld_options[] =
     'd', NULL, N_("Force common symbols to be defined"), ONE_DASH },
   { {"dp", no_argument, NULL, 'd'},
     '\0', NULL, NULL, ONE_DASH },
+  { {"force-group-allocation", no_argument, NULL,
+     OPTION_FORCE_GROUP_ALLOCATION},
+    '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
   { {"entry", required_argument, NULL, 'e'},
     'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
   { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
@@ -767,6 +770,9 @@ parse_args (unsigned argc, char **argv)
 	case 'd':
 	  command_line.force_common_definition = TRUE;
 	  break;
+        case OPTION_FORCE_GROUP_ALLOCATION:
+          command_line.force_group_allocation = TRUE;
+          break;
 	case OPTION_DEFSYM:
 	  lex_string = optarg;
 	  lex_redirect (optarg, "--defsym", ++defsym_count);
diff --git a/ld/testsuite/ld-elf/group11.d b/ld/testsuite/ld-elf/group11.d
new file mode 100644
index 0000000..245cf440
--- /dev/null
+++ b/ld/testsuite/ld-elf/group11.d
@@ -0,0 +1,6 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -r --force-group-allocation
+#readelf: -g
+
+There are no section groups in this file.
diff --git a/ld/testsuite/ld-elf/group12.d b/ld/testsuite/ld-elf/group12.d
new file mode 100644
index 0000000..3fa7be8
--- /dev/null
+++ b/ld/testsuite/ld-elf/group12.d
@@ -0,0 +1,6 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -r -T group12.ld
+#readelf: -g
+
+There are no section groups in this file.
diff --git a/ld/testsuite/ld-elf/group12.ld b/ld/testsuite/ld-elf/group12.ld
new file mode 100644
index 0000000..4a36ee5
--- /dev/null
+++ b/ld/testsuite/ld-elf/group12.ld
@@ -0,0 +1,14 @@
+FORCE_GROUP_ALLOCATION
+
+PHDRS
+{
+  header PT_PHDR PHDRS ;
+  image  PT_LOAD PHDRS;
+}
+
+SECTIONS
+{
+  . = 0x1000;
+  .text : { *(.text) *(.rodata.brlt) } :image :header
+  /DISCARD/ : { *(.dropme) *(.reginfo) *(.MIPS.abiflags) }
+}
-- 
2.5.1

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-05-25 16:54         ` Andrew Burgess
@ 2017-06-05  0:53           ` Alan Modra
  2017-06-06  9:22             ` Andrew Burgess
  0 siblings, 1 reply; 8+ messages in thread
From: Alan Modra @ 2017-06-05  0:53 UTC (permalink / raw)
  To: Andrew Burgess; +Cc: binutils

On Thu, May 25, 2017 at 03:24:32PM +0100, Andrew Burgess wrote:
> I've updated the patch to remove all trace (I believe) of the INHIBIT
> side of things.  The only _new_ code is a couple of asserts inside bfd
> that if we're _not_ resolving, then we _must_ be doing a relocatable
> link.
> 
> Would you be happy with this version?

Yes, looks OK to commit.

-- 
Alan Modra
Australia Development Lab, IBM

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [PATCH] ld: Allow section groups to be resolved as part of a relocatable link
  2017-06-05  0:53           ` Alan Modra
@ 2017-06-06  9:22             ` Andrew Burgess
  0 siblings, 0 replies; 8+ messages in thread
From: Andrew Burgess @ 2017-06-06  9:22 UTC (permalink / raw)
  To: binutils; +Cc: Alan Modra

* Alan Modra <amodra@gmail.com> [2017-06-05 10:23:25 +0930]:

> On Thu, May 25, 2017 at 03:24:32PM +0100, Andrew Burgess wrote:
> > I've updated the patch to remove all trace (I believe) of the INHIBIT
> > side of things.  The only _new_ code is a couple of asserts inside bfd
> > that if we're _not_ resolving, then we _must_ be doing a relocatable
> > link.
> > 
> > Would you be happy with this version?
> 
> Yes, looks OK to commit.

Thanks for all the reviews on this, I appreciate you help.

Below is the part of the original patch that was removed (allows
inhibiting of group allocation).  As you pointed out this created
invalid ELFs, so I'm NOT proposing this patch for inclusion (so no
review needed), but I thought I'd post this just in case its ever of
use to anyone.

Again, thanks for all your help,

Andrew

---

ld: Add support for preventing group allocation

Adds new command line flag --inhibit-group-allocation and a linker
script command INHIBIT_GROUP_ALLOCATION, these have the effect of
preventing section groups from being resolved in a final link.

Using this flag will result in an ELF that does not comply with the gABI
specification of an ELF, the specification clearly says that a section
of type SHT_GROUP can only appear in a relocatable ELF.

ld/ChangeLog:

	* ld.h (enum group_allocation): New enum.
	(struct args_type): Change type of group_allocation field.
	* ldgram.y: Add support for FORCE_GROUP_ALLOCATION and
	INHIBIT_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/group13.d: New file.
	* testsuite/ld-elf/group13.ld: New file.
	* testsuite/ld-elf/group14.d: New file.
	* ld.texinfo (Options): Document --inhibit-group-allocation.
	(Miscellaneous Commands): Document INHIBIT_GROUP_ALLOCATION.
	* NEWS: Document new feature.
---
 ld/ChangeLog                   | 23 +++++++++++++++++++++++
 ld/NEWS                        |  5 +++++
 ld/ld.h                        | 16 ++++++++++++----
 ld/ld.texinfo                  | 25 +++++++++++++++++++++++++
 ld/ldgram.y                    |  5 ++++-
 ld/ldlex.h                     |  1 +
 ld/ldlex.l                     |  1 +
 ld/ldmain.c                    |  5 +++--
 ld/lexsup.c                    |  8 +++++++-
 ld/testsuite/ld-elf/group13.d  | 10 ++++++++++
 ld/testsuite/ld-elf/group13.ld | 14 ++++++++++++++
 ld/testsuite/ld-elf/group14.d  | 10 ++++++++++
 12 files changed, 115 insertions(+), 8 deletions(-)
 create mode 100644 ld/testsuite/ld-elf/group13.d
 create mode 100644 ld/testsuite/ld-elf/group13.ld
 create mode 100644 ld/testsuite/ld-elf/group14.d

diff --git a/ld/NEWS b/ld/NEWS
index 98055b5f4e..aa894f186e 100644
--- a/ld/NEWS
+++ b/ld/NEWS
@@ -20,6 +20,11 @@
   option --force-group-allocation or by placing FORCE_GROUP_ALLOCATION into the
   linker script.
 
+* Resolution of section groups can be prevented in a final link using the
+  --inhibit-group-allocation command line flag, or the linker script command
+  INHIBIT_GROUP_ALLOCATION.  Using these will result in section groups in a fully
+  linked ELF, which is non-standard compliant (and therefore an invalid ELF).
+
 Changes in 2.28:
 
 * The EXCLUDE_FILE linker script construct can now be applied outside of the
diff --git a/ld/ld.h b/ld/ld.h
index 162e156f08..46b4792625 100644
--- a/ld/ld.h
+++ b/ld/ld.h
@@ -127,6 +127,13 @@ enum dynamic_list_enum
   dynamic_list
 };
 
+enum group_allocation
+{
+  group_allocation_unset = 0,
+  group_allocation_force,
+  group_allocation_inhibit
+};
+
 typedef struct
 {
   /* 1 => assign space to common symbols even if `relocatable_output'.  */
@@ -172,10 +179,11 @@ typedef struct
   /* If set, display the target memory usage (per memory region).  */
   bfd_boolean print_memory_usage;
 
-  /* Should we force section groups to be resolved?  Controlled with
-     --force-group-allocation on the command line or FORCE_GROUP_ALLOCATION
-     in the linker script.  */
-  bfd_boolean force_group_allocation;
+  /* How are sections within groups handled.  Controlled with
+     --force-group-allocation and --inhibit-group-allocation on the command
+     line, or FORCE_GROUP_ALLOCATION and INHIBIT_GROUP_ALLOCATION in the
+     linker script.  */
+  enum group_allocation group_allocation;
 
   /* Big or little endian as set on command line.  */
   enum endian_enum endian;
diff --git a/ld/ld.texinfo b/ld/ld.texinfo
index 790b52f025..7a05319a99 100644
--- a/ld/ld.texinfo
+++ b/ld/ld.texinfo
@@ -1496,6 +1496,19 @@
 command @code{FORCE_GROUP_ALLOCATION} has the same
 effect. @xref{Miscellaneous Commands}.
 
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+@kindex --inhibit-group-allocation
+@item --inhibit-group-allocation
+This option prevents the linker from resolving sections groups,
+sections that are part of a group remain group members in the output
+file and the section groups are retained.  This is the default
+behaviour for a relocatable link (@samp{-r}) but this option can be
+used to change the behaviour of a final link.  The script command
+@code{INHIBIT_GROUP_ALLOCATION} has the same
+effect. @xref{Miscellaneous Commands}.
+
 @cindex symbols, from command line
 @kindex --defsym=@var{symbol}=@var{exp}
 @item --defsym=@var{symbol}=@var{expression}
@@ -3749,6 +3762,18 @@
 and to delete the section groups even if a relocatable output file is
 specified (@samp{-r}).
 
+@item INHIBIT_GROUP_ALLOCATION
+@kindex INHIBIT_GROUP_ALLOCATION
+@cindex group allocation in linker script
+@cindex section groups
+@cindex COMDAT
+This command has the same effect as the
+@samp{--inhibit-group-allocation} command-line option: @command{ld}
+will preserve section groups in the output file even if a final link
+is performed.  Section group members will not be placed like normal
+input sections but will instead be left as unique sections in the
+output file.
+
 @item INSERT [ AFTER | BEFORE ] @var{output_section}
 @kindex INSERT
 @cindex insert user script into default script
diff --git a/ld/ldgram.y b/ld/ldgram.y
index 4c1efdc2ed..7ceff2434e 100644
--- a/ld/ldgram.y
+++ b/ld/ldgram.y
@@ -132,6 +132,7 @@ static int error_index;
 %token '{' '}'
 %token SIZEOF_HEADERS OUTPUT_FORMAT FORCE_COMMON_ALLOCATION OUTPUT_ARCH
 %token INHIBIT_COMMON_ALLOCATION FORCE_GROUP_ALLOCATION
+%token INHIBIT_GROUP_ALLOCATION
 %token SEGMENT_START
 %token INCLUDE
 %token MEMORY
@@ -337,9 +338,11 @@ ifile_p1:
 	|	FORCE_COMMON_ALLOCATION
 		{ command_line.force_common_definition = TRUE ; }
 	|	FORCE_GROUP_ALLOCATION
-		{ command_line.force_group_allocation = TRUE ; }
+		{ command_line.group_allocation = group_allocation_force ; }
 	|	INHIBIT_COMMON_ALLOCATION
 		{ command_line.inhibit_common_definition = TRUE ; }
+	|	INHIBIT_GROUP_ALLOCATION
+		{command_line.group_allocation = group_allocation_inhibit ; }
 	|	INPUT '(' input_list ')'
 	|	GROUP
 		  { lang_enter_group (); }
diff --git a/ld/ldlex.h b/ld/ldlex.h
index 5aa7f6bc3e..4f8bf70e77 100644
--- a/ld/ldlex.h
+++ b/ld/ldlex.h
@@ -147,6 +147,7 @@ enum option_values
   OPTION_REQUIRE_DEFINED_SYMBOL,
   OPTION_ORPHAN_HANDLING,
   OPTION_FORCE_GROUP_ALLOCATION,
+  OPTION_INHIBIT_GROUP_ALLOCATION,
 };
 
 /* The initial parser states.  */
diff --git a/ld/ldlex.l b/ld/ldlex.l
index ba618ecc27..7cc8665047 100644
--- a/ld/ldlex.l
+++ b/ld/ldlex.l
@@ -276,6 +276,7 @@ V_IDENTIFIER [*?.$_a-zA-Z\[\]\-\!\^\\]([*?.$_a-zA-Z0-9\[\]\-\!\^\\]|::)*
 <BOTH,SCRIPT>"FORCE_COMMON_ALLOCATION"	{ RTOKEN(FORCE_COMMON_ALLOCATION);}
 <BOTH,SCRIPT>"FORCE_GROUP_ALLOCATION"	{ RTOKEN(FORCE_GROUP_ALLOCATION);}
 <BOTH,SCRIPT>"INHIBIT_COMMON_ALLOCATION" { RTOKEN(INHIBIT_COMMON_ALLOCATION);}
+<BOTH,SCRIPT>"INHIBIT_GROUP_ALLOCATION" { RTOKEN(INHIBIT_GROUP_ALLOCATION);}
 <BOTH,SCRIPT>"SECTIONS"			{ RTOKEN(SECTIONS);}
 <BOTH,SCRIPT>"INSERT"			{ RTOKEN(INSERT_K);}
 <BOTH,SCRIPT>"AFTER"			{ RTOKEN(AFTER);}
diff --git a/ld/ldmain.c b/ld/ldmain.c
index ee5ab1166a..ee534abe30 100644
--- a/ld/ldmain.c
+++ b/ld/ldmain.c
@@ -386,8 +386,9 @@ main (int argc, char **argv)
       info_msg ("\n==================================================\n");
     }
 
-  if (command_line.force_group_allocation
-      || !bfd_link_relocatable (&link_info))
+  if (command_line.group_allocation == group_allocation_force
+      || (command_line.group_allocation == group_allocation_unset
+	  && !bfd_link_relocatable (&link_info)))
     link_info.resolve_section_groups = TRUE;
   else
     link_info.resolve_section_groups = FALSE;
diff --git a/ld/lexsup.c b/ld/lexsup.c
index 95c7e599b9..880b5dee49 100644
--- a/ld/lexsup.c
+++ b/ld/lexsup.c
@@ -115,6 +115,9 @@ static const struct ld_option ld_options[] =
   { {"force-group-allocation", no_argument, NULL,
      OPTION_FORCE_GROUP_ALLOCATION},
     '\0', NULL, N_("Force group members out of groups"), TWO_DASHES },
+  { {"inhibit-group-allocation", no_argument, NULL,
+     OPTION_INHIBIT_GROUP_ALLOCATION},
+    '\0', NULL, N_("Prevent section groups from being resolved"), TWO_DASHES },
   { {"entry", required_argument, NULL, 'e'},
     'e', N_("ADDRESS"), N_("Set start address"), TWO_DASHES },
   { {"export-dynamic", no_argument, NULL, OPTION_EXPORT_DYNAMIC},
@@ -771,7 +774,10 @@ parse_args (unsigned argc, char **argv)
 	  command_line.force_common_definition = TRUE;
 	  break;
         case OPTION_FORCE_GROUP_ALLOCATION:
-          command_line.force_group_allocation = TRUE;
+          command_line.group_allocation = group_allocation_force;
+          break;
+        case OPTION_INHIBIT_GROUP_ALLOCATION:
+          command_line.group_allocation = group_allocation_inhibit;
           break;
 	case OPTION_DEFSYM:
 	  lex_string = optarg;
diff --git a/ld/testsuite/ld-elf/group13.d b/ld/testsuite/ld-elf/group13.d
new file mode 100644
index 0000000000..bba9b08cb0
--- /dev/null
+++ b/ld/testsuite/ld-elf/group13.d
@@ -0,0 +1,10 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -T group13.ld
+#readelf: -g
+#xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-*
+# generic linker targets don't comply with all symbol merging rules
+
+COMDAT group section \[ +[0-9]+\] `\.group' \[foo_group\] contains 1 sections:
+   \[Index\]    Name
+   \[ +[0-9]+\]   \.text
diff --git a/ld/testsuite/ld-elf/group13.ld b/ld/testsuite/ld-elf/group13.ld
new file mode 100644
index 0000000000..dcbbd7790c
--- /dev/null
+++ b/ld/testsuite/ld-elf/group13.ld
@@ -0,0 +1,14 @@
+INHIBIT_GROUP_ALLOCATION
+
+PHDRS
+{
+  header PT_PHDR PHDRS ;
+  image  PT_LOAD PHDRS;
+}
+
+SECTIONS
+{
+  . = 0x1000;
+  .text : { *(.text) *(.rodata.brlt) } :image :header
+  /DISCARD/ : { *(.dropme) *(.reginfo) *(.MIPS.abiflags) }
+}
diff --git a/ld/testsuite/ld-elf/group14.d b/ld/testsuite/ld-elf/group14.d
new file mode 100644
index 0000000000..bce6806327
--- /dev/null
+++ b/ld/testsuite/ld-elf/group14.d
@@ -0,0 +1,10 @@
+#source: group1a.s
+#source: group1b.s
+#ld: -T group.ld --inhibit-group-allocation
+#readelf: -g
+#xfail: d30v-*-* dlx-*-* i960-*-* pj*-*-*
+# generic linker targets don't comply with all symbol merging rules
+
+COMDAT group section \[ +[0-9]+\] `\.group' \[foo_group\] contains 1 sections:
+   \[Index\]    Name
+   \[ +[0-9]+\]   \.text
-- 
2.12.2

^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2017-06-06  9:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-03-24 15:11 [PATCH] ld: Allow section groups to be resolved as part of a relocatable link Andrew Burgess
2017-04-04 10:01 ` Alan Modra
2017-04-13 22:07   ` Andrew Burgess
2017-05-09 17:29     ` Andrew Burgess
2017-05-10  2:46       ` Alan Modra
2017-05-25 16:54         ` Andrew Burgess
2017-06-05  0:53           ` Alan Modra
2017-06-06  9:22             ` Andrew Burgess

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).