Skip to content

Commit c693efe

Browse files
committed
[lld][WebAssembly] Fix stub library deps causing LTO archive members to be required post-LTO
Fixes: emscripten-core/emscripten#16836 Fixes: emscripten-core/emscripten#20275
1 parent da0e66e commit c693efe

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

lld/test/wasm/lto/stub-library.s

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown -o %t.o %s
2-
# RUN: llvm-as %S/Inputs/foo.ll -o %t1.o
3-
# RUN: wasm-ld %t.o %t1.o %p/Inputs/stub.so -o %t.wasm
2+
# RUN: mkdir -p %t
3+
# RUN: llvm-as %S/Inputs/foo.ll -o %t/foo.o
4+
# RUN: rm -f %t/libfoo.a
5+
# RUN: llvm-ar rcs %t/libfoo.a %t/foo.o
6+
# RUN: wasm-ld %t.o %t/libfoo.a %p/Inputs/stub.so -o %t.wasm
47
# RUN: obj2yaml %t.wasm | FileCheck %s
58

6-
# The function `bar` is declared in stub.so and depends on `foo`, which happens
7-
# be in an LTO object.
8-
# This verifies that stub library dependencies (required exports) can be defined
9-
# in LTO objects.
9+
## The function `bar` is declared in stub.so and depends on `foo`, which happens
10+
## be in an LTO object, in an archive file.
11+
## This verifies that stub library dependencies (required exports) can be defined
12+
## in LTO objects.
1013
.functype bar () -> ()
1114

1215
.globl _start

lld/wasm/Driver.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -949,6 +949,17 @@ static void processStubLibrariesPreLTO() {
949949
auto* needed = symtab->find(dep);
950950
if (needed ) {
951951
needed->isUsedInRegularObj = true;
952+
// Like with handleLibcall we have extract any archive members
953+
// that might need to be exported due to stub library symbol being
954+
// used. Without this the LTO object could be extracted during
955+
// processStubLibraries, which is too late since LTO has already
956+
// beeing performed at that point.
957+
if (needed->isLazy() && isa<BitcodeFile>(needed->getFile())) {
958+
if (!config->whyExtract.empty())
959+
ctx.whyExtractRecords.emplace_back("<stubdep>",
960+
needed->getFile(), *needed);
961+
cast<LazySymbol>(needed)->extract();
962+
}
952963
}
953964
}
954965
}

lld/wasm/InputFiles.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -761,7 +761,7 @@ void StubFile::parse() {
761761
}
762762

763763
// Lines starting with # are considered comments
764-
if (line.starts_with("#"))
764+
if (line.starts_with("#") || !line.size())
765765
continue;
766766

767767
StringRef sym;

0 commit comments

Comments
 (0)