r282444 introduced new issue, sample program below
fails to link on
assert(Piece.Live);
int main() { return 0; }
clang test.cpp -c -o out.o -g
ld.lld -flavor gnu --gc-sections out.o -o out
Problem is that .debug_info contains relocations to .debug_str:
Section (7) .rela.debug_info {
..
0xC R_X86_64_32 .debug_str 0x0 0x12 R_X86_64_32 .debug_str 0x37
..
But we do not preserve .debug_str in a right way now.
To fix this we should ignore relocations from non-allocatable sections to allocatable
to allow GC work at full power, but still should proccess relocations from non-allocatable to non-allocatable sections
as usual to mark some parts of debug sections alive to keep them so we do not end
up with such assert when trying to access dead pieces. That looks like what gold/ld do, they do
not strip .debug_str section from what I saw using sample provided.
Thanks to Evgeny Leviant for suggestions about how to fix this.
Add a third, unused string and check if it is kept or not.