Skip to content

Commit 2509569

Browse files
authored
[ATfE]: Enable sanitizer for ATfE as 2-stage pipeline (#464)
[ATfE]: Enable address sanitizer for ATfE as 2-stage pipeline
1 parent d68c1bf commit 2509569

File tree

2 files changed

+32
-15
lines changed

2 files changed

+32
-15
lines changed

arm-software/embedded/scripts/build_atfe_address_sanitizer.sh renamed to arm-software/embedded/scripts/build_atfe_sanitizer.sh

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
# A bash script to build the Arm Toolchain for Embedded, with address sanitizer enabled.
99

10+
# Script implements 2-stage pipeline: first clang is built using arm-toolchain sources.
11+
# Then this clang is used to compile ATfE sanitizer build.
12+
#
1013
# The script creates a build of the toolchain in the 'build' directory, inside
1114
# the repository tree.
1215

@@ -23,11 +26,23 @@ clang --version
2326
export CC=clang
2427
export CXX=clang++
2528

26-
# Get processor count, to execute job in parallel threads
27-
PROCESSOR_COUNT=$(getconf _NPROCESSORS_ONLN)
29+
# Stage 1: Compile clang
30+
mkdir -p "${REPO_ROOT}"/build_llvm
31+
cd "${REPO_ROOT}"/build_llvm
2832

29-
# Disable memory leaks detection of LeakSanitizer
30-
export ASAN_OPTIONS=detect_leaks=0
33+
cmake ../llvm -G Ninja \
34+
-DLLVM_ENABLE_PROJECTS="clang;llvm;lld" \
35+
-DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi;libunwind;compiler-rt" \
36+
-DCMAKE_BUILD_TYPE=Release \
37+
-DCLANG_DEFAULT_LINKER="lld"
38+
39+
ninja
40+
41+
echo "==> Stage 1: Completed clang build"
42+
43+
# Stage 2: Compile ATfE with sanitizer
44+
export CC="${REPO_ROOT}/build_llvm/bin/clang"
45+
export CXX="${REPO_ROOT}/build_llvm/bin/clang++"
3146

3247
if [[ ! -z "${FVP_INSTALL_DIR}" ]]; then
3348
EXTRA_CMAKE_ARGS="${EXTRA_CMAKE_ARGS} -DENABLE_FVP_TESTING=ON -DFVP_INSTALL_DIR=${FVP_INSTALL_DIR}"
@@ -36,6 +51,11 @@ fi
3651
mkdir -p "${REPO_ROOT}"/build
3752
cd "${REPO_ROOT}"/build
3853

39-
cmake ../arm-software/embedded -GNinja -DFETCHCONTENT_QUIET=OFF -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER="Address" -DLLVM_ENABLE_ASSERTIONS=ON ${EXTRA_CMAKE_ARGS}
54+
# Enable below flag to disable memory leaks detection of LeakSanitizer.
55+
# export ASAN_OPTIONS=detect_leaks=0
56+
57+
cmake ../arm-software/embedded -GNinja -DFETCHCONTENT_QUIET=OFF -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_BUILD_TYPE=Release -DLLVM_USE_SANITIZER="Address;Undefined" -DLLVM_ENABLE_ASSERTIONS=ON ${EXTRA_CMAKE_ARGS}
58+
59+
ninja package-llvm-toolchain
4060

41-
ninja -j$PROCESSOR_COUNT package-llvm-toolchain
61+
echo "==> Stage 2: Completed sanitizer build"

arm-software/embedded/scripts/test_atfe_sanitizer.sh

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,6 @@ set -vx
1818
SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
1919
REPO_ROOT=$( git -C "${SCRIPT_DIR}" rev-parse --show-toplevel )
2020

21-
# Get processor count, to execute job in parallel threads
22-
PROCESSOR_COUNT=$(getconf _NPROCESSORS_ONLN)
23-
2421
cd "${REPO_ROOT}"/build
2522

2623
# If a test fails, lit will ordinarily return a non-zero result,
@@ -32,15 +29,15 @@ cd "${REPO_ROOT}"/build
3229
# Additionally setting the --xunit-xml-output option store the
3330
# results.
3431
export LIT_OPTS="--ignore-fail --xunit-xml-output=results.xml"
35-
ninja -j$PROCESSOR_COUNT check-all
32+
ninja check-all
3633

3734
# The llvm-toolchain targets already set --xunit-xml-output so
3835
# only the --ignore-fail option is needed.
3936
# The picolibc tests do not use lit so do not support this option.
4037
# Command for each test is splitted across individual lines, to aid in debugging.
4138
export LIT_OPTS="--ignore-fail"
42-
ninja -j$PROCESSOR_COUNT check-compiler-rt-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
43-
ninja -j$PROCESSOR_COUNT check-picolibc-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
44-
ninja -j$PROCESSOR_COUNT check-cxx-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
45-
ninja -j$PROCESSOR_COUNT check-cxxabi-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
46-
ninja -j$PROCESSOR_COUNT check-unwind-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
39+
ninja check-compiler-rt-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
40+
ninja check-picolibc-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
41+
ninja check-cxx-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
42+
ninja check-cxxabi-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size
43+
ninja check-unwind-armv7m_hard_fpv5_d16_exn_rtti_unaligned_size

0 commit comments

Comments
 (0)