diff options
author | Fangrui Song <maskray@google.com> | 2020-08-03 13:35:59 -0700 |
---|---|---|
committer | Fangrui Song <i@maskray.me> | 2020-08-03 13:43:48 -0700 |
commit | 11bb7c220ccdff1ffec4780ff92fb5acec8f6f0b (patch) | |
tree | 22e238b0944d1c64941b9980beb310b7e70ac25a /llvm/lib/MC/ELFObjectWriter.cpp | |
parent | 41b1e97b12c1407e40d8e5081bf1f9cf183934b0 (diff) | |
download | llvm-11bb7c220ccdff1ffec4780ff92fb5acec8f6f0b.zip llvm-11bb7c220ccdff1ffec4780ff92fb5acec8f6f0b.tar.gz llvm-11bb7c220ccdff1ffec4780ff92fb5acec8f6f0b.tar.bz2 |
[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
Diffstat (limited to 'llvm/lib/MC/ELFObjectWriter.cpp')
-rw-r--r-- | llvm/lib/MC/ELFObjectWriter.cpp | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp index 5a5692c..b44a36b 100644 --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -1024,9 +1024,13 @@ void ELFWriter::writeSection(const SectionIndexMapTy &SectionIndexMap, } if (Section.getFlags() & ELF::SHF_LINK_ORDER) { + // If the value in the associated metadata is not a definition, Sym will be + // undefined. Represent this with sh_link=0. const MCSymbol *Sym = Section.getLinkedToSymbol(); - const MCSectionELF *Sec = cast<MCSectionELF>(&Sym->getSection()); - sh_link = SectionIndexMap.lookup(Sec); + if (Sym && Sym->isInSection()) { + const MCSectionELF *Sec = cast<MCSectionELF>(&Sym->getSection()); + sh_link = SectionIndexMap.lookup(Sec); + } } WriteSecHdrEntry(StrTabBuilder.getOffset(Section.getName()), |