Stream: t-compiler/help

Topic: Building core with PIC relocation model?

osa1 (Aug 03 2020 at 14:00, on Zulip):

How do I build core for a specific target (wasm32-wasi and wasm32-unknown-emscripten in my case) with PIC relocation model? xargo can do it and I think it uses RUSTFLAGS env variable, but I don't know how to set this only when building the a specific library for a specific target.

osa1 (Aug 03 2020 at 14:37, on Zulip):

I currently do this:

diff --git a/src/librustc_target/spec/ b/src/librustc_target/spec/
index 8423573b52d..fa9499b37a8 100644
--- a/src/librustc_target/spec/
+++ b/src/librustc_target/spec/
@@ -126,14 +126,7 @@ pub fn options() -> TargetOptions {

         crt_objects_fallback: Some(CrtObjectsFallback::Wasm),

-        // This has no effect in LLVM 8 or prior, but in LLVM 9 and later when
-        // PIC code is implemented this has quite a drastric effect if it stays
-        // at the default, `pic`. In an effort to keep wasm binaries as minimal
-        // as possible we're defaulting to `static` for now, but the hope is
-        // that eventually we can ship a `pic`-compatible standard library which
-        // works with `static` as well (or works with some method of generating
-        // non-relative calls and such later on).
-        relocation_model: RelocModel::Static,
+        relocation_model: RelocModel::Pic,

         // When the atomics feature is activated then these two keys matter,
         // otherwise they're basically ignored by the standard library. In this
Last update: Sep 28 2020 at 16:45UTC