diff --git a/README.md b/README.md index 7444ce8..8863fc6 100644 --- a/README.md +++ b/README.md @@ -211,3 +211,20 @@ ccache - the main reason for not removing `./build` automatically, aside from simplifying the debugging in case of errors, is not to run `rm -rf` with computed paths, as this can be harmful to the host system in case of misconfiguration. + +## Testing run-time libraries + +It is possible to make use of the build directories configured during a +non-containerized build to execute the tests of run-time libraries. +On an x86_64 host, this requires qemu-user to be installed. + +```bash +./build.sh sources ... +./build.sh host-build +cd build/compiler-rt-full-aarch64-linux-pauthtest +ninja check-profile +``` + +Not all test cases currently pass, nevertheless this environment is basically +usable to evaluate the changes to these libraries against their regression +test suites. diff --git a/cmake/compiler-rt-common.cmake b/cmake/compiler-rt-common.cmake index cdd1366..bb938ba 100644 --- a/cmake/compiler-rt-common.cmake +++ b/cmake/compiler-rt-common.cmake @@ -5,3 +5,15 @@ set(COMPILER_RT_BUILD_SANITIZERS FALSE CACHE BOOL "" FORCE) set(COMPILER_RT_BUILD_XRAY FALSE CACHE BOOL "" FORCE) set(COMPILER_RT_BUILD_MEMPROF FALSE CACHE BOOL "" FORCE) set(COMPILER_RT_BUILD_ORC FALSE CACHE BOOL "" FORCE) + +# Enable `check-*` targets, so that they can be manually executed after +# building the toolchain with `./build.sh host-build`. +set(test_cflags "") +set(sysroot_lib_path "${TOOLCHAIN_BUILD_INSTALL_DIR}/${TOOLCHAIN_BUILD_TARGET}/usr/lib") +string(APPEND test_cflags " -march=armv8.3-a+pauth") +string(APPEND test_cflags " -Wl,--rpath=${sysroot_lib_path}") +string(APPEND test_cflags " -L ${sysroot_lib_path}") +string(APPEND test_cflags " -Wl,--dynamic-linker=${sysroot_lib_path}/libc.so") +set(COMPILER_RT_TEST_COMPILER_CFLAGS "${test_cflags}" CACHE STRING "" FORCE) +set(COMPILER_RT_CAN_EXECUTE_TESTS TRUE CACHE BOOL "" FORCE) +set(COMPILER_RT_INCLUDE_TESTS TRUE CACHE BOOL "" FORCE) diff --git a/scripts/build-compiler-rt.sh b/scripts/build-compiler-rt.sh index f5d02d3..d0c564f 100755 --- a/scripts/build-compiler-rt.sh +++ b/scripts/build-compiler-rt.sh @@ -5,6 +5,7 @@ cd "$(dirname "$0")" . ./global-vars COMPILER_RT_INSTALL_PREFIX="$("$INSTALL_DIR/bin/clang" --print-resource-dir)" +normalized_triple="$("$INSTALL_DIR/bin/clang" -target $CROSS_TARGET --print-target-triple)" # Assertion: COMPILER_RT_INSTALL_PREFIX should be under INSTALL_DIR. rel_install_prefix="$(realpath --relative-to="$INSTALL_DIR" "$COMPILER_RT_INSTALL_PREFIX")" @@ -27,4 +28,11 @@ cmake \ -C "$CMAKE_DIR/compiler-rt-common.cmake" \ -C "$CMAKE_DIR/compiler-rt-${COMPILER_RT_BUILD}.cmake" +# Provide the run-time libraries to link the tests executables. +mkdir -p "${BUILD_DIR}/lib/${normalized_triple}" +ln -sr "${COMPILER_RT_INSTALL_PREFIX}/lib/${normalized_triple}/clang_rt.crtbegin.o" \ + "${COMPILER_RT_INSTALL_PREFIX}/lib/${normalized_triple}/clang_rt.crtend.o" \ + "${COMPILER_RT_INSTALL_PREFIX}/lib/${normalized_triple}/libclang_rt.builtins.a" \ + "${BUILD_DIR}/lib/${normalized_triple}" + cmake --build "$BUILD_DIR" --target install -- -j$CPU_COUNT