aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorH.J. Lu <hjl.tools@gmail.com>2020-02-06 19:37:54 -0800
committerH.J. Lu <hjl.tools@gmail.com>2020-02-06 19:40:38 -0800
commit5242a0a000ad7d3f2fa1cd0023f692d53261b302 (patch)
treed63d80ceaf397af290aadb5619a6a20299984ded
parentb7d072167715829eed0622616f6ae0182900de3e (diff)
downloadgdb-5242a0a000ad7d3f2fa1cd0023f692d53261b302.zip
gdb-5242a0a000ad7d3f2fa1cd0023f692d53261b302.tar.gz
gdb-5242a0a000ad7d3f2fa1cd0023f692d53261b302.tar.bz2
ld: Issue an error for GC on __patchable_function_entries section
__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.
-rw-r--r--bfd/ChangeLog7
-rw-r--r--bfd/elflink.c7
-rw-r--r--ld/ChangeLog6
-rw-r--r--ld/testsuite/ld-elf/pr25490-1.d3
-rw-r--r--ld/testsuite/ld-elf/pr25490-1.s9
5 files changed, 32 insertions, 0 deletions
diff --git a/bfd/ChangeLog b/bfd/ChangeLog
index 9971885..e1a8412 100644
--- a/bfd/ChangeLog
+++ b/bfd/ChangeLog
@@ -1,5 +1,12 @@
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
* bfd-in2.h: Regenerated.
* elflink.c (_bfd_elf_gc_mark_extra_sections): Call mark_hook
diff --git a/bfd/elflink.c b/bfd/elflink.c
index 30a572d..3add9f1 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -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
diff --git a/ld/ChangeLog b/ld/ChangeLog
index b5c8326..3ad571f 100644
--- a/ld/ChangeLog
+++ b/ld/ChangeLog
@@ -1,5 +1,11 @@
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
PR ld/25021
PR ld/25490
diff --git a/ld/testsuite/ld-elf/pr25490-1.d b/ld/testsuite/ld-elf/pr25490-1.d
new file mode 100644
index 0000000..3f58264
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25490-1.d
@@ -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
index 0000000..51ba1ea
--- /dev/null
+++ b/ld/testsuite/ld-elf/pr25490-1.s
@@ -0,0 +1,9 @@
+ .text
+ .globl _start
+ .type _start, %function
+_start:
+ .section __patchable_function_entries,"aw",%progbits
+ .dc.a .LPFE1
+ .text
+.LPFE1:
+ .byte 0