From 8628117143d73743c6b6d5a3e47613d488858b26 Mon Sep 17 00:00:00 2001 From: "H.J. Lu" Date: Sun, 2 Feb 2020 15:32:34 -0800 Subject: [PATCH] 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. The linker bug will be fixed by implementing the 'o' section flag with linked-to section: https://sourceware.org/bugzilla/show_bug.cgi?id=25381 In the meantime, 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.d: Likewise. --- bfd/elflink.c | 7 +++++++ ld/testsuite/ld-elf/pr25490-1.d | 2 ++ ld/testsuite/ld-elf/pr25490-1.s | 9 +++++++++ 3 files changed, 18 insertions(+) create mode 100644 ld/testsuite/ld-elf/pr25490-1.d create mode 100644 ld/testsuite/ld-elf/pr25490-1.s diff --git a/bfd/elflink.c b/bfd/elflink.c index 5217528a79b..e4d92952aaf 100644 --- a/bfd/elflink.c +++ b/bfd/elflink.c @@ -13350,6 +13350,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/testsuite/ld-elf/pr25490-1.d b/ld/testsuite/ld-elf/pr25490-1.d new file mode 100644 index 00000000000..7cc2e6aaa1c --- /dev/null +++ b/ld/testsuite/ld-elf/pr25490-1.d @@ -0,0 +1,2 @@ +#ld: --gc-sections -e _start +#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 00000000000..51ba1ea8014 --- /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 -- 2.24.1