From a33dafc30dd1cbe7b7659b5b15c553804abef185 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Wed, 14 Jan 2009 21:52:49 +0000 Subject: [PATCH] bfd/ 2009-01-14 H.J. Lu PR ld/9727 * elflink.c (elf_gc_sweep): Exclude the group section if the first member of the section group is excluded. ld/testsuite/ 2009-01-14 H.J. Lu 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. --- bfd/ChangeLog | 6 ++++++ bfd/elflink.c | 19 +++++++++++++++---- ld/testsuite/ChangeLog | 10 ++++++++++ ld/testsuite/ld-elf/group8.s | 10 ++++++++++ ld/testsuite/ld-elf/group8a.d | 8 ++++++++ ld/testsuite/ld-elf/group8b.d | 8 ++++++++ ld/testsuite/ld-elf/group9.s | 15 +++++++++++++++ ld/testsuite/ld-elf/group9a.d | 9 +++++++++ ld/testsuite/ld-elf/group9b.d | 13 +++++++++++++ 9 files changed, 94 insertions(+), 4 deletions(-) create mode 100644 ld/testsuite/ld-elf/group8.s create mode 100644 ld/testsuite/ld-elf/group8a.d create mode 100644 ld/testsuite/ld-elf/group8b.d create mode 100644 ld/testsuite/ld-elf/group9.s create mode 100644 ld/testsuite/ld-elf/group9a.d create mode 100644 ld/testsuite/ld-elf/group9b.d diff --git a/bfd/ChangeLog b/bfd/ChangeLog index e45d26274c3..bc2df929852 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,9 @@ +2009-01-14 H.J. Lu + + PR ld/9727 + * elflink.c (elf_gc_sweep): Exclude the group section if the + first member of the section group is excluded. + 2009-01-14 Alan Modra PR 9735 diff --git a/bfd/elflink.c b/bfd/elflink.c index 29523c4614e..d2cc31a8b16 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -11397,10 +11397,21 @@ elf_gc_sweep (bfd *abfd, struct bfd_link_info *info) 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; diff --git a/ld/testsuite/ChangeLog b/ld/testsuite/ChangeLog index ae1513dc182..fe0d80239a5 100644 --- a/ld/testsuite/ChangeLog +++ b/ld/testsuite/ChangeLog @@ -1,3 +1,13 @@ +2009-01-14 H.J. Lu + + 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. + 2009-01-13 Alan Modra * ld-spu/icache1.s: New file. diff --git a/ld/testsuite/ld-elf/group8.s b/ld/testsuite/ld-elf/group8.s new file mode 100644 index 00000000000..7766c6cc9c8 --- /dev/null +++ b/ld/testsuite/ld-elf/group8.s @@ -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 diff --git a/ld/testsuite/ld-elf/group8a.d b/ld/testsuite/ld-elf/group8a.d new file mode 100644 index 00000000000..1efd6f30109 --- /dev/null +++ b/ld/testsuite/ld-elf/group8a.d @@ -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 diff --git a/ld/testsuite/ld-elf/group8b.d b/ld/testsuite/ld-elf/group8b.d new file mode 100644 index 00000000000..95ea4394514 --- /dev/null +++ b/ld/testsuite/ld-elf/group8b.d @@ -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 diff --git a/ld/testsuite/ld-elf/group9.s b/ld/testsuite/ld-elf/group9.s new file mode 100644 index 00000000000..1e6bcffd718 --- /dev/null +++ b/ld/testsuite/ld-elf/group9.s @@ -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 diff --git a/ld/testsuite/ld-elf/group9a.d b/ld/testsuite/ld-elf/group9a.d new file mode 100644 index 00000000000..7f851001403 --- /dev/null +++ b/ld/testsuite/ld-elf/group9a.d @@ -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 diff --git a/ld/testsuite/ld-elf/group9b.d b/ld/testsuite/ld-elf/group9b.d new file mode 100644 index 00000000000..82ca0623454 --- /dev/null +++ b/ld/testsuite/ld-elf/group9b.d @@ -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 -- 2.30.2