Skip to content

Add unit test for issue #26038. - #27966

Closed
juj wants to merge 1 commit into
mainfrom
add_test_for_issue_26038
Closed

juj wants to merge 1 commit into
mainfrom
add_test_for_issue_26038

Conversation

@juj

@juj juj commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

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.

Comment thread test/test_core.py Fixed
@juj
juj force-pushed the add_test_for_issue_26038 branch from 4da0fff to f6618db Compare October 13, 2026 23:49
@coderabbitai

coderabbitai Bot commented Oct 13, 2026

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration
  • Configuration used: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 43f462bb-2645-42f7-860a-00190be6f9a8

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@sbc100

sbc100 commented Oct 13, 2026

Copy link
Copy Markdown
Collaborator

Please excuse the noise.. I'm experimenting with coderabbit integration right now.

@juj

juj commented Oct 27, 2026

Copy link
Copy Markdown
Collaborator Author

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) {

@juj

juj commented Nov 18, 2026

Copy link
Copy Markdown
Collaborator Author

Hey @dschuff @tlively I wonder what you might think about this? This is a rather painful LTO related issue that I'm running routinely into with Emscripten - would be great to find a fix for this.

When I locally applied the above fix, it did resolve the problem for me. Does that look proper?

@tlively

tlively commented Nov 19, 2026

Copy link
Copy Markdown
Member

@sbc100 would know best about whether that wasm-ld fix makes sense.

@juj

juj commented Nov 21, 2026

Copy link
Copy Markdown
Collaborator Author

Closing in favor of #28355

@juj juj closed this Nov 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants