[ELF] Fix non-relocatable-non-emit-relocs --gc-sections to discard .L symbols
authorFangrui Song <i@maskray.me>
Thu, 7 Apr 2022 21:34:31 +0000 (14:34 -0700)
committerFangrui Song <i@maskray.me>
Thu, 7 Apr 2022 21:34:32 +0000 (14:34 -0700)
commitbe01af4a0f4ae4633929985cc689ad98a449db05
treec6117f0f151869971308e6987fdd454f77a224dd
parente66f0edb4031dc1742d5f074822e9e8be58d63fc
[ELF] Fix non-relocatable-non-emit-relocs --gc-sections to discard .L symbols

This reverts commit 764cd491b126318add093c7c8ba3884967d64b21, which I
incorrectly assumed NFC partly because there were no test coverage for the
non-relocatable non-emit-relocs case before 9d6d936243fe343abe89323a27c7241b395af541.

The interaction of {,-r,--emit-relocs} {,--discard-locals} {,--gc-sections} is
complex but without -r/--emit-relocs, --gc-sections does need to discard .L
symbols like --no-gc-sections. The behavior matches GNU ld.
lld/ELF/Writer.cpp
lld/test/ELF/discard-locals.s