Skip to content

Commit

Permalink
rust: fix musl build
Browse files Browse the repository at this point in the history
  • Loading branch information
Rasmus Thomsen committed Oct 8, 2018
1 parent 892afb7 commit 32b7b78
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 11 deletions.
71 changes: 61 additions & 10 deletions srcpkgs/rust/files/musl.patch
Original file line number Diff line number Diff line change
@@ -1,11 +1,62 @@
--- rustc-1.28.0-src/src/librustc_target/spec/x86_64_unknown_linux_musl.rs.orig 2018-08-08 23:21:51.673454236 +0200
+++ rustc-1.28.0-src/src/librustc_target/spec/x86_64_unknown_linux_musl.rs 2018-08-08 23:23:11.080834122 +0200
@@ -11,7 +11,7 @@
use spec::{LinkerFlavor, Target, TargetResult};
From: Jakub Jirutka <jakub@jirutka.cz>
Date: Sat, 08 Aug 2016 15:06:00 +0200
Subject: [PATCH] Fix linux_musl_base for native musl host

See https://github.com/rust-lang/rust/pull/40113

--- a/src/librustc_target/spec/linux_musl_base.rs
+++ b/src/librustc_target/spec/linux_musl_base.rs
@@ -13,53 +13,12 @@
pub fn opts() -> TargetOptions {
let mut base = super::linux_base::opts();

pub fn target() -> TargetResult {
- let mut base = super::linux_musl_base::opts();
+ let mut base = super::linux_base::opts();
base.cpu = "x86-64".to_string();
base.max_atomic_width = Some(64);
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-m64".to_string());
- // Make sure that the linker/gcc really don't pull in anything, including
- // default objects, libs, etc.
- base.pre_link_args_crt.insert(LinkerFlavor::Gcc, Vec::new());
- base.pre_link_args_crt.get_mut(&LinkerFlavor::Gcc).unwrap().push("-nostdlib".to_string());
-
// At least when this was tested, the linker would not add the
// `GNU_EH_FRAME` program header to executables generated, which is required
// when unwinding to locate the unwinding information. I'm not sure why this
// argument is *not* necessary for normal builds, but it can't hurt!
base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,--eh-frame-hdr".to_string());

- // There's a whole bunch of circular dependencies when dealing with MUSL
- // unfortunately. To put this in perspective libc is statically linked to
- // liblibc and libunwind is statically linked to libstd:
- //
- // * libcore depends on `fmod` which is in libc (transitively in liblibc).
- // liblibc, however, depends on libcore.
- // * compiler-rt has personality symbols that depend on libunwind, but
- // libunwind is in libstd which depends on compiler-rt.
- //
- // Recall that linkers discard libraries and object files as much as
- // possible, and with all the static linking and archives flying around with
- // MUSL the linker is super aggressively stripping out objects. For example
- // the first case has fmod stripped from liblibc (it's in its own object
- // file) so it's not there when libcore needs it. In the second example all
- // the unused symbols from libunwind are stripped (each is in its own object
- // file in libstd) before we end up linking compiler-rt which depends on
- // those symbols.
- //
- // To deal with these circular dependencies we just force the compiler to
- // link everything as a group, not stripping anything out until everything
- // is processed. The linker will still perform a pass to strip out object
- // files but it won't do so until all objects/archives have been processed.
- base.pre_link_args.get_mut(&LinkerFlavor::Gcc).unwrap().push("-Wl,-(".to_string());
- base.post_link_args.insert(LinkerFlavor::Gcc, vec!["-Wl,-)".to_string()]);
-
- // When generating a statically linked executable there's generally some
- // small setup needed which is listed in these files. These are provided by
- // a musl toolchain and are linked by default by the `musl-gcc` script. Note
- // that `gcc` also does this by default, it just uses some different files.
- //
- // Each target directory for musl has these object files included in it so
- // they'll be included from there.
- base.pre_link_objects_exe_crt.push("crt1.o".to_string());
- base.pre_link_objects_exe_crt.push("crti.o".to_string());
- base.post_link_objects_crt.push("crtn.o".to_string());
-
// These targets statically link libc by default
base.crt_static_default = true;
// These targets allow the user to choose between static and dynamic linking.
2 changes: 1 addition & 1 deletion srcpkgs/rust/template
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ do_configure() {
fi
case "$XBPS_TARGET_MACHINE" in
*-musl)
configure_args+=" --musl-root=/usr"
configure_args+=" --set=target.${_host_triplet}.musl-root=/usr"
;;
esac

Expand Down

0 comments on commit 32b7b78

Please sign in to comment.