This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: objcopy --strip-debug breaks GROUP sections
This fixes SHT_GROUP contents when objcopy is used to remove group
member sections. Nick, I see you made a change here when committing
2009-01-15 Douglas B Rupp. I assume that was by accident since I
could find no ChangeLog entry or discussion on the mailing list. Were
you looking at implementing removal of group members during ld -r via
a linker script?
bfd/
* elf.c (bfd_elf_set_group_contents): Revert accidental 2009-01-15
commit. Don't write zeros for removed group members.
(_bfd_elf_copy_private_header_data): Adjust size of group section
when group members are removed by objcopy.
binutils/testsuite/
* binutils-all/group-5.s, * binutils-all/group-5.d: New test.
* binutils-all/objcopy.exp: Run it.
Index: bfd/elf.c
===================================================================
RCS file: /cvs/src/src/bfd/elf.c,v
retrieving revision 1.502
diff -u -p -r1.502 elf.c
--- bfd/elf.c 9 Feb 2010 12:14:42 -0000 1.502
+++ bfd/elf.c 17 Feb 2010 22:57:54 -0000
@@ -2743,17 +2743,16 @@ bfd_elf_set_group_contents (bfd *abfd, a
while (elt != NULL)
{
asection *s;
- unsigned int idx;
s = elt;
- if (! elf_discarded_section (s))
+ if (!gas)
+ s = s->output_section;
+ if (s != NULL
+ && !bfd_is_abs_section (s))
{
+ unsigned int idx = elf_section_data (s)->this_idx;
+
loc -= 4;
- if (!gas)
- s = s->output_section;
- idx = 0;
- if (s != NULL)
- idx = elf_section_data (s)->this_idx;
H_PUT_32 (abfd, idx, loc);
}
elt = elf_next_in_group (elt);
@@ -6160,21 +6156,27 @@ _bfd_elf_copy_private_header_data (bfd *
return FALSE;
}
- /* _bfd_elf_copy_private_section_data copied over the SHF_GROUP flag
- but this might be wrong if we deleted the group section. */
for (isec = ibfd->sections; isec != NULL; isec = isec->next)
- if (elf_section_type (isec) == SHT_GROUP
- && isec->output_section == NULL)
+ if (elf_section_type (isec) == SHT_GROUP)
{
asection *first = elf_next_in_group (isec);
asection *s = first;
while (s != NULL)
{
- if (s->output_section != NULL)
+ /* If this member section is being output but the
+ SHT_GROUP section is not, then clear the group info
+ set up by _bfd_elf_copy_private_section_data. */
+ if (s->output_section != NULL
+ && isec->output_section == NULL)
{
elf_section_flags (s->output_section) &= ~SHF_GROUP;
elf_group_name (s->output_section) = NULL;
}
+ /* Conversely, if the member section is not being output
+ but the SHT_GROUP section is, then adjust its size. */
+ else if (s->output_section == NULL
+ && isec->output_section != NULL)
+ isec->output_section->size -= 4;
s = elf_next_in_group (s);
if (s == first)
break;
Index: binutils/testsuite/binutils-all/objcopy.exp
===================================================================
RCS file: /cvs/src/src/binutils/testsuite/binutils-all/objcopy.exp,v
retrieving revision 1.64
diff -u -p -r1.64 objcopy.exp
--- binutils/testsuite/binutils-all/objcopy.exp 1 Feb 2010 09:59:46 -0000 1.64
+++ binutils/testsuite/binutils-all/objcopy.exp 17 Feb 2010 22:58:08 -0000
@@ -834,6 +834,7 @@ if [is_elf_format] {
objcopy_test_readelf "ELF group" group-2.s
objcopy_test_readelf "ELF group" group-3.s
objcopy_test_readelf "ELF group" group-4.s
+ run_dump_test "group-5"
run_dump_test "copy-1"
run_dump_test "note-1"
}
Index: binutils/testsuite/binutils-all/group-5.d
===================================================================
RCS file: binutils/testsuite/binutils-all/group-5.d
diff -N binutils/testsuite/binutils-all/group-5.d
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ binutils/testsuite/binutils-all/group-5.d 17 Feb 2010 22:59:23 -0000
@@ -0,0 +1,19 @@
+#PROG: objcopy
+#readelf: -Sg --wide
+#objcopy: --remove-section .dropme
+#name: copy removing group member
+
+#readelf: -Sg --wide
+
+#...
+ \[[ 0-9]+\] foo_group[ \t]+GROUP[ \t]+.*
+#...
+ \[[ 0-9]+\] \.text.*[ \t]+PROGBITS[ \t0-9a-f]+AXG.*
+#...
+ \[[ 0-9]+\] \.data.*[ \t]+PROGBITS[ \t0-9a-f]+WAG.*
+#...
+COMDAT group section \[[ 0-9]+\] `foo_group' \[foo_group\] contains 2 sections:
+ \[Index\] Name
+ \[[ 0-9]+\] .text.*
+ \[[ 0-9]+\] .data.*
+#pass
Index: binutils/testsuite/binutils-all/group-5.s
===================================================================
RCS file: binutils/testsuite/binutils-all/group-5.s
diff -N binutils/testsuite/binutils-all/group-5.s
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ binutils/testsuite/binutils-all/group-5.s 17 Feb 2010 22:59:23 -0000
@@ -0,0 +1,12 @@
+ .section .text.foo,"axG",%progbits,foo_group,comdat
+ .global foo
+foo:
+ .word 0
+
+ .section .data.foo,"awG",%progbits,foo_group,comdat
+ .global bar
+bar:
+ .word 1
+
+ .section .dropme,"G",%progbits,foo_group,comdat
+ .word 2
--
Alan Modra
Australia Development Lab, IBM