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
Differential D76935
[COFF] Don't treat DWARF sections as GC roots rnk on Mar 27 2020, 9:19 AM. Authored by
Details DWARF sections are typically live and not COMDAT, so they would be Fixes PR45273
Diff Detail
Event TimelineComment Actions Looks good I think. I'm not very familiar with the GC parts of LLD, but the explanations sound sensible to me, and I believe this solution has been vetted by at least two others already (bug reporter and @rnk). Comment Actions The code change looks good, but I've got some test suggestions. I have some thoughts if COFF/MarkLive.cpp is ever made more sophisticated. In ELF, gc is for sections which are part of the load image (SHF_ALLOC) and non-SHF_ALLOC sections are generally not discarded. I don't know what is similar to SHF_ALLOC in COFF, though.
Comment Actions I guess the analogous flag would be IMAGE_SCN_MEM_DISCARDABLE. It is phrased in the opposite direction: sections lacking the flag are loaded, sections with the flag are not loaded into memory, and are generally sorted to the end of the image. Strangely, LLVM MC suppresses the D assembler flag when printing textual assembly, and infers it from the section name: I realized, though, that there is one major difference in behavior. isDWARF() returns true for .eh_frame sections, but they are not discardable. They must be loaded into memory for unwinding to work. So, in this situation, GC will not work: void foo(); int main() { foo(); } void unused1() { foo(); } void unused2() { foo(); } Compiled like so: The unwind data is not separated into nice little comdat .pdata/.xdata sections, it is a single monolithic .eh_frame section: $ llvm-objdump -h t.o t.o: file format coff-x86-64 Sections: Idx Name Size VMA Type 0 .text 00000000 0000000000000000 TEXT 1 .data 00000000 0000000000000000 DATA 2 .bss 00000000 0000000000000000 BSS 3 .text$main 0000001a 0000000000000000 TEXT 4 .text$unused1 0000000e 0000000000000000 TEXT 5 .text$unused2 0000000e 0000000000000000 TEXT 6 .eh_frame 00000080 0000000000000000 DATA 7 .llvm_addrsig 00000000 0000000000000000 I checked, and it has relocations against all the functions. :( Blech. I think we have to do the isDWARF check.
Comment Actions Also, I hope we don't have to make it sophisticated. Simplicity is a good thing. :) Anyway, I didn't make any code changes, so I will land this with the updated .eh_frame test. Thanks! |
This can be --input-file=%t.map to avoid a cat.