diff options
author | Shiz <hi@shiz.me> | 2017-04-16 16:55:05 +0000 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-04-21 01:44:33 +0200 |
commit | 3b034a254fa89558cf04d8e54ee6d01f28bdf85b (patch) | |
tree | 22cc8ccc463991e1aa2b89c37c5ef436f77898c7 /testing/rust/musl-fix-static-linking.patch | |
parent | 9e94cc5fbd98ff048290548c2077ef0ce3be3c96 (diff) | |
download | aports-3b034a254fa89558cf04d8e54ee6d01f28bdf85b.tar.bz2 aports-3b034a254fa89558cf04d8e54ee6d01f28bdf85b.tar.xz |
testing/rust: factor out fully static support from static PIE support
Diffstat (limited to 'testing/rust/musl-fix-static-linking.patch')
-rw-r--r-- | testing/rust/musl-fix-static-linking.patch | 48 |
1 files changed, 43 insertions, 5 deletions
diff --git a/testing/rust/musl-fix-static-linking.patch b/testing/rust/musl-fix-static-linking.patch index a0a7c1bc6f..786b7d3a41 100644 --- a/testing/rust/musl-fix-static-linking.patch +++ b/testing/rust/musl-fix-static-linking.patch @@ -1,3 +1,41 @@ +From: Shiz <hi@shiz.me> +Date: Fri, 21 Apr 2017 01:04:46 +0200 +Subject: [PATCH] Support fully static linking on *nix targets + +This patch adds support for full static linking on *nix targets. + +It adds `Session::fully_static()` to determine whether full static linking +should be utilised. By default, this is the case if the target is not +MSVC-like and the `crt-static` target feature is requested, as for *nix +targets this implies a fully static result. In the future, a target feature +or other compile option could perhaps be added to have the invoker decide +this more flexibly at run-time. + +It also adds the proper linker argument for static result objects to `Linker` +and implements them for `GnuLinker` and `MsvcLinker`. Additionally, when +statically linking, all the objects are linked in a group (-Wl,-( and -Wl,-) +on GNU-compatible linkers) to resolve dependency and order issues that may +normally arise. For `MsvcLinker`, this is a no-op as it already exhibits +this behavior by default. + +Finally, if no linking preference is given for native libraries +(`NativeLibraryKind::NativeUnknown`), they are linked statically if full +static linking is requested, instead of dynamically as before. + +--- a/src/librustc/session/mod.rs ++++ b/src/librustc/session/mod.rs +@@ -409,6 +409,11 @@ + return crt_static; + } + ++ pub fn fully_static(&self) -> bool { ++ // TODO: figure out better semantics for this, possibly a target option? ++ return self.crt_static() && !self.target.target.options.is_like_msvc ++ } ++ + pub fn must_not_eliminate_frame_pointers(&self) -> bool { + self.opts.debuginfo != DebugInfoLevel::NoDebugInfo || + !self.target.target.options.eliminate_frame_pointer --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -239,8 +239,8 @@ @@ -6,7 +44,7 @@ crate_type: config::CrateType) -> bool { - match (sess.target.target.options.dynamic_linking, - sess.target.target.options.executables, crate_type) { -+ let dynamic_linking = sess.target.target.options.dynamic_linking && !sess.crt_static(); ++ let dynamic_linking = sess.target.target.options.dynamic_linking && !sess.fully_static(); + match (dynamic_linking, sess.target.target.options.executables, crate_type) { (false, _, config::CrateTypeCdylib) | (false, _, config::CrateTypeProcMacro) | @@ -15,7 +53,7 @@ let used_link_args = sess.cstore.used_link_args(); -+ if crate_type == config::CrateTypeExecutable && sess.crt_static() { ++ if crate_type == config::CrateTypeExecutable && sess.fully_static() { + cmd.static_executable(); + } + @@ -65,15 +103,15 @@ } - cmd.hint_dynamic(); -+ let crt_static = sess.crt_static(); -+ if !crt_static { ++ let fully_static = sess.fully_static(); ++ if !fully_static { + cmd.hint_dynamic(); + } for lib in others { match lib.kind { - NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()), -+ NativeLibraryKind::NativeUnknown => if crt_static { cmd.link_staticlib(&lib.name.as_str()) } else { cmd.link_dylib(&lib.name.as_str()) }, ++ NativeLibraryKind::NativeUnknown => if fully_static { cmd.link_staticlib(&lib.name.as_str()) } else { cmd.link_dylib(&lib.name.as_str()) }, NativeLibraryKind::NativeFramework => cmd.link_framework(&lib.name.as_str()), NativeLibraryKind::NativeStatic => bug!(), } |