[PATCH] D91291: [ELF] Don't consider SHF_ALLOC ".debug*" sections debug sections

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Nov 11 12:22:01 PST 2020


MaskRay created this revision.
MaskRay added reviewers: dim, grimar, psmith.
Herald added subscribers: llvm-commits, JDevlieghere, arichardson, emaste.
Herald added a reviewer: espindola.
Herald added a project: LLVM.
MaskRay requested review of this revision.

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`)


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91291

Files:
  lld/ELF/InputSection.h
  lld/test/ELF/gc-sections-strip-debug.s


Index: lld/test/ELF/gc-sections-strip-debug.s
===================================================================
--- /dev/null
+++ 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
+
+# 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"
Index: lld/ELF/InputSection.h
===================================================================
--- lld/ELF/InputSection.h
+++ lld/ELF/InputSection.h
@@ -397,7 +397,8 @@
 #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.


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91291.304619.patch
Type: text/x-patch
Size: 1153 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201111/7f4b4db4/attachment.bin>


More information about the llvm-commits mailing list