[lld] [lld][WebAssembly] Fix stub library deps causing LTO archive members to be required post-LTO (PR #101894)
Sam Clegg via llvm-commits
llvm-commits at lists.llvm.org
Mon Aug 5 08:43:08 PDT 2024
https://github.com/sbc100 updated https://github.com/llvm/llvm-project/pull/101894
>From c693efe4c9294d2410dea3c28e71d9814cbce6e9 Mon Sep 17 00:00:00 2001
From: Sam Clegg <sbc at chromium.org>
Date: Sun, 4 Aug 2024 07:17:55 -0700
Subject: [PATCH] [lld][WebAssembly] Fix stub library deps causing LTO archive
members to be required post-LTO
Fixes: https://github.com/emscripten-core/emscripten/issues/16836
Fixes: https://github.com/emscripten-core/emscripten/issues/20275
---
lld/test/wasm/lto/stub-library.s | 15 +++++++++------
lld/wasm/Driver.cpp | 11 +++++++++++
lld/wasm/InputFiles.cpp | 2 +-
3 files changed, 21 insertions(+), 7 deletions(-)
diff --git a/lld/test/wasm/lto/stub-library.s b/lld/test/wasm/lto/stub-library.s
index 20e2a62211413..a5c724012faec 100644
--- a/lld/test/wasm/lto/stub-library.s
+++ b/lld/test/wasm/lto/stub-library.s
@@ -1,12 +1,15 @@
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
-# RUN: llvm-as %S/Inputs/foo.ll -o %t1.o
-# RUN: wasm-ld %t.o %t1.o %p/Inputs/stub.so -o %t.wasm
+# RUN: mkdir -p %t
+# RUN: llvm-as %S/Inputs/foo.ll -o %t/foo.o
+# RUN: rm -f %t/libfoo.a
+# RUN: llvm-ar rcs %t/libfoo.a %t/foo.o
+# RUN: wasm-ld %t.o %t/libfoo.a %p/Inputs/stub.so -o %t.wasm
# RUN: obj2yaml %t.wasm | FileCheck %s
-# The function `bar` is declared in stub.so and depends on `foo`, which happens
-# be in an LTO object.
-# This verifies that stub library dependencies (required exports) can be defined
-# in LTO objects.
+## The function `bar` is declared in stub.so and depends on `foo`, which happens
+## be in an LTO object, in an archive file.
+## This verifies that stub library dependencies (required exports) can be defined
+## in LTO objects.
.functype bar () -> ()
.globl _start
diff --git a/lld/wasm/Driver.cpp b/lld/wasm/Driver.cpp
index 8c83d17db02f5..32fbb01eb6ce5 100644
--- a/lld/wasm/Driver.cpp
+++ b/lld/wasm/Driver.cpp
@@ -949,6 +949,17 @@ static void processStubLibrariesPreLTO() {
auto* needed = symtab->find(dep);
if (needed ) {
needed->isUsedInRegularObj = true;
+ // Like with handleLibcall we have extract any archive members
+ // that might need to be exported due to stub library symbol being
+ // used. Without this the LTO object could be extracted during
+ // processStubLibraries, which is too late since LTO has already
+ // beeing performed at that point.
+ if (needed->isLazy() && isa<BitcodeFile>(needed->getFile())) {
+ if (!config->whyExtract.empty())
+ ctx.whyExtractRecords.emplace_back("<stubdep>",
+ needed->getFile(), *needed);
+ cast<LazySymbol>(needed)->extract();
+ }
}
}
}
diff --git a/lld/wasm/InputFiles.cpp b/lld/wasm/InputFiles.cpp
index f3f0ef9a99497..532c2e619e1bb 100644
--- a/lld/wasm/InputFiles.cpp
+++ b/lld/wasm/InputFiles.cpp
@@ -761,7 +761,7 @@ void StubFile::parse() {
}
// Lines starting with # are considered comments
- if (line.starts_with("#"))
+ if (line.starts_with("#") || !line.size())
continue;
StringRef sym;
More information about the llvm-commits
mailing list