diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs index 3a8b243349c6b..772d13da0ea0a 100644 --- a/src/bootstrap/builder.rs +++ b/src/bootstrap/builder.rs @@ -1140,6 +1140,14 @@ impl<'a> Builder<'a> { } } + // Compile everything except libraries and proc macros with the more + // efficient initial-exec TLS model. This doesn't work with `dlopen`, + // so we can't use it by default in general, but we can use it for tools + // and our own internal libraries. + if !mode.must_support_dlopen() { + rustflags.arg("-Ztls-model=initial-exec"); + } + if self.config.incremental { cargo.env("CARGO_INCREMENTAL", "1"); } else { diff --git a/src/bootstrap/lib.rs b/src/bootstrap/lib.rs index 0878b0ff78930..3d111839dc725 100644 --- a/src/bootstrap/lib.rs +++ b/src/bootstrap/lib.rs @@ -332,6 +332,10 @@ impl Mode { pub fn is_tool(&self) -> bool { matches!(self, Mode::ToolBootstrap | Mode::ToolRustc | Mode::ToolStd) } + + pub fn must_support_dlopen(&self) -> bool { + matches!(self, Mode::Std | Mode::Codegen) + } } impl Build {