Skip to content

Commit 68db72d

Browse files
committedJan 22, 2018
Do not assume dynamic linking for musl/mips[el] targets
All musl targets except mips[el] assume static linking by default. This can be confusing https://users.rust-lang.org/t/static-cross-compiled-binaries-arent-really-static/6084 When the musl/mips[el] targets was [added](rust-lang#31298), dynamic linking was chosen because of binary size concerns, and probably also because libunwind [didn't](https://users.rust-lang.org/t/static-cross-compiled-binaries-arent-really-static/6084/8) supported mips. Now that we have `crt-static` target-feature (the user can choose dynamic link for musl targets), and libunwind [6.0](https://github.com/llvm-mirror/libunwind/commits/release_60) add support to mips, we do not need to assume dynamic linking.

File tree

9 files changed

+56
-38
lines changed

9 files changed

+56
-38
lines changed
 

‎src/bootstrap/compile.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ impl Step for Std {
8080

8181
// Even if we're not building std this stage, the new sysroot must
8282
// still contain the musl startup objects.
83-
if target.contains("musl") && !target.contains("mips") {
83+
if target.contains("musl") {
8484
let libdir = builder.sysroot_libdir(compiler, target);
8585
copy_musl_third_party_objects(build, target, &libdir);
8686
}
@@ -97,7 +97,7 @@ impl Step for Std {
9797
println!("Building stage{} std artifacts ({} -> {})", compiler.stage,
9898
&compiler.host, target);
9999

100-
if target.contains("musl") && !target.contains("mips") {
100+
if target.contains("musl") {
101101
let libdir = builder.sysroot_libdir(compiler, target);
102102
copy_musl_third_party_objects(build, target, &libdir);
103103
}

‎src/bootstrap/configure.py

+4
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ def v(*args):
120120
"armv7-unknown-linux-musleabihf install directory")
121121
v("musl-root-aarch64", "target.aarch64-unknown-linux-musl.musl-root",
122122
"aarch64-unknown-linux-musl install directory")
123+
v("musl-root-mips", "target.mips-unknown-linux-musl.musl-root",
124+
"mips-unknown-linux-musl install directory")
125+
v("musl-root-mipsel", "target.mipsel-unknown-linux-musl.musl-root",
126+
"mipsel-unknown-linux-musl install directory")
123127
v("qemu-armhf-rootfs", "target.arm-unknown-linux-gnueabihf.qemu-rootfs",
124128
"rootfs in qemu testing, you probably don't want to use this")
125129
v("qemu-aarch64-rootfs", "target.aarch64-unknown-linux-gnu.qemu-rootfs",

‎src/bootstrap/sanity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub fn check(build: &mut Build) {
170170
}
171171

172172
// Make sure musl-root is valid
173-
if target.contains("musl") && !target.contains("mips") {
173+
if target.contains("musl") {
174174
// If this is a native target (host is also musl) and no musl-root is given,
175175
// fall back to the system toolchain in /usr before giving up
176176
if build.musl_root(*target).is_none() && build.config.build == *target {

‎src/ci/docker/dist-various-1/Dockerfile

+21-10
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,15 @@ RUN ./build-rumprun.sh
3030
COPY dist-various-1/install-x86_64-redox.sh /build
3131
RUN ./install-x86_64-redox.sh
3232

33+
COPY dist-various-1/install-mips-musl.sh /build
34+
RUN ./install-mips-musl.sh
35+
36+
COPY dist-various-1/install-mipsel-musl.sh /build
37+
RUN ./install-mipsel-musl.sh
38+
39+
# Suppress some warnings in the openwrt toolchains we downloaded
40+
ENV STAGING_DIR=/tmp
41+
3342
COPY scripts/musl.sh /build
3443
RUN env \
3544
CC=arm-linux-gnueabi-gcc CFLAGS="-march=armv6 -marm" \
@@ -47,14 +56,16 @@ RUN env \
4756
CC=aarch64-linux-gnu-gcc \
4857
CXX=aarch64-linux-gnu-g++ \
4958
bash musl.sh aarch64 && \
59+
env \
60+
CC=mips-openwrt-linux-gcc \
61+
CXX=mips-openwrt-linux-g++ \
62+
bash musl.sh mips && \
63+
env \
64+
CC=mipsel-openwrt-linux-gcc \
65+
CXX=mipsel-openwrt-linux-g++ \
66+
bash musl.sh mipsel && \
5067
rm -rf /build/*
5168

52-
COPY dist-various-1/install-mips-musl.sh /build
53-
RUN ./install-mips-musl.sh
54-
55-
COPY dist-various-1/install-mipsel-musl.sh /build
56-
RUN ./install-mipsel-musl.sh
57-
5869
ENV TARGETS=asmjs-unknown-emscripten
5970
ENV TARGETS=$TARGETS,wasm32-unknown-emscripten
6071
ENV TARGETS=$TARGETS,x86_64-rumprun-netbsd
@@ -77,16 +88,16 @@ ENV CC_mipsel_unknown_linux_musl=mipsel-openwrt-linux-gcc \
7788
CC_armv5te_unknown_linux_gnueabi=arm-linux-gnueabi-gcc \
7889
CFLAGS_armv5te_unknown_linux_gnueabi="-march=armv5te -marm -mfloat-abi=soft"
7990

80-
# Suppress some warnings in the openwrt toolchains we downloaded
81-
ENV STAGING_DIR=/tmp
82-
8391
ENV RUST_CONFIGURE_ARGS \
8492
--enable-extended \
8593
--target=$TARGETS \
8694
--musl-root-arm=/musl-arm \
8795
--musl-root-armhf=/musl-armhf \
8896
--musl-root-armv7=/musl-armv7 \
89-
--musl-root-aarch64=/musl-aarch64
97+
--musl-root-aarch64=/musl-aarch64 \
98+
--musl-root-mips=/musl-mips \
99+
--musl-root-mipsel=/musl-mipsel
100+
90101
ENV SCRIPT python2.7 ../x.py dist --target $TARGETS
91102

92103
# sccache

‎src/ci/docker/scripts/musl.sh

+10-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,16 @@ hide_output make clean
4949

5050
cd ..
5151

52-
LLVM=39
52+
# use version 60 for all targets after llvm 6.0 release
53+
case $TAG in
54+
mips|mipsel)
55+
LLVM=60
56+
;;
57+
*)
58+
LLVM=39
59+
;;
60+
esac
61+
5362
# may have been downloaded in a previous run
5463
if [ ! -d libunwind-release_$LLVM ]; then
5564
curl -L https://github.com/llvm-mirror/llvm/archive/release_$LLVM.tar.gz | tar xzf -

‎src/librustc_back/target/mips_unknown_linux_musl.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
// except according to those terms.
1010

1111
use LinkerFlavor;
12-
use target::{Target, TargetOptions, TargetResult};
12+
use target::{Target, TargetResult};
1313

1414
pub fn target() -> TargetResult {
15+
let mut base = super::linux_musl_base::opts();
16+
base.cpu = "mips32r2".to_string();
17+
base.features = "+mips32r2,+soft-float".to_string();
18+
base.max_atomic_width = Some(32);
19+
// see #36994
20+
base.exe_allocation_crate = None;
1521
Ok(Target {
1622
llvm_target: "mips-unknown-linux-musl".to_string(),
1723
target_endian: "big".to_string(),
@@ -23,15 +29,6 @@ pub fn target() -> TargetResult {
2329
target_env: "musl".to_string(),
2430
target_vendor: "unknown".to_string(),
2531
linker_flavor: LinkerFlavor::Gcc,
26-
options: TargetOptions {
27-
cpu: "mips32r2".to_string(),
28-
features: "+mips32r2,+soft-float".to_string(),
29-
max_atomic_width: Some(32),
30-
31-
// see #36994
32-
exe_allocation_crate: None,
33-
34-
..super::linux_base::opts()
35-
}
32+
options: base,
3633
})
3734
}

‎src/librustc_back/target/mipsel_unknown_linux_musl.rs

+8-11
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,15 @@
99
// except according to those terms.
1010

1111
use LinkerFlavor;
12-
use target::{Target, TargetOptions, TargetResult};
12+
use target::{Target, TargetResult};
1313

1414
pub fn target() -> TargetResult {
15+
let mut base = super::linux_musl_base::opts();
16+
base.cpu = "mips32".to_string();
17+
base.features = "+mips32,+soft-float".to_string();
18+
base.max_atomic_width = Some(32);
19+
// see #36994
20+
base.exe_allocation_crate = None;
1521
Ok(Target {
1622
llvm_target: "mipsel-unknown-linux-musl".to_string(),
1723
target_endian: "little".to_string(),
@@ -23,15 +29,6 @@ pub fn target() -> TargetResult {
2329
target_env: "musl".to_string(),
2430
target_vendor: "unknown".to_string(),
2531
linker_flavor: LinkerFlavor::Gcc,
26-
options: TargetOptions {
27-
cpu: "mips32".to_string(),
28-
features: "+mips32,+soft-float".to_string(),
29-
max_atomic_width: Some(32),
30-
31-
// see #36994
32-
exe_allocation_crate: None,
33-
34-
..super::linux_base::opts()
35-
}
32+
options: base,
3633
})
3734
}

‎src/libunwind/build.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ fn main() {
1515
let target = env::var("TARGET").expect("TARGET was not set");
1616

1717
if target.contains("linux") {
18-
if target.contains("musl") && !target.contains("mips") {
18+
if target.contains("musl") {
1919
// musl is handled in lib.rs
2020
} else if !target.contains("android") {
2121
println!("cargo:rustc-link-lib=gcc_s");

‎src/libunwind/lib.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ cfg_if! {
3535
}
3636
}
3737

38-
#[cfg(all(target_env = "musl", not(target_arch = "mips")))]
38+
#[cfg(target_env = "musl")]
3939
#[link(name = "unwind", kind = "static", cfg(target_feature = "crt-static"))]
4040
#[link(name = "gcc_s", cfg(not(target_feature = "crt-static")))]
4141
extern {}

0 commit comments

Comments
 (0)
Please sign in to comment.