diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index bf840056..9ce41d56 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -35,14 +35,6 @@ jobs: fail-fast: false matrix: include: - - - image: alpine:3.13 - typ: alpine - allow-failure: false - - - image: alpine:3.14 - typ: alpine - allow-failure: false - image: alpine:3.15 typ: alpine @@ -59,6 +51,10 @@ jobs: image: alpine:3.18 typ: alpine allow-failure: false + - + image: alpine:3.19 + typ: alpine + allow-failure: false - image: alpine:edge typ: alpine @@ -75,6 +71,14 @@ jobs: image: debian:bookworm typ: debian allow-failure: false + - + image: debian:bookworm-backports + typ: debian + allow-failure: false + - + image: debian:trixie + typ: debian + allow-failure: false - image: debian:sid typ: debian @@ -87,6 +91,14 @@ jobs: image: ubuntu:22.04 typ: debian allow-failure: false + - + image: ubuntu:23.04 + typ: debian + allow-failure: false + - + image: ubuntu:24.04 + typ: debian + allow-failure: false - image: redhat/ubi8 typ: rhel @@ -99,6 +111,10 @@ jobs: image: fedora:38 typ: rhel allow-failure: false + - + image: fedora:39 + typ: rhel + allow-failure: false - image: centos:7 typ: rhel diff --git a/.github/workflows/ld.yml b/.github/workflows/ld.yml index b1ba4d9a..f8f0c858 100644 --- a/.github/workflows/ld.yml +++ b/.github/workflows/ld.yml @@ -77,33 +77,8 @@ jobs: *.cache-from=type=gha,scope=${{ matrix.target }} *.cache-to=type=gha,scope=${{ matrix.target }} - ld64-targets: - runs-on: ubuntu-latest - outputs: - matrix: ${{ steps.targets.outputs.matrix }} - steps: - - - name: Checkout - uses: actions/checkout@v3 - - - name: Create targets matrix - id: targets - run: | - matrix=$(docker buildx bake ld64-static-tgz --print | jq -cr '.group."ld64-static-tgz".targets') - echo "matrix=${matrix}" >> ${GITHUB_OUTPUT} - - - name: Show matrix - run: | - echo ${{ steps.targets.outputs.matrix }} - ld64: runs-on: ubuntu-latest - needs: - - ld64-targets - strategy: - fail-fast: false - matrix: - target: ${{ fromJson(needs.ld64-targets.outputs.matrix) }} steps: - name: Checkout @@ -120,11 +95,11 @@ jobs: name: Build uses: docker/bake-action@v2 with: - targets: ${{ matrix.target }} + targets: ld64-static-tgz set: | - *.cache-from=type=gha,scope=${{ matrix.target }} - *.cache-to=type=gha,scope=${{ matrix.target }} - *.output=type=local,dest=./dist,platform-split=false + ld64-static-tgz.cache-from=type=gha,scope=ld64-static-tgz + ld64-static-tgz.cache-to=type=gha,scope=ld64-static-tgz + ld64-static-tgz.output=type=local,dest=./dist,platform-split=false - name: List artifacts run: | @@ -201,6 +176,52 @@ jobs: if-no-files-found: error retention-days: 1 + utils-lipo: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + driver-opts: image=${{ env.BUILDKIT_IMAGE }} + - + name: Build + uses: docker/bake-action@v2 + with: + targets: lipo + set: | + lipo.cache-from=type=gha,scope=lipo + lipo.cache-to=type=gha,scope=lipo + + utils-sigtool: + runs-on: ubuntu-latest + steps: + - + name: Checkout + uses: actions/checkout@v3 + - + name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - + name: Set up Docker Buildx + uses: docker/setup-buildx-action@v2 + with: + driver-opts: image=${{ env.BUILDKIT_IMAGE }} + - + name: Build + uses: docker/bake-action@v2 + with: + targets: sigtool + set: | + sigtool.cache-from=type=gha,scope=sigtool + sigtool.cache-to=type=gha,scope=sigtool + release: runs-on: ubuntu-latest if: ${{ inputs.release }} diff --git a/docker-bake.hcl b/docker-bake.hcl index c6d40c0f..5914e79b 100644 --- a/docker-bake.hcl +++ b/docker-bake.hcl @@ -14,6 +14,8 @@ variable "DEV_SDK_PLATFORM" { default = null } +variable "DEV_WITH_LD64" {} + // Special target: https://github.com/docker/metadata-action#bake-definition target "meta-helper" { tags = ["${XX_REPO}:test"] @@ -135,7 +137,8 @@ target "_all-platforms" { "linux/mips64le", "linux/ppc64le", "linux/s390x", - "linux/riscv64" + "linux/riscv64", + "linux/loong64" ] } @@ -169,6 +172,7 @@ target "sdk-extras" { "linux/mips64le", "linux/ppc64le", "linux/riscv64", + "linux/loong64", "linux/s390x", "windows/386", "windows/amd64", @@ -236,32 +240,21 @@ target "binutils" { tags = binutilsTag(XX_REPO, BINUTILS_VERSION, BINUTILS_VERSION_ONLY, tgt) } -target "ld64-static-tgz" { - name = "ld64-${tgt}-static-tgz" +target "ld64" { inherits = ["_ld-base"] - matrix = { - tgt = [ - "linux-386", - "linux-amd64", - "linux-arm64", - "linux-armv6", - "linux-armv7" - ] - } - target = "ld64-static-tgz" - args = { - LD_TARGET = tgt - } + target = "ld64-signed-static" +} + +target "ld64-static-tgz" { + inherits = ["ld64"] platforms = [ "linux/386", "linux/amd64", "linux/arm64", - "linux/arm/v6", - "linux/arm/v7" + "linux/arm/v7", ] - cache-from = [join("", ["type=registry,ref=", binutilsTag(XX_REPO, BINUTILS_VERSION, "1", tgt)[0]])] - cache-to = ["type=inline"] output = ["./bin/ld-static-tgz"] + target = "ld64-static-tgz" } target "ld-static-tgz" { @@ -330,6 +323,7 @@ target "dev" { contexts = { "tonistiigi/xx" = "target:xx" "sdk-extras" = DEV_SDK_PLATFORM != null ? "target:sdk-extras-dev" : "docker-image://scratch" + "ld64" = DEV_WITH_LD64 != "" ? "target:ld64" : "docker-image://scratch" } args = { TEST_BASE_TYPE = TEST_BASE_TYPE @@ -339,4 +333,30 @@ target "dev" { output = [ "type=docker" ] +} + +target "lipo" { + context = "src/ld" + target = "lipo-static" + contexts = { + "tonistiigi/xx" = "target:xx" + } + platforms = [ + "linux/amd64", + "linux/arm64", + "linux/arm/v7", + ] +} + +target "sigtool" { + context = "src/ld" + target = "sigtool-static" + contexts = { + "tonistiigi/xx" = "target:xx" + } + platforms = [ + "linux/amd64", + "linux/arm64", + "linux/arm/v7", + ] } \ No newline at end of file diff --git a/src/Dockerfile b/src/Dockerfile index d3cf5135..40f425e4 100644 --- a/src/Dockerfile +++ b/src/Dockerfile @@ -97,11 +97,14 @@ COPY test-cargo.bats test_helper.bash ./ RUN --mount=type=cache,target=/pkg-cache,sharing=locked ./test-cargo.bats +# these targets can be overwritten with build contexts FROM scratch AS sdk-extras +FROM scratch AS ld64 # dev can be used for debugging during development FROM test-base AS dev COPY --link --from=sdk-extras / / +COPY --link --from=ld64 / /usr/bin/ COPY --link --from=xx / / COPY fixtures fixtures COPY *.bats test_helper.bash ./ diff --git a/src/ld/Dockerfile b/src/ld/Dockerfile index f410ec4b..16b87dc2 100644 --- a/src/ld/Dockerfile +++ b/src/ld/Dockerfile @@ -1,25 +1,25 @@ #syntax=docker/dockerfile:1.5 -ARG ALPINE_VERSION=3.18 -ARG LIBTAPI_VERSION=1100.0.11 -ARG CCTOOLS_VERSION=949.0.1-ld64-530 -ARG SIGTOOL_VERSION=1dafd2ca4651210ba9acce10d279ace22b50fb01 -# BINUTILS_PATCHES_VERSION defines version of aports to use for patches -ARG BINUTILS_PATCHES_VERSION=master +ARG ALPINE_VERSION=3.19 +ARG LIBTAPI_VERSION=1300.6.5 +ARG CCTOOLS_VERSION=1009.2-ld64-907 +ARG SIGTOOL_VERSION=c6242cb29c412168f771e97d75417e55af6cdb2e +ARG LIBDISPATCH_VERSION=swift-5.9.2-RELEASE +ARG APORTS_VERSION=3.19-stable ARG BINUTILS_VERSION=2.41 FROM --platform=$BUILDPLATFORM tonistiigi/xx AS xx FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS libtapi-base RUN apk add --no-cache git clang lld cmake make python3 bash -COPY --from=xx / / +COPY --link --from=xx / / ARG LIBTAPI_VERSION RUN git clone https://github.com/tpoechtrager/apple-libtapi --depth 1 -b ${LIBTAPI_VERSION} WORKDIR ./apple-libtapi RUN --mount=target=/tmp/libtapi-cmake-args.patch,source=libtapi-cmake-args.patch \ git apply /tmp/libtapi-cmake-args.patch RUN apk add --no-cache gcc g++ -RUN NOMAKE=1 CMAKE_EXTRA_ARGS="$(xx-clang --print-cmake-defines)" ./build.sh && \ +RUN NOMAKE=1 CMAKE_EXTRA_ARGS="$(xx-clang --print-cmake-defines) -DCMAKE_CXX_FLAGS=-D_LARGEFILE64_SOURCE" ./build.sh && \ cd build && \ make -j $(nproc) clang-tblgen llvm-tblgen && \ cp -a bin/clang-tblgen bin/llvm-tblgen /usr/bin/ && \ @@ -29,7 +29,7 @@ FROM libtapi-base AS libtapi ARG TARGETPLATFORM RUN xx-apk add g++ RUN INSTALLPREFIX=/opt/libtapi/ \ - CMAKE_EXTRA_ARGS="-DCLANG_TABLEGEN_EXE=/usr/bin/clang-tblgen -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/clang-tblgen $(xx-clang --print-cmake-defines)" \ + CMAKE_EXTRA_ARGS="-DCLANG_TABLEGEN_EXE=/usr/bin/clang-tblgen -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/clang-tblgen -DCMAKE_CXX_FLAGS=-D_LARGEFILE64_SOURCE $(xx-clang --print-cmake-defines)" \ ./build.sh && ./install.sh && \ xx-verify /opt/libtapi/lib/libtapi.so && \ rm -rf build @@ -38,21 +38,58 @@ FROM libtapi-base AS libtapi-static ARG TARGETPLATFORM RUN xx-apk add g++ RUN export INSTALLPREFIX=/opt/libtapi/ \ - CMAKE_EXTRA_ARGS="-DCLANG_TABLEGEN_EXE=/usr/bin/clang-tblgen -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/clang-tblgen $(xx-clang --print-cmake-defines)" \ - && sed -i s/SHARED/STATIC/g src/llvm/projects/libtapi/tools/libtapi/CMakeLists.txt && \ - ./build.sh && cd build && make -j $(nproc) LLVMObject tapiCore LLVMSupport LLVMDemangle LLVMMC LLVMBinaryFormat install-tapi-headers && mkdir /opt/libtapi/lib && cp -a ./lib/*.a /opt/libtapi/lib/ && \ + CMAKE_EXTRA_ARGS="-DCLANG_TABLEGEN_EXE=/usr/bin/clang-tblgen -DLLVM_TABLEGEN=/usr/bin/llvm-tblgen -DCLANG_TABLEGEN=/usr/bin/clang-tblgen -DCMAKE_CXX_FLAGS=-D_LARGEFILE64_SOURCE $(xx-clang --print-cmake-defines)" \ + && sed -i s/SHARED/STATIC/g src/tapi/tools/libtapi/CMakeLists.txt && \ + ./build.sh && cd build && make -j $(nproc) LLVMObject tapiCore LLVMSupport LLVMDemangle LLVMMC LLVMBinaryFormat tapiObjCMetadata tapiNoInits LLVMTextAPI install-tapi-headers && \ + mkdir /opt/libtapi/lib && cp -a ./lib/*.a /opt/libtapi/lib/ && \ cd .. && rm -rf build +FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS aports +RUN apk add git +WORKDIR /work +ARG APORTS_VERSION +RUN git clone --depth 1 -b ${APORTS_VERSION} https://github.com/alpinelinux/aports.git + +FROM scratch AS patches-binutils +COPY --from=aports /work/aports/main/binutils/*.patch / + +FROM scratch AS patches-libdispatch +COPY --from=aports /work/aports/community/libdispatch/*.patch / + +# libdispatch is needed because alpine does not provide static library in apk +FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS libdispatch-base +RUN apk add git clang lld cmake samurai patch +ARG LIBDISPATCH_VERSION +COPY --link --from=xx / / +RUN --mount=target=/patches,from=patches-libdispatch \ + git clone -b ${LIBDISPATCH_VERSION} --depth 1 https://github.com/apple/swift-corelibs-libdispatch.git && \ + cd swift-corelibs-libdispatch && \ + for f in /patches/*; do patch -p1 < $f; done +WORKDIR ./swift-corelibs-libdispatch +ARG TARGETPLATFORM +RUN xx-apk add --no-cache gcc g++ musl-dev linux-headers bsd-compat-headers +RUN cmake $(xx-clang --print-cmake-defines) -G Ninja -B build -DCMAKE_INSTALL_PREFIX=/out/libdispatch -DCMAKE_INSTALL_LIBDIR=lib -DBUILD_SHARED_LIBS=False -DCMAKE_BUILD_TYPE=MinSizeRel && \ + cmake --build build && \ + cmake --install build && \ + rm -rf build +RUN ls -l /out/libdispatch/lib && \ + [ -f /out/libdispatch/lib/libdispatch.a ] && [ -f /out/libdispatch/lib/libBlocksRuntime.a ] + +FROM scratch AS libdispatch +COPY --from=libdispatch-base /out/libdispatch/lib/*.a /lib/ + FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS cctools-base -RUN apk add --no-cache git clang lld make llvm -COPY --from=xx / / +RUN apk add --no-cache git clang lld make llvm llvm-dev libdispatch-dev +COPY --link --from=xx / / WORKDIR /work ARG CCTOOLS_REPO=https://github.com/tpoechtrager/cctools-port ARG CCTOOLS_VERSION RUN git clone $CCTOOLS_REPO -b ${CCTOOLS_VERSION} WORKDIR ./cctools-port/cctools ARG TARGETPLATFORM -RUN xx-apk add --no-cache musl-dev gcc g++ +RUN --mount=target=/libdispatch,from=libdispatch \ + xx-apk add --no-cache musl-dev gcc g++ libdispatch-dev && \ + cp -a /libdispatch/. $(xx-clang --print-sysroot)usr/ FROM cctools-base AS lipo-base ARG LIPO_CFLAGS="-Wl,-s -Os" @@ -64,25 +101,15 @@ RUN export CFLAGS=${LIPO_CFLAGS} && \ FROM scratch AS lipo-static COPY --from=lipo-base /work/cctools-port/cctools/misc/lipo / -FROM cctools-base AS codesign-base +FROM cctools-base AS codesign-allocate-base ARG CODESIGN_CFLAGS="-Wl,-s -Os" RUN export CFLAGS=${CODESIGN_CFLAGS} && \ ./configure --host=$(xx-clang --print-target-triple) LDFLAGS=--static && \ make -C libmacho && make -C libstuff && make -C misc codesign_allocate && \ xx-verify --static misc/codesign_allocate -FROM scratch AS codesign-static -COPY --from=codesign-base /work/cctools-port/cctools/misc/codesign_allocate / - -FROM cctools-base AS otool-base -ARG OTOOL_CFLAGS="-Wl,-s -Os" -RUN export CFLAGS=${OTOOL_CFLAGS} && \ - ./configure --host=$(xx-clang --print-target-triple) LDFLAGS=--static && \ - make -C libstuff && make -C libobjc2 && make -C otool && \ - xx-verify --static otool/otool - -FROM scratch AS otool-static -COPY --from=otool-base /work/cctools-port/cctools/otool/otool / +FROM scratch AS codesign-allocate-static +COPY --from=codesign-allocate-base /work/cctools-port/cctools/misc/codesign_allocate / FROM cctools-base AS ld64-static-base # for LTO @@ -90,16 +117,44 @@ RUN apk add llvm-dev ARG LD64_CXXFLAGS="-Wl,-s -Os" RUN --mount=from=libtapi-static,source=/opt/libtapi,target=/opt/libtapi \ export CXXFLAGS=${LD64_CXXFLAGS} && ./configure --with-libtapi=/opt/libtapi --host=$(xx-clang --print-target-triple) &&\ - sed -i 's/-ltapi/-ltapi -ltapiCore -lLLVMObject -lLLVMSupport -lLLVMDemangle -lLLVMMC -lLLVMBinaryFormat --static/' ld64/src/ld/Makefile && \ + sed -i 's/-ltapi/-ltapi -ltapiCore -ltapiObjCMetadata -lLLVMObject -lLLVMTextAPI -lLLVMSupport -lLLVMDemangle -lLLVMMC -lLLVMBinaryFormat --static/' ld64/src/ld/Makefile && \ make -j $(nproc) -C ld64 && \ xx-verify --static ld64/src/ld/ld +FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS sigtool-base +RUN apk add --no-cache git clang lld cmake make pkgconf +COPY --from=xx / / +WORKDIR /work +ARG SIGTOOL_VERSION +RUN git clone https://github.com/thefloweringash/sigtool && \ + cd sigtool && \ + git checkout ${SIGTOOL_VERSION} +WORKDIR ./sigtool +RUN --mount=target=/tmp/sigtool-static.patch,source=sigtool-static.patch \ + git apply /tmp/sigtool-static.patch +ARG TARGETPLATFORM +RUN xx-apk add --no-cache g++ openssl-dev openssl-libs-static +ARG SIGTOOL_CXXFLAGS="-Wl,-s -Os" +RUN export CXXFLAGS=${SIGTOOL_CXXFLAGS} && \ + mkdir build && cd build && \ + cmake -DBUILD_SHARED_LIBS=False $(xx-clang --print-cmake-defines) -DCMAKE_EXE_LINKER_FLAGS=-static .. && \ + make -j $(nproc) && \ + xx-verify --static ./sigtool ./codesign + +FROM scratch AS sigtool-static +COPY --link --from=codesign-allocate-static / / +COPY --link --from=sigtool-base /work/sigtool/build/sigtool / + +FROM scratch AS codesign-static +COPY --link --from=codesign-allocate-static / / +COPY --link --from=sigtool-base /work/sigtool/build/codesign / + FROM scratch AS ld64-static COPY --from=ld64-static-base /work/cctools-port/cctools/ld64/src/ld/ld /ld64 FROM scratch AS ld64-signed-static -COPY --from=ld64-static / / -COPY --from=sigtool / / +COPY --link --from=ld64-static / / +COPY --link --from=codesign-static / / COPY ld64.signed / FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS ld64-tgz-build @@ -125,47 +180,15 @@ RUN --mount=from=libtapi,source=/opt/libtapi,target=/opt/libtapi \ xx-verify /opt/cctools/bin/ld FROM scratch AS cctools -COPY --from=libtapi /opt/libtapi/lib/*.so /usr/lib/ -COPY --from=cctools-build /opt/cctools /usr - -FROM --platform=${BUILDPLATFORM} alpine:${ALPINE_VERSION} AS sigtool-base -RUN apk add --no-cache git clang lld cmake make pkgconf -COPY --from=xx / / -WORKDIR /work -RUN git clone https://github.com/CLIUtils/CLI11 && \ - cd CLI11 && \ - cp -a include/CLI /usr/include/ && \ - cd .. && rm -rf CLI11 -ARG SIGTOOL_VERSION -RUN git clone https://github.com/thefloweringash/sigtool && \ - cd sigtool && \ - git checkout ${SIGTOOL_VERSION} -WORKDIR ./sigtool -RUN --mount=target=/tmp/sigtool-static.patch,source=sigtool-static.patch \ - git apply /tmp/sigtool-static.patch -ARG TARGETPLATFORM -RUN xx-apk add --no-cache g++ openssl-dev openssl-libs-static -ARG SIGTOOL_CXXFLAGS="-Wl,-s -Os" -RUN if xx-info is-cross; then cp -a /usr/include/CLI /$(xx-info triple)/usr/include/; fi && \ - export CXXFLAGS=${SIGTOOL_CXXFLAGS} && \ - mkdir build && cd build && \ - cmake $(xx-clang --print-cmake-defines) -DCMAKE_EXE_LINKER_FLAGS=-static .. && \ - make -j $(nproc) && \ - xx-verify --static ./gensig +COPY --link --from=libtapi /opt/libtapi/lib/*.so /usr/lib/ +COPY --link --from=cctools-build /opt/cctools /usr -FROM scratch AS sigtool -COPY --from=codesign-static / / -COPY --from=sigtool-base /work/sigtool/build/gensig /sigtool-gensig FROM --platform=$BUILDPLATFORM alpine:${ALPINE_VERSION} AS binutils-base0 RUN apk add --no-cache file git clang lld linux-headers zlib-dev zstd-dev gcc patch make musl-dev musl-libintl bison flex texinfo WORKDIR /work -ARG BINUTILS_PATCHES_VERSION -RUN git clone --depth 1 -b ${BINUTILS_PATCHES_VERSION} https://github.com/alpinelinux/aports.git && \ - mkdir patches && \ - cp -a aports/main/binutils/*.patch patches/ && \ - rm -rf aports -COPY --from=xx / / +COPY --link --from=xx / / +COPY --link --from=patches-binutils / patches/ ARG BINUTILS_VERSION RUN wget https://ftp.gnu.org/gnu/binutils/binutils-${BINUTILS_VERSION}.tar.gz ARG TARGETPLATFORM diff --git a/src/ld/ld64.signed b/src/ld/ld64.signed index 1e2b7fcb..485a1103 100755 --- a/src/ld/ld64.signed +++ b/src/ld/ld64.signed @@ -2,19 +2,7 @@ set -e -signDarwinBinary() { - local path="$1" - local sigsize arch - - arch=$(sigtool-gensig --file "$path" show-arch) - - sigsize=$(sigtool-gensig --file "$path" size) - sigsize=$(( ((sigsize + 15) / 16) * 16 + 1024 )) - - codesign_allocate -i "$path" -a "$arch" "$sigsize" -o "$path.unsigned" - sigtool-gensig --identifier "$(basename "$path")" --file "$path.unsigned" inject - mv -f "$path.unsigned" "$path" -} +ld64 "$@" out="a.out" isout= @@ -29,6 +17,4 @@ for f in "$@"; do fi done -ld64 "$@" - -signDarwinBinary "$out" \ No newline at end of file +codesign -f -s - "$out" \ No newline at end of file diff --git a/src/ld/libtapi-cmake-args.patch b/src/ld/libtapi-cmake-args.patch index 71f92f61..cd4c8dad 100644 --- a/src/ld/libtapi-cmake-args.patch +++ b/src/ld/libtapi-cmake-args.patch @@ -1,17 +1,17 @@ diff --git a/build.sh b/build.sh -index 37588d1..788dc60 100755 +index 2ceb4c189..f16bca00d 100755 --- a/build.sh +++ b/build.sh -@@ -13,7 +13,7 @@ mkdir build +@@ -35,7 +35,7 @@ mkdir build pushd build &>/dev/null -CMAKE_EXTRA_ARGS="" +: ${CMAKE_EXTRA_ARGS} - if [ $OPERATING_SYSTEM == "Android" ]; then + if [ "$OPERATING_SYSTEM" = "Android" ]; then export CC="$CC -D__ANDROID_API__=26" -@@ -68,6 +68,8 @@ cmake ../src/llvm \ +@@ -64,6 +64,8 @@ cmake -G "$cmakegen" ../src/llvm \ -DTAPI_FULL_VERSION=$TAPI_VERSION \ $CMAKE_EXTRA_ARGS @@ -20,11 +20,12 @@ index 37588d1..788dc60 100755 echo "" echo "## Building clangBasic ##" echo "" -@@ -80,5 +82,7 @@ echo "" +@@ -76,6 +78,8 @@ echo "" $MAKE libtapi -j $JOBS +fi + - popd &>/dev/null - popd &>/dev/null + if [ -n "$BUILD_TAPI_TOOLS" ]; then + echo "" + echo "## Building tapi tools ##" diff --git a/src/ld/sigtool-static.patch b/src/ld/sigtool-static.patch index 6a657373..ed0536c7 100644 --- a/src/ld/sigtool-static.patch +++ b/src/ld/sigtool-static.patch @@ -1,25 +1,14 @@ diff --git a/CMakeLists.txt b/CMakeLists.txt -index 0e41f27..d89de6c 100644 +index 16024ad..77f77b4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt -@@ -17,7 +17,7 @@ set(CMAKE_CXX_STANDARD 11) - add_executable(gensig main.cpp macho.cpp signature.cpp hash.cpp) - target_link_libraries(gensig - PRIVATE -- PkgConfig::OPENSSL -+ ${OPENSSL_STATIC_LDFLAGS} - #CLI11:CLI11 - ) - -diff --git a/main.cpp b/main.cpp -index 515428f..3b82dbf 100644 ---- a/main.cpp -+++ b/main.cpp -@@ -4,6 +4,7 @@ - #include "hash.h" - #include "signature.h" - #include "macho.h" -+#include - - #include - #include +@@ -7,6 +7,9 @@ IF(CMAKE_BUILD_TYPE STREQUAL "Debug") + set(CMAKE_CXX_FLAGS "-g") + ENDIF() + ++if(NOT BUILD_SHARED_LIBS) ++ set(OPENSSL_USE_STATIC_LIBS TRUE) ++endif() + find_package(OpenSSL REQUIRED) + + set(CMAKE_CXX_STANDARD 11) diff --git a/src/test-cargo.bats b/src/test-cargo.bats index 9244cea5..24f85877 100755 --- a/src/test-cargo.bats +++ b/src/test-cargo.bats @@ -91,6 +91,10 @@ testHelloCargoRustup() { testHelloCargoRustup } +@test "loong64-hellocargo-rustup" { + skip "LOONG64 not supported" # rust stdlib package not available +} + @test "386-hellocargo-rustup" { export TARGETARCH=386 testHelloCargoRustup @@ -143,6 +147,10 @@ testHelloCargoRustup() { testHelloCargo } +@test "loong64-hellocargo-rustpkg" { + skip "LOONG64 not supported" # rust stdlib package not available +} + @test "386-hellocargo-rustpkg" { export TARGETARCH=386 testHelloCargo diff --git a/src/test-clang.bats b/src/test-clang.bats index 6a7efdbd..a2b14f0d 100755 --- a/src/test-clang.bats +++ b/src/test-clang.bats @@ -14,7 +14,11 @@ clean() { testHelloCLLD() { clean - add clang lld + if [ "$(xx-info arch)" = "loong64" ]; then + add clang binutils + else + add clang lld + fi xxadd xx-c-essentials run sh -c 'xx-clang --print-target-triple | sed s/unknown-// | sed s/pc-//' assert_success @@ -254,6 +258,14 @@ testBuildHello() { expectedSuffix= } +@test "loong64-c-ld" { + if ! supportLoongArch; then + skip "LOONGARCH not supported" + fi + export TARGETARCH=loong64 + testHelloCLLD +} + @test "ppc64le-c-lld" { export TARGETARCH=ppc64le testHelloCLLD @@ -300,6 +312,12 @@ testBuildHello() { testHelloCPPLLD # actually runs with ld } +@test "loong64-c++-ld" { + skip "LOONG64 not supported" + export TARGETARCH=loong64 + testHelloCPPLLD # actually runs with ld +} + @test "386-c++-lld" { export TARGETARCH=386 testHelloCPPLLD diff --git a/src/test-go.bats b/src/test-go.bats index 92d56bd2..7480e78c 100755 --- a/src/test-go.bats +++ b/src/test-go.bats @@ -9,7 +9,11 @@ ensureGo() { else add golang fi - add clang lld + if [ "$(xx-info arch)" = "loong64" ]; then + add clang binutils + else + add clang lld + fi } setup_file() { @@ -118,6 +122,11 @@ testEnv() { testEnv } +@test "loong64-env" { + export TARGETARCH=loong64 + testEnv +} + @test "s390x-env" { export TARGETARCH=s390x testEnv @@ -253,6 +262,14 @@ testHelloGO() { testHelloGO } +@test "loong64-hellogo" { + if ! supportLoongArchGo; then + skip "LOONGARCH GO not supported" + fi + export TARGETARCH=loong64 + testHelloGO +} + @test "386-hellogo" { export TARGETARCH=386 testHelloGO @@ -335,6 +352,10 @@ testHelloCGO() { testHelloCGO } +@test "loong64-hellocgo" { + skip "LOONG64 CGO not supported" +} + @test "386-hellocgo" { export TARGETARCH=386 testHelloCGO diff --git a/src/test-info-alpine.bats b/src/test-info-alpine.bats index b01b6c7e..dea7d57a 100755 --- a/src/test-info-alpine.bats +++ b/src/test-info-alpine.bats @@ -74,6 +74,11 @@ load 'assert' assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc xx-info pkg-arch)" # does not change } +@test "loong64" { + assert_equal "loong64-alpine-linux-muslabi" "$(TARGETPLATFORM=linux/loong64 xx-info triple)" + assert_equal "loongarch64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "custom-vendor" { assert_equal "riscv64-unknown-linux-musl" "$(TARGETPLATFORM=linux/riscv64 XX_VENDOR=unknown xx-info triple)" } diff --git a/src/test-info-common.bats b/src/test-info-common.bats index 80d90c8a..b315b5b1 100755 --- a/src/test-info-common.bats +++ b/src/test-info-common.bats @@ -77,6 +77,10 @@ load 'assert' assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info march)" } +@test "loong64" { + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info march)" +} + @test "s390x" { assert_equal "s390x" "$(TARGETPLATFORM=linux/s390x xx-info march)" } @@ -134,6 +138,10 @@ load 'assert' assert_success assert_output "$(TARGETPLATFORM=linux/riscv64 xx-info)" + TARGETPAIR=linux-loong64 run xx-info + assert_success + assert_output "$(TARGETPLATFORM=linux/loong64 xx-info)" + TARGETPAIR=linux-mips run xx-info assert_success assert_output "$(TARGETPLATFORM=linux/mips xx-info)" diff --git a/src/test-info-debian.bats b/src/test-info-debian.bats index 3654f1ed..b626436b 100755 --- a/src/test-info-debian.bats +++ b/src/test-info-debian.bats @@ -77,6 +77,11 @@ fi assert_equal "riscv64gc-unknown-linux-gnu" "$(TARGETPLATFORM=linux/riscv64 RISCV64_TARGET_ARCH=riscv64gc XX_VENDOR=unknown xx-info triple)" } +@test "loong64" { + assert_equal "loong64-linux-gnuabi" "$(TARGETPLATFORM=linux/loong64 xx-info triple)" + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "mips" { assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)" assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)" diff --git a/src/test-info-rhel.bats b/src/test-info-rhel.bats index 1dff15c8..707ce1a1 100755 --- a/src/test-info-rhel.bats +++ b/src/test-info-rhel.bats @@ -60,6 +60,10 @@ fi assert_equal "riscv64" "$(TARGETPLATFORM=linux/riscv64 xx-info pkg-arch)" } +@test "loong64" { + assert_equal "loong64" "$(TARGETPLATFORM=linux/loong64 xx-info pkg-arch)" +} + @test "mips" { assert_equal "mips-linux-gnu" "$(TARGETPLATFORM=linux/mips xx-info triple)" assert_equal "mips" "$(TARGETPLATFORM=linux/mips xx-info pkg-arch)" diff --git a/src/test-verify.bats b/src/test-verify.bats index 34e51fcb..f69f066b 100755 --- a/src/test-verify.bats +++ b/src/test-verify.bats @@ -222,6 +222,11 @@ load 'assert' run xx-verify /idontexist assert_success + export XX_VERIFY_FILE_CMD_OUTPUT=": ELF 64-bit LSB executable, LoongArch, version 1 (SYSV), statically linked, BuildID[sha1]=4d126b33c220ba2efd23ed68a46ef0db96c31f76, not stripped" + export TARGETPLATFORM=linux/loong64 + run xx-verify /idontexist + assert_success + export TARGETPLATFORM=linux/amd64 run xx-verify /idontexist assert_failure diff --git a/src/test_helper.bash b/src/test_helper.bash index 21c18f97..10ae7597 100644 --- a/src/test_helper.bash +++ b/src/test_helper.bash @@ -91,6 +91,21 @@ supportRiscVCGo() { versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.16" } +supportLoongArchGo() { + versionGTE "$(go version | awk '{print $3}' | sed 's/^go//')" "1.19" +} + +supportLoongArch() { + if [ -f /etc/debian_version ]; then + if grep "sid" /etc/apt/sources.list 2>/dev/null >/dev/null; then + return 0 + else + return 1 + fi + fi + return 0 +} + supportRC() { command -v llvm-rc >/dev/null 2>&1 } diff --git a/src/xx-apk b/src/xx-apk index df040626..fae5dee7 100755 --- a/src/xx-apk +++ b/src/xx-apk @@ -51,6 +51,12 @@ setup() { echo "https://dl-cdn.alpinelinux.org/alpine/edge/main" >"$apk_dir/repositories" echo "https://dl-cdn.alpinelinux.org/alpine/edge/community" >>"$apk_dir/repositories" fi + # add loongarch support + if [ "$TARGETARCH" = "loong64" ]; then + echo "http://alpine.loongnix.cn/v3.11/main" >"$apk_dir/repositories" + echo "http://alpine.loongnix.cn/v3.11/community" >>"$apk_dir/repositories" + echo "http://alpine.loongnix.cn/v3.11/testing" >>"$apk_dir/repositories" + fi mkdir "$apk_dir/keys" mkdir "$apk_dir/protected_paths.d" echo "$XX_PKG_ARCH" >"$apk_dir/arch" diff --git a/src/xx-apt b/src/xx-apt index 20400e5c..8aabb3b0 100755 --- a/src/xx-apt +++ b/src/xx-apt @@ -140,6 +140,13 @@ if [ "$TARGETARCH" = "riscv64" ] && [ "$(xx-info vendor)" = "debian" ]; then echo "deb [ arch=riscv64 ] http://ftp.ports.debian.org/debian-ports sid main" >>/etc/apt/sources.list.d/riscv64-sid.list fi +if [ "$TARGETARCH" = "loong64" ] && [ "$(xx-info vendor)" = "debian" ]; then + apt-get update + apt-get install -y debian-ports-archive-keyring + echo "deb [ arch=loong64 ] http://ftp.ports.debian.org/debian-ports sid main + deb [ arch=loong64 ] http://ftp.ports.debian.org/debian-ports unreleased main" >>/etc/apt/sources.list.d/loong64-sid.list +fi + if ! dpkg --print-foreign-architectures | grep "$XX_PKG_ARCH" >/dev/null; then if [ "$XX_OS" = "linux" ]; then if [ "$(xx-info vendor)" = "ubuntu" ] && [ -z "$nocross" ]; then diff --git a/src/xx-cargo b/src/xx-cargo index 1af1b1bb..7e869c1a 100755 --- a/src/xx-cargo +++ b/src/xx-cargo @@ -79,12 +79,12 @@ if [ -n "$XX_RUSTFLAGS" ]; then fi export "CC_$(xx-info | tr - _)=$(xx-info)-clang" -if which "qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)" >/dev/null 2>&1; then - export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUNNER=qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info march)" +if which "qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info march)" >/dev/null 2>&1; then + export "CARGO_TARGET_$(xx-info | tr '[:lower:]' '[:upper:]' | tr - _)_RUNNER=qemu-$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info march)" if [ -f /etc/alpine-release ]; then - export "QEMU_LD_PREFIX=/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' xx-info)/" + export "QEMU_LD_PREFIX=/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' xx-info)/" else - export "QEMU_LD_PREFIX=/lib/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' XX_VENDOR='' xx-info)/" + export "QEMU_LD_PREFIX=/lib/$(RISCV64_TARGET_ARCH='' ARM_TARGET_ARCH='' LOONG64_TARGET_ARCH='' XX_VENDOR='' xx-info)/" fi fi diff --git a/src/xx-cc b/src/xx-cc index 8b06bc7b..835db222 100755 --- a/src/xx-cc +++ b/src/xx-cc @@ -175,6 +175,8 @@ detectTargetOSArch() { targetarch="s390x" elif [ "$arch" = "powerpc64le" ]; then targetarch="ppc64le" + elif [ "$arch" = "loong64" ]; then + targetarch="loong64" fi if [ -z "$targetarch" ]; then @@ -334,6 +336,10 @@ setup() { if [ "${target#riscv64}" != "${target}" ]; then prefer_lld= fi + # lld has no support for loong64 + if [ "${target#loong64}" != "${target}" ]; then + prefer_lld= + fi if [ -n "${XX_CC_PREFER_STATIC_LINKER}" ] && { [ "${target#386}" != "${target}" ] || [ "${target#powerpc64le}" != "${target}" ]; }; then prefer_lld= @@ -402,6 +408,9 @@ setup() { if [ "$exp" = "riscv64" ]; then exp="riscv" fi + if [ "$exp" = "loong64" ]; then + exp="loongarch" + fi if ld -V 2>/dev/null | grep $exp >/dev/null; then ln -s "$(command -v ld)" "/usr/bin/${target}-ld" linker="/usr/bin/${target}-ld" @@ -443,10 +452,41 @@ setup() { return fi + config="--target=$(echo "${target}" | sed s/^riscv64gc-/riscv64-/) -fuse-ld=${linker}" + if [ "${nativeTarget}" != "${target}" ]; then + if [ "$targetos" = "darwin" ]; then + detectMacOSSDK + config="${config} -isysroot ${macos_sdk_path} -stdlib=libc++" + elif [ "$targetos" = "windows" ]; then + config="${config} -I/usr/${target}/include -L/usr/${target}/lib" + elif [ -f /etc/alpine-release ]; then + config="${config} --sysroot=/${target}/" + + if [ -n "$is_bfd" ]; then + config="${config} -Wl,-rpath-link,/${target}/usr/lib" + fi + + cat <"/usr/bin/${target}-pkg-config" +#!/usr/bin/env sh +export PKG_CONFIG_SYSROOT_DIR=/${target} +export PKG_CONFIG_LIBDIR=/${target}/usr/lib/pkgconfig/ +exec pkg-config "\$@" +EOT + chmod +x "/usr/bin/${target}-pkg-config" + + fi + elif [ ! -f "/usr/bin/${target}-pkg-config" ] && [ ! -h "/usr/bin/${target}-pkg-config" ]; then + ln -s pkg-config "/usr/bin/${target}-pkg-config" + fi + f="$(dirname "$(readlink -f "$(command -v /usr/bin/clang)")")/${target}.cfg" + echo "$config" >"${f}" + if [ "${f}" != "/usr/bin/${target}.cfg" ]; then + ln -s "${f}" "/usr/bin/${target}.cfg" + fi + for f in clang clang++; do if [ -f /usr/bin/$f ]; then - # there seems to be a bug in llvm that prevents config to be loaded if target contains a dot , like macos10.4 - if echo "${target}" | grep '\.' 2>/dev/null >/dev/null; then + if [ -f "/usr/bin/${target}.cfg" ]; then cat <"/usr/bin/${target}-$f" #!/usr/bin/env sh $f --config /usr/bin/${target}.cfg "\$@" @@ -488,38 +528,6 @@ EOT fi fi - config="--target=$(echo "${target}" | sed s/^riscv64gc-/riscv64-/) -fuse-ld=${linker}" - if [ "${nativeTarget}" != "${target}" ]; then - if [ "$targetos" = "darwin" ]; then - detectMacOSSDK - config="${config} -isysroot ${macos_sdk_path} -stdlib=libc++" - elif [ "$targetos" = "windows" ]; then - config="${config} -I/usr/${target}/include -L/usr/${target}/lib" - elif [ -f /etc/alpine-release ]; then - config="${config} --sysroot=/${target}/" - - if [ -n "$is_bfd" ]; then - config="${config} -Wl,-rpath-link,/${target}/usr/lib" - fi - - cat <"/usr/bin/${target}-pkg-config" -#!/usr/bin/env sh -export PKG_CONFIG_SYSROOT_DIR=/${target} -export PKG_CONFIG_LIBDIR=/${target}/usr/lib/pkgconfig/ -exec pkg-config "\$@" -EOT - chmod +x "/usr/bin/${target}-pkg-config" - - fi - elif [ ! -f "/usr/bin/${target}-pkg-config" ] && [ ! -h "/usr/bin/${target}-pkg-config" ]; then - ln -s pkg-config "/usr/bin/${target}-pkg-config" - fi - f="$(dirname "$(readlink -f "$(command -v /usr/bin/clang)")")/${target}.cfg" - echo "$config" >"${f}" - if [ "${f}" != "/usr/bin/${target}.cfg" ]; then - ln -s "${f}" "/usr/bin/${target}.cfg" - fi - if [ -f /etc/alpine-release ]; then # if vendor is not alpine then sysroot needs to be linked to the custom vendor alpinetriple=$(echo "$target" | sed s/-[[:alpha:]][[:alpha:]]*-/-alpine-/ | sed s/^riscv64gc-/riscv64-/) @@ -554,6 +562,7 @@ check_compiler() { setupTarget= printTarget= printCmake= +printSysroot= target= nextIsTarget= downloadLD= @@ -572,6 +581,9 @@ for p in "$@"; do setupTarget=1 printCmake=1 fi + if [ "${p}" = "--print-sysroot" ] || [ "${p}" = "-print-sysroot" ]; then + printSysroot=1 + fi if [ "${p}" = "--download-prog=ld" ]; then downloadLD=1 fi @@ -630,6 +642,24 @@ if [ -n "${printCmake}" ]; then exit 0 fi +if [ -n "${printSysroot}" ]; then + setup + + if xx-info is-cross; then + if [ -f "/etc/alpine-release" ]; then + echo "/${target}/" + exit 0 + fi + if [ "$(xx-info os)" = "darwin" ]; then + detectMacOSSDK + echo "${macos_sdk_path}" + exit 0 + fi + fi + echo "/" + exit 0 +fi + # if setup then setup and exit if [ -n "${setupTarget}" ]; then setup diff --git a/src/xx-info b/src/xx-info index 61451862..0c85f319 100755 --- a/src/xx-info +++ b/src/xx-info @@ -189,6 +189,9 @@ if [ -z "$TARGETARCH" ]; then "mips64le") TARGETARCH="mips64le" ;; + "loongarch64") + TARGETARCH="loong64" + ;; esac fi @@ -337,6 +340,14 @@ case "$TARGETARCH" in XX_RHEL_ARCH="mips64el" XX_TRIPLE="mips64el${vendor}-linux-${XX_LIBC}abi64" ;; + "loong64") + XX_MARCH="loong64" + XX_DEBIAN_ARCH="loong64" + XX_ALPINE_ARCH="loongarch64" + XX_RHEL_ARCH="loong64" + XX_TRIPLE="loong64${vendor}-linux-${XX_LIBC}abi" + ;; + esac XX_PKG_ARCH=$TARGETARCH diff --git a/src/xx-verify b/src/xx-verify index 4951aa43..6ad7d603 100755 --- a/src/xx-verify +++ b/src/xx-verify @@ -220,6 +220,10 @@ for f in "$@"; do expArch="MIPS" expArch2="64-bit LSB" ;; + "loong64") + expArch="LoongArch" + expArch2="ELF 64-bit LSB" + ;; "386") expArch="Intel 80386" if [ "$TARGETOS" != "windows" ]; then