[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-29 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

Oop no I did not, thank you for the heads up! I'll work on updating wasi-sdk 
now.

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-22 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

Yes it's expected that wasi-sdk will need changes to incorporate this PR. I'm 
waiting for this to be in an LLVM release before updating wasi-sdk.

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread Alex Crichton via cfe-commits

https://github.com/alexcrichton updated 
https://github.com/llvm/llvm-project/pull/84569

>From 99ca952b60344d2ff683d05d8baa423aa11da83a Mon Sep 17 00:00:00 2001
From: Alex Crichton 
Date: Fri, 8 Mar 2024 13:36:18 -0800
Subject: [PATCH 1/2] [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.
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp | 6 ++
 clang/lib/Driver/ToolChains/WebAssembly.h   | 2 +-
 clang/test/Driver/wasm-toolchain.c  | 8 
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index b8c2573d6265fb..a6c43c627f7206 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -221,6 +221,12 @@ WebAssembly::WebAssembly(const Driver , const 
llvm::Triple ,
   }
 }
 
+const char *WebAssembly::getDefaultLinker() const {
+  if (getOS() == "wasip2")
+return "wasm-component-ld";
+  return "wasm-ld";
+}
+
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
 
 bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h 
b/clang/lib/Driver/ToolChains/WebAssembly.h
index ae60f464c10818..76e0ca39bd748d 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
@@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public 
ToolChain {
llvm::opt::ArgStringList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
 
-  const char *getDefaultLinker() const override { return "wasm-ld"; }
+  const char *getDefaultLinker() const override;
 
   CXXStdlibType GetDefaultCXXStdlibType() const override {
 return ToolChain::CST_Libcxx;
diff --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index f950283ec42aa0..59cfdfb3cb113b 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -197,3 +197,11 @@
 // RUN: not %clang -### %s --target=wasm32-unknown-unknown 
--sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s
 // PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with 
'-mno-mutable-globals'
+
+// Test that `wasm32-wasip2` invokes the `wasm-component-ld` linker by default
+// instead of `wasm-ld`.
+
+// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK_WASIP2 %s
+// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_WASIP2: wasm-component-ld{{.*}}" "-L/foo/lib/wasm32-wasip2" "crt1.o" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"

>From 7284fd4c545388985f44e6bf336aad44c083a197 Mon Sep 17 00:00:00 2001
From: Alex Crichton 
Date: Mon, 18 Mar 2024 12:23:23 -0700
Subject: [PATCH 2/2] Pass a path to `wasm-ld` to `wasm-component-ld`

This commit adds an explicit argument that's passed to
`wasm-component-ld` containing the location of `wasm-ld` itself. This
enables `wasm-component-ld` to avoid hunting around looking for it and
instead use the install that's paired with Clang itself.

Additionally this reinterprets the `-fuse-ld=lld` argument to explicitly
requesting the `wasm-ld` linker flavor, even on `wasm32-wasip2` targets.
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp | 21 +++--
 clang/test/Driver/wasm-toolchain.c  | 16 
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index a6c43c627f7206..b7c6efab83e806 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -44,8 +44,15 @@ std::string wasm::Linker::getLinkerPath(const ArgList ) 
const {
   llvm::sys::fs::can_execute(UseLinker))
 return std::string(UseLinker);
 
-  // Accept 'lld', and 'ld' as aliases for the default linker
-  if (UseLinker != "lld" && UseLinker != "ld")
+  // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that
+  // linker. Note that for `wasm32-wasip2` this overrides the default 
linker
+  // of `wasm-component-ld`.
+  if (UseLinker 

[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

At @sunfishcode's request I've pushed up a second commit which pass the path to 
`wasm-ld` to `wasm-component-ld`, and in testing it I also added the ability 
for `-fuse-ld=lld` to explicitly request that `wasm-ld` is used, regardless of 
target.

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread Alex Crichton via cfe-commits

https://github.com/alexcrichton updated 
https://github.com/llvm/llvm-project/pull/84569

>From 99ca952b60344d2ff683d05d8baa423aa11da83a Mon Sep 17 00:00:00 2001
From: Alex Crichton 
Date: Fri, 8 Mar 2024 13:36:18 -0800
Subject: [PATCH 1/2] [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.
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp | 6 ++
 clang/lib/Driver/ToolChains/WebAssembly.h   | 2 +-
 clang/test/Driver/wasm-toolchain.c  | 8 
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index b8c2573d6265fb..a6c43c627f7206 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -221,6 +221,12 @@ WebAssembly::WebAssembly(const Driver , const 
llvm::Triple ,
   }
 }
 
+const char *WebAssembly::getDefaultLinker() const {
+  if (getOS() == "wasip2")
+return "wasm-component-ld";
+  return "wasm-ld";
+}
+
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
 
 bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h 
b/clang/lib/Driver/ToolChains/WebAssembly.h
index ae60f464c10818..76e0ca39bd748d 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
@@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public 
ToolChain {
llvm::opt::ArgStringList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
 
-  const char *getDefaultLinker() const override { return "wasm-ld"; }
+  const char *getDefaultLinker() const override;
 
   CXXStdlibType GetDefaultCXXStdlibType() const override {
 return ToolChain::CST_Libcxx;
diff --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index f950283ec42aa0..59cfdfb3cb113b 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -197,3 +197,11 @@
 // RUN: not %clang -### %s --target=wasm32-unknown-unknown 
--sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s
 // PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with 
'-mno-mutable-globals'
+
+// Test that `wasm32-wasip2` invokes the `wasm-component-ld` linker by default
+// instead of `wasm-ld`.
+
+// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK_WASIP2 %s
+// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_WASIP2: wasm-component-ld{{.*}}" "-L/foo/lib/wasm32-wasip2" "crt1.o" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"

>From d1a1b22da3e1361a34f2d4fa8a2f9ef361f109ee Mon Sep 17 00:00:00 2001
From: Alex Crichton 
Date: Mon, 18 Mar 2024 12:23:23 -0700
Subject: [PATCH 2/2] Pass a path to `wasm-ld` to `wasm-component-ld`

This commit adds an explicit argument that's passed to
`wasm-component-ld` containing the location of `wasm-ld` itself. This
enables `wasm-component-ld` to avoid hunting around looking for it and
instead use the install that's paired with Clang itself.

Additionally this reinterprets the `-fuse-ld=lld` argument to explicitly
requesting the `wasm-ld` linker flavor, even on `wasm32-wasip2` targets.
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp | 20 ++--
 clang/test/Driver/wasm-toolchain.c  | 16 
 2 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index a6c43c627f7206..61bf9d8aae72d2 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -44,8 +44,15 @@ std::string wasm::Linker::getLinkerPath(const ArgList ) 
const {
   llvm::sys::fs::can_execute(UseLinker))
 return std::string(UseLinker);
 
-  // Accept 'lld', and 'ld' as aliases for the default linker
-  if (UseLinker != "lld" && UseLinker != "ld")
+  // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that
+  // linker. Note that for `wasm32-wasip2` this overrides the default 
linker
+  // of `wasm-component-ld`.
+  if (UseLinker 

[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-18 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

ping @sbc100, happy to answer any more questions if you have them! 

I was tentatively hoping this could get backported to an 18.1.x release so we 
could get a wasi-sdk release with p1/p2/etc

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-08 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

> So the core module + metadata is kind of isomorphic with that 
> single-core-module-component?

Sort of and sort of not. At a high level you're correct, but at a technical 
level this isn't correct. The subtle differences are:

* Most wasm binaries today using WASI probably use `wasi_snapshot_preview1` 
imports. That means they need an "adapter" to switch to to WASIp2-based 
imports. That adapter is a core wasm which is currently baked into 
`wasm-component-ld` (see the adapters in [this 
folder](https://github.com/alexcrichton/wasm-component-ld/tree/main/src))
* Due to the way components and lifting and lowering works many imports need a 
"shim". For example in the component model when you "lower" a function from a 
component function to a core function you need to specify a linear memory. A 
linear memory isn't available until you instantiate the core module, but the 
core module needs the lowered imports to be instantiated. To break this cycle 
we introduce a shim wasm module which uses `call_indirect` through a table for 
its exports, so that's used to pass in as imports when instantiating the main 
module, and then after the main module is instantiated we instantiate another 
shim module that fills in the table.

Going from core module + metadata into a component is a pretty nontrivial 
operation, so the raw output of `wasm-ld` (module + metadata) isn't suitable as 
an intermediate artifact for components. 

> I was more asking about whether the file types is accepts are anything more 
> than object files and libraries. i.e. can you pass other core modules and 
> have wasm-component-ld build a component that contains more than one core 
> module?


Ah sory I misunderstood! Currently wasm-component-ld takes no other inputs and 
it assumes everything goes into `wasm-ld`. In the future for the dynamic 
linking case above it may start taking in `*.wasm` binaries compiled as shared 
libraries to bundle and/or refer to in the output component, but that's in the 
future. That means that at this time wasm-component-ld will always build a 
component with a single "main module", e.g. the one from `wasm-ld`.

> Also, can you say more about the metadata that is being using to drive 
> wasm-componenet-ld? If the core module is all based on canonical ABI what 
> extra metdata is needed/planned?

Certainly! The canonical ABI gives the ability to say that for any component 
model function type it corresponds to a particular core wasm function type. 
That operation is not reversible, though, you can't go from core wasm back to 
the component model function type. Thus the metadata carries along this 
information. That way the componentization process draws a mapping from 
component model import/export to core wasm import/export and then can 
synthesize the right type in the component binary format.

The short answer to your question, though, is `wasm-tools component wit 
./my-wit-files --wasm`. That output blob, which is itself a component but only 
with type information, is embedded in core wasm. Put another way we start with 
WIT files, then those are converted into their binary format as a component 
with only types, that gets fed through LLVM/wasm-ld, then on the other end we 
deserialize the component-with-type-information, turn it back into WIT, and 
then make the real component.

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-08 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

Currently it accepts no extra inputs, but in the future I'd expect that it'll 
grow an option or two of its own. Currently it [hand-codes the list of options 
to forward to 
`wasm-ld`](https://github.com/alexcrichton/wasm-component-ld/blob/2f6106e395e2db99a8bb0524088d08bb6964997a/src/main.rs#L23-L53)
 which I'm sure will need updates over time, but that should be ok. And yes, 
the purpose of `wasm-component-ld` is twofold:

1. First it invokes `wasm-ld` internally, producing the core wasm that's 
expected today.
2. Next it invokes the "componentization process" which activates some Rust 
crates that converts this output core wasm module into a component.

In step (2) it's using component type information smuggled through LLVM/wasm-ld 
through custom sections to create the final output component.

> Do we expect clang users to be building compound components using a single 
> clang command?

If by compound you mean linking multiple components internally, then no. The 
intention is that `wasm32-wasip2` outputs a component but internally it's 
"just" a core wasm module. The next phase of composing components together 
we've got other tooling for, and that's intended to be outside the scope of 
individual language toolchains. (e.g. in theory composition works the same 
regardless of source language)

> Would it make more sense to have clang default to building core modules and 
> have the component creation be a higher level thing built on top clang 
> outputs?

That's actually what we currently have to day with converting `wasm32-wasip1` 
outputs into components. The purpose of `wasm32-wasip2`, however, is that core 
wasms are not natively usable as-is because WASI APIs are defined at the level 
of the component model, not core wasm. There is of course definitions for core 
wasm using the canonical ABI, but that's not the focus of WASI nowdays.

I do plan on having a flag (also answering the question about 
wasm-component-ld-specific-flags) to not emit a component and instead skip the 
componentization step. This step could also be done by using `-fuse-ld=wasm-ld` 
(or the equivalent thereof) to just switch the default linker back to `wasm-ld`.

> Regarding WebAssembly/wasi-sdk and WebAssembly/wasi-libc, is there any reason 
> why simple programs wouldn't be core modules? Won't most C/C++ programs still 
> be build-able as just core modules?

Yep, they'll all still be buildable as core modules (as that's the internals of 
a component anyway, a big thing produced by LLVM). With the p2 target though 
the thinking is that components are the default output, not core wasm modules.

---

Another future feature on the theoretical roadmap for wasm-component-ld is that 
Joel has componentize-py built on "dynamic linking" of a sort which gets 
`dlopen` working enough for Python to open its native extensions. This is all 
built on the Emscripten dynamic linking model and a component packages that all 
up into a single component where the dynamic libraries are statically known at 
build time. This is all wrapped up in `wasm-tools component link` and is 
something I'd like to also automatically bake in to `wasm-component-ld` so 
building that style of component is much easier.

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-08 Thread Alex Crichton via cfe-commits

alexcrichton wrote:

cc @sunfishcode and @sbc100 

https://github.com/llvm/llvm-project/pull/84569
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [WebAssembly] Change the default linker for `wasm32-wasip2` (PR #84569)

2024-03-08 Thread Alex Crichton via cfe-commits

https://github.com/alexcrichton created 
https://github.com/llvm/llvm-project/pull/84569

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.

>From fb90a737233a9f8928c44c4563c0f0ad33a68142 Mon Sep 17 00:00:00 2001
From: Alex Crichton 
Date: Fri, 8 Mar 2024 13:36:18 -0800
Subject: [PATCH] [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.
---
 clang/lib/Driver/ToolChains/WebAssembly.cpp | 6 ++
 clang/lib/Driver/ToolChains/WebAssembly.h   | 2 +-
 clang/test/Driver/wasm-toolchain.c  | 8 
 3 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Driver/ToolChains/WebAssembly.cpp 
b/clang/lib/Driver/ToolChains/WebAssembly.cpp
index b8c2573d6265fb..a6c43c627f7206 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.cpp
+++ b/clang/lib/Driver/ToolChains/WebAssembly.cpp
@@ -221,6 +221,12 @@ WebAssembly::WebAssembly(const Driver , const 
llvm::Triple ,
   }
 }
 
+const char *WebAssembly::getDefaultLinker() const {
+  if (getOS() == "wasip2")
+return "wasm-component-ld";
+  return "wasm-ld";
+}
+
 bool WebAssembly::IsMathErrnoDefault() const { return false; }
 
 bool WebAssembly::IsObjCNonFragileABIDefault() const { return true; }
diff --git a/clang/lib/Driver/ToolChains/WebAssembly.h 
b/clang/lib/Driver/ToolChains/WebAssembly.h
index ae60f464c10818..76e0ca39bd748d 100644
--- a/clang/lib/Driver/ToolChains/WebAssembly.h
+++ b/clang/lib/Driver/ToolChains/WebAssembly.h
@@ -67,7 +67,7 @@ class LLVM_LIBRARY_VISIBILITY WebAssembly final : public 
ToolChain {
llvm::opt::ArgStringList ) const override;
   SanitizerMask getSupportedSanitizers() const override;
 
-  const char *getDefaultLinker() const override { return "wasm-ld"; }
+  const char *getDefaultLinker() const override;
 
   CXXStdlibType GetDefaultCXXStdlibType() const override {
 return ToolChain::CST_Libcxx;
diff --git a/clang/test/Driver/wasm-toolchain.c 
b/clang/test/Driver/wasm-toolchain.c
index f950283ec42aa0..5f18e56f79b657 100644
--- a/clang/test/Driver/wasm-toolchain.c
+++ b/clang/test/Driver/wasm-toolchain.c
@@ -197,3 +197,11 @@
 // RUN: not %clang -### %s --target=wasm32-unknown-unknown 
--sysroot=%s/no-sysroot-there -fPIC -mno-mutable-globals %s 2>&1 \
 // RUN:   | FileCheck -check-prefix=PIC_NO_MUTABLE_GLOBALS %s
 // PIC_NO_MUTABLE_GLOBALS: error: invalid argument '-fPIC' not allowed with 
'-mno-mutable-globals'
+
+// Test that `wasm32-wasip2` invokes a the `wasm-component-ld` linker by 
default
+// instead of `wasm-ld`.
+
+// RUN: %clang -### -O2 --target=wasm32-wasip2 %s --sysroot /foo 2>&1 \
+// RUN:   | FileCheck -check-prefix=LINK_WASIP2 %s
+// LINK_WASIP2: "-cc1" {{.*}} "-o" "[[temp:[^"]*]]"
+// LINK_WASIP2: wasm-component-ld{{.*}}" "-L/foo/lib/wasm32-wasip2" "crt1.o" 
"[[temp]]" "-lc" "{{.*[/\\]}}libclang_rt.builtins-wasm32.a" "-o" "a.out"

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits