[MC] Set sh_link to 0 if the associated symbol is undefined
authorFangrui Song <maskray@google.com>
Mon, 3 Aug 2020 20:35:59 +0000 (13:35 -0700)
committerFangrui Song <i@maskray.me>
Mon, 3 Aug 2020 20:43:48 +0000 (13:43 -0700)
commit11bb7c220ccdff1ffec4780ff92fb5acec8f6f0b
tree22e238b0944d1c64941b9980beb310b7e70ac25a
parent41b1e97b12c1407e40d8e5081bf1f9cf183934b0
[MC] Set sh_link to 0 if the associated symbol is undefined

Part of https://bugs.llvm.org/show_bug.cgi?id=41734

LTO can drop externally available definitions. Such AssociatedSymbol is
not associated with a symbol. ELFWriter::writeSection() will assert.

Allow a SHF_LINK_ORDER section to have sh_link=0.

We need to give sh_link a syntax, a literal zero in the linked-to symbol
position, e.g. `.section name,"ao",@progbits,0`

Reviewed By: pcc

Differential Revision: https://reviews.llvm.org/D72899
llvm/lib/CodeGen/TargetLoweringObjectFileImpl.cpp
llvm/lib/MC/ELFObjectWriter.cpp
llvm/lib/MC/MCParser/ELFAsmParser.cpp
llvm/lib/MC/MCSectionELF.cpp
llvm/test/CodeGen/X86/elf-associated-discarded.ll [new file with mode: 0644]
llvm/test/CodeGen/X86/elf-associated.ll
llvm/test/MC/ELF/section-linkorder.s [new file with mode: 0644]