From f73b7b7b819823d39b3a17b8c281e3a8a9452990 Mon Sep 17 00:00:00 2001 From: liyunfei Date: Thu, 3 Jul 2025 16:34:29 +0800 Subject: [PATCH 1/5] Add build script to the project. --- build.sh | 519 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 519 insertions(+) create mode 100644 build.sh diff --git a/build.sh b/build.sh new file mode 100644 index 000000000000..ec412a9b4dc3 --- /dev/null +++ b/build.sh @@ -0,0 +1,519 @@ +#!/bin/bash + +# Tools to use for bootstrapping. +C_COMPILER_PATH=gcc +CXX_COMPILER_PATH=g++ + +# Initialize our own variables: +enable_acpo="1" +enable_autotuner="1" +enable_bolt="1" +buildtype=RelWithDebInfo +backends="all" +build_for_openeuler="0" +enabled_projects="clang;lld;openmp;clang-tools-extra" +embedded_toolchain="0" +split_dwarf=on +use_ccache="0" +enable_classic_flang="0" +do_install="0" +clean=0 +containerize=0 +docker=$(type -p docker) +host_arch="$(uname -m)" +unit_test="" +install="install" +install_toolchain_only="0" +verbose="" +dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null && pwd )" +build_dir_name="build" +install_dir_name="install" +build_prefix="$dir/$build_dir_name" +install_prefix="$dir/$install_dir_name" +container=openEuler +containerize_needed=0 + +# Use 8 threads for builds and tests by default. Use more threads if possible, +# but avoid overloading the system by using up to 50% of available cores. +threads=8 +nproc=$(type -p nproc) +if [ -x "$nproc" -a -f /proc/loadavg ]; then + loadavg=$(awk '{printf "%.0f\n", $1}' < /proc/loadavg) + let threads="($($nproc) - $loadavg) / 2" + if [ $threads -le 0 ]; then + threads=1 + fi +fi + +# Exit script on first error. +set -e + +usage() { + cat < /dev/null 2>&1 +} + +# Handle interrupts. When not running a containerized build, we have to enable +# job control (-m), and make sure to delete our own long-running child +# processes. In particular, ninja and python (llvm-lit) refuse to terminate +# when Jenkins aborts the parent process and disconnects. +set -m +handle_abort() { + local rc=$1 sig=$2 + build_cleanup + trap - EXIT SIGHUP SIGINT SIGTERM + local children="$(jobs -p)" + for cgrp in $children ; do + kill -$sig -${cgrp} > /dev/null 2>&1 + done + if [ -n "$sig" ]; then + kill -$sig 0 + else + exit $rc + fi +} + +if [ $containerize -eq 0 ]; then + trap - SIGCHLD + trap 'handle_abort $?' EXIT + trap 'handle_abort 129 HUP' SIGHUP + trap 'handle_abort 130 INT' SIGINT + trap 'handle_abort 143 TERM' SIGTERM + if [ $containerize_needed -eq 1 ]; then + echo "$0: -C is needed for containerize build" + exit 1 + fi +else + cmd=$(readlink --canonicalize-existing $0) + + # Generate passwd/group files for the container. + # lit.py depends on correct results from getpwent. + homedir=$(realpath $HOME) + passwd=$(mktemp /tmp/passwd.XXXXXX) + echo "root:x:0:0::/root:/bin/bash" > $passwd + echo "user:x:$(id -u):$(id -g)::$homedir:/bin/bash" >> $passwd + + group=$(mktemp /tmp/group.XXXXXX) + echo "root:x:0:" > $group + echo "users:x:$(id -g):" >> $group + + # Re-run myself in a openEuler container. The --cap-add option is needed + # to pacify llvm-exegesis unit tests. Make sure that the container is + # stopped if the child process is interrupted (e.g. by Jenkins). + # Note that the container ID file is created with `mktemp -u` because + # `docker run` refuses to overwrite an existing ID file. + echo "Re-launching in container." + containerid=$(mktemp -u /tmp/docker-cid.$$.XXXXXX) + docker_cleanup() { + local rc=$1 sig=$2 + docker container stop $(cat $containerid) > /dev/null 2>&1 + rm $passwd $group $containerid + build_cleanup + trap - EXIT SIGHUP SIGINT SIGTERM # avoid infinite recursion + if [ -n "$sig" ]; then + kill -$sig 0 + else + exit $rc + fi + } + trap 'docker_cleanup $?' EXIT + trap 'docker_cleanup 129 HUP' SIGHUP + trap 'docker_cleanup 130 INT' SIGINT + trap 'docker_cleanup 143 TERM' SIGTERM + + if [ "$container" == "CentOS" ]; then + DOCKER_IMAGE="swr.cn-north-4.myhuaweicloud.com/llvm4oe/llvm-build-dep-centos7.6:latest" + else + DOCKER_IMAGE="hub.oepkgs.net/openeuler/llvm-build-deps:latest" + fi + docker_opts="--rm + --cap-add=SYS_ADMIN + --cap-add=SYS_PTRACE + --security-opt seccomp=unconfined + --user $(id -u):$(id -g) + --workdir=$(realpath $PWD) + --ulimit core=0 + --ulimit stack=-1 + --cidfile $containerid + -v $homedir:$homedir + -v $passwd:/etc/passwd + -v $group:/etc/group + -e BINUTILS_INCDIR=/usr/local/include + ${DOCKER_IMAGE}" + + if [ -t 1 ]; then + $docker run -it $docker_opts ${cmd} ${containerized_opts[@]} + exit $? + else + set -x + $docker run $docker_opts ${cmd} ${containerized_opts[@]} & + wait $! || exit $? + exit 0 + fi +fi + +echo "Using $threads threads." + +CMAKE_OPTIONS="-DCMAKE_INSTALL_PREFIX=$install_prefix \ + -DCMAKE_BUILD_TYPE=$buildtype \ + -DCMAKE_C_COMPILER=$C_COMPILER_PATH \ + -DCMAKE_CXX_COMPILER=$CXX_COMPILER_PATH \ + -DLLVM_TARGETS_TO_BUILD=$backends " + +gold=$(type -p ld.gold) +if [ -z "$gold" -o ! -x "$gold" ]; then + echo "$0: no usable ld.gold" + exit 1 +fi + +# If the invocation does not force a particular binutils installation, check +# that we are using an acceptable version. +if [ -n "$BINUTILS_INCDIR" ]; then + llvm_binutils_incdir="-DLLVM_BINUTILS_INCDIR=$BINUTILS_INCDIR" +else + incdir=$(realpath --canonicalize-existing $(dirname $gold)/../include) + if [ -z "$incdir" -o ! -f "$incdir/plugin-api.h" ]; then + echo "$0: plugin-api.h not found; required to build LLVMgold.so" + exit 1 + fi + llvm_binutils_incdir="-DLLVM_BINUTILS_INCDIR=$incdir" +fi + +# Warning: the -DLLVM_ENABLE_PROJECTS option is specified with cmake +# to avoid issues with nested quotation marks +if [ $use_ccache == "1" ]; then + echo "Build using ccache" + CMAKE_OPTIONS="$CMAKE_OPTIONS \ + -DCMAKE_C_COMPILER_LAUNCHER=ccache \ + -DCMAKE_CXX_COMPILER_LAUNCHER=ccache " +fi + +if [ $enable_classic_flang == "1" ]; then + echo "Enable classic flang" + CMAKE_OPTIONS="$CMAKE_OPTIONS \ + -DLLVM_ENABLE_CLASSIC_FLANG=on" +fi + +if [ $embedded_toolchain == "1" ]; then + echo "Build for embedded cross tool chain" + enabled_projects="clang;lld;" + CMAKE_OPTIONS="$CMAKE_OPTIONS \ + -DLLVM_BUILD_FOR_EMBEDDED=ON" +fi + +# When set LLVM_INSTALL_TOOLCHAIN_ONLY to On it removes many of the LLVM development +# and testing tools as well as component libraries from the default install target. +if [ $install_toolchain_only == "1" ]; then + echo "Only install toolchain" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DLLVM_INSTALL_TOOLCHAIN_ONLY=ON" +fi + +if [ $build_for_openeuler == "1" ]; then + echo "Build for openEuler" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DBUILD_FOR_OPENEULER=ON" +fi + +if [ $enable_autotuner == "1" ]; then + echo "enable BiSheng-Autotuner" + CMAKE_OPTIONS="$CMAKE_OPTIONS -DLLVM_ENABLE_AUTOTUNER=ON" +fi + +if [ $enable_acpo == "1" ]; then + echo "enable ACPO" + export CFLAGS="-Wp,-DENABLE_ACPO ${CFLAGS}" + export CXXFLAGS="-Wp,-DENABLE_ACPO ${CXXFLAGS}" +fi + + +if [ $enable_bolt == "1" ]; then + echo "enable BOLT" + #There is internal error when linking with gold while compiling BOLT. + unset llvm_use_linker + enabled_projects+=";bolt" + EXE_LINKER_FLAGS="-Wl,--compress-debug-sections=zlib" +else + llvm_use_linker="-DLLVM_USE_LINKER=gold" + EXE_LINKER_FLAGS="-Wl,--gdb-index -Wl,--compress-debug-sections=zlib" +fi + +# Build and install +if [ $clean -eq 1 -a -e "$install_prefix" ]; then + rm -rf "$install_prefix" +fi +mkdir -p "$install_prefix/bin" + +if [ $clean -eq 1 -a -e "$build_prefix" ]; then + rm -rf "$build_prefix" +fi + +mkdir -p "$build_prefix" && cd "$build_prefix" +cmake $CMAKE_OPTIONS \ + -DCOMPILER_RT_BUILD_SANITIZERS=on \ + -DLLVM_ENABLE_PROJECTS=$enabled_projects \ + -DLLVM_ENABLE_RUNTIMES="compiler-rt;libunwind" \ + $llvm_use_linker \ + -DLLVM_LIT_ARGS="-sv -j$threads" \ + -DLLVM_USE_SPLIT_DWARF=$split_dwarf \ + -DCMAKE_EXE_LINKER_FLAGS_RELWITHDEBINFO=$EXE_LINKER_FLAGS \ + -DCMAKE_EXE_LINKER_FLAGS_DEBUG=$EXE_LINKER_FLAGS \ + -DBUILD_SHARED_LIBS=OFF \ + -DLLVM_STATIC_LINK_CXX_STDLIB=ON \ + -DLLVM_ENABLE_ZLIB=ON \ + -DLLVM_BUILD_RUNTIME=ON \ + -DLLVM_INCLUDE_TOOLS=ON \ + -DLLVM_BUILD_TOOLS=ON \ + -DLLVM_INCLUDE_TESTS=ON \ + -DLLVM_BUILD_TESTS=ON \ + -DLLVM_INCLUDE_EXAMPLES=ON \ + -DLLVM_BUILD_EXAMPLES=OFF \ + -DCLANG_DEFAULT_PIE_ON_LINUX=ON \ + -DCLANG_ENABLE_ARCMT=ON \ + -DCLANG_ENABLE_STATIC_ANALYZER=ON \ + -DCLANG_PLUGIN_SUPPORT=ON \ + -DLLVM_DYLIB_COMPONENTS="all" \ + -DLLVM_ENABLE_PER_TARGET_RUNTIME_DIR=ON \ + -DCMAKE_SKIP_RPATH=ON \ + -DLLVM_ENABLE_FFI=ON \ + -DLLVM_ENABLE_RTTI=ON \ + -DLLVM_USE_PERF=ON \ + -DLLVM_INSTALL_GTEST=ON \ + -DLLVM_INCLUDE_UTILS=ON \ + -DLLVM_INSTALL_UTILS=ON \ + -DLLVM_INCLUDE_BENCHMARKS=OFF \ + -DENABLE_LINKER_BUILD_ID=ON \ + -DLLVM_ENABLE_EH=ON \ + -DCLANG_DEFAULT_UNWINDLIB=libgcc \ + -DLIBCXX_STATICALLY_LINK_ABI_IN_STATIC_LIBRARY=ON \ + -DLIBCXX_ENABLE_ABI_LINKER_SCRIPT=ON \ + -DLIBOMP_INSTALL_ALIASES=OFF \ + -DENABLE_ACPO=$enable_acpo \ + $llvm_binutils_incdir \ + $verbose \ + ../llvm + +make -j$threads +if [ $do_install == "1" ]; then + make -j$threads $verbose $install +fi + +# build libcxx/libcxxabi with the just-built clang/clang++ +c_compiler="$build_prefix/bin/clang" +cxx_compiler="$build_prefix/bin/clang++" +if pushd runtimes > /dev/null 2>&1; then + if [ ! -f "$build_prefix"/projects/libcxx/CMakeCache.txt ]; then + mkdir -p "$build_prefix/projects/libcxx" && cd "$build_prefix/projects/libcxx" + cmake -Wno-dev \ + -DCMAKE_BUILD_TYPE=$buildtype \ + -DCMAKE_INSTALL_PREFIX="$install_prefix" \ + -DCMAKE_C_COMPILER="$c_compiler" \ + -DCMAKE_CXX_COMPILER="$cxx_compiler" \ + -DLLVM_ENABLE_RUNTIMES="libcxx;libcxxabi" \ + -DLIBCXX_ENABLE_ASSERTIONS=OFF \ + -DLLVM_LIT_ARGS="-sv -j$threads" \ + -DBUILD_SHARED_LIBS=OFF \ + -DCMAKE_SKIP_RPATH=ON \ + $llvm_use_linker\ + -DLLVM_USE_SPLIT_DWARF=$split_dwarf \ + ../../../runtimes + else + cd "$build_prefix"/projects/libcxx + fi + install_libcxx=${install/\/strip/-strripped} + make -j$threads $verbose \ + ${install_libcxx/install/install-cxx} ${install_libcxx/install/install-cxxabi} ${install_libcxx/install/install-cxxabi-headers} + if [ -n "$unit_test" ]; then + make -j$threads $verbose ${unit_test/all/cxx} ${unit_test/all/cxxabi} + fi + popd > /dev/null 2>&1 +else + echo "$0: directory not found: libcxx" + exit 1 +fi + +if [ -n "$unit_test" ]; then + make -j$threads $verbose check-all +fi + +cd .. + +# When building official deliverables, minimize file permissions under the +# installation directory. +if [ "$install" = "install/strip" ]; then + find $install_prefix/bin/ -type f -exec strip {} \; + find $install_prefix -type f -exec chmod a-w {} \; +fi + +# In openEuler embedded building system, it need wrap llvm-readelf +# to replace binutils-readelf. +if [ -e "$install_prefix/bin/llvm-readobj" ]; then + ln -sf llvm-readobj $install_prefix/bin/llvm-readelf +fi + +echo "$0: SUCCESS" -- Gitee From 9e5461d1d7f75cfd05e2fb618fd42d801d5f064c Mon Sep 17 00:00:00 2001 From: cf_zhao Date: Sat, 13 Jan 2024 12:27:35 +0800 Subject: [PATCH 2/5] [test] Disable several cases which failed on Aarch64 platform --- compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp | 1 + compiler-rt/test/lsan/TestCases/malloc_zero.c | 1 + compiler-rt/test/lsan/TestCases/realloc_too_big.c | 1 + openmp/runtime/test/ompt/synchronization/masked.c | 1 + openmp/runtime/test/ompt/synchronization/master.c | 1 + 5 files changed, 5 insertions(+) diff --git a/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp b/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp index e2f59ea693c4..df8d721bcd60 100644 --- a/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp +++ b/compiler-rt/test/lsan/TestCases/Linux/log-path_test.cpp @@ -13,6 +13,7 @@ // RUN: cat %device_rundir/%t.log.* >> %t.log // RUN: %adb_shell 'cat %device_rundir/%t.log.*' >> %t.log // RUN: FileCheck %s --check-prefix=CHECK-ERROR < %t.log.* +// UNSUPPORTED: aarch64-target-arch #include #include diff --git a/compiler-rt/test/lsan/TestCases/malloc_zero.c b/compiler-rt/test/lsan/TestCases/malloc_zero.c index 5c8d1850a0f9..89c6f6f424c6 100644 --- a/compiler-rt/test/lsan/TestCases/malloc_zero.c +++ b/compiler-rt/test/lsan/TestCases/malloc_zero.c @@ -3,6 +3,7 @@ /// Fails when only leak sanitizer is enabled // UNSUPPORTED: arm-linux, armhf-linux +// UNSUPPORTED: aarch64-target-arch #include #include diff --git a/compiler-rt/test/lsan/TestCases/realloc_too_big.c b/compiler-rt/test/lsan/TestCases/realloc_too_big.c index bb1316024b5c..98cdfb6cd44b 100644 --- a/compiler-rt/test/lsan/TestCases/realloc_too_big.c +++ b/compiler-rt/test/lsan/TestCases/realloc_too_big.c @@ -3,6 +3,7 @@ /// Fails when only leak sanitizer is enabled // UNSUPPORTED: arm-linux, armhf-linux +// UNSUPPORTED: aarch64-target-arch #include #include diff --git a/openmp/runtime/test/ompt/synchronization/masked.c b/openmp/runtime/test/ompt/synchronization/masked.c index 3eb45d9592d8..d06061d61381 100644 --- a/openmp/runtime/test/ompt/synchronization/masked.c +++ b/openmp/runtime/test/ompt/synchronization/masked.c @@ -2,6 +2,7 @@ // REQUIRES: ompt // GCC generates code that does not call the runtime for the master construct // XFAIL: gcc +// UNSUPPORTED: aarch64-target-arch #include "callback.h" #include diff --git a/openmp/runtime/test/ompt/synchronization/master.c b/openmp/runtime/test/ompt/synchronization/master.c index 34ecc522b85f..16dd7cafca68 100644 --- a/openmp/runtime/test/ompt/synchronization/master.c +++ b/openmp/runtime/test/ompt/synchronization/master.c @@ -2,6 +2,7 @@ // REQUIRES: ompt // GCC generates code that does not call the runtime for the master construct // XFAIL: gcc +// UNSUPPORTED: aarch64-target-arch #define USE_PRIVATE_TOOL 1 #include "callback.h" -- Gitee From 9705077cdedaa636c8ec467a9b3a3ef1075e4984 Mon Sep 17 00:00:00 2001 From: Sebastian Pop Date: Sat, 18 Feb 2023 01:12:33 +0000 Subject: [PATCH 3/5] [Backport][BOLT] fix tests on arm64 The two tests were failing on arm64-linux with: BOLT-ERROR: invalid target 'x86-64'. Differential Revision: https://reviews.llvm.org/D144593 --- bolt/test/{ => X86}/pseudoprobe-decoding-inline.test | 2 +- bolt/test/{ => X86}/pseudoprobe-decoding-noinline.test | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) rename bolt/test/{ => X86}/pseudoprobe-decoding-inline.test (97%) rename bolt/test/{ => X86}/pseudoprobe-decoding-noinline.test (95%) diff --git a/bolt/test/pseudoprobe-decoding-inline.test b/bolt/test/X86/pseudoprobe-decoding-inline.test similarity index 97% rename from bolt/test/pseudoprobe-decoding-inline.test rename to bolt/test/X86/pseudoprobe-decoding-inline.test index fa8b3852a9c4..15e93b1630a6 100644 --- a/bolt/test/pseudoprobe-decoding-inline.test +++ b/bolt/test/X86/pseudoprobe-decoding-inline.test @@ -1,5 +1,5 @@ # REQUIRES: system-linux -# RUN: llvm-bolt %S/../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s +# RUN: llvm-bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/inline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s CHECK: Report of decoding input pseudo probe binaries diff --git a/bolt/test/pseudoprobe-decoding-noinline.test b/bolt/test/X86/pseudoprobe-decoding-noinline.test similarity index 95% rename from bolt/test/pseudoprobe-decoding-noinline.test rename to bolt/test/X86/pseudoprobe-decoding-noinline.test index 65e814126595..5dd6c2e25bcf 100644 --- a/bolt/test/pseudoprobe-decoding-noinline.test +++ b/bolt/test/X86/pseudoprobe-decoding-noinline.test @@ -1,5 +1,5 @@ # REQUIRES: system-linux -# RUN: llvm-bolt %S/../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s +# RUN: llvm-bolt %S/../../../llvm/test/tools/llvm-profgen/Inputs/noinline-cs-pseudoprobe.perfbin --print-pseudo-probes=all -o %t.bolt 2>&1 | FileCheck %s ;; Report of decoding input pseudo probe binaries -- Gitee From d9b7e525e0cc7f41f7d6a3db4613b707b0431a24 Mon Sep 17 00:00:00 2001 From: Amy Huang Date: Wed, 22 Mar 2023 15:55:18 -0700 Subject: [PATCH 4/5] [Backport] Add "REQUIRES: asserts" to test that uses --debug-only flag --- bolt/test/X86/section-end-sym.s | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bolt/test/X86/section-end-sym.s b/bolt/test/X86/section-end-sym.s index a9bca5604ec1..38517bf7e071 100644 --- a/bolt/test/X86/section-end-sym.s +++ b/bolt/test/X86/section-end-sym.s @@ -1,7 +1,7 @@ ## Check that BOLT doesn't consider end-of-section symbols (e.g., _etext) as ## functions. -# REQUIRES: system-linux +# REQUIRES: system-linux, asserts # RUN: llvm-mc -filetype=obj -triple x86_64-unknown-linux %s -o %t.o # RUN: ld.lld %t.o -o %t.exe -q -- Gitee From 8cae95e92b16515e39bd440a12033787925c1f0e Mon Sep 17 00:00:00 2001 From: Antoine Moynault Date: Fri, 14 Apr 2023 15:32:41 +0000 Subject: [PATCH 5/5] [Backport][fuzzer][test] Disable noasan-strncmp test for AArch64 This test fails on several aarch64 bots clang-aarch64-lld-2stage ( https://lab.llvm.org/buildbot/#/builders/185/builds/3525 ) clang-aarch64-full-2stage ( https://lab.llvm.org/buildbot/#/builders/179/builds/5904 ) clang-aarch64-sve-vla ( https://lab.llvm.org/buildbot/#/builders/197/builds/4519 ) Disable it while this is analyzed. Reviewed By: DavidSpickett Differential Revision: https://reviews.llvm.org/D148332 --- compiler-rt/test/fuzzer/noasan-strncmp.test | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/compiler-rt/test/fuzzer/noasan-strncmp.test b/compiler-rt/test/fuzzer/noasan-strncmp.test index 4cb3e11573a1..ba1309cd3fd3 100644 --- a/compiler-rt/test/fuzzer/noasan-strncmp.test +++ b/compiler-rt/test/fuzzer/noasan-strncmp.test @@ -1,4 +1,4 @@ -UNSUPPORTED: darwin, target={{.*(freebsd|windows).*}} +UNSUPPORTED: darwin, target={{.*(freebsd|windows).*}}, target=aarch64{{.*}} RUN: %cpp_compiler -fno-sanitize=address %S/StrncmpTest.cpp -o %t-NoAsanStrncmpTest RUN: not %run %t-NoAsanStrncmpTest -seed=2 -runs=10000000 2>&1 | FileCheck %s -- Gitee