about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Triplett <josh@joshtriplett.org>2020-10-25 22:11:20 -0700
committerJosh Triplett <josh@joshtriplett.org>2020-11-06 15:07:05 -0800
commit0328e69287b083af4d5d4b49cfc9175e9c82c88e (patch)
tree27ea505131b83f7324d459f28475d6813457750c
parent9d78d1d02761b906038ba4d54c5f3427f920f5fb (diff)
downloadrust-0328e69287b083af4d5d4b49cfc9175e9c82c88e.tar.gz
rust-0328e69287b083af4d5d4b49cfc9175e9c82c88e.zip
Compile tools and internal libraries with the initial-exec TLS model
This should produce more efficient code, with fewer calls to
__tls_get_addr. The tradeoff is that libraries using it won't work with
dlopen, but that shouldn't be a problem for tools or for our own
internal libraries.

Co-authored-by: Mark Rousskov <mark.simulacrum@gmail.com>
-rw-r--r--src/bootstrap/builder.rs8
-rw-r--r--src/bootstrap/lib.rs4
2 files changed, 12 insertions, 0 deletions
diff --git a/src/bootstrap/builder.rs b/src/bootstrap/builder.rs
index 3a8b243349c..772d13da0ea 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 0878b0ff789..3d111839dc7 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 {