rustc_target: Add convenience functions for adding linker arguments
They ensure that lld and non-lld linker flavors get the same set of arguments
This commit is contained in:
@@ -29,27 +29,27 @@ pub fn target() -> Target {
|
||||
// code on this target due to this ABI mismatch.
|
||||
options.default_adjusted_cabi = Some(Abi::Wasm);
|
||||
|
||||
let clang_args = options.pre_link_args.entry(LinkerFlavor::Gcc).or_default();
|
||||
|
||||
// Make sure clang uses LLD as its linker and is configured appropriately
|
||||
// otherwise
|
||||
clang_args.push("--target=wasm32-unknown-unknown".into());
|
||||
|
||||
// For now this target just never has an entry symbol no matter the output
|
||||
// type, so unconditionally pass this.
|
||||
clang_args.push("-Wl,--no-entry".into());
|
||||
|
||||
// Rust really needs a way for users to specify exports and imports in
|
||||
// the source code. --export-dynamic isn't the right tool for this job,
|
||||
// however it does have the side effect of automatically exporting a lot
|
||||
// of symbols, which approximates what people want when compiling for
|
||||
// wasm32-unknown-unknown expect, so use it for now.
|
||||
clang_args.push("-Wl,--export-dynamic".into());
|
||||
options.add_pre_link_args(
|
||||
LinkerFlavor::Gcc,
|
||||
&[
|
||||
// Make sure clang uses LLD as its linker and is configured appropriately
|
||||
// otherwise
|
||||
"--target=wasm32-unknown-unknown",
|
||||
// For now this target just never has an entry symbol no matter the output
|
||||
// type, so unconditionally pass this.
|
||||
"-Wl,--no-entry",
|
||||
// Rust really needs a way for users to specify exports and imports in
|
||||
// the source code. --export-dynamic isn't the right tool for this job,
|
||||
// however it does have the side effect of automatically exporting a lot
|
||||
// of symbols, which approximates what people want when compiling for
|
||||
// wasm32-unknown-unknown expect, so use it for now.
|
||||
"-Wl,--export-dynamic",
|
||||
],
|
||||
);
|
||||
|
||||
// Add the flags to wasm-ld's args too.
|
||||
let lld_args = options.pre_link_args.entry(LinkerFlavor::Lld(LldFlavor::Wasm)).or_default();
|
||||
lld_args.push("--no-entry".into());
|
||||
lld_args.push("--export-dynamic".into());
|
||||
options
|
||||
.add_pre_link_args(LinkerFlavor::Lld(LldFlavor::Wasm), &["--no-entry", "--export-dynamic"]);
|
||||
|
||||
Target {
|
||||
llvm_target: "wasm32-unknown-unknown".into(),
|
||||
|
||||
Reference in New Issue
Block a user