From 9ff7d9cd3b2232afe17b1eba5526f3ec4f423858 Mon Sep 17 00:00:00 2001 From: Ulrich Weigand Date: Thu, 10 Nov 2022 14:23:58 +0100 Subject: [PATCH] Basic support for s390x target --- .github/workflows/ci.yml | 12 ++++++++++++ include/ring-core/target.h | 3 +++ mk/cargo.sh | 8 ++++++++ mk/install-build-tools.sh | 8 ++++++++ src/constant_time.rs | 1 + 5 files changed, 32 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 971e28032c..e82ce1bc8e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -185,6 +185,7 @@ jobs: - x86_64-apple-darwin - x86_64-unknown-linux-musl - x86_64-unknown-linux-gnu + - s390x-unknown-linux-gnu mode: - # debug @@ -261,6 +262,9 @@ jobs: - target: x86_64-unknown-linux-gnu host_os: ubuntu-22.04 + - target: s390x-unknown-linux-gnu + host_os: ubuntu-22.04 + steps: - if: ${{ contains(matrix.host_os, 'ubuntu') }} run: sudo apt-get update -y @@ -333,6 +337,7 @@ jobs: - aarch64-unknown-linux-musl - i686-pc-windows-msvc - x86_64-unknown-linux-gnu + - s390x-unknown-linux-gnu mode: - # debug @@ -354,6 +359,9 @@ jobs: - target: x86_64-unknown-linux-gnu host_os: ubuntu-22.04 + - target: s390x-unknown-linux-gnu + host_os: ubuntu-22.04 + steps: - if: ${{ contains(matrix.host_os, 'ubuntu') }} run: sudo apt-get update -y @@ -485,6 +493,7 @@ jobs: - aarch64-unknown-linux-gnu - i686-unknown-linux-gnu - x86_64-unknown-linux-musl + - s390x-unknown-linux-gnu mode: - # debug @@ -510,6 +519,9 @@ jobs: - target: x86_64-unknown-linux-musl host_os: ubuntu-22.04 + - target: s390x-unknown-linux-gnu + host_os: ubuntu-22.04 + # TODO: Add an ARM target after # https://github.com/rust-lang/rust/issues/79555 is fixed. This may # require https://github.com/rust-lang/rust/issues/79555 to be fixed diff --git a/include/ring-core/target.h b/include/ring-core/target.h index 5b46611550..264e7df731 100644 --- a/include/ring-core/target.h +++ b/include/ring-core/target.h @@ -40,6 +40,9 @@ #elif defined(__MIPSEL__) && defined(__LP64__) #define OPENSSL_64_BIT #define OPENSSL_MIPS64 +#elif defined(__s390x__) +#define OPENSSL_64_BIT +#define OPENSSL_S390X #elif defined(__wasm__) #define OPENSSL_32_BIT #else diff --git a/mk/cargo.sh b/mk/cargo.sh index d990220279..6cfe12bcbb 100755 --- a/mk/cargo.sh +++ b/mk/cargo.sh @@ -21,6 +21,7 @@ rustflags_self_contained="-Clink-self-contained=yes -Clinker=rust-lld" qemu_aarch64="qemu-aarch64 -L /usr/aarch64-linux-gnu" qemu_arm="qemu-arm -L /usr/arm-linux-gnueabihf" qemu_mipsel="qemu-mipsel -L /usr/mipsel-linux-gnu" +qemu_s390x="qemu-s390x -L /usr/s390x-linux-gnu" # Avoid putting the Android tools in `$PATH` because there are tools in this # directory like `clang` that would conflict with the same-named tools that may @@ -109,6 +110,13 @@ case $target in export CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_RUSTFLAGS="$rustflags_self_contained" fi ;; + s390x-unknown-linux-gnu) + export CC_s390x_unknown_linux_gnu=clang-$llvm_version + export AR_s390x_unknown_linux_gnu=llvm-ar-$llvm_version + export CFLAGS_s390x_unknown_linux_gnu="--sysroot=/usr/s390x-linux-gnu" + export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_LINKER=s390x-linux-gnu-gcc + export CARGO_TARGET_S390X_UNKNOWN_LINUX_GNU_RUNNER="$qemu_s390x" + ;; wasm32-unknown-unknown) # The first two are only needed for when the "wasm_c" feature is enabled. export CC_wasm32_unknown_unknown=clang-$llvm_version diff --git a/mk/install-build-tools.sh b/mk/install-build-tools.sh index 234516f032..12e1d458eb 100755 --- a/mk/install-build-tools.sh +++ b/mk/install-build-tools.sh @@ -91,6 +91,14 @@ case $target in libc6-dev-mipsel-cross \ qemu-user ;; +--target=s390x-unknown-linux-gnu) + # Clang is needed for code coverage. + use_clang=1 + install_packages \ + qemu-user \ + gcc-s390x-linux-gnu \ + libc6-dev-s390x-cross + ;; --target=wasm32-unknown-unknown) cargo install wasm-bindgen-cli --bin wasm-bindgen-test-runner use_clang=1 diff --git a/src/constant_time.rs b/src/constant_time.rs index 9ccf8f6653..2bed3824e0 100644 --- a/src/constant_time.rs +++ b/src/constant_time.rs @@ -40,6 +40,7 @@ mod tests { use crate::{bssl, error}; #[test] + #[cfg(not(target_arch = "s390x"))] // Triggers a qemu bug before 8.0.3 fn test_constant_time() -> Result<(), error::Unspecified> { prefixed_extern! { fn bssl_constant_time_test_main() -> bssl::Result;