diff --git a/README.md b/README.md index cf6e08933..5c23c1826 100644 --- a/README.md +++ b/README.md @@ -191,6 +191,7 @@ worst, "hang" (never terminate). | `arm-linux-androideabi` | N/A | 4.9 | 1.0.2k | ✓ | N/A | | | `arm-unknown-linux-gnueabi` | 2.19 | 4.8.2 | 1.0.2k | ✓ | 2.8.0 | ✓ | | `arm-unknown-linux-musleabi` | 1.1.15 | 5.3.1 | N/A | | 2.8.0 | ✓ | +| `armel-unknown-linux-gnueabi` [5] | 2.19 | 4.9.2 | 1.0.2k | ✓ | 2.9.0 | ✓ | | `armv7-linux-androideabi` | N/A | 4.9 | 1.0.2k | ✓ | N/A | | | `armv7-unknown-linux-gnueabihf` | 2.15 | 4.6.2 | 1.0.2k | ✓ | 2.8.0 | ✓ | | `armv7-unknown-linux-musleabihf` | 1.1.15 | 5.3.1 | N/A | | 2.8.0 | ✓ | @@ -232,6 +233,8 @@ where libc was extracted. [4] libc = musl, gcc = emcc; Some projects that use libc may fail due to wrong definitions (will be fixed by https://github.com/rust-lang/libc/pull/610) +[5] armel = armv5te; See [Target Notes](./TARGET-NOTES.md#armv5) for additional info + ## Debugging ### QEMU_STRACE (v0.1.9+) diff --git a/TARGET-NOTES.md b/TARGET-NOTES.md new file mode 100644 index 000000000..2a0ccdc8d --- /dev/null +++ b/TARGET-NOTES.md @@ -0,0 +1,71 @@ +# Target Notes + +This page details target specific information when using `cross`. + +## ARMv5 + +### Background + +Currently, Rust's built-in definition for the ARM9 family of processors with glibc support (referred to as `armel-unknown-linux-gnueabi` by GCC, and `armv5te-unknown-linux-gnueabi` by Rust/LLVM) defines `max-atomic-width` as `0`, as there is no hardware-level support for atomic operations. However when linked with `libgcc`, there are atomic primatives provided by the operating system. Additionally, this target uses the system allocator rather than jemalloc, as jemalloc does not currently build for this target. `unwind` is also not supported, so `panic` will abort. + +This `cross` target uses those OS intrinsics to provided atomic operations, and uses the gcc name of `armel-unknown-linux-gnueabi` to avoid aliasing the builtin specification. + +Previous discussion of this topic is available [in this reddit thread](https://www.reddit.com/r/rust/comments/64j39d/crosscompiling_for_arm926ejs/) + +### Integration steps + +Depending on which version of Rust you are using, the integration steps differ. + +#### Rust 1.19.0 and before + +Edit your `Cargo.toml`. Make sure the following sections are included: + +```toml +[profile.release] +panic = "abort" + +[profile.dev] +debug = true +panic = "abort" +``` + +Create a file in your project directory (next to `Cargo.toml`) called `Xargo.toml`. This file should have the following contents: + +```toml +[target.armel-unknown-linux-gnueabi.dependencies.std] +default-features = false +features=["panic_abort", "force_alloc_system"] +``` + +#### Rust 1.20.0 and above + +Edit your `Cargo.toml`. Make sure the following sections are included: + +```toml +[profile.release] +panic = "abort" + +[profile.dev] +debug = true +panic = "abort" +``` + +Create a file in your project directory (next to `Cargo.toml`) called `Xargo.toml`. This file should have the following contents: + +```toml +[target.armel-unknown-linux-gnueabi.dependencies.std] +default-features = false +features=["panic_abort"] +``` + +In your `main.rs`, add this to the top of your file: + +```rust +#![feature(global_allocator)] +#![feature(allocator_api)] + +use std::heap::System; + +#[global_allocator] +static mut SYSTEM_ALLOCATOR: System = System; +``` \ No newline at end of file diff --git a/docker/armel-unknown-linux-gnueabi/Dockerfile b/docker/armel-unknown-linux-gnueabi/Dockerfile new file mode 100644 index 000000000..8c777ce36 --- /dev/null +++ b/docker/armel-unknown-linux-gnueabi/Dockerfile @@ -0,0 +1,45 @@ +FROM debian:jessie + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + software-properties-common \ + wget \ + curl + +RUN add-apt-repository "deb http://emdebian.org/tools/debian/ jessie main" && \ + curl http://emdebian.org/tools/debian/emdebian-toolchain-archive.key | apt-key add - && \ + dpkg --add-architecture armel && \ + apt-get update && \ + apt-get install -y --no-install-recommends \ + crossbuild-essential-armel + +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + ca-certificates \ + cmake \ + gcc \ + libc6-dev \ + make \ + pkg-config + +COPY xargo.sh / +RUN bash /xargo.sh + +COPY openssl.sh qemu.sh / +RUN bash /openssl.sh linux-armv4 arm-linux-gnueabi- && \ + bash /qemu.sh arm + +COPY armel-unknown-linux-gnueabi/armel-unknown-linux-gnueabi.json /json/armel-unknown-linux-gnueabi.json + +ENV CARGO_TARGET_ARMEL_UNKNOWN_LINUX_GNUEABI_LINKER=arm-linux-gnueabi-gcc \ + RUST_TARGET_PATH=/json \ + HOST=x86_64-unknown-linux-gnu \ + CC_armel_unknown_linux_gnueabi=arm-linux-gnueabi-gcc \ + CXX_armel_unknown_linux_gnueabi=arm-linux-gnueabi-g++ \ + CFLAGS_armel_unknown_linux_gnueabi="-march=armv5te -Wall -Os -fPIC -D__arm__ -mfloat-abi=soft" \ + OPENSSL_DIR=/openssl \ + OPENSSL_INCLUDE_DIR=/openssl/include \ + OPENSSL_LIB_DIR=/openssl/lib \ + QEMU_LD_PREFIX=/usr/arm-linux-gnueabi \ + RUST_TEST_THREADS=1 + diff --git a/docker/armel-unknown-linux-gnueabi/armel-unknown-linux-gnueabi.json b/docker/armel-unknown-linux-gnueabi/armel-unknown-linux-gnueabi.json new file mode 100644 index 000000000..f3d8fa1b8 --- /dev/null +++ b/docker/armel-unknown-linux-gnueabi/armel-unknown-linux-gnueabi.json @@ -0,0 +1,37 @@ +{ + "abi-blacklist": [ + "stdcall", + "fastcall", + "vectorcall", + "thiscall", + "win64", + "sysv64" + ], + "arch": "arm", + "data-layout": "e-m:e-p:32:32-i64:64-v128:64:128-a:0:32-n32-S64", + "dynamic-linking": true, + "env": "gnu", + "exe-allocation-crate": "alloc_system", + "lib-allocation-crate": "alloc_system", + "executables": true, + "features": "+soft-float,+strict-align", + "has-elf-tls": true, + "has-rpath": true, + "is-builtin": false, + "linker-flavor": "gcc", + "linker-is-gnu": true, + "llvm-target": "armv5te-unknown-linux-gnueabi", + "max-atomic-width": 32, + "os": "linux", + "position-independent-executables": true, + "pre-link-args": { + "gcc": [ + "-Wl,--as-needed", + "-Wl,-z,noexecstack" + ] + }, + "target-endian": "little", + "target-family": "unix", + "target-pointer-width": "32", + "vendor": "unknown" +} diff --git a/src/main.rs b/src/main.rs index ce95cb2a5..8fa2af6dc 100644 --- a/src/main.rs +++ b/src/main.rs @@ -112,6 +112,9 @@ pub enum Target { X86_64UnknownLinuxGnu, X86_64UnknownLinuxMusl, + // Linux, but must rebuild std + ArmelUnknownLinuxGnueabi, + // *BSD I686UnknownFreebsd, X86_64UnknownDragonfly, @@ -147,6 +150,7 @@ impl Target { fn is_builtin(&self) -> bool { match *self { Target::Custom { .. } => false, + Target::ArmelUnknownLinuxGnueabi => false, _ => true, } } @@ -246,6 +250,7 @@ impl Target { ArmLinuxAndroideabi => "arm-linux-androideabi", ArmUnknownLinuxGnueabi => "arm-unknown-linux-gnueabi", ArmUnknownLinuxMusleabi => "arm-unknown-linux-musleabi", + ArmelUnknownLinuxGnueabi => "armel-unknown-linux-gnueabi", Armv7LinuxAndroideabi => "armv7-linux-androideabi", Armv7UnknownLinuxGnueabihf => "armv7-unknown-linux-gnueabihf", Armv7UnknownLinuxMusleabihf => "armv7-unknown-linux-musleabihf", @@ -296,6 +301,7 @@ impl Target { "arm-linux-androideabi" => ArmLinuxAndroideabi, "arm-unknown-linux-gnueabi" => ArmUnknownLinuxGnueabi, "arm-unknown-linux-musleabi" => ArmUnknownLinuxMusleabi, + "armel-unknown-linux-gnueabi" => ArmelUnknownLinuxGnueabi, "armv7-linux-androideabi" => Armv7LinuxAndroideabi, "armv7-unknown-linux-gnueabihf" => Armv7UnknownLinuxGnueabihf, "armv7-unknown-linux-musleabihf" => Armv7UnknownLinuxMusleabihf,