[ELF] Don't consider SHF_ALLOC ".debug*" sections debug sections
authorFangrui Song <i@maskray.me>
Thu, 12 Nov 2020 17:59:43 +0000 (09:59 -0800)
committerFangrui Song <i@maskray.me>
Thu, 12 Nov 2020 17:59:43 +0000 (09:59 -0800)
commit8df4e60945fa9efdeab1a2fa2a5cdf22ea9c9112
tree979e87fb2bf345ab8d040833ce10dc4ea1f816b1
parentac523d2de51c4119ae6233200af07599d61de1fc
[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
lld/ELF/InputSection.h
lld/test/ELF/gc-sections-strip-debug.s [new file with mode: 0644]