Skip to content

Commit 99ca952

Browse files
committed
[WebAssembly] Change the default linker for wasm32-wasip2
This commit changes the default linker in the WebAssembly toolchain for the `wasm32-wasip2` target. This target is being added to the WebAssembly/wasi-sdk and WebAssembly/wasi-libc projects to target the Component Model by default, in contrast with the preexisting `wasm32-wasi` target (in the process of being renamed to `wasm32-wasip1`) which outputs a core WebAssembly module by default. The `wasm-component-ld` project currently lives in my GitHub account at https://github.com/alexcrichton/wasm-component-ld and isn't necessarily "official" yet, but it's expected to continue to evolve as the `wasm32-wasip2` target continues to shape up and evolve.
1 parent 7d55b91 commit 99ca952

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

clang/lib/Driver/ToolChains/WebAssembly.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,12 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
221221
}
222222
}
223223

224+
const char *WebAssembly::getDefaultLinker() const {
225+
if (getOS() == "wasip2")
226+
return "wasm-component-ld";
227+
return "wasm-ld";
228+
}
229+
224230
bool WebAssembly::IsMathErrnoDefault() const { return false; }
225231

226232
bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }

clang/lib/Driver/ToolChains/WebAssembly.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public ToolChain {
6767
llvm::opt::ArgStringList &CmdArgs) const override;
6868
SanitizerMask getSupportedSanitizers() const override;
6969

70-
const char *getDefaultLinker() const override { return "wasm-ld"; }
70+
const char *getDefaultLinker() const override;
7171

7272
CXXStdlibType GetDefaultCXXStdlibType() const override {
7373
return ToolChain::CST_Libcxx;

clang/test/Driver/wasm-toolchain.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -197,3 +197,11 @@
197197
// RUN: not %clang -### %s --target=wasm32-unknown-unknown --sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \
198198
// RUN: | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s
199199
// PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with '-mno-mutable-globals'
200+
201+
// Test that `wasm32-wasip2` invokes the `wasm-component-ld` linker by default
202+
// instead of `wasm-ld`.
203+
204+
// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \
205+
// RUN: | FileCheck -check-prefix=LINK_WASIP2 %s
206+
// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
207+
// LINK_WASIP2: wasm-component-ld{{.*}}" "-L/foo/lib/wasm32-wasip2" "crt1.o" "[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"

0 commit comments

Comments
 (0)