Skip to content

Commit afdc4b1

Browse files
authored
[lld][WebAssembly] Don't mark --start-lib/--end-lib files as live (#137714)
Without this change files in `--start-lib`/`--end-lib` groups were being marked as live, which means there static constructors were being included in the link.
1 parent 0e07478 commit afdc4b1

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

lld/test/wasm/Inputs/start-lib1.s

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,10 @@ foo:
55
.functype foo () -> ()
66
call bar
77
end_function
8+
9+
# Static constructor inserted here to ensure the object file is not
10+
# being processed as "live". Live object files have their static constructors
11+
# preserved even if no symbol within is used.
12+
.section .init_array,"",@
13+
.p2align 2
14+
.int32 foo

lld/wasm/Driver.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -318,10 +318,6 @@ void LinkerDriver::addFile(StringRef path) {
318318
if (inWholeArchive) {
319319
for (const auto &[m, offset] : members) {
320320
auto *object = createObjectFile(m, path, offset);
321-
// Mark object as live; object members are normally not
322-
// live by default but -whole-archive is designed to treat
323-
// them as such.
324-
object->markLive();
325321
files.push_back(object);
326322
}
327323

lld/wasm/InputFiles.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,10 @@ ObjFile::ObjFile(MemoryBufferRef m, StringRef archiveName, bool lazy)
423423
// https://github.com/llvm/llvm-project/issues/98778
424424
checkArch(wasmObj->getArch());
425425

426-
// If this isn't part of an archive, it's eagerly linked, so mark it live.
427-
if (archiveName.empty())
426+
// Unless we are processing this as a lazy object file (e.g. part of an
427+
// archive file or within `--start-lib`/`--end-lib`, it's eagerly linked, so
428+
// mark it live.
429+
if (!lazy)
428430
markLive();
429431
}
430432

0 commit comments

Comments
 (0)