Skip to content

Commit c579a5b

Browse files
committed
[COFF] Don't treat DWARF sections as GC roots
DWARF sections are typically live and not COMDAT, so they would be treated as GC roots. Enabling DWARF would essentially keep all code with debug info alive, preventing any section GC. Fixes PR45273 Reviewed By: mstorsjo, MaskRay Differential Revision: https://reviews.llvm.org/D76935
1 parent 457eb05 commit c579a5b

File tree

2 files changed

+64
-2
lines changed

2 files changed

+64
-2
lines changed

lld/COFF/MarkLive.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ void markLive(ArrayRef<Chunk *> chunks) {
2828
// as we push, so sections never appear twice in the list.
2929
SmallVector<SectionChunk *, 256> worklist;
3030

31-
// COMDAT section chunks are dead by default. Add non-COMDAT chunks.
31+
// COMDAT section chunks are dead by default. Add non-COMDAT chunks. Do not
32+
// traverse DWARF sections. They are live, but they should not keep other
33+
// sections alive.
3234
for (Chunk *c : chunks)
3335
if (auto *sc = dyn_cast<SectionChunk>(c))
34-
if (sc->live)
36+
if (sc->live && !sc->isDWARF())
3537
worklist.push_back(sc);
3638

3739
auto enqueue = [&](SectionChunk *c) {

lld/test/COFF/gc-dwarf.s

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# REQUIRES: x86
2+
3+
# RUN: llvm-mc -triple=x86_64-windows-msvc %s -filetype=obj -o %t.obj
4+
# RUN: lld-link -lldmap:%t.map -out:%t.exe -opt:ref -entry:main %t.obj -verbose 2>&1 | FileCheck %s
5+
# RUN: FileCheck %s --check-prefix=MAP --input-file=%t.map
6+
7+
# CHECK: Discarded unused1
8+
# CHECK-NEXT: Discarded unused2
9+
# CHECK-NOT: Discarded
10+
11+
# MAP: In Symbol
12+
# MAP: gc-dwarf.s.tmp.obj:(.text)
13+
# MAP: {{ main$}}
14+
# MAP: gc-dwarf.s.tmp.obj:(.text)
15+
# MAP: {{ used$}}
16+
17+
.def @feat.00; .scl 3; .type 0; .endef
18+
.globl @feat.00
19+
.set @feat.00, 0
20+
21+
.def main; .scl 2; .type 32; .endef
22+
.section .text,"xr",one_only,main
23+
.globl main
24+
main:
25+
callq used
26+
xorl %eax, %eax
27+
retq
28+
29+
.def used; .scl 2; .type 32; .endef
30+
.section .text,"xr",one_only,used
31+
.globl used
32+
used:
33+
retq
34+
35+
36+
.def unused1; .scl 2; .type 32; .endef
37+
.section .text,"xr",one_only,unused1
38+
.globl unused1
39+
unused1:
40+
retq
41+
42+
.def unused2; .scl 2; .type 32; .endef
43+
.section .text,"xr",one_only,unused2
44+
.globl unused2
45+
unused2:
46+
retq
47+
48+
# This isn't valid DWARF, but LLD doesn't care. Make up some data that
49+
# references the functions above.
50+
.section .debug_info,"r"
51+
.long main@IMGREL
52+
.long unused1@IMGREL
53+
.long unused2@IMGREL
54+
55+
# Similarly, .eh_frame unwind info should not keep functions alive. Again, this
56+
# is not valid unwind info, but it doesn't matter for testing purposes.
57+
.section .eh_frame,"r"
58+
.long main@IMGREL
59+
.long unused1@IMGREL
60+
.long unused2@IMGREL

0 commit comments

Comments
 (0)