PATCH: PR ld/9727: "ld -r --gc-sections --entry" doesn't work with COMDAT group

H.J. Lu hongjiu.lu@intel.com
Wed Jan 14 18:06:00 GMT 2009


When any section in a section group is kept, we keep all sections in the
section group.  If the first member of the section group is excluded, we
should also exclude the group section.  OK to install?

Thanks.

H.J.
---
bfd/

2009-01-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/9727
	* elflink.c (elf_gc_sweep): Exclude the group section if the
	the first member of the section group is excluded.

ld/testsuite/

2009-01-14  H.J. Lu  <hongjiu.lu@intel.com>

	PR ld/9727
	* ld-elf/group8.s: New.
	* ld-elf/group8a.d: Likewise.
	* ld-elf/group8b.d: Likewise.
	* ld-elf/group9.s: Likewise.
	* ld-elf/group9a.d: Likewise.
	* ld-elf/group9b.d: Likewise.

--- binutils/bfd/elflink.c.gc	2009-01-12 08:53:25.000000000 -0800
+++ binutils/bfd/elflink.c	2009-01-14 09:46:23.000000000 -0800
@@ -11482,10 +11482,21 @@ elf_gc_sweep (bfd *abfd, struct bfd_link
 
       for (o = sub->sections; o != NULL; o = o->next)
 	{
-	  /* Keep debug and special sections.  */
-	  if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
-	      || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
-	    o->gc_mark = 1;
+	  /* When any section in a section group is kept, we keep all
+	     sections in the section group.  If the first member of
+	     the section group is excluded, we will also exclude the
+	     group section.  */
+	  if (o->flags & SEC_GROUP)
+	    {
+	      asection *first = elf_next_in_group (o);
+	      o->gc_mark = first->gc_mark;
+	    }
+	  else if ((o->flags & (SEC_DEBUGGING | SEC_LINKER_CREATED)) != 0
+		   || (o->flags & (SEC_ALLOC | SEC_LOAD | SEC_RELOC)) == 0)
+	    {
+	      /* Keep debug and special sections.  */
+	      o->gc_mark = 1;
+	    }
 
 	  if (o->gc_mark)
 	    continue;
--- binutils/ld/testsuite/ld-elf/group8.s.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group8.s	2009-01-14 09:55:12.000000000 -0800
@@ -0,0 +1,10 @@
+	.section	.text.foo,"axG",%progbits,foo,comdat
+	.globl foo
+	.type	foo,%function
+foo:
+	.byte 0
+	.section	.text.bar,"axG",%progbits,bar,comdat
+	.globl bar
+	.type	bar,%function
+bar:
+	.byte 0
--- binutils/ld/testsuite/ld-elf/group8a.d.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group8a.d	2009-01-14 10:00:54.000000000 -0800
@@ -0,0 +1,8 @@
+#source: group8.s
+#ld: -r --gc-sections --entry foo
+#readelf: -g --wide
+#notarget: ia64-*-*
+
+COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains 1 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.foo
--- binutils/ld/testsuite/ld-elf/group8b.d.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group8b.d	2009-01-14 10:00:58.000000000 -0800
@@ -0,0 +1,8 @@
+#source: group8.s
+#ld: -r --gc-sections --entry bar
+#readelf: -g --wide
+#notarget: ia64-*-*
+
+COMDAT group section \[[ 0-9]+\] `.group' \[bar\] contains 1 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.bar
--- binutils/ld/testsuite/ld-elf/group9.s.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group9.s	2009-01-14 09:55:32.000000000 -0800
@@ -0,0 +1,15 @@
+	.section	.text.foo,"axG",%progbits,foo,comdat
+	.globl foo
+	.type	foo,%function
+foo:
+	.byte 0
+	.section	.data.foo,"axG",%progbits,foo,comdat
+	.globl foo.data
+	.type	foo,%object
+foo.data:
+	.byte 0
+	.section	.text.bar,"axG",%progbits,bar,comdat
+	.globl bar
+	.type	bar,%function
+bar:
+	.byte foo.data
--- binutils/ld/testsuite/ld-elf/group9a.d.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group9a.d	2009-01-14 10:01:01.000000000 -0800
@@ -0,0 +1,9 @@
+#source: group9.s
+#ld: -r --gc-sections --entry foo
+#readelf: -g --wide
+#notarget: ia64-*-*
+
+COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains 2 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.foo
+   \[[ 0-9]+\]   .data.foo
--- binutils/ld/testsuite/ld-elf/group9b.d.gc	2009-01-14 09:57:04.000000000 -0800
+++ binutils/ld/testsuite/ld-elf/group9b.d	2009-01-14 10:01:05.000000000 -0800
@@ -0,0 +1,13 @@
+#source: group9.s
+#ld: -r --gc-sections --entry bar
+#readelf: -g --wide
+#notarget: ia64-*-*
+
+COMDAT group section \[[ 0-9]+\] `.group' \[foo\] contains 2 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.foo
+   \[[ 0-9]+\]   .data.foo
+
+COMDAT group section \[[ 0-9]+\] `.group' \[bar\] contains 1 sections:
+   \[Index\]    Name
+   \[[ 0-9]+\]   .text.bar



More information about the Binutils mailing list