[lld] 8df4e60 - [ELF] Don't consider SHF_ALLOC ".debug*" sections debug sections
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 12 09:59:52 PST 2020
Author: Fangrui Song
Date: 2020-11-12T09:59:43-08:00
New Revision: 8df4e60945fa9efdeab1a2fa2a5cdf22ea9c9112
URL: https://github.com/llvm/llvm-project/commit/8df4e60945fa9efdeab1a2fa2a5cdf22ea9c9112
DIFF: https://github.com/llvm/llvm-project/commit/8df4e60945fa9efdeab1a2fa2a5cdf22ea9c9112.diff
LOG: [ELF] Don't consider SHF_ALLOC ".debug*" sections debug sections
Fixes PR48071
* The Rust compiler produces SHF_ALLOC `.debug_gdb_scripts` (which normally does not have the flag)
* `.debug_gdb_scripts` sections are removed from `inputSections` due to --strip-debug/--strip-all
* When processing --gc-sections, pieces of a SHF_MERGE section can be marked live separately
`=>` segfault when marking liveness of a `.debug_gdb_scripts` which is not split into pieces (because it is not in `inputSections`)
This patch circumvents the problem by not treating SHF_ALLOC ".debug*" as debug sections (to prevent --strip-debug's stripping)
(which is still useful on its own).
Reviewed By: grimar
Differential Revision: https://reviews.llvm.org/D91291
Added:
lld/test/ELF/gc-sections-strip-debug.s
Modified:
lld/ELF/InputSection.h
Removed:
################################################################################
diff --git a/lld/ELF/InputSection.h b/lld/ELF/InputSection.h
index a8771bad0f8a..5b91c1c90bd2 100644
--- a/lld/ELF/InputSection.h
+++ b/lld/ELF/InputSection.h
@@ -397,7 +397,8 @@ static_assert(sizeof(InputSection) <= 184, "InputSection is too big");
#endif
inline bool isDebugSection(const InputSectionBase &sec) {
- return sec.name.startswith(".debug") || sec.name.startswith(".zdebug");
+ return (sec.flags & llvm::ELF::SHF_ALLOC) == 0 &&
+ (sec.name.startswith(".debug") || sec.name.startswith(".zdebug"));
}
// The list of all input sections.
diff --git a/lld/test/ELF/gc-sections-strip-debug.s b/lld/test/ELF/gc-sections-strip-debug.s
new file mode 100644
index 000000000000..e7a5fc0bbf50
--- /dev/null
+++ b/lld/test/ELF/gc-sections-strip-debug.s
@@ -0,0 +1,17 @@
+# REQUIRES: x86
+## Test that we don't strip SHF_ALLOC .debug* or crash (PR48071
+## mark liveness of a merge section which has not been split).
+
+# RUN: llvm-mc -filetype=obj -triple=x86_64 %s -o %t.o
+# RUN: ld.lld %t.o --gc-sections --strip-debug -o %t
+# RUN: llvm-readelf -S %t | FileCheck %s
+
+# CHECK: .debug_gdb_scripts
+
+.globl _start
+_start:
+ leaq .L.str(%rip), %rax
+
+.section .debug_gdb_scripts,"aMS", at progbits,1
+.L.str:
+ .asciz "Rust uses SHF_ALLOC .debug_gdb_scripts"
More information about the llvm-commits
mailing list