diff options
| author | Sam Clegg <sbc@chromium.org> | 2019-01-30 18:55:15 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2019-01-30 18:55:15 +0000 |
| commit | 89e4dcb4be63ae71c533abac0a05fec284898a56 (patch) | |
| tree | eebcef9ac167c09df4945a0ef34cd19b53597a76 /lld/wasm/Writer.cpp | |
| parent | edb874b2310dc6eeaa27330ca1b1c013da7bdd65 (diff) | |
| download | bcm5719-llvm-89e4dcb4be63ae71c533abac0a05fec284898a56.tar.gz bcm5719-llvm-89e4dcb4be63ae71c533abac0a05fec284898a56.zip | |
[WebAssembly] Fix crash with LTO + relocatable + undefined symbols
Change the way we create the symbol table to be closer to how its done
on ELF. Now the output symbol table matches the internal symtab order
and includes local and undefined symbols.
Fixes PR40204
Differential Revision: https://reviews.llvm.org/D56947
llvm-svn: 352645
Diffstat (limited to 'lld/wasm/Writer.cpp')
| -rw-r--r-- | lld/wasm/Writer.cpp | 58 |
1 files changed, 30 insertions, 28 deletions
diff --git a/lld/wasm/Writer.cpp b/lld/wasm/Writer.cpp index 9ae020e0f61..d8986c83738 100644 --- a/lld/wasm/Writer.cpp +++ b/lld/wasm/Writer.cpp @@ -903,40 +903,42 @@ void Writer::assignSymtab() { StringMap<uint32_t> SectionSymbolIndices; unsigned SymbolIndex = SymtabEntries.size(); - for (ObjFile *File : Symtab->ObjectFiles) { - LLVM_DEBUG(dbgs() << "Symtab entries: " << File->getName() << "\n"); - for (Symbol *Sym : File->getSymbols()) { - if (Sym->getFile() != File) - continue; - - if (auto *S = dyn_cast<SectionSymbol>(Sym)) { - StringRef Name = S->getName(); - if (CustomSectionMapping.count(Name) == 0) - continue; - - auto SSI = SectionSymbolIndices.find(Name); - if (SSI != SectionSymbolIndices.end()) { - Sym->setOutputSymbolIndex(SSI->second); - continue; - } - SectionSymbolIndices[Name] = SymbolIndex; - CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym); + auto AddSymbol = [&](Symbol *Sym) { + if (auto *S = dyn_cast<SectionSymbol>(Sym)) { + StringRef Name = S->getName(); + if (CustomSectionMapping.count(Name) == 0) + return; - Sym->markLive(); + auto SSI = SectionSymbolIndices.find(Name); + if (SSI != SectionSymbolIndices.end()) { + Sym->setOutputSymbolIndex(SSI->second); + return; } - // (Since this is relocatable output, GC is not performed so symbols must - // be live.) - assert(Sym->isLive()); - Sym->setOutputSymbolIndex(SymbolIndex++); - SymtabEntries.emplace_back(Sym); + SectionSymbolIndices[Name] = SymbolIndex; + CustomSectionSymbols[Name] = cast<SectionSymbol>(Sym); + + Sym->markLive(); } - } - // For the moment, relocatable output doesn't contain any synthetic functions, - // so no need to look through the Symtab for symbols not referenced by - // Symtab->ObjectFiles. + // (Since this is relocatable output, GC is not performed so symbols must + // be live.) + assert(Sym->isLive()); + Sym->setOutputSymbolIndex(SymbolIndex++); + SymtabEntries.emplace_back(Sym); + }; + + for (Symbol *Sym : Symtab->getSymbols()) + if (!Sym->isLazy()) + AddSymbol(Sym); + + for (ObjFile *File : Symtab->ObjectFiles) { + LLVM_DEBUG(dbgs() << "Local symtab entries: " << File->getName() << "\n"); + for (Symbol *Sym : File->getSymbols()) + if (Sym->isLocal()) + AddSymbol(Sym); + } } uint32_t Writer::lookupType(const WasmSignature &Sig) { |

