diff options
author | Marat Safin <jeizsm@gmail.com> | 2017-10-23 22:18:55 +0300 |
---|---|---|
committer | Jakub Jirutka <jakub@jirutka.cz> | 2017-10-28 13:06:08 +0200 |
commit | eb064c8d0fafe5b638f0fb1f487acfa80c8d777b (patch) | |
tree | 3d80b62246e29dcd1d636569c0fcda95518f3914 /community/rust/musl-fix-static-linking.patch | |
parent | 0a6875fd87508400ae23cc57e63f51a81fac9214 (diff) | |
download | aports-eb064c8d0fafe5b638f0fb1f487acfa80c8d777b.tar.bz2 aports-eb064c8d0fafe5b638f0fb1f487acfa80c8d777b.tar.xz |
community/rust: upgrade to 1.21
Diffstat (limited to 'community/rust/musl-fix-static-linking.patch')
-rw-r--r-- | community/rust/musl-fix-static-linking.patch | 146 |
1 files changed, 20 insertions, 126 deletions
diff --git a/community/rust/musl-fix-static-linking.patch b/community/rust/musl-fix-static-linking.patch index 93fe79d15f..1e228a0307 100644 --- a/community/rust/musl-fix-static-linking.patch +++ b/community/rust/musl-fix-static-linking.patch @@ -2,16 +2,7 @@ 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` +It 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 @@ -22,61 +13,6 @@ 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 @@ - /// Checks if target supports crate_type as output - pub fn invalid_output_for_target(sess: &Session, - 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.fully_static(); -+ match (dynamic_linking, sess.target.target.options.executables, crate_type) { - (false, _, config::CrateTypeCdylib) | - (false, _, config::CrateTypeProcMacro) | - (false, _, config::CrateTypeDylib) => true, -@@ -840,6 +840,10 @@ - - let used_link_args = sess.cstore.used_link_args(); - -+ if crate_type == config::CrateTypeExecutable && sess.fully_static() { -+ cmd.static_executable(); -+ } -+ - if crate_type == config::CrateTypeExecutable && - t.options.position_independent_executables { - let empty_vec = Vec::new(); -@@ -870,15 +870,8 @@ - cmd.no_default_libraries(); - } - -- // Take careful note of the ordering of the arguments we pass to the linker -- // here. Linkers will assume that things on the left depend on things to the -- // right. Things on the right cannot depend on things on the left. This is -- // all formally implemented in terms of resolving symbols (libs on the right -- // resolve unknown symbols of libs on the left, but not vice versa). -+ // We have organized the arguments we pass to the linker as such: - // -- // For this reason, we have organized the arguments we pass to the linker as -- // such: -- // - // 1. The local object that LLVM just generated - // 2. Local native libraries - // 3. Upstream rust libraries --- a/src/librustc_trans/back/link.rs +++ b/src/librustc_trans/back/link.rs @@ -951,17 +951,12 @@ @@ -109,7 +45,7 @@ static linking is requested, instead of dynamically as before. for lib in relevant_libs { match lib.kind { - NativeLibraryKind::NativeUnknown => cmd.link_dylib(&lib.name.as_str()), -+ NativeLibraryKind::NativeUnknown => if sess.fully_static() { cmd.link_staticlib(&lib.name.as_str()) } else { cmd.link_dylib(&lib.name.as_str()) }, ++ NativeLibraryKind::NativeUnknown => if sess.crt_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::NativeStaticNobundle => cmd.link_staticlib(&lib.name.as_str()), NativeLibraryKind::NativeStatic => cmd.link_whole_staticlib(&lib.name.as_str(), @@ -117,17 +53,7 @@ static linking is requested, instead of dynamically as before. } --- a/src/librustc_trans/back/linker.rs +++ b/src/librustc_trans/back/linker.rs -@@ -82,6 +82,7 @@ - fn add_object(&mut self, path: &Path); - fn gc_sections(&mut self, keep_metadata: bool); - fn position_independent_executable(&mut self); -+ fn static_executable(&mut self); - fn optimize(&mut self); - fn debuginfo(&mut self); - fn no_default_libraries(&mut self); -@@ -93,8 +93,10 @@ - fn no_whole_archives(&mut self); - fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType); +@@ -116,6 +116,8 @@ pub trait Linker { fn subsystem(&mut self, subsystem: &str); // Should have been finalize(self), but we don't support self-by-value on trait objects (yet?). fn finalize(&mut self) -> Command; @@ -136,75 +62,43 @@ static linking is requested, instead of dynamically as before. } pub struct GccLinker<'a> { -@@ -116,6 +117,9 @@ +@@ -178,6 +180,8 @@ impl<'a> Linker for GccLinker<'a> { fn output_filename(&mut self, path: &Path) { self.cmd.arg("-o").arg(path); } fn add_object(&mut self, path: &Path) { self.cmd.arg(path); } fn position_independent_executable(&mut self) { self.cmd.arg("-pie"); } -+ fn static_executable(&mut self) { self.cmd.arg("-static"); } + fn start_group(&mut self) { self.cmd.arg("-Wl,-("); } + fn end_group(&mut self) { self.cmd.arg("-Wl,-)"); } - fn args(&mut self, args: &[String]) { self.cmd.args(args); } - - fn link_rust_dylib(&mut self, lib: &str, _path: &Path) { -@@ -359,6 +361,10 @@ - - fn position_independent_executable(&mut self) { - // noop -+ } -+ -+ fn static_executable(&mut self) { -+ self.cmd.arg("-MT"); + fn partial_relro(&mut self) { self.linker_arg("-z,relro"); } + fn full_relro(&mut self) { self.linker_arg("-z,relro,-z,now"); } + fn build_static_executable(&mut self) { self.cmd.arg("-static"); } +@@ -577,6 +581,15 @@ impl<'a> Linker for MsvcLinker<'a> { + } } - fn no_default_libraries(&mut self) { -@@ -484,6 +488,14 @@ - if subsystem == "windows" { - self.cmd.arg("/ENTRY:mainCRTStartup"); - } -+ } + + fn start_group(&mut self) { + // Not needed + } -+ ++ + fn end_group(&mut self) { + // Not needed - } - } - -@@ -562,6 +562,10 @@ - // noop - } - -+ fn static_executable(&mut self) { -+ // noop + } + - fn args(&mut self, args: &[String]) { - self.cmd.args(args); + fn finalize(&mut self) -> Command { + let mut cmd = Command::new(""); + ::std::mem::swap(&mut cmd, &mut self.cmd); +@@ -727,6 +740,14 @@ impl<'a> Linker for EmLinker<'a> { + // noop } -@@ -657,6 +661,14 @@ - fn subsystem(&mut self, _subsystem: &str) { - // noop -+ } -+ + fn start_group(&mut self) { + self.cmd.arg("-Wl,-("); + } + + fn end_group(&mut self) { + self.cmd.arg("-Wl,-)"); - } - } - ---- a/src/librustc_trans/back/linker.rs -+++ b/src/librustc_trans/back/linker.rs -@@ -158,6 +158,7 @@ impl<'a> GccLinker<'a> { - } - - fn hint_dynamic(&mut self) { -+ if self.sess.fully_static() { return } - if !self.takes_hints() { return } - if self.hinted_static { - self.linker_arg("-Bdynamic"); ++ } ++ + fn finalize(&mut self) -> Command { + let mut cmd = Command::new(""); + ::std::mem::swap(&mut cmd, &mut self.cmd); |