diff options
author | Sam Clegg <sbc@chromium.org> | 2023-03-28 21:54:51 -0700 |
---|---|---|
committer | Sam Clegg <sbc@chromium.org> | 2023-03-30 14:27:19 -0700 |
commit | 2ea8a3a56a513484ee36c8ad12f93f35665321d1 (patch) | |
tree | 85022b8e727284827a30e5ea7a736ad59bdb122f /lld/wasm | |
parent | bc73ef0031b50f7443615fef614fb4ecaaa4bd11 (diff) | |
download | llvm-2ea8a3a56a513484ee36c8ad12f93f35665321d1.tar.gz |
[lld][WebAssembly] Process stub libraries before performing LTO
There are cases where stub library processing can trigger new exports
which might require them to be included at LTO time.
Specifically `processStubLibraries` marks symbols as `forceExports`
which even effect the LTO process.
And since the LTO process can generate new undefined symbols
(specifically libcall function) we need to also process the stub
libraries after LTO.
Differential Revision: https://reviews.llvm.org/D147190
Diffstat (limited to 'lld/wasm')
-rw-r--r-- | lld/wasm/Driver.cpp | 14 |
1 files changed, 10 insertions, 4 deletions
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp index 68cd8cabbd7f..7ce221e1f663 100644 --- a/lld/wasm/Driver.cpp +++ b/lld/wasm/Driver.cpp @@ -881,8 +881,7 @@ static void processStubLibraries() { << "processing stub file: " << stub_file->getName() << "\n"); for (auto [name, deps]: stub_file->symbolDependencies) { auto* sym = symtab->find(name); - if (!sym || !sym->isUndefined() || !sym->isUsedInRegularObj || - sym->forceImport) { + if (!sym || !sym->isUndefined() || sym->forceImport) { LLVM_DEBUG(llvm::dbgs() << "stub not in needed: " << name << "\n"); continue; } @@ -907,7 +906,6 @@ static void processStubLibraries() { LLVM_DEBUG(llvm::dbgs() << "force export: " << toString(*needed) << "\n"); needed->forceExport = true; - needed->isUsedInRegularObj = true; if (auto *lazy = dyn_cast<LazySymbol>(needed)) { lazy->fetch(); if (!config->whyExtract.empty()) @@ -1211,7 +1209,9 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { if (errorCount()) return; - writeWhyExtract(); + // processStubLibraries must happen before LTO because it can trigger the + // export of arbirary symbols that might themselves be defined in LTO objects. + processStubLibraries(); // Do link-time optimization if given files are LLVM bitcode files. // This compiles bitcode files into real object files. @@ -1219,8 +1219,14 @@ void LinkerDriver::linkerMain(ArrayRef<const char *> argsArr) { if (errorCount()) return; + // The LTO process can generate new undefined symbols, specifically libcall + // functions. Because those symbols might be declared in a stub library we + // need the process the stub libraries once again after LTO to handle any + // newly undefined symbols. processStubLibraries(); + writeWhyExtract(); + createOptionalSymbols(); // Resolve any variant symbols that were created due to signature |