Allow note sections to be discarded when they are linked to another discarded secction.
authorH.J. Lu <hongjiu.lu@intel.com>
Fri, 2 Oct 2020 10:08:19 +0000 (11:08 +0100)
committerNick Clifton <nickc@redhat.com>
Fri, 2 Oct 2020 10:08:19 +0000 (11:08 +0100)
PR 26681
bfd * elflink.c (bfd_elf_gc_sections): Do not arbitrarily keep note
sections which are linked to another section.

ld * testsuite/ld-elf/pr26681.s: New test.
* testsuite/ld-elf/pr26681.d: New test driver.
* testsuite/ld-elf/pr26681.l: New test output.

bfd/ChangeLog
bfd/elflink.c
ld/ChangeLog
ld/testsuite/ld-elf/pr26681.d [new file with mode: 0644]
ld/testsuite/ld-elf/pr26681.l [new file with mode: 0644]
ld/testsuite/ld-elf/pr26681.s [new file with mode: 0644]

index 317c0d39d86195f96eec2294812c7daa14396e88..623cb8a188b870bcc8fad503e27ef5d598094eca 100644 (file)
@@ -1,3 +1,9 @@
+2020-10-02  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR 26681
+       * elflink.c (bfd_elf_gc_sections): Do not arbitrarily keep note
+       sections which are linked to another section.
+
 2020-09-28  Przemyslaw Wirkus  <przemyslaw.wirkus@arm.com>
 
        * cpu-arm.c: (processors) Add Cortex-X1.
index b6937293e8fb0894977f7901213955edc58d426b..e23d189b9835047c90f84a37970f6cc534727597 100644 (file)
@@ -14102,7 +14102,8 @@ bfd_elf_gc_sections (bfd *abfd, struct bfd_link_info *info)
                        || (elf_section_data (o)->this_hdr.sh_type
                            == SHT_FINI_ARRAY)))
                || (elf_section_data (o)->this_hdr.sh_type == SHT_NOTE
-                   && elf_next_in_group (o) == NULL )))
+                   && elf_next_in_group (o) == NULL
+                   && elf_linked_to_section (o) == NULL)))
          {
            if (!_bfd_elf_gc_mark (info, o, gc_mark_hook))
              return FALSE;
index 134db8cdac80b628565cee29fba6676927e7fc12..a6beac08449a91583d4ddecf18f9a3474c2bcd33 100644 (file)
@@ -1,3 +1,10 @@
+2020-10-01  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR 26681
+       * testsuite/ld-elf/pr26681.s: New test.
+       * testsuite/ld-elf/pr26681.d: New test driver.
+       * testsuite/ld-elf/pr26681.l: New test output.
+
 2020-09-30  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/26675
diff --git a/ld/testsuite/ld-elf/pr26681.d b/ld/testsuite/ld-elf/pr26681.d
new file mode 100644 (file)
index 0000000..01c1ce8
--- /dev/null
@@ -0,0 +1,3 @@
+#ld: --gc-sections --print-gc-sections -e _start
+#warning_output: pr26681.l
+#target: [check_gc_sections_available]
diff --git a/ld/testsuite/ld-elf/pr26681.l b/ld/testsuite/ld-elf/pr26681.l
new file mode 100644 (file)
index 0000000..05da9b2
--- /dev/null
@@ -0,0 +1,5 @@
+#...
+.*: removing unused section '\.unused1' in file 'tmpdir/.*\.o'
+#...
+.*: removing unused section '\.gnu.note1' in file 'tmpdir/.*\.o'
+#...
diff --git a/ld/testsuite/ld-elf/pr26681.s b/ld/testsuite/ld-elf/pr26681.s
new file mode 100644 (file)
index 0000000..0417bed
--- /dev/null
@@ -0,0 +1,10 @@
+       .text
+       .globl _start
+_start:
+       .nop
+
+       .section .unused1, "ax", %progbits
+       .nop
+
+       .section .gnu.note1, "o", %note, .unused1
+       .word 2