Repository navigation
Conversation
4da0fff to
f6618db
Compare
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configuration
You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Please excuse the noise.. I'm experimenting with coderabbit integration right now. |
|
I had AI craft this kind of change to LLVM, but I don't know enough to say if that's valid or not. diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 1de9851d5ed3..68594fe49663 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -1025,15 +1025,43 @@ static void createOptionalSymbols() {
static void processStubLibrariesPreLTO() {
log("-- processStubLibrariesPreLTO");
+ // The LTO code generator may introduce references to compiler-rt libcall
+ // functions that are not present in the input bitcode (e.g. lowering an
+ // llvm.memcpy intrinsic to a call to memcpy). For a stub symbol that is
+ // one of those libcalls we must preserve its native dependencies even
+ // though the symbol is not (yet) present in the symbol table.
+ DenseSet<StringRef> ltoLibcallSymbols;
+ if (!ctx.bitcodeFiles.empty()) {
+ llvm::Triple TT(ctx.bitcodeFiles.front()->obj->getTargetTriple());
+ for (auto *s : lto::LTO::getRuntimeLibcallSymbols(TT))
+ ltoLibcallSymbols.insert(s);
+ }
for (auto &stub_file : ctx.stubFiles) {
LLVM_DEBUG(llvm::dbgs()
<< "processing stub file: " << stub_file->getName() << "\n");
for (auto [name, deps] : stub_file->symbolDependencies) {
auto *sym = symtab->find(name);
- // If the symbol is not present at all (yet), or if it is present but
- // undefined, then mark the dependent symbols as used by a regular
- // object so they will be preserved and exported by the LTO process.
- if (!sym || sym->isUndefined()) {
+ // Preserve a stub symbol's native dependencies through the LTO process
+ // only if the symbol is (or will be) imported by the final wasm module,
+ // i.e. if it is referenced by code that is part of the link. Pre-LTO
+ // that reference is visible in exactly two cases:
+ // - the symbol is present in the table as an undefined reference,
+ // meaning some active input (a regular object or an already
+ // extracted bitcode archive member) references it;
+ // - the symbol is absent but is a compiler-rt libcall that the LTO
+ // code generator may reference (see above).
+ //
+ // In every other case the symbol is not referenced by any input in the
+ // link: lazy archive members do not contribute their undefined
+ // references to the table (see BitcodeFile::parseLazy), and LTO does
+ // not create references to arbitrary external symbols. The symbol will
+ // therefore not be imported and its native dependencies may be DCE'd by
+ // the LTO process. Preserving them unconditionally, as was done
+ // before, forced every stub dependency to be kept and its archive
+ // member extracted even when nothing referenced the JS symbol, dragging
+ // a large amount of dead code (e.g. the whole itimer/signal machinery)
+ // into -flto builds. See emscripten-core/emscripten#26038.
+ if ((sym && sym->isUndefined()) || (!sym && ltoLibcallSymbols.contains(name))) {
for (const auto dep : deps) {
auto *needed = symtab->find(dep);
if (needed) { |
|
@sbc100 would know best about whether that wasm-ld fix makes sense. |
|
Closing in favor of #28355 |
This PR adds a unit test that fails on issue #26038, and should become green after that issue is fixed.
The problem #26038 is particularly annoying for my 3D engine sizecoding experiment, so looking to find a way to resolve that.
Not to land until #26038 is fixed.