diff options
| author | Sam Clegg <sbc@chromium.org> | 2019-03-01 22:35:47 +0000 |
|---|---|---|
| committer | Sam Clegg <sbc@chromium.org> | 2019-03-01 22:35:47 +0000 |
| commit | 0e6b42f5ebd4206f4d491915fe0f10aea13b983b (patch) | |
| tree | 3655ef721fb5165d052e25170d55eaeff02a2f38 /lld/wasm/MarkLive.cpp | |
| parent | f6ca8cba5cdb64afef3657e24419bc454b5d0b10 (diff) | |
| download | bcm5719-llvm-0e6b42f5ebd4206f4d491915fe0f10aea13b983b.tar.gz bcm5719-llvm-0e6b42f5ebd4206f4d491915fe0f10aea13b983b.zip | |
[WebAssebmly] Allow __wasm_call_ctors to be GC'ed
Differential Revision: https://reviews.llvm.org/D58806
llvm-svn: 355240
Diffstat (limited to 'lld/wasm/MarkLive.cpp')
| -rw-r--r-- | lld/wasm/MarkLive.cpp | 28 |
1 files changed, 19 insertions, 9 deletions
diff --git a/lld/wasm/MarkLive.cpp b/lld/wasm/MarkLive.cpp index 5d4b379e297..c3786da06cf 100644 --- a/lld/wasm/MarkLive.cpp +++ b/lld/wasm/MarkLive.cpp @@ -38,32 +38,42 @@ void lld::wasm::markLive() { LLVM_DEBUG(dbgs() << "markLive\n"); SmallVector<InputChunk *, 256> Q; - auto Enqueue = [&](Symbol *Sym) { + std::function<void(Symbol*)> Enqueue = [&](Symbol *Sym) { if (!Sym || Sym->isLive()) return; LLVM_DEBUG(dbgs() << "markLive: " << Sym->getName() << "\n"); Sym->markLive(); if (InputChunk *Chunk = Sym->getChunk()) Q.push_back(Chunk); + + // The ctor functions are all referenced by the synthetic CallCtors + // function. However, this function does not contain relocations so we + // have to manually mark the ctors as live if CallCtors itself is live. + if (Sym == WasmSym::CallCtors) { + for (const ObjFile *Obj : Symtab->ObjectFiles) { + const WasmLinkingData &L = Obj->getWasmObj()->linkingData(); + for (const WasmInitFunc &F : L.InitFunctions) + Enqueue(Obj->getFunctionSymbol(F.Symbol)); + } + } }; // Add GC root symbols. if (!Config->Entry.empty()) Enqueue(Symtab->find(Config->Entry)); - Enqueue(WasmSym::CallCtors); // We need to preserve any exported symbol for (Symbol *Sym : Symtab->getSymbols()) if (Sym->isExported()) Enqueue(Sym); - // The ctor functions are all used in the synthetic __wasm_call_ctors - // function, but since this function is created in-place it doesn't contain - // relocations which mean we have to manually mark the ctors. - for (const ObjFile *Obj : Symtab->ObjectFiles) { - const WasmLinkingData &L = Obj->getWasmObj()->linkingData(); - for (const WasmInitFunc &F : L.InitFunctions) - Enqueue(Obj->getFunctionSymbol(F.Symbol)); + // For relocatable output, we need to preserve all the ctor functions + if (Config->Relocatable) { + for (const ObjFile *Obj : Symtab->ObjectFiles) { + const WasmLinkingData &L = Obj->getWasmObj()->linkingData(); + for (const WasmInitFunc &F : L.InitFunctions) + Enqueue(Obj->getFunctionSymbol(F.Symbol)); + } } // Follow relocations to mark all reachable chunks. |

