forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The targets are: - `arm-unknown-linux-musleabi` - `arm-unknown-linux-musleabihf` - `armv7-unknown-linux-musleabihf` These mirror the existing `gnueabi` targets. All of these targets produce fully static binaries, similar to the x86 MUSL targets. For now these targets can only be used with `--rustbuild` builds, as rust-lang/compiler-rt#22 only made the necessary compiler-rt changes in the CMake configs, not the plain GNU Make configs. I've tested these targets GCC 5.3.0 compiled again musl-1.1.12 (downloaded from http://musl.codu.org/). An example `./configure` invocation is: ``` ./configure \ --enable-rustbuild --target=arm-unknown-linux-musleabi \ --musl-root="$MUSL_ROOT" ``` where `MUSL_ROOT` points to the `arm-linux-musleabi` prefix. Usually that path will be of the form `/foobar/arm-linux-musleabi/arm-linux-musleabi`. Usually the cross-compile toolchain will live under `/foobar/arm-linux-musleabi/bin`. That path should either by added to your `PATH` variable, or you should add a section to your `config.toml` as follows: ``` [target.arm-unknown-linux-musleabi] cc = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-gcc" cxx = "/foobar/arm-linux-musleabi/bin/arm-linux-musleabi-g++" ``` As a prerequisite you'll also have to put a cross-compiled static `libunwind.a` library in `$MUSL_ROOT/lib`. This is similar to [how the x86_64 MUSL targets are built] (https://doc.rust-lang.org/book/advanced-linking.html).
- Loading branch information
Showing
15 changed files
with
210 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file is intentially left empty to indicate that, while this target is | ||
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild | ||
# instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file is intentially left empty to indicate that, while this target is | ||
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild | ||
# instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# This file is intentially left empty to indicate that, while this target is | ||
# supported, it's not supported using plain GNU Make builds. Use a --rustbuild | ||
# instead. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use target::Target; | ||
|
||
pub fn target() -> Target { | ||
let mut base = super::musl_base::opts(); | ||
|
||
// Most of these settings are copied from the arm_unknown_linux_gnueabi | ||
// target. | ||
base.features = "+v6".to_string(); | ||
Target { | ||
// It's important we use "gnueabi" and not "musleabi" here. LLVM uses it | ||
// to determine the calling convention and float ABI, and it doesn't | ||
// support the "musleabi" value. | ||
llvm_target: "arm-unknown-linux-gnueabi".to_string(), | ||
target_endian: "little".to_string(), | ||
target_pointer_width: "32".to_string(), | ||
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | ||
arch: "arm".to_string(), | ||
target_os: "linux".to_string(), | ||
target_env: "musleabi".to_string(), | ||
target_vendor: "unknown".to_string(), | ||
options: base, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use target::Target; | ||
|
||
pub fn target() -> Target { | ||
let mut base = super::musl_base::opts(); | ||
|
||
// Most of these settings are copied from the arm_unknown_linux_gnueabihf | ||
// target. | ||
base.features = "+v6,+vfp2".to_string(); | ||
Target { | ||
// It's important we use "gnueabihf" and not "musleabihf" here. LLVM | ||
// uses it to determine the calling convention and float ABI, and it | ||
// doesn't support the "musleabihf" value. | ||
llvm_target: "arm-unknown-linux-gnueabihf".to_string(), | ||
target_endian: "little".to_string(), | ||
target_pointer_width: "32".to_string(), | ||
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | ||
arch: "arm".to_string(), | ||
target_os: "linux".to_string(), | ||
target_env: "musleabi".to_string(), | ||
target_vendor: "unknown".to_string(), | ||
options: base, | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/librustc_back/target/armv7_unknown_linux_musleabihf.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use target::Target; | ||
|
||
pub fn target() -> Target { | ||
let mut base = super::musl_base::opts(); | ||
|
||
// Most of these settings are copied from the armv7_unknown_linux_gnueabihf | ||
// target. | ||
base.features = "+v7,+vfp3,+neon".to_string(); | ||
base.cpu = "cortex-a8".to_string(); | ||
Target { | ||
// It's important we use "gnueabihf" and not "musleabihf" here. LLVM | ||
// uses it to determine the calling convention and float ABI, and LLVM | ||
// doesn't support the "musleabihf" value. | ||
llvm_target: "armv7-unknown-linux-gnueabihf".to_string(), | ||
target_endian: "little".to_string(), | ||
target_pointer_width: "32".to_string(), | ||
data_layout: "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64".to_string(), | ||
arch: "arm".to_string(), | ||
target_os: "linux".to_string(), | ||
target_env: "musleabi".to_string(), | ||
target_vendor: "unknown".to_string(), | ||
options: base, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
// Copyright 2016 The Rust Project Developers. See the COPYRIGHT | ||
// file at the top-level directory of this distribution and at | ||
// http://rust-lang.org/COPYRIGHT. | ||
// | ||
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or | ||
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license | ||
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your | ||
// option. This file may not be copied, modified, or distributed | ||
// except according to those terms. | ||
|
||
use target::TargetOptions; | ||
|
||
pub fn opts() -> TargetOptions { | ||
let mut base = super::linux_base::opts(); | ||
|
||
// Make sure that the linker/gcc really don't pull in anything, including | ||
// default objects, libs, etc. | ||
base.pre_link_args.push("-nostdlib".to_string()); | ||
base.pre_link_args.push("-static".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.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.push("-Wl,-(".to_string()); | ||
base.post_link_args.push("-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.push("crt1.o".to_string()); | ||
base.pre_link_objects_exe.push("crti.o".to_string()); | ||
base.post_link_objects.push("crtn.o".to_string()); | ||
|
||
// MUSL support doesn't currently include dynamic linking, so there's no | ||
// need for dylibs or rpath business. Additionally `-pie` is incompatible | ||
// with `-static`, so we can't pass `-pie`. | ||
base.dynamic_linking = false; | ||
base.has_rpath = false; | ||
base.position_independent_executables = false; | ||
|
||
return base; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters