From: Alan Modra <amodra@gmail.com>
To: Eirik Byrkjeflot Anonsen <eirik@opera.com>
Cc: binutils@sourceware.org
Subject: Re: objcopy --strip-debug breaks GROUP sections
Date: Thu, 18 Feb 2010 00:43:00 -0000 [thread overview]
Message-ID: <20100218004332.GE9546@bubble.grove.modra.org> (raw)
In-Reply-To: <87d404hu7k.fsf@opera.com>
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
next prev parent reply other threads:[~2010-02-18 0:43 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-16 10:08 Eirik Byrkjeflot Anonsen
2010-02-16 17:26 ` Eirik Byrkjeflot Anonsen
2010-02-16 17:46 ` H.J. Lu
2010-02-17 8:50 ` Eirik Byrkjeflot Anonsen
2010-02-17 10:36 ` Alan Modra
2010-02-17 13:23 ` Eirik Byrkjeflot Anonsen
2010-02-18 0:43 ` Alan Modra [this message]
2010-02-18 10:56 ` Nick Clifton
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100218004332.GE9546@bubble.grove.modra.org \
--to=amodra@gmail.com \
--cc=binutils@sourceware.org \
--cc=eirik@opera.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).