Skip to content

[lld][WebAssembly] Reject shared libraries when -static/-Bstatic is used #108263

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions lld/test/wasm/static-error.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// RUN: llvm-mc -filetype=obj -triple=wasm32-unknown-unknown %s -o %t.o
// RUN: wasm-ld --experimental-pic -shared -o %t.so %t.o

// RUN: wasm-ld --experimental-pic -pie -o /dev/null %t.o %t.so
// RUN: not wasm-ld -o /dev/null -static %t.o %t.so 2>&1 | FileCheck %s

// CHECK: attempted static link of dynamic object

.global _start
_start:
.functype _start () -> ()
end_function
10 changes: 8 additions & 2 deletions lld/wasm/Driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -333,9 +333,15 @@ void LinkerDriver::addFile(StringRef path) {
return;
}
case file_magic::bitcode:
case file_magic::wasm_object:
files.push_back(createObjectFile(mbref, "", 0, inLib));
case file_magic::wasm_object: {
auto obj = createObjectFile(mbref, "", 0, inLib);
if (config->isStatic && isa<SharedFile>(obj)) {
error("attempted static link of dynamic object " + path);
break;
}
files.push_back(obj);
break;
}
case file_magic::unknown:
if (mbref.getBuffer().starts_with("#STUB")) {
files.push_back(make<StubFile>(mbref));
Expand Down
Loading