2024-10-25 17:38:20 +00:00
|
|
|
From 348b03695d916ab23a9d66c4ceed2ecbecfc68e7 Mon Sep 17 00:00:00 2001
|
2023-10-16 23:19:16 +00:00
|
|
|
From: Josh Stone <jistone@redhat.com>
|
|
|
|
Date: Thu, 28 Sep 2023 18:18:16 -0700
|
|
|
|
Subject: [PATCH 2/2] set an external library path for wasm32-wasi
|
|
|
|
|
|
|
|
---
|
2024-06-17 09:30:31 +00:00
|
|
|
compiler/rustc_codegen_ssa/src/back/link.rs | 9 +++++++++
|
|
|
|
compiler/rustc_target/src/spec/mod.rs | 4 ++++
|
|
|
|
compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs | 7 ++++---
|
|
|
|
3 files changed, 17 insertions(+), 3 deletions(-)
|
2023-10-16 23:19:16 +00:00
|
|
|
|
|
|
|
diff --git a/compiler/rustc_codegen_ssa/src/back/link.rs b/compiler/rustc_codegen_ssa/src/back/link.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
index 8c582fac0d82..169d86cd6224 100644
|
2023-10-16 23:19:16 +00:00
|
|
|
--- a/compiler/rustc_codegen_ssa/src/back/link.rs
|
|
|
|
+++ b/compiler/rustc_codegen_ssa/src/back/link.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -1586,6 +1586,12 @@ fn get_object_file_path(sess: &Session, name: &str, self_contained: bool) -> Pat
|
2023-10-16 23:19:16 +00:00
|
|
|
return file_path;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
+ if let Some(lib_path) = &sess.target.options.external_lib_path {
|
|
|
|
+ let file_path = Path::new(lib_path.as_ref()).join(name);
|
|
|
|
+ if file_path.exists() {
|
|
|
|
+ return file_path;
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
for search_path in fs.search_paths() {
|
|
|
|
let file_path = search_path.dir.join(name);
|
|
|
|
if file_path.exists() {
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -2076,6 +2082,9 @@ fn add_library_search_dirs(cmd: &mut dyn Linker, sess: &Session, self_contained:
|
2023-10-16 23:19:16 +00:00
|
|
|
let lib_path = sess.target_filesearch(PathKind::All).get_self_contained_lib_path();
|
|
|
|
cmd.include_path(&fix_windows_verbatim_for_gcc(&lib_path));
|
|
|
|
}
|
|
|
|
+ if let Some(lib_path) = &sess.target.options.external_lib_path {
|
|
|
|
+ cmd.include_path(Path::new(lib_path.as_ref()));
|
|
|
|
+ }
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Add options making relocation sections in the produced ELF files read-only
|
|
|
|
diff --git a/compiler/rustc_target/src/spec/mod.rs b/compiler/rustc_target/src/spec/mod.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
index 607eeac7ccdc..63070622502e 100644
|
2023-10-16 23:19:16 +00:00
|
|
|
--- a/compiler/rustc_target/src/spec/mod.rs
|
|
|
|
+++ b/compiler/rustc_target/src/spec/mod.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -2033,6 +2033,7 @@ pub struct TargetOptions {
|
2023-10-16 23:19:16 +00:00
|
|
|
/// Objects to link before and after all other object code.
|
|
|
|
pub pre_link_objects: CrtObjects,
|
|
|
|
pub post_link_objects: CrtObjects,
|
|
|
|
+ pub external_lib_path: Option<StaticCow<str>>,
|
|
|
|
/// Same as `(pre|post)_link_objects`, but when self-contained linking mode is enabled.
|
|
|
|
pub pre_link_objects_self_contained: CrtObjects,
|
|
|
|
pub post_link_objects_self_contained: CrtObjects,
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -2520,6 +2521,7 @@ fn default() -> TargetOptions {
|
2023-10-16 23:19:16 +00:00
|
|
|
relro_level: RelroLevel::None,
|
|
|
|
pre_link_objects: Default::default(),
|
|
|
|
post_link_objects: Default::default(),
|
|
|
|
+ external_lib_path: None,
|
|
|
|
pre_link_objects_self_contained: Default::default(),
|
|
|
|
post_link_objects_self_contained: Default::default(),
|
|
|
|
link_self_contained: LinkSelfContainedDefault::False,
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -3202,6 +3204,7 @@ macro_rules! key {
|
2024-06-17 09:30:31 +00:00
|
|
|
key!(linker_is_gnu_json = "linker-is-gnu", bool);
|
|
|
|
key!(pre_link_objects = "pre-link-objects", link_objects);
|
|
|
|
key!(post_link_objects = "post-link-objects", link_objects);
|
|
|
|
+ key!(external_lib_path, optional);
|
|
|
|
key!(pre_link_objects_self_contained = "pre-link-objects-fallback", link_objects);
|
|
|
|
key!(post_link_objects_self_contained = "post-link-objects-fallback", link_objects);
|
|
|
|
// Deserializes the backwards-compatible variants of `-Clink-self-contained`
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -3464,6 +3467,7 @@ macro_rules! target_option_val {
|
2024-06-17 09:30:31 +00:00
|
|
|
target_option_val!(linker_is_gnu_json, "linker-is-gnu");
|
|
|
|
target_option_val!(pre_link_objects);
|
|
|
|
target_option_val!(post_link_objects);
|
|
|
|
+ target_option_val!(external_lib_path);
|
|
|
|
target_option_val!(pre_link_objects_self_contained, "pre-link-objects-fallback");
|
|
|
|
target_option_val!(post_link_objects_self_contained, "post-link-objects-fallback");
|
|
|
|
target_option_val!(link_args - pre_link_args_json, "pre-link-args");
|
|
|
|
diff --git a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
index a8e7f22c0689..55949557d6bb 100644
|
2024-06-17 09:30:31 +00:00
|
|
|
--- a/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
|
|
|
+++ b/compiler/rustc_target/src/spec/targets/wasm32_wasip1.rs
|
2024-10-25 17:38:20 +00:00
|
|
|
@@ -21,11 +21,12 @@ pub fn target() -> Target {
|
|
|
|
options.env = "p1".into();
|
2024-06-17 09:30:31 +00:00
|
|
|
options.add_pre_link_args(LinkerFlavor::WasmLld(Cc::Yes), &["--target=wasm32-wasi"]);
|
|
|
|
|
|
|
|
- options.pre_link_objects_self_contained = crt_objects::pre_wasi_self_contained();
|
|
|
|
- options.post_link_objects_self_contained = crt_objects::post_wasi_self_contained();
|
|
|
|
+ options.pre_link_objects = crt_objects::pre_wasi_self_contained();
|
|
|
|
+ options.post_link_objects = crt_objects::post_wasi_self_contained();
|
2023-10-16 23:19:16 +00:00
|
|
|
|
|
|
|
// FIXME: Figure out cases in which WASM needs to link with a native toolchain.
|
|
|
|
- options.link_self_contained = LinkSelfContainedDefault::True;
|
|
|
|
+ options.link_self_contained = LinkSelfContainedDefault::False;
|
|
|
|
+ options.external_lib_path = Some("/usr/wasm32-wasi/lib/wasm32-wasi".into());
|
|
|
|
|
|
|
|
// Right now this is a bit of a workaround but we're currently saying that
|
|
|
|
// the target by default has a static crt which we're taking as a signal
|
|
|
|
--
|
2024-10-25 17:38:20 +00:00
|
|
|
2.46.0
|
2023-10-16 23:19:16 +00:00
|
|
|
|