From faae6f0bbd4d83389b1063786a2b79250cd1d095 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Tue, 31 Oct 2023 14:23:17 +0000 Subject: [PATCH] add linux cross llvm clang-rt support 1 --- _build.sh | 32 +++++++++++++++++++++++++------- _ci-linux-debian.sh | 38 +++++++++++++++++++------------------- 2 files changed, 44 insertions(+), 26 deletions(-) diff --git a/_build.sh b/_build.sh index 723a1da0a..9e0ffbcae 100755 --- a/_build.sh +++ b/_build.sh @@ -87,7 +87,6 @@ set -o xtrace -o errexit -o nounset; [ -n "${BASH:-}${ZSH_NAME:-}" ] && set -o p # https://developer.apple.com/forums/thread/715385 # - linux: musl alpine why need -static-pie and not -static? # - linux: musl libcurl.so.4.8.0 tweak to be also portable (possible?) -# - linux: cross non-musl builds to use libclang_rt (instead of libgcc). # - merge _ci-*.sh scripts into one. # - FIXME: curl-autotools: .map file support and clang builds broken. # - win: Drop x86 builds. @@ -829,14 +828,18 @@ build_single_target() { [ "${_CPU}" = 'x86' ] && _CFLAGS_GLOBAL="${_CFLAGS_GLOBAL} -fno-asynchronous-unwind-tables" _CCRT='libgcc' # compiler runtime, 'libgcc' (for libgcc and libstdc++) or 'clang-rt' (for compiler-rt and libc++) - # Debian does not support clang-rt for cross-builds easily, - # it requires manually installing package `libclang-rt-16-dev` or `libclang-common-15-dev`. - if [ "${_CC}" = 'llvm' ] && [ "${_CRT}" = 'musl' ]; then - _CCRT='clang-rt' - elif [ "${_TOOLCHAIN}" = 'llvm-apple' ] || \ - [ "${_TOOLCHAIN}" = 'llvm-mingw' ]; then + if [ "${_TOOLCHAIN}" = 'llvm-apple' ] || \ + [ "${_TOOLCHAIN}" = 'llvm-mingw' ]; then # Not an option _CCRT='clang-rt' + elif [ "${_CC}" = 'llvm' ]; then + if [ "${_DISTRO}" = 'alpine' ]; then + _CCRT='clang-rt' + # Debian does not support clang-rt for cross-builds easily, + # it requires manually installing package `libclang-rt-16-dev` or `libclang-common-15-dev`. + elif [ "${_DISTRO}" = 'debian' ] && [ -d 'my-pkg/usr/lib/clang' ]; then + _CCRT='clang-rt' + fi fi export _LD @@ -1230,6 +1233,21 @@ build_single_target() { _LDFLAGS_GLOBAL="${_LDFLAGS_GLOBAL} -nostdlib -nodefaultlibs -nostartfiles -L${libprefix} ${libprefix}/crt1.o ${libprefix}/crti.o -L${ccrtdir} ${libprefix}/crtn.o" _LIBS_GLOBAL="${_LIBS_GLOBAL} -lc ${ccrtlib}" else + if [ "${_DISTRO}" = 'debian' ] && [ "${unamem}" != "${_machine}" ] && [ -d 'my-pkg/usr/lib/clang' ]; then + # If we have the target CPU's clang-rt package installed, use it: + ccrtdir="$(find -L \ + "$(pwd)/my-pkg/usr/lib/clang" -mindepth 1 -maxdepth 1 -type d | sort | tail -n 1)" # ./my-pkg/usr/lib/clang/15/lib/linux + if [ -z "${ccrtdir}" ]; then + >&2 echo '! Error: Failed to detect cross-clang-rt env root.' + exit 1 + fi + ccrtdir="${ccrtdir}/lib/linux" + ccrtlib="${ccrtdir}/libclang_rt.builtins-${_machine}.a" + ccrtlib="$(basename "${ccrtlib}" | cut -c 4-)" # delete 'lib' prefix + ccrtlib="-l${ccrtlib%.*}" # clang_rt.builtins-aarch64 or gcc + _LDFLAGS_GLOBAL="${_LDFLAGS_GLOBAL} -nodefaultlibs -L${ccrtdir}" + _LIBS_GLOBAL="${_LIBS_GLOBAL} -lc ${ccrtlib}" + fi _LDFLAGS_GLOBAL="${_LDFLAGS_GLOBAL} -rtlib=compiler-rt" # `-Wc,...` is necessary for libtool to pass this option to the compiler # at link-time. Otherwise libtool strips it. diff --git a/_ci-linux-debian.sh b/_ci-linux-debian.sh index 33b3242e0..579ae4bfb 100755 --- a/_ci-linux-debian.sh +++ b/_ci-linux-debian.sh @@ -29,6 +29,25 @@ elif [[ "${CW_CONFIG:-}" = *'linux'* ]]; then if [[ "${CW_CONFIG:-}" = *'gcc'* ]]; then extra="${extra} gcc${CW_GCCSUFFIX} g++${CW_GCCSUFFIX}" export CW_CCSUFFIX="${CW_GCCSUFFIX}" + else + # These packages do not install due to dependency requirements. + # We download unpack them manually as a workaround. + if [ "${CW_CCSUFFIX}" = '-15' ]; then + # ./my-pkg/usr/lib/clang/15/lib + # ./my-pkg/usr/lib/llvm-15/lib/clang/15.0.6/lib/linux/libclang_rt.builtins-aarch64.a + if [ "$(uname -m)" = 'aarch64' ]; then + dl="${dl} libclang-common${CW_CCSUFFIX}-dev:amd64" + else + dl="${dl} libclang-common${CW_CCSUFFIX}-dev:arm64" + fi + else + # ./my-pkg/usr/lib/llvm-16/lib/clang/16/lib/linux/libclang_rt.builtins-aarch64.a + if [ "$(uname -m)" = 'aarch64' ]; then + dl="${dl} libclang-rt${CW_CCSUFFIX}-dev:amd64" + else + dl="${dl} libclang-rt${CW_CCSUFFIX}-dev:arm64" + fi + fi fi if [[ "${CW_CONFIG:-}" = *'musl'* ]]; then extra="${extra} musl musl-dev" @@ -46,25 +65,6 @@ elif [[ "${CW_CONFIG:-}" = *'linux'* ]]; then else extra="${extra} g++${CW_GCCSUFFIX}-aarch64-linux-gnu" fi - else - # These packages do not install due to dependency requirements. - # We download unpack them manually as a workaround. - if [ "${CW_CCSUFFIX}" = '-15' ]; then - # ./my-pkg/usr/lib/clang/15/lib - # ./my-pkg/usr/lib/llvm-15/lib/clang/15.0.6/lib/linux/libclang_rt.builtins-aarch64.a - if [ "$(uname -m)" = 'aarch64' ]; then - dl="${dl} libclang-common${CW_CCSUFFIX}-dev:amd64" - else - dl="${dl} libclang-common${CW_CCSUFFIX}-dev:arm64" - fi - else - # ./my-pkg/usr/lib/llvm-16/lib/clang/16/lib/linux/libclang_rt.builtins-aarch64.a - if [ "$(uname -m)" = 'aarch64' ]; then - dl="${dl} libclang-rt${CW_CCSUFFIX}-dev:amd64" - else - dl="${dl} libclang-rt${CW_CCSUFFIX}-dev:arm64" - fi - fi fi # for openssl 'secure-memory' feature if [ "$(uname -m)" = 'aarch64' ]; then