From 8521530f49383f5d014062a450b19a3b87b43b49 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Tue, 14 May 2019 12:26:09 -0700 Subject: [PATCH] Fix __divsi3 and __udivsi3 on thumbv6m targets This commit fixes a bug accidentally introduced in #285 where some lingering references remained to `#[cfg(thumbv6m)]` but this, since the historical revert, was renamed to `#[cfg(thumb_1)]`. This caused on the thumbv6m platform for the intrinsics to be accidentally omitted because the build script didn't actually compile them but the Rust code thought the C code was in use. After correcting the `#[cfg]` statements the CI configuration for the `thumb*` family of targets was all updated. The support for xargo testing was removed from `run.sh` since it had long since bitrotted, and the script was updated to simply build the intrinsics example to attempt to link for each of these targets. This in turn exposed the bug locally and allowed to confirm a fix once the `#[cfg]` statements were corrected. cc rust-lang/rust#60782 --- Cargo.toml | 2 +- azure-pipelines.yml | 20 ++++----- ci/docker/thumbv6m-linux-eabi/Dockerfile | 10 ----- ci/docker/thumbv6m-none-eabi/Dockerfile | 7 +++ ci/docker/thumbv7em-linux-eabi/Dockerfile | 10 ----- ci/docker/thumbv7em-linux-eabihf/Dockerfile | 10 ----- ci/docker/thumbv7em-none-eabi/Dockerfile | 7 +++ ci/docker/thumbv7em-none-eabihf/Dockerfile | 7 +++ ci/docker/thumbv7m-linux-eabi/Dockerfile | 10 ----- ci/docker/thumbv7m-none-eabi/Dockerfile | 7 +++ ci/run-docker.sh | 1 - ci/run.sh | 50 +++++---------------- examples/intrinsics.rs | 14 +++++- src/int/sdiv.rs | 2 +- src/int/udiv.rs | 2 +- 15 files changed, 64 insertions(+), 95 deletions(-) delete mode 100644 ci/docker/thumbv6m-linux-eabi/Dockerfile create mode 100644 ci/docker/thumbv6m-none-eabi/Dockerfile delete mode 100644 ci/docker/thumbv7em-linux-eabi/Dockerfile delete mode 100644 ci/docker/thumbv7em-linux-eabihf/Dockerfile create mode 100644 ci/docker/thumbv7em-none-eabi/Dockerfile create mode 100644 ci/docker/thumbv7em-none-eabihf/Dockerfile delete mode 100644 ci/docker/thumbv7m-linux-eabi/Dockerfile create mode 100644 ci/docker/thumbv7m-none-eabi/Dockerfile diff --git a/Cargo.toml b/Cargo.toml index a05825a..e799591 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -62,7 +62,7 @@ rustc-dep-of-std = ['c', 'compiler-builtins', 'core'] [[example]] name = "intrinsics" -required-features = ["c", "compiler-builtins"] +required-features = ["compiler-builtins"] [workspace] members = ["testcrate"] diff --git a/azure-pipelines.yml b/azure-pipelines.yml index da3a1bb..eac3fb5 100644 --- a/azure-pipelines.yml +++ b/azure-pipelines.yml @@ -33,18 +33,14 @@ jobs: TARGET: powerpc64-unknown-linux-gnu powerpc64le: TARGET: powerpc64le-unknown-linux-gnu - # thumbv6m: - # TARGET: thumbv6m-linux-eabi - # XARGO: 1 - # thumbv7em: - # TARGET: thumbv7em-linux-eabi - # XARGO: 1 - # thumbv7emhf: - # TARGET: thumbv7em-linux-eabihf - # XARGO: 1 - # thumbv7m: - # TARGET: thumbv7m-linux-eabi - # XARGO: 1 + thumbv6m: + TARGET: thumbv6m-none-eabi + thumbv7em: + TARGET: thumbv7em-none-eabi + thumbv7emhf: + TARGET: thumbv7em-none-eabihf + thumbv7m: + TARGET: thumbv7m-none-eabi wasm32: TARGET: wasm32-unknown-unknown ONLY_BUILD: 1 diff --git a/ci/docker/thumbv6m-linux-eabi/Dockerfile b/ci/docker/thumbv6m-linux-eabi/Dockerfile deleted file mode 100644 index 789bdf4..0000000 --- a/ci/docker/thumbv6m-linux-eabi/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:18.04 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates curl gcc gcc-arm-none-eabi libc6-dev libcurl4-openssl-dev libssh2-1 libnewlib-dev qemu-user-static -RUN curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- --git japaric/xargo --tag v0.3.1 --target x86_64-unknown-linux-gnu --to /usr/bin -ENV AR_thumbv6m_linux_eabi=arm-none-eabi-ar \ - CARGO_TARGET_THUMBV6M_LINUX_EABI_LINKER=arm-none-eabi-gcc \ - CARGO_TARGET_THUMBV6M_LINUX_EABI_RUNNER=qemu-arm-static \ - CC_thumbv6m_linux_eabi=arm-none-eabi-gcc \ diff --git a/ci/docker/thumbv6m-none-eabi/Dockerfile b/ci/docker/thumbv6m-none-eabi/Dockerfile new file mode 100644 index 0000000..04d4f44 --- /dev/null +++ b/ci/docker/thumbv6m-none-eabi/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi +ENV XARGO=1 diff --git a/ci/docker/thumbv7em-linux-eabi/Dockerfile b/ci/docker/thumbv7em-linux-eabi/Dockerfile deleted file mode 100644 index c6ce273..0000000 --- a/ci/docker/thumbv7em-linux-eabi/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:18.04 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates curl gcc gcc-arm-none-eabi libc6-dev libcurl4-openssl-dev libssh2-1 libnewlib-dev qemu-user-static -RUN curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- --git japaric/xargo --tag v0.3.1 --target x86_64-unknown-linux-gnu --to /usr/bin -ENV AR_thumbv7em_linux_eabi=arm-none-eabi-ar \ - CARGO_TARGET_THUMBV7EM_LINUX_EABI_LINKER=arm-none-eabi-gcc \ - CARGO_TARGET_THUMBV7EM_LINUX_EABI_RUNNER=qemu-arm-static \ - CC_thumbv7em_linux_eabi=arm-none-eabi-gcc \ diff --git a/ci/docker/thumbv7em-linux-eabihf/Dockerfile b/ci/docker/thumbv7em-linux-eabihf/Dockerfile deleted file mode 100644 index c7518aa..0000000 --- a/ci/docker/thumbv7em-linux-eabihf/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:18.04 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates curl gcc gcc-arm-none-eabi libc6-dev libcurl4-openssl-dev libssh2-1 libnewlib-dev qemu-user-static -RUN curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- --git japaric/xargo --tag v0.3.1 --target x86_64-unknown-linux-gnu --to /usr/bin -ENV AR_thumbv7em_linux_eabihf=arm-none-eabi-ar \ - CARGO_TARGET_THUMBV7EM_LINUX_EABIHF_LINKER=arm-none-eabi-gcc \ - CARGO_TARGET_THUMBV7EM_LINUX_EABIHF_RUNNER=qemu-arm-static \ - CC_thumbv7em_linux_eabihf=arm-none-eabi-gcc \ diff --git a/ci/docker/thumbv7em-none-eabi/Dockerfile b/ci/docker/thumbv7em-none-eabi/Dockerfile new file mode 100644 index 0000000..04d4f44 --- /dev/null +++ b/ci/docker/thumbv7em-none-eabi/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi +ENV XARGO=1 diff --git a/ci/docker/thumbv7em-none-eabihf/Dockerfile b/ci/docker/thumbv7em-none-eabihf/Dockerfile new file mode 100644 index 0000000..04d4f44 --- /dev/null +++ b/ci/docker/thumbv7em-none-eabihf/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi +ENV XARGO=1 diff --git a/ci/docker/thumbv7m-linux-eabi/Dockerfile b/ci/docker/thumbv7m-linux-eabi/Dockerfile deleted file mode 100644 index c907109..0000000 --- a/ci/docker/thumbv7m-linux-eabi/Dockerfile +++ /dev/null @@ -1,10 +0,0 @@ -FROM ubuntu:18.04 -RUN apt-get update && \ - apt-get install -y --no-install-recommends \ - ca-certificates curl gcc gcc-arm-none-eabi libc6-dev libcurl4-openssl-dev libssh2-1 libnewlib-dev qemu-user-static -RUN curl -LSfs https://japaric.github.io/trust/install.sh | \ - sh -s -- --git japaric/xargo --tag v0.3.1 --target x86_64-unknown-linux-gnu --to /usr/bin -ENV AR_thumbv7m_linux_eabi=arm-none-eabi-ar \ - CARGO_TARGET_THUMBV7M_LINUX_EABI_LINKER=arm-none-eabi-gcc \ - CARGO_TARGET_THUMBV7M_LINUX_EABI_RUNNER=qemu-arm-static \ - CC_thumbv7m_linux_eabi=arm-none-eabi-gcc \ diff --git a/ci/docker/thumbv7m-none-eabi/Dockerfile b/ci/docker/thumbv7m-none-eabi/Dockerfile new file mode 100644 index 0000000..04d4f44 --- /dev/null +++ b/ci/docker/thumbv7m-none-eabi/Dockerfile @@ -0,0 +1,7 @@ +FROM ubuntu:18.04 +RUN apt-get update && \ + apt-get install -y --no-install-recommends \ + gcc libc6-dev ca-certificates \ + gcc-arm-none-eabi \ + libnewlib-arm-none-eabi +ENV XARGO=1 diff --git a/ci/run-docker.sh b/ci/run-docker.sh index bed84ed..ddb970c 100755 --- a/ci/run-docker.sh +++ b/ci/run-docker.sh @@ -18,7 +18,6 @@ run() { --user $(id -u):$(id -g) \ -e CARGO_HOME=/cargo \ -e CARGO_TARGET_DIR=/target \ - -e XARGO \ -v $HOME/.cargo:/cargo \ -v `pwd`/target:/target \ -v `pwd`:/checkout:ro \ diff --git a/ci/run.sh b/ci/run.sh index 27e2de2..ae32806 100755 --- a/ci/run.sh +++ b/ci/run.sh @@ -1,53 +1,24 @@ set -ex -# FIXME(japarix/xargo#186) this shouldn't be necessary -export RUST_TARGET_PATH=`pwd` - cargo=cargo -if [ "$XARGO" = "1" ]; then - cargo=xargo -fi - -INTRINSICS_FEATURES="c" - -# Some architectures like ARM apparently seem to require the `mem` feature -# enabled to successfully compile the `intrinsics` example, and... we're not -# sure why! -if [ -z "$INTRINSICS_FAILS_WITH_MEM_FEATURE" ]; then - INTRINSICS_FEATURES="$INTRINSICS_FEATURES mem" -fi # Test our implementation if [ "$XARGO" = "1" ]; then - run="xargo test --manifest-path testcrate/Cargo.toml --target $1" - for t in $(ls testcrate/tests); do - t=${t%.rs} - - RUSTFLAGS="-C debug-assertions=no -C lto" \ - CARGO_INCREMENTAL=0 \ - $run --test $t --no-default-features --features 'mem c' --no-run - qemu-arm-static target/${1}/debug/$t-* - done - - for t in $(ls testcrate/tests); do - t=${t%.rs} - RUSTFLAGS="-C lto" \ - CARGO_INCREMENTAL=0 \ - $run --test $t --no-default-features --features 'mem c' --no-run --release - qemu-arm-static target/${1}/release/$t-* - done + # FIXME: currently these tests don't work... + echo nothing to do else run="cargo test --manifest-path testcrate/Cargo.toml --target $1" $run $run --release $run --features c $run --features c --release - cargo build --target $1 - cargo build --target $1 --release - cargo build --target $1 --features c - cargo build --target $1 --release --features c fi +cargo build --target $1 +cargo build --target $1 --release +cargo build --target $1 --features c +cargo build --target $1 --release --features c + PREFIX=$(echo $1 | sed -e 's/unknown-//')- case $1 in armv7-*) @@ -101,8 +72,11 @@ done rm -f $path # Verify that we haven't drop any intrinsic/symbol -RUSTFLAGS="-C debug-assertions=no" \ - $cargo build --features "$INTRINSICS_FEATURES" --target $1 --example intrinsics -v +build_intrinsics="$cargo build --target $1 -v --example intrinsics" +RUSTFLAGS="-C debug-assertions=no" $build_intrinsics +RUSTFLAGS="-C debug-assertions=no" $build_intrinsics --release +RUSTFLAGS="-C debug-assertions=no" $build_intrinsics --features c +RUSTFLAGS="-C debug-assertions=no" $build_intrinsics --features c --release # Verify that there are no undefined symbols to `panic` within our # implementations diff --git a/examples/intrinsics.rs b/examples/intrinsics.rs index ccd7015..8de108d 100644 --- a/examples/intrinsics.rs +++ b/examples/intrinsics.rs @@ -27,7 +27,14 @@ extern {} mod intrinsics { // trunccdfsf2 pub fn aeabi_d2f(x: f64) -> f32 { - x as f32 + // This is only implemented in C currently, so only test it there. + #[cfg(feature = "c")] + return x as f32; + #[cfg(not(feature = "c"))] + { + drop(x); + 0.0 + } } // fixdfsi @@ -263,6 +270,10 @@ mod intrinsics { pub fn modti3(a: i128, b: i128) -> i128 { a % b } + + pub fn udivsi3(a: u32, b: u32) -> u32 { + a / b + } } fn run() { @@ -325,6 +336,7 @@ fn run() { bb(umodti3(bb(2), bb(2))); bb(divti3(bb(2), bb(2))); bb(modti3(bb(2), bb(2))); + bb(udivsi3(bb(2), bb(2))); something_with_a_dtor(&|| assert_eq!(bb(1), 1)); diff --git a/src/int/sdiv.rs b/src/int/sdiv.rs index d7ae71a..82262a4 100644 --- a/src/int/sdiv.rs +++ b/src/int/sdiv.rs @@ -57,7 +57,7 @@ impl Divmod for i32 {} impl Divmod for i64 {} intrinsics! { - #[use_c_shim_if(all(target_arch = "arm", not(target_os = "ios"), not(thumbv6m)))] + #[use_c_shim_if(all(target_arch = "arm", not(target_os = "ios"), not(thumb_1)))] #[arm_aeabi_alias = __aeabi_idiv] pub extern "C" fn __divsi3(a: i32, b: i32) -> i32 { a.div(b) diff --git a/src/int/udiv.rs b/src/int/udiv.rs index 7b7f5b4..8837126 100644 --- a/src/int/udiv.rs +++ b/src/int/udiv.rs @@ -154,7 +154,7 @@ macro_rules! udivmod_inner { intrinsics! { #[use_c_shim_if(all(target_arch = "arm", not(target_os = "ios"), - not(thumbv6m)))] + not(thumb_1)))] #[arm_aeabi_alias = __aeabi_uidiv] /// Returns `n / d` pub extern "C" fn __udivsi3(n: u32, d: u32) -> u32 {