From 17ca19ed4e8685326c43dbe95e4c16424c6d1186 Mon Sep 17 00:00:00 2001 From: Viktor Szakats Date: Wed, 11 Oct 2023 00:43:42 +0000 Subject: [PATCH] try manual musl gcc config on debian --- _build.sh | 34 ++++++++++++++-------------------- _ci-linux-debian.sh | 11 ++++++----- 2 files changed, 20 insertions(+), 25 deletions(-) diff --git a/_build.sh b/_build.sh index 7208b708b..59d9f8aa7 100755 --- a/_build.sh +++ b/_build.sh @@ -677,15 +677,6 @@ build_single_target() { if [ "${_CC}" = 'llvm' ]; then ccver="$("clang${_CCSUFFIX}" -dumpversion)" else - if [ "${_CRT}" = 'musl' ] && [ "${_HOST}" != 'mac' ] && [ "${_DISTRO}" != 'alpine' ]; then - # method 1 - # FIXME: Downside: supports the prefix-less gcc only. - # Migrate to the manual method for better control over this. - # Only for CC, not for binutils - _CCPREFIX='musl-' - _CCSUFFIX='' - fi - ccver="$("${_CCPREFIX}gcc${_CCSUFFIX}" -dumpversion)" if [ "${_CRT}" = 'ucrt' ]; then @@ -833,11 +824,7 @@ build_single_target() { fi export _LD - if [ "${_CCPREFIX}" = 'musl-' ]; then # Do not apply the Debian 'musl-' prefix to binutils - _BINUTILS_PREFIX='' - else - _BINUTILS_PREFIX="${_CCPREFIX}" - fi + _BINUTILS_PREFIX="${_CCPREFIX}" _BINUTILS_SUFFIX='' if [ "${_TOOLCHAIN}" = 'llvm-apple' ]; then _arch="${_machine}" @@ -988,11 +975,7 @@ build_single_target() { fi _CMAKE_GLOBAL="${_CMAKE_GLOBAL} -DCMAKE_C_COMPILER=${_CCPREFIX}gcc${_CCSUFFIX}" - if [ "${_CCPREFIX}" != 'musl-' ]; then - _CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=${_CCPREFIX}g++${_CCSUFFIX}" - else - _CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=g++" - fi + _CMAKE_CXX_GLOBAL="${_CMAKE_CXX_GLOBAL} -DCMAKE_CXX_COMPILER=${_CCPREFIX}g++${_CCSUFFIX}" _LD='ld' @@ -1142,6 +1125,17 @@ build_single_target() { fi fi + if [ "${_CC}" = 'gcc' ] && [ "${_CRT}" = 'musl' ] && [ "${_DISTRO}" = 'debian' ]; then + clangrtlib="$("${_CCPREFIX}gcc${_CCSUFFIX}" -print-libgcc-file-name)" # /usr/lib/gcc/aarch64-linux-gnu/10/libgcc.a + clangrsdir="$(dirname "${clangrtlib}")" # /usr/lib/gcc/aarch64-linux-gnu/10 + clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)" # delete 'lib' prefix + clangrtlib="${clangrtlib%.*}" # gcc + libprefix="/usr/lib/${_machine}-linux-musl" + _CFLAGS_GLOBAL="${_CFLAGS_GLOBAL} -nostdinc -isystem ${clangrsdir}/include -isystem /usr/include/${_machine}-linux-musl" + _LDFLAGS_GLOBAL="${_LDFLAGS_GLOBAL} -nostdlib -nodefaultlibs -nostartfiles -L${libprefix} ${libprefix}/crt1.o ${libprefix}/crti.o -L${clangrsdir} ${libprefix}/crtn.o" + _LIBS_GLOBAL="${_LIBS_GLOBAL} -lc -l${clangrtlib}" + fi + if [ "${_CCRT}" = 'clang-rt' ]; then if [ "${_TOOLCHAIN}" != 'llvm-apple' ]; then if [ "${_CRT}" = 'musl' ] && [ "${_DISTRO}" = 'debian' ]; then @@ -1149,7 +1143,7 @@ build_single_target() { clangrsdir="$("clang${_CCSUFFIX}" -print-resource-dir)" # /usr/lib/llvm-13/lib/clang/13.0.1 clangrtdir="$("clang${_CCSUFFIX}" -print-runtime-dir)" # /usr/lib/llvm-13/lib/clang/13.0.1/lib/linux clangrtlib="$("clang${_CCSUFFIX}" -print-libgcc-file-name -rtlib=compiler-rt)" # /usr/lib/llvm-13/lib/clang/13.0.1/lib/linux/libclang_rt.builtins-aarch64.a - clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)" + clangrtlib="$(basename "${clangrtlib}" | cut -c 4-)" # delete 'lib' prefix clangrtlib="${clangrtlib%.*}" # clang_rt.builtins-aarch64 libprefix="/usr/lib/${_machine}-linux-musl" _CFLAGS_GLOBAL="${_CFLAGS_GLOBAL} -nostdinc -isystem ${clangrsdir}/include -isystem /usr/include/${_machine}-linux-musl" diff --git a/_ci-linux-debian.sh b/_ci-linux-debian.sh index 8270451ac..0b39822e3 100755 --- a/_ci-linux-debian.sh +++ b/_ci-linux-debian.sh @@ -23,10 +23,14 @@ if [[ "${CW_CONFIG:-}" = *'win'* ]]; then extra="${extra} nasm" fi elif [[ "${CW_CONFIG:-}" = *'linux'* ]]; then + [ -n "${CW_GCCSUFFIX:-}" ] || CW_GCCSUFFIX='-13' extra="${extra} checksec" + if [[ "${CW_CONFIG:-}" = *'gcc'* ]]; then + extra="${extra} gcc${CW_GCCSUFFIX} g++${CW_GCCSUFFIX}" + export CW_CCSUFFIX="${CW_GCCSUFFIX}" + fi if [[ "${CW_CONFIG:-}" = *'musl'* ]]; then - extra="${extra} musl musl-dev musl-tools" - [[ "${CW_CONFIG:-}" = *'gcc'* ]] && extra="${extra} g++" + extra="${extra} musl musl-dev" # for openssl 'secure-memory' feature if [ "$(uname -m)" = 'aarch64' ]; then extra="${extra} linux-headers-arm64" @@ -34,10 +38,7 @@ elif [[ "${CW_CONFIG:-}" = *'linux'* ]]; then extra="${extra} linux-headers-amd64" fi else - [ -n "${CW_GCCSUFFIX:-}" ] || CW_GCCSUFFIX='-13' if [[ "${CW_CONFIG:-}" = *'gcc'* ]]; then - extra="${extra} gcc${CW_GCCSUFFIX} g++${CW_GCCSUFFIX}" - export CW_CCSUFFIX="${CW_GCCSUFFIX}" if [ "$(uname -m)" = 'aarch64' ]; then extra="${extra} gcc${CW_GCCSUFFIX}-x86-64-linux-gnu g++${CW_GCCSUFFIX}-x86-64-linux-gnu" else