ld: Issue an error for GC on __patchable_function_entries section
authorH.J. Lu <hjl.tools@gmail.com>
Fri, 7 Feb 2020 03:37:54 +0000 (19:37 -0800)
committerH.J. Lu <hjl.tools@gmail.com>
Fri, 7 Feb 2020 03:40:38 +0000 (19:40 -0800)
__patchable_function_entries section is generated by a compiler with
-fpatchable-function-entry=XX.  The assembly code looks like this:

---
.text
.globl _start
.type _start, %function
_start:
.section __patchable_function_entries,"aw",%progbits
.dc.a .LPFE1
.text
.LPFE1:
.byte 0
---

But --gc-sections will silently remove __patchable_function_entries
section and generate corrupt result.  This patch disallows garbage
collection on __patchable_function_entries section without linked-to
section.

bfd/

PR ld/25490
* elflink.c (_bfd_elf_gc_mark_extra_sections): Issue an error
for garbage collection on __patchable_function_entries section
without linked-to section.

ld/

PR ld/25490
* testsuite/ld-elf/pr25490-1.d: New file.
* testsuite/ld-elf/pr25490-1.s: Likewise.

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

index 997188570711d59524d8f88b0f810dfceb05f745..e1a84123254cd1afeb6bb5f4eb01053dc48553ff 100644 (file)
@@ -1,3 +1,10 @@
+2020-02-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/25490
+       * elflink.c (_bfd_elf_gc_mark_extra_sections): Issue an error
+       for garbage collection on __patchable_function_entries section
+       without linked-to section.
+
 2020-02-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR gas/25381
index 30a572d32de8b501a7d7ba50ee69b2bab961958a..3add9f18bd7e940f6e4874e875e09b2b6f50a17d 100644 (file)
@@ -13365,6 +13365,13 @@ _bfd_elf_gc_mark_extra_sections (struct bfd_link_info *info,
              && (isec->flags & SEC_DEBUGGING)
              && CONST_STRNEQ (isec->name, ".debug_line."))
            debug_frag_seen = TRUE;
+         else if (strcmp (bfd_section_name (isec),
+                          "__patchable_function_entries") == 0
+                  && elf_linked_to_section (isec) == NULL)
+             info->callbacks->einfo (_("%F%P: %pB(%pA): error: "
+                                       "need linked-to section "
+                                       "for --gc-sections\n"),
+                                     isec->owner, isec);
        }
 
       /* If no non-note alloc section in this file will be kept, then
index b5c8326efb69b21b4f8d1938d903a2cc78ad0053..3ad571f169179811e97e5136a40093ed5cbaa98d 100644 (file)
@@ -1,3 +1,9 @@
+2020-02-06  H.J. Lu  <hongjiu.lu@intel.com>
+
+       PR ld/25490
+       * testsuite/ld-elf/pr25490-1.d: New file.
+       * testsuite/ld-elf/pr25490-1.s: Likewise.
+
 2020-02-06  H.J. Lu  <hongjiu.lu@intel.com>
 
        PR ld/24526
diff --git a/ld/testsuite/ld-elf/pr25490-1.d b/ld/testsuite/ld-elf/pr25490-1.d
new file mode 100644 (file)
index 0000000..3f58264
--- /dev/null
@@ -0,0 +1,3 @@
+#ld: --gc-sections -e _start
+#target: [check_gc_sections_available]
+#error: .*\(__patchable_function_entries\): error: need linked-to section for --gc-sections
diff --git a/ld/testsuite/ld-elf/pr25490-1.s b/ld/testsuite/ld-elf/pr25490-1.s
new file mode 100644 (file)
index 0000000..51ba1ea
--- /dev/null
@@ -0,0 +1,9 @@
+       .text
+       .globl  _start
+       .type   _start, %function
+_start:
+       .section        __patchable_function_entries,"aw",%progbits
+       .dc.a   .LPFE1
+       .text
+.LPFE1:
+       .byte 0