@@ -44,8 +44,15 @@ std::string wasm::Linker::getLinkerPath(const ArgList &Args) const {
44
44
llvm::sys::fs::can_execute (UseLinker))
45
45
return std::string (UseLinker);
46
46
47
- // Accept 'lld', and 'ld' as aliases for the default linker
48
- if (UseLinker != " lld" && UseLinker != " ld" )
47
+ // Interpret 'lld' as explicitly requesting `wasm-ld`, so look for that
48
+ // linker. Note that for `wasm32-wasip2` this overrides the default linker
49
+ // of `wasm-component-ld`.
50
+ if (UseLinker == " lld" ) {
51
+ return ToolChain.GetProgramPath (" wasm-ld" );
52
+ }
53
+
54
+ // Allow 'ld' as an alias for the default linker
55
+ if (UseLinker != " ld" )
49
56
ToolChain.getDriver ().Diag (diag::err_drv_invalid_linker_name)
50
57
<< A->getAsString (Args);
51
58
}
@@ -73,6 +80,16 @@ void wasm::Linker::ConstructJob(Compilation &C, const JobAction &JA,
73
80
if (Args.hasArg (options::OPT_s))
74
81
CmdArgs.push_back (" --strip-all" );
75
82
83
+ // On `wasip2` the default linker is `wasm-component-ld` which wraps the
84
+ // execution of `wasm-ld`. Find `wasm-ld` and pass it as an argument of where
85
+ // to find it to avoid it needing to hunt and rediscover or search `PATH` for
86
+ // where it is.
87
+ if (llvm::sys::path::stem (Linker).ends_with_insensitive (
88
+ " wasm-component-ld" )) {
89
+ CmdArgs.push_back (" --wasm-ld-path" );
90
+ CmdArgs.push_back (Args.MakeArgString (ToolChain.GetProgramPath (" wasm-ld" )));
91
+ }
92
+
76
93
Args.addAllArgs (CmdArgs, {options::OPT_L, options::OPT_u});
77
94
78
95
ToolChain.AddFilePathLibArgs (Args, CmdArgs);
@@ -221,6 +238,12 @@ WebAssembly::WebAssembly(const Driver &D, const llvm::Triple &Triple,
221
238
}
222
239
}
223
240
241
+ const char *WebAssembly::getDefaultLinker () const {
242
+ if (getOS () == " wasip2" )
243
+ return " wasm-component-ld" ;
244
+ return " wasm-ld" ;
245
+ }
246
+
224
247
bool WebAssembly::IsMathErrnoDefault () const { return false ; }
225
248
226
249
bool WebAssembly::IsObjCNonFragileABIDefault () const { return true ; }
0 commit comments