From bc3eb354e753368060f5156b36ac3874ccc599b9 Mon Sep 17 00:00:00 2001 From: Jonah Petri Date: Fri, 17 Sep 2021 17:18:11 -0400 Subject: [PATCH] add platform support details file for armv7-unknown-linux-uclibc --- compiler/rustc_codegen_llvm/src/callee.rs | 3 +- .../spec/armv7_unknown_linux_uclibceabihf.rs | 1 + .../std/src/sys/unix/process/process_unix.rs | 2 +- .../armv7-unknown-linux-uclibceabihf.md | 66 +++++++++++++++++++ 4 files changed, 69 insertions(+), 3 deletions(-) create mode 100644 src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md diff --git a/compiler/rustc_codegen_llvm/src/callee.rs b/compiler/rustc_codegen_llvm/src/callee.rs index 13a15009ad2f2..1bc924d3b90b0 100644 --- a/compiler/rustc_codegen_llvm/src/callee.rs +++ b/compiler/rustc_codegen_llvm/src/callee.rs @@ -175,8 +175,7 @@ pub fn get_fn(cx: &CodegenCx<'ll, 'tcx>, instance: Instance<'tcx>) -> &'ll Value // should use dllimport for functions. if cx.use_dll_storage_attrs && tcx.is_dllimport_foreign_item(instance_def_id) - && tcx.sess.target.env != "gnu" - && tcx.sess.target.env != "uclibc" + && !matches!(tcx.sess.target.env.as_ref(), "gnu" | "uclibc") { llvm::LLVMSetDLLStorageClass(llfn, llvm::DLLStorageClass::DllImport); } diff --git a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs index 40ec5f4a86f3a..d230f77bde284 100644 --- a/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs +++ b/compiler/rustc_target/src/spec/armv7_unknown_linux_uclibceabihf.rs @@ -17,6 +17,7 @@ pub fn target() -> Target { cpu: "generic".to_string(), max_atomic_width: Some(64), mcount: "_mcount".to_string(), + abi: "eabihf".to_string(), ..base }, } diff --git a/library/std/src/sys/unix/process/process_unix.rs b/library/std/src/sys/unix/process/process_unix.rs index ac852717f1eca..99013efb495d0 100644 --- a/library/std/src/sys/unix/process/process_unix.rs +++ b/library/std/src/sys/unix/process/process_unix.rs @@ -419,7 +419,7 @@ impl Command { } // Only glibc 2.24+ posix_spawn() supports returning ENOENT directly. - #[cfg(all(target_os = "linux", any(target_env = "gnu", target_env = "uclibc")))] + #[cfg(all(target_os = "linux", target_env = "gnu"))] { if let Some(version) = sys::os::glibc_version() { if version < (2, 24) { diff --git a/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md new file mode 100644 index 0000000000000..b3a4275c6ee92 --- /dev/null +++ b/src/doc/rustc/src/platform-support/armv7-unknown-linux-uclibceabihf.md @@ -0,0 +1,66 @@ +# armv7-unknown-linux-uclibceabihf + +**Tier: 3** + +This tier supports the ARMv7 processor running a Linux kernel and uClibc-ng standard library. It provides full support for rust and the rust standard library. + +## Designated Developers + +* [@skrap](https://github.com/skrap) + +## Requirements + +This target is cross compiled, and requires a cross toolchain. You can find suitable pre-built toolchains at [bootlin](https://toolchains.bootlin.com/) or build one yourself via [buildroot](https://buildroot.org). + +## Building + +### Get a C toolchain + +Compiling rust for this target has been tested on `x86_64` linux hosts. Other host types have not been tested, but may work, if you can find a suitable cross compilation toolchain for them. + +If you don't already have a suitable toolchain, download one [here](https://toolchains.bootlin.com/downloads/releases/toolchains/armv7-eabihf/tarballs/armv7-eabihf--uclibc--bleeding-edge-2020.08-1.tar.bz2), and unpack it into a directory. + +### Configure rust + +The target can be built by enabling it for a `rustc` build, by placing the following in `config.toml`: + +```toml +[build] +target = ["armv7-unknown-linux-uclibceabihf"] +stage = 2 + +[target.armv7-unknown-linux-uclibceabihf] +# ADJUST THIS PATH TO POINT AT YOUR TOOLCHAIN +cc = "/TOOLCHAIN_PATH/bin/arm-buildroot-linux-uclibcgnueabihf-gcc" +``` + +### Build + +```sh +# in rust dir +./x.py build --stage 2 +``` + +## Building and Running Rust Programs + +To test cross-compiled binaries on a `x86_64` system, you can use the `qemu-arm` [userspace emulation](https://qemu-project.gitlab.io/qemu/user/main.html) program. This avoids having a full emulated ARM system by doing dynamic binary translation and dynamic system call translation. It lets you run ARM programs directly on your `x86_64` kernel. It's very convenient! + +To use: + +* Install `qemu-arm` according to your distro. +* Link your built toolchain via: + * `rustup toolchain link stage2 ${RUST}/build/x86_64-unknown-linux-gnu/stage2` +* Create a test program + +```sh +cargo new hello_world +cd hello_world +``` + +* Build and run + +```sh +CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_RUNNER="qemu-arm -L ${TOOLCHAIN}/arm-buildroot-linux-uclibcgnueabihf/sysroot/" \ +CARGO_TARGET_ARMV7_UNKNOWN_LINUX_UCLIBCEABIHF_LINKER=${TOOLCHAIN}/bin/arm-buildroot-linux-uclibcgnueabihf-gcc \ +cargo +stage2 run --target armv7-unknown-linux-uclibceabihf +```