Skip to content

Commit

Permalink
Add support for s390x architecture. (#1431)
Browse files Browse the repository at this point in the history
### Description of changes: 

Add support for s390x architecture.

This is pretty trivial change (a few defines), since the big-endian
support was previously added for PowerPC architectures.


### Call-outs:

There is a false-positive error when compiling using
`s390x-linux-gnu-gcc-11` with `-O3` (i.e. `Release` profile):
```
crypto/pem/pem_lib.c:705:11: error: ‘strncmp’ of strings of length 1 and 9 and bound of 9 evaluates to nonzero [-Werror=string-compare]
 705 |       if (strncmp(buf, "-----END ", 9) == 0) {
     |           ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
cc1: all warnings being treated as errors
```
but there are no issues when using `-O2` or when building with
`s390x-linux-gnu-gcc-12`.


### Testing:

All tests from `run_cross_tests.sh`, i.e.
```
crypto/crypto_test --gtest_also_run_disabled_tests
crypto/urandom_test
crypto/mem_test
crypto/mem_set_test
crypto/dynamic_loading_test

ssl/ssl_test
ssl/integration_test
```
passed, with the exception of `BIOTest.InvokeConnectCallback`, which
fails for me on all platforms.


By submitting this pull request, I confirm that my contribution is made
under the terms of the Apache 2.0 license and the ISC license.


cc @andrewhop @justsmth

---------

Signed-off-by: Piotr Sikora <[email protected]>
Co-authored-by: Justin Smith <[email protected]>
Co-authored-by: Justin W Smith <[email protected]>
  • Loading branch information
3 people authored Mar 4, 2024
1 parent 6bc2e52 commit e16ea3d
Show file tree
Hide file tree
Showing 11 changed files with 145 additions and 0 deletions.
17 changes: 17 additions & 0 deletions .github/workflows/cross-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,20 @@ jobs:
- uses: actions/checkout@v4
- name: PPC64LE Build/Test
run: tests/ci/run_cross_tests.sh ppc64le powerpc64le-unknown-linux-gnu "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_BUILD_TYPE=Release -DFIPS=1 -DBUILD_SHARED_LIBS=1"
s390x-non-fips-build-test:
runs-on: ubuntu-latest
steps:
- name: Install qemu
run: |
sudo apt-get update
sudo apt-get -y install qemu-user qemu-user-binfmt
- uses: actions/checkout@v4
- name: s390x Build/Test
# The flag below is set to avoid the following error with GCC 11.4.0:
#
# /home/runner/work/aws-lc/aws-lc/crypto/pem/pem_lib.c:705:11: error: 'strncmp' of strings of length 1 and 9 and bound of 9 evaluates to nonzero [-Werror=string-compare]
# 705 | if (strncmp(buf, "-----END ", 9) == 0) {
# | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~
env:
CFLAGS: "-Wno-string-compare"
run: tests/ci/run_cross_tests.sh s390x s390x-ibm-linux-gnu "-DCMAKE_BUILD_TYPE=Release"
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -764,6 +764,8 @@ elseif(CMAKE_SYSTEM_PROCESSOR MATCHES "powerpc64le|ppc64le")
set(ARCH "ppc64le")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "riscv64")
set(ARCH "riscv64")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "s390x")
set(ARCH "s390x")
elseif (${CMAKE_SYSTEM_PROCESSOR} STREQUAL "loongarch64")
set(ARCH "loongarch64")
else()
Expand Down
2 changes: 2 additions & 0 deletions crypto/fipsmodule/rand/getrandom_fillin.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@
#define EXPECTED_NR_getrandom 359
#elif defined(OPENSSL_RISCV64)
#define EXPECTED_NR_getrandom 278
#elif defined(OPENSSL_S390X)
#define EXPECTED_NR_getrandom 349
#elif defined(OPENSSL_LOONGARCH64)
#define EXPECTED_NR_getrandom 278
#endif
Expand Down
4 changes: 4 additions & 0 deletions include/openssl/target.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@
#define OPENSSL_32_BIT
#define OPENSSL_PPC32BE
#define OPENSSL_BIG_ENDIAN
#elif defined(__s390x__)
#define OPENSSL_64_BIT
#define OPENSSL_S390X
#define OPENSSL_BIG_ENDIAN
#elif defined(__MIPSEL__) && !defined(__LP64__)
#define OPENSSL_32_BIT
#define OPENSSL_MIPS
Expand Down
2 changes: 2 additions & 0 deletions tests/ci/run_cross_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ set(ENABLE_EXPERIMENTAL_BIG_ENDIAN_SUPPORT true)
set(CMAKE_GENERATOR Ninja)
EOF

cat ${TARGET_CPU}.cmake

export QEMU_LD_PREFIX="${SCRATCH_FOLDER}/${TARGET_PLATFORM}/${TARGET_PLATFORM}/sysroot"
export LD_LIBRARY_PATH="${SCRATCH_FOLDER}/${TARGET_PLATFORM}/${TARGET_PLATFORM}/sysroot/lib"

Expand Down
1 change: 1 addition & 0 deletions tests/docker_images/linux-ppc/ubuntu-x-tools/ppc.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ set(CMAKE_CXX_COMPILER /powerpc-unknown-linux-gnu/bin/powerpc-unknown-linux-gnu-
# Specify the sysroot for the target system
set(CMAKE_SYSROOT /powerpc-unknown-linux-gnu/powerpc-unknown-linux-gnu/sysroot)
set(CMAKE_GENERATOR Ninja)
set(ENABLE_EXPERIMENTAL_BIG_ENDIAN_SUPPORT true)
1 change: 1 addition & 0 deletions tests/docker_images/linux-ppc64/ubuntu-x-tools/ppc64.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ set(CMAKE_CXX_COMPILER /powerpc64-unknown-linux-gnu/bin/powerpc64-unknown-linux-
# Specify the sysroot for the target system
set(CMAKE_SYSROOT /powerpc64-unknown-linux-gnu/powerpc64-unknown-linux-gnu/sysroot/)
set(CMAKE_GENERATOR Ninja)
set(ENABLE_EXPERIMENTAL_BIG_ENDIAN_SUPPORT true)
41 changes: 41 additions & 0 deletions tests/docker_images/linux-s390x/build_images.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/usr/bin/env bash
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 OR ISC

set -ex

# Note:
# After host reboot, qemu registration may need to be performed.
# `docker run --rm --privileged multiarch/qemu-user-static --reset -p yes`

# On Linux, you can see which architectures that qemu is registered for by looking
# under `/proc/sys/fs/binfmt_misc`.

# If needed, you can clear these entries using the following command:
# `sudo find /proc/sys/fs/binfmt_misc -type f -name 'qemu-*' -exec sh -c 'echo -1 > {}' \;`

# Log Docker hub limit https://docs.docker.com/docker-hub/download-rate-limit/#how-can-i-check-my-current-rate
TOKEN=$(curl "https://auth.docker.io/token?service=registry.docker.io&scope=repository:ratelimitpreview/test:pull" | jq -r .token)
curl --head -H "Authorization: Bearer $TOKEN" https://registry-1.docker.io/v2/ratelimitpreview/test/manifests/latest

SCRIPT_DIR=$(dirname "$(readlink -f "${0}")")

docker run --rm --privileged multiarch/qemu-user-static --reset -p yes

ARCH_NAME=s390x

X_TOOLS_FILE=${ARCH_NAME}-x-tools
if [ ! -f "./ubuntu-x-tools/${X_TOOLS_FILE}.tar.xz" ]; then
wget "https://aws-libcrypto.s3.us-west-2.amazonaws.com/cross-compile-toolchains/host-x86_64-pc-linux-gnu/${X_TOOLS_FILE}.tar.xz"
mv ${X_TOOLS_FILE}.tar.xz ./ubuntu-x-tools/
fi

BUILDER_NAME=${ARCH_NAME}-builder
if ! docker buildx inspect ${BUILDER_NAME}; then
docker buildx create --name ${BUILDER_NAME} --use
fi

docker buildx build -t ubuntu-${ARCH_NAME}:test "${SCRIPT_DIR}"/ubuntu-test --load
docker buildx build -t ubuntu-${ARCH_NAME}:x-tools "${SCRIPT_DIR}"/ubuntu-x-tools --load

docker buildx rm ${BUILDER_NAME}
23 changes: 23 additions & 0 deletions tests/docker_images/linux-s390x/ubuntu-test/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 OR ISC

FROM --platform=$BUILDPLATFORM s390x/ubuntu

SHELL ["/bin/bash", "-c"]

# Note: valgind was not available on this platform
RUN apt-get update && apt-get install -y \
git gcc g++ cmake golang gdb gdbserver \
libclang-dev clang \
build-essential \
ssh \
rsync \
tar \
python3 \
&& apt-get clean

EXPOSE 7777

ENV GOCACHE=/tmp

CMD ["/bin/bash"]
40 changes: 40 additions & 0 deletions tests/docker_images/linux-s390x/ubuntu-x-tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0 OR ISC

FROM ubuntu:22.04

RUN apt-get update && apt-get install -y \
git cmake golang gdb gdbserver valgrind \
libclang1 \
build-essential \
ssh \
rsync \
tar \
python3 \
xz-utils \
ninja-build

RUN apt-get install -y \
qemu-system-s390x \
qemu-user \
qemu-user-binfmt

RUN apt-get clean

COPY s390x-x-tools.tar.xz /
RUN tar Jxvf s390x-x-tools.tar.xz -C / && rm /s390x-x-tools.tar.xz
COPY s390x.cmake /

EXPOSE 1234

ENV GOCACHE=/tmp \
CMAKE_TOOLCHAIN_FILE=/s390x.cmake \
CMAKE_SYSTEM_NAME=Linux \
CMAKE_SYSTEM_PROCESSOR=s390x \
PATH="${PATH}:/s390x-ibm-linux-gnu/bin/" \
CMAKE_C_COMPILER=/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc \
CMAKE_CXX_COMPILER=/s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-g++ \
CMAKE_SYSROOT=/s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot \
CMAKE_GENERATOR=Ninja

CMD ["/bin/bash"]
12 changes: 12 additions & 0 deletions tests/docker_images/linux-s390x/ubuntu-x-tools/s390x.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Specify the target system
set(CMAKE_SYSTEM_NAME Linux)
set(CMAKE_SYSTEM_PROCESSOR s390x)

# Specify the cross-compiler
set(CMAKE_C_COMPILER /s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-gcc)
set(CMAKE_CXX_COMPILER /s390x-ibm-linux-gnu/bin/s390x-ibm-linux-gnu-g++)

# Specify the sysroot for the target system
set(CMAKE_SYSROOT /s390x-ibm-linux-gnu/s390x-ibm-linux-gnu/sysroot)
set(CMAKE_GENERATOR Ninja)
set(ENABLE_EXPERIMENTAL_BIG_ENDIAN_SUPPORT true)

0 comments on commit e16ea3d

Please sign in to comment.