From 4fe167adba47478e1a443c7b82e67e020253eac8 Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Mon, 1 Jan 2018 21:46:22 +0100 Subject: [PATCH 1/2] Use the right TLS model for CloudABI. CloudABI doesn't do dynamic linking. For this reason, there is no need to handle any other TLS model than local-exec. CloudABI's C library doesn't provide a __tls_get_addr() function to do Dynamic TLS. By forcing local-exec to be used here, we ensure that we don't generate function calls to __tls_get_addr(). --- src/librustc_back/target/cloudabi_base.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/librustc_back/target/cloudabi_base.rs b/src/librustc_back/target/cloudabi_base.rs index 3353e7936f0..c41c6b23358 100644 --- a/src/librustc_back/target/cloudabi_base.rs +++ b/src/librustc_back/target/cloudabi_base.rs @@ -27,6 +27,7 @@ pub fn opts() -> TargetOptions { linker_is_gnu: true, pre_link_args: args, position_independent_executables: true, + tls_model: "local-exec".to_string(), relro_level: RelroLevel::Full, exe_allocation_crate: super::maybe_jemalloc(), .. Default::default() From 05949b09a87e8753601441484e17aecc8438e3ce Mon Sep 17 00:00:00 2001 From: Ed Schouten Date: Wed, 3 Jan 2018 18:32:41 +0100 Subject: [PATCH 2/2] Explain why local-exec is used by CloudABI. --- src/librustc_back/target/cloudabi_base.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/librustc_back/target/cloudabi_base.rs b/src/librustc_back/target/cloudabi_base.rs index c41c6b23358..4cd52ebb26d 100644 --- a/src/librustc_back/target/cloudabi_base.rs +++ b/src/librustc_back/target/cloudabi_base.rs @@ -27,6 +27,17 @@ pub fn opts() -> TargetOptions { linker_is_gnu: true, pre_link_args: args, position_independent_executables: true, + // As CloudABI only supports static linkage, there is no need + // for dynamic TLS. The C library therefore does not provide + // __tls_get_addr(), which is normally used to perform dynamic + // TLS lookups by programs that make use of dlopen(). Only the + // "local-exec" and "initial-exec" TLS models can be used. + // + // "local-exec" is more efficient than "initial-exec", as the + // latter has one more level of indirection: it accesses the GOT + // (Global Offset Table) to obtain the effective address of a + // thread-local variable. Using a GOT is useful only when doing + // dynamic linking. tls_model: "local-exec".to_string(), relro_level: RelroLevel::Full, exe_allocation_crate: super::maybe_jemalloc(),