diff --git a/.github/workflows/Dockerfile.base b/.github/workflows/Dockerfile.base new file mode 100644 index 00000000000000..f1ed6236be4d3f --- /dev/null +++ b/.github/workflows/Dockerfile.base @@ -0,0 +1,6 @@ +FROM alpine:latest + +RUN apk add --no-cache gcc g++ ncurses-dev git rsync perl tar bash patch findutils diffutils grep gzip unzip bzip2 wget python3 file which make gawk coreutils linux-headers argp-standalone musl-fts-dev musl-obstack-dev musl-libintl +RUN adduser -D buildbot + +WORKDIR /home/buildbot diff --git a/.github/workflows/Dockerfile.toolchain b/.github/workflows/Dockerfile.toolchain new file mode 100644 index 00000000000000..949bc2bb5c2041 --- /dev/null +++ b/.github/workflows/Dockerfile.toolchain @@ -0,0 +1,8 @@ +ARG OWNER_LC +ARG CONTAINER_TAG + +FROM ghcr.io/$OWNER_LC/tools:$CONTAINER_TAG + +ARG TOOLCHAIN_NAME + +ADD $TOOLCHAIN_NAME /external-toolchain/ diff --git a/.github/workflows/Dockerfile.tools b/.github/workflows/Dockerfile.tools index c2ae7dc89659ab..8af0bcdf0b2e55 100644 --- a/.github/workflows/Dockerfile.tools +++ b/.github/workflows/Dockerfile.tools @@ -1,3 +1,6 @@ -FROM registry.gitlab.com/openwrt/buildbot/buildworker-3.4.1 +ARG OWNER_LC +ARG CONTAINER_TAG + +FROM ghcr.io/$OWNER_LC/base-alpine:$CONTAINER_TAG COPY --chown=buildbot:buildbot tools.tar /tools.tar diff --git a/.github/workflows/build-tools.yml b/.github/workflows/build-tools.yml index ca415489c5a58f..1faa3d71505411 100644 --- a/.github/workflows/build-tools.yml +++ b/.github/workflows/build-tools.yml @@ -3,6 +3,9 @@ name: Build host tools on: workflow_call: inputs: + container: + type: string + default: registry.gitlab.com/openwrt/buildbot/buildworker-3.4.1 generate_prebuilt_artifacts: type: boolean @@ -13,7 +16,7 @@ jobs: build: name: Build tools runs-on: ubuntu-latest - container: registry.gitlab.com/openwrt/buildbot/buildworker-3.4.1 + container: ${{ inputs.container }} steps: - name: Checkout diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index c892857999c12f..6745d036c9ac22 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,8 +1,11 @@ name: Build sub target -on: +on: workflow_call: inputs: + container_name: + type: string + default: tools target: required: true type: string @@ -22,6 +25,10 @@ on: type: boolean build_all_boards: type: boolean + build_external_toolchain: + type: boolean + upload_external_toolchain: + type: boolean permissions: contents: read @@ -86,7 +93,7 @@ jobs: needs: setup_build runs-on: ubuntu-latest - container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/tools:${{ needs.setup_build.outputs.container_tag }} + container: ghcr.io/${{ needs.setup_build.outputs.owner_lc }}/${{ inputs.container_name }}:${{ needs.setup_build.outputs.container_tag }} permissions: contents: read @@ -150,6 +157,11 @@ jobs: id: parse-toolchain working-directory: openwrt run: | + if [ -d /external-toolchain/ ]; then + echo "toolchain-type=external_container" >> $GITHUB_OUTPUT + exit 0 + fi + TOOLCHAIN_PATH=snapshots if [ -n "${{ github.base_ref }}" ]; then @@ -196,7 +208,7 @@ jobs: echo "TOOLCHAIN_PATH=$TOOLCHAIN_PATH" >> "$GITHUB_ENV" - name: Cache external toolchain/sdk - if: inputs.build_toolchain == false + if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'external_container' id: cache-external-toolchain uses: actions/cache@v3 with: @@ -212,7 +224,7 @@ jobs: ccache-kernel-${{ env.TARGET }}/${{ env.SUBTARGET }}- - name: Download external toolchain/sdk - if: inputs.build_toolchain == false && steps.cache-external-toolchain.outputs.cache-hit != 'true' + if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type != 'external_container' && steps.cache-external-toolchain.outputs.cache-hit != 'true' shell: su buildbot -c "sh -e {0}" working-directory: openwrt run: | @@ -254,6 +266,20 @@ jobs: echo CONFIG_TARGET_PER_DEVICE_ROOTFS=y >> .config echo CONFIG_TARGET_ALL_PROFILES=y >> .config + - name: Configure external toolchain in container + if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_container' + shell: su buildbot -c "sh -e {0}" + working-directory: openwrt + run: | + echo CONFIG_DEVEL=y >> .config + echo CONFIG_AUTOREMOVE=y >> .config + echo CONFIG_CCACHE=y >> .config + + ./scripts/ext-toolchain.sh \ + --toolchain /external-toolchain/$(ls /external-toolchain/ | grep openwrt-toolchain)/toolchain-* \ + --overwrite-config \ + --config ${{ env.TARGET }}/${{ env.SUBTARGET }} + - name: Configure external toolchain if: inputs.build_toolchain == false && steps.parse-toolchain.outputs.toolchain-type == 'external_toolchain' shell: su buildbot -c "sh -e {0}" @@ -357,9 +383,32 @@ jobs: working-directory: openwrt run: make -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh + - name: Build external toolchain + if: inputs.build_external_toolchain == true + shell: su buildbot -c "sh -e {0}" + working-directory: openwrt + run: make target/toolchain/compile -j$(nproc) BUILD_LOG=1 || ret=$? .github/workflows/scripts/show_build_failures.sh + - name: Upload logs if: failure() uses: actions/upload-artifact@v3 with: name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-logs path: "openwrt/logs" + + - name: Find external toolchain name + if: inputs.upload_external_toolchain == true + working-directory: openwrt + run: | + SUBTARGET_DIR=$(ls bin/targets/${{ env.TARGET }} | grep ${{ env.SUBTARGET }}) + TOOLCHAIN_NAME=$(ls bin/targets/${{ env.TARGET }}/$SUBTARGET_DIR | grep toolchain) + echo "SUBTARGET_DIR=$SUBTARGET_DIR" >> "$GITHUB_ENV" + echo "TOOLCHAIN_NAME=$TOOLCHAIN_NAME" >> "$GITHUB_ENV" + + - name: Upload prebuilt toolchain + if: inputs.upload_external_toolchain == true + uses: actions/upload-artifact@v3 + with: + name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-external-toolchain + path: openwrt/bin/targets/${{ env.TARGET }}/${{ env.SUBTARGET_DIR }}/${{ env.TOOLCHAIN_NAME }} + retention-days: 1 diff --git a/.github/workflows/kernel.yml b/.github/workflows/kernel.yml index d886002ed16414..2c0c20097bbf49 100644 --- a/.github/workflows/kernel.yml +++ b/.github/workflows/kernel.yml @@ -21,6 +21,10 @@ on: permissions: contents: read +concurrency: + group: ${{ github.ref }} + cancel-in-progress: ${{ github.event_name == 'pull_request' }} + jobs: determine_targets: name: Set targets @@ -66,6 +70,7 @@ jobs: target: ${{fromJson(needs.determine_targets.outputs.target)}} uses: ./.github/workflows/build.yml with: + container_name: toolchain-${{ matrix.target }} target: ${{ matrix.target }} build_kernel: true build_all_kmods: true diff --git a/.github/workflows/packages.yml b/.github/workflows/packages.yml index 7bcaa2b3d33566..60072fb6f4392b 100644 --- a/.github/workflows/packages.yml +++ b/.github/workflows/packages.yml @@ -37,6 +37,7 @@ jobs: - target: x86/64 uses: ./.github/workflows/build.yml with: + container_name: toolchain-${{ matrix.target }} target: ${{ matrix.target }} build_kernel: true build_all_kmods: true diff --git a/.github/workflows/push-containers.yml b/.github/workflows/push-containers.yml index 56e0daa611b872..83e9ae2eb4196b 100644 --- a/.github/workflows/push-containers.yml +++ b/.github/workflows/push-containers.yml @@ -7,32 +7,30 @@ on: - '.github/workflows/build-tools.yml' - '.github/workflows/push-containers.yml' - '.github/workflows/Dockerfile.tools' + - '.github/workflows/Dockerfile.base' + - 'toolchain/**' + - '.github/workflows/build.yml' + - '.github/workflows/toolchain.yml' + - '.github/workflows/Dockerfile.toolchain' permissions: contents: read jobs: - build-linux-buildbot: - name: Build tools with buildbot container - uses: ./.github/workflows/build-tools.yml - with: - generate_prebuilt_artifacts: true - - push-tools-container: - needs: build-linux-buildbot - name: Push prebuilt tools container + determine-container-info: + name: Determine needed info to push containers runs-on: ubuntu-latest - - permissions: - contents: read - packages: write + outputs: + owner-lc: ${{ steps.generate-owner-lc.outputs.owner-lc }} + container-tag: ${{ steps.determine-container-tag.outputs.container-tag }} steps: - name: Set lower case owner name + id: generate-owner-lc env: OWNER: ${{ github.repository_owner }} run: | - echo "OWNER_LC=${OWNER,,}" >> "$GITHUB_ENV" + echo "owner-lc=${OWNER,,}" >> "$GITHUB_OUTPUT" # Per branch tools container tag # By default stick to latest @@ -43,6 +41,7 @@ jobs: # (example branch openwrt-22.03 -> tools:openwrt-22.03) # (example branch openwrt-22.03-test -> tools:openwrt-22.03) - name: Determine tools container tag + id: determine-container-tag run: | CONTAINER_TAG=latest @@ -56,9 +55,57 @@ jobs: fi fi - echo "Tools container to push tools:$CONTAINER_TAG" - echo "CONTAINER_TAG=$CONTAINER_TAG" >> "$GITHUB_ENV" + echo "Container tag to push for tools and toolchain is $CONTAINER_TAG" + echo "container-tag=$CONTAINER_TAG" >> "$GITHUB_OUTPUT" + + build-push-base-container: + needs: determine-container-info + name: Build and push base alpine container + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + path: 'openwrt' + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: openwrt + push: true + tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/base-alpine:${{ needs.determine-container-info.outputs.container-tag }} + file: openwrt/.github/workflows/Dockerfile.base + + build-linux-buildbot: + needs: [ determine-container-info, build-push-base-container ] + name: Build tools with buildbot container + uses: ./.github/workflows/build-tools.yml + with: + container: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/base-alpine:${{ needs.determine-container-info.outputs.container-tag }} + generate_prebuilt_artifacts: true + + push-tools-container: + needs: [ determine-container-info, build-linux-buildbot ] + name: Push prebuilt tools container + runs-on: ubuntu-latest + + permissions: + contents: read + packages: write + + steps: - name: Checkout uses: actions/checkout@v3 with: @@ -82,5 +129,114 @@ jobs: with: context: openwrt push: true - tags: ghcr.io/${{ env.OWNER_LC }}/tools:${{ env.CONTAINER_TAG }} + tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/tools:${{ needs.determine-container-info.outputs.container-tag }} file: openwrt/.github/workflows/Dockerfile.tools + build-args: | + OWNER_LC=${{ needs.determine-container-info.outputs.owner-lc }} + CONTAINER_TAG=${{ needs.determine-container-info.outputs.container-tag }} + + determine-targets: + name: Set targets + runs-on: ubuntu-latest + outputs: + target: ${{ steps.find_targets.outputs.target }} + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Set targets + id: find_targets + run: | + export TARGETS="$(perl ./scripts/dump-target-info.pl targets 2>/dev/null \ + | sort -u -t '/' -k1,1 \ + | awk '{ print $1 }')" + + JSON='[' + FIRST=1 + for TARGET in $TARGETS; do + [[ $FIRST -ne 1 ]] && JSON="$JSON"',' + JSON="$JSON"'"'"${TARGET}"'"' + FIRST=0 + done + JSON="$JSON"']' + + echo -e "\n---- targets ----\n" + echo "$JSON" + echo -e "\n---- targets ----\n" + + echo "target=$JSON" >> $GITHUB_OUTPUT + + build: + name: Build Target Toolchain + needs: [ determine-targets, push-tools-container ] + permissions: + contents: read + packages: read + strategy: + fail-fast: False + matrix: + target: ${{fromJson(needs.determine-targets.outputs.target)}} + uses: ./.github/workflows/build.yml + with: + target: ${{ matrix.target }} + build_toolchain: true + build_external_toolchain: true + upload_external_toolchain: true + + push-toolchain-container: + needs: [ determine-container-info, determine-targets, build ] + runs-on: ubuntu-latest + + strategy: + fail-fast: False + matrix: + target: ${{fromJson(needs.determine-targets.outputs.target)}} + + permissions: + contents: read + packages: write + + steps: + - name: Initialization environment + run: | + TARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 1) + SUBTARGET=$(echo ${{ matrix.target }} | cut -d "/" -f 2) + echo "TARGET=$TARGET" >> "$GITHUB_ENV" + echo "SUBTARGET=$SUBTARGET" >> "$GITHUB_ENV" + + - name: Checkout + uses: actions/checkout@v3 + with: + path: 'openwrt' + + - name: Download external toolchain from build job + uses: actions/download-artifact@v3 + with: + name: ${{ env.TARGET }}-${{ env.SUBTARGET }}-external-toolchain + path: openwrt + + - name: Find external toolchain name + working-directory: openwrt + run: | + TOOLCHAIN_NAME=$(ls | grep toolchain-${{ env.TARGET }}-${{ env.SUBTARGET }}) + echo "TOOLCHAIN_NAME=$TOOLCHAIN_NAME" >> "$GITHUB_ENV" + + - name: Login to GitHub Container Registry + uses: docker/login-action@v2 + with: + registry: ghcr.io + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v3 + with: + context: openwrt + push: true + tags: ghcr.io/${{ needs.determine-container-info.outputs.owner-lc }}/toolchain-${{ matrix.target }}:${{ needs.determine-container-info.outputs.container-tag }} + file: openwrt/.github/workflows/Dockerfile.toolchain + build-args: | + OWNER_LC=${{ needs.determine-container-info.outputs.owner-lc }} + CONTAINER_TAG=${{ needs.determine-container-info.outputs.container-tag }} + TOOLCHAIN_NAME=${{ env.TOOLCHAIN_NAME }} diff --git a/toolchain/binutils/patches/2.39/0001-gprofng-fix-build-issues-on-musl.patch b/toolchain/binutils/patches/2.39/0001-gprofng-fix-build-issues-on-musl.patch new file mode 100644 index 00000000000000..a64bda03a32bcd --- /dev/null +++ b/toolchain/binutils/patches/2.39/0001-gprofng-fix-build-issues-on-musl.patch @@ -0,0 +1,1184 @@ +From fe39ffdc202f04397f31557f17170b40bc42b77a Mon Sep 17 00:00:00 2001 +From: Vladimir Mezentsev +Date: Wed, 14 Sep 2022 01:11:45 -0700 +Subject: [PATCH] gprofng: fix build issues on musl + +gprofng/ChangeLog +2022-09-14 Vladimir Mezentsev + + PR gprofng/29477 + * configure.ac: Set __MUSL_LIBC. + * configure: Rebuild. + * common/config.h.in: Rebuild. + * src/collector_module.h: Fix compiler errors because mmap64, open64, + pwrite64 are macros and getcontext() is absent on musl. + * libcollector/collector.c: Likewise. + * libcollector/hwprofile.c: Likewise. + * libcollector/iolib.c: Likewise. + * libcollector/libcol_util.c: Likewise. + * libcollector/linetrace.c: Likewise. + * libcollector/memmgr.c: Likewise. + * libcollector/profile.c: Likewise. + * libcollector/unwind.c: Likewise. + * libcollector/dispatcher.c: Likewise. + * src/Experiment.cc: Likewise. + * libcollector/collector.h: Use dlsym() because dlvsym() is not defined + on musl. + * libcollector/iotrace.c: Remove interposition of versioned functions. + * libcollector/mmaptrace.c: Likewise. + * libcollector/libcol_util.h: Fix -Wint-to-pointer-cast warnings. + * libcollector/jprofile.c: Likewise. + * libcollector/synctrace.c: Include "collector.h". + * src/Print.cc: Use get_basename() because basename() is not defined + on musl. + * common/hwcdrv.c: Fix -Wformat= warnings. +--- + gprofng/common/config.h.in | 3 + + gprofng/common/hwcdrv.c | 6 +- + gprofng/configure | 30 ++++- + gprofng/configure.ac | 27 ++++- + gprofng/libcollector/collector.c | 9 +- + gprofng/libcollector/collector.h | 6 +- + gprofng/libcollector/dispatcher.c | 4 +- + gprofng/libcollector/hwprofile.c | 11 +- + gprofng/libcollector/iolib.c | 52 ++++----- + gprofng/libcollector/iotrace.c | 179 +++++++++++++++-------------- + gprofng/libcollector/jprofile.c | 6 - + gprofng/libcollector/libcol_util.c | 19 ++- + gprofng/libcollector/libcol_util.h | 9 +- + gprofng/libcollector/linetrace.c | 4 +- + gprofng/libcollector/memmgr.c | 2 +- + gprofng/libcollector/mmaptrace.c | 132 ++++++++------------- + gprofng/libcollector/profile.c | 2 +- + gprofng/libcollector/synctrace.c | 3 +- + gprofng/libcollector/unwind.c | 2 +- + gprofng/src/Experiment.cc | 4 +- + gprofng/src/Print.cc | 6 +- + gprofng/src/collector_module.h | 6 +- + 22 files changed, 277 insertions(+), 245 deletions(-) + +diff --git a/gprofng/common/config.h.in b/gprofng/common/config.h.in +index 8409ce74a57..f8484f238fd 100644 +--- a/gprofng/common/config.h.in ++++ b/gprofng/common/config.h.in +@@ -118,3 +118,6 @@ + + /* Define to 1 if you need to in order for `stat' and other things to work. */ + #undef _POSIX_SOURCE ++ ++/* Build with musl-libc. */ ++#undef __MUSL_LIBC +diff --git a/gprofng/common/hwcdrv.c b/gprofng/common/hwcdrv.c +index caab9839b49..05390e239df 100644 +--- a/gprofng/common/hwcdrv.c ++++ b/gprofng/common/hwcdrv.c +@@ -440,7 +440,7 @@ typedef struct + { // per-thread context + counter_state_t *ctr_list; + int signal_fd; // fd that caused the most recent signal +- pthread_t tid; // for debugging signal delivery problems ++ pid_t tid; // for debugging signal delivery problems + } hdrv_pcl_ctx_t; + + /*---------------------------------------------------------------------------*/ +@@ -1321,7 +1321,7 @@ hwcdrv_free_counters () // note: only performs shutdown for this thread + for (int ii = 0; ii < hdrv_pcl_state.hwcdef_cnt; ii++) + if (stop_one_ctr (ii, ctr_list)) + hwc_rc = HWCFUNCS_ERROR_GENERIC; +- TprintfT (DBG_LT1, "hwcdrv: hwcdrv_free_counters(tid=0x%lx).\n", pctx->tid); ++ TprintfT (DBG_LT1, "hwcdrv: hwcdrv_free_counters(tid=0x%lx).\n", (long) pctx->tid); + pctx->ctr_list = NULL; + return hwc_rc; + } +@@ -1351,7 +1351,7 @@ hwcdrv_start (void) /* must be called from each thread ? */ + return HWCFUNCS_ERROR_UNEXPECTED; + } + pctx->tid = hwcdrv_gettid (); +- TprintfT (DBG_LT1, "hwcdrv: hwcdrv_start(tid=0x%lx)\n", pctx->tid); ++ TprintfT (DBG_LT1, "hwcdrv: hwcdrv_start(tid=0x%lx)\n", (long) pctx->tid); + + /* + * create per-thread counter list +diff --git a/gprofng/configure b/gprofng/configure +index fad5b030072..301ac10050b 100755 +--- a/gprofng/configure ++++ b/gprofng/configure +@@ -16572,7 +16572,7 @@ class Simple{ + } + } + EOF +- if { ac_try='$JAVAC conftest.java &5 2>&1' ++ if { ac_try='$JAVAC configtest.java &5 2>&1' + { { eval echo "\"\$as_me\":${as_lineno-$LINENO}: \"$ac_try\""; } >&5 + (eval $ac_try) 2>&5 + ac_status=$? +@@ -16608,6 +16608,34 @@ $as_echo "#define DEBUG 1" >>confdefs.h + + fi + ++cat > "dummy.c" << EOF ++#include ++#if defined(__UCLIBC__) ++LIBC=uclibc ++#elif defined(__dietlibc__) ++LIBC=dietlibc ++#elif defined(__GLIBC__) ++LIBC=gnu ++#else ++#include ++/* First heuristic to detect musl libc. */ ++#ifdef __DEFINED_va_list ++LIBC=musl ++#else ++LIBC=gnu ++#endif ++#endif ++EOF ++cc_set_libc=`$CC -E "dummy.c" 2>/dev/null | grep '^LIBC=' | sed 's, ,,g'` ++eval "$cc_set_libc" ++echo "cc_set_libc=$cc_set_libc;" ++if test "$LIBC" = musl; then ++ ++$as_echo "#define __MUSL_LIBC 1" >>confdefs.h ++ ++fi ++ ++ + # Check if linker supports --as-needed and --no-as-needed options. + { $as_echo "$as_me:${as_lineno-$LINENO}: checking linker --as-needed support" >&5 + $as_echo_n "checking linker --as-needed support... " >&6; } +diff --git a/gprofng/configure.ac b/gprofng/configure.ac +index e9453109602..2d7640dfdc8 100644 +--- a/gprofng/configure.ac ++++ b/gprofng/configure.ac +@@ -142,7 +142,7 @@ class Simple{ + } + } + EOF +- if AC_TRY_COMMAND($JAVAC conftest.java &AS_MESSAGE_LOG_FD 2>&1); then ++ if AC_TRY_COMMAND($JAVAC configtest.java &AS_MESSAGE_LOG_FD 2>&1); then + GPROFNG_BROKEN_JAVAC=no + else + GPROFNG_BROKEN_JAVAC=yes +@@ -159,6 +159,31 @@ if test "${enable_gprofng_debug}" = yes; then + AC_DEFINE(DEBUG, 1, [Enable debugging output.]) + fi + ++cat > "dummy.c" << EOF ++#include ++#if defined(__UCLIBC__) ++LIBC=uclibc ++#elif defined(__dietlibc__) ++LIBC=dietlibc ++#elif defined(__GLIBC__) ++LIBC=gnu ++#else ++#include ++/* First heuristic to detect musl libc. */ ++#ifdef __DEFINED_va_list ++LIBC=musl ++#else ++LIBC=gnu ++#endif ++#endif ++EOF ++cc_set_libc=`$CC -E "dummy.c" 2>/dev/null | grep '^LIBC=' | sed 's, ,,g'` ++eval "$cc_set_libc" ++if test "$LIBC" = musl; then ++ AC_DEFINE(__MUSL_LIBC, 1, [Build with musl-libc.]) ++fi ++ ++ + # Check if linker supports --as-needed and --no-as-needed options. + AC_CACHE_CHECK(linker --as-needed support, bfd_cv_ld_as_needed, + [bfd_cv_ld_as_needed=no +diff --git a/gprofng/libcollector/collector.c b/gprofng/libcollector/collector.c +index ceff2c1cacc..93015305587 100644 +--- a/gprofng/libcollector/collector.c ++++ b/gprofng/libcollector/collector.c +@@ -2155,7 +2155,7 @@ log_header_write (sp_origin_t origin) + ucontext_t ucp; + ucp.uc_stack.ss_sp = NULL; + ucp.uc_stack.ss_size = 0; +- if (getcontext (&ucp) == 0) ++ if (CALL_UTIL (getcontext) (&ucp) == 0) + { + (void) __collector_log_write ("\n", + (unsigned long) ucp.uc_stack.ss_sp + ucp.uc_stack.ss_size); +@@ -2413,10 +2413,9 @@ __collector_dlog (int tflag, int level, char *format, ...) + int left = bufsz; + if ((tflag & SP_DUMP_NOHEADER) == 0) + { +- p += CALL_UTIL (snprintf)(p, left, "P%d,L%02u,t%02lu", +- (int) getpid (), +- (unsigned int) __collector_lwp_self (), +- __collector_no_threads ? 0 : __collector_thr_self ()); ++ p += CALL_UTIL (snprintf) (p, left, "P%ld,L%02lu,t%02lu", ++ (long) getpid (), (unsigned long) __collector_lwp_self (), ++ (unsigned long) (__collector_no_threads ? 0 : __collector_thr_self ())); + left = bufsz - (p - buf); + if (tflag) + { +diff --git a/gprofng/libcollector/collector.h b/gprofng/libcollector/collector.h +index c54568d891c..b589d3f3d18 100644 +--- a/gprofng/libcollector/collector.h ++++ b/gprofng/libcollector/collector.h +@@ -21,7 +21,6 @@ + #ifndef _COLLECTOR_H + #define _COLLECTOR_H + +-#include + #include + + #include "gp-defs.h" +@@ -31,6 +30,11 @@ + + #define GETRELTIME() (__collector_gethrtime() - __collector_start_time) + ++#if defined(__MUSL_LIBC) ++#define dlvsym(f, nm, v) dlsym (f, nm) ++#define SIGEV_THREAD_ID 4 ++#endif ++ + extern hrtime_t __collector_start_time; + + /* ========================================================== */ +diff --git a/gprofng/libcollector/dispatcher.c b/gprofng/libcollector/dispatcher.c +index f0308605d76..d3e4c52d667 100644 +--- a/gprofng/libcollector/dispatcher.c ++++ b/gprofng/libcollector/dispatcher.c +@@ -30,9 +30,7 @@ + #include + #include + #include +-#include + #include +-#include + #include + #include + #include +@@ -575,7 +573,9 @@ collector_timer_create (timer_t * ptimerid) + sigev.sigev_notify = SIGEV_THREAD_ID | SIGEV_SIGNAL; + sigev.sigev_signo = SIGPROF; + sigev.sigev_value.sival_ptr = ptimerid; ++#if !defined(__MUSL_LIBC) + sigev._sigev_un._tid = __collector_gettid (); ++#endif + if (CALL_REAL (timer_create)(CLOCK_THREAD_CPUTIME_ID, &sigev, ptimerid) == -1) + { + TprintfT (DBG_LT2, "collector_timer_settime() failed! errno=%d\n", errno); +diff --git a/gprofng/libcollector/hwprofile.c b/gprofng/libcollector/hwprofile.c +index 6fdaf1bd8ff..e360068ea30 100644 +--- a/gprofng/libcollector/hwprofile.c ++++ b/gprofng/libcollector/hwprofile.c +@@ -29,7 +29,6 @@ + #include + #include + #include +-#include + + #include "gp-defs.h" + #define _STRING_H 1 /* XXX MEZ: temporary workaround */ +@@ -378,23 +377,23 @@ static void + init_ucontexts (void) + { + /* initialize dummy context for "collector" frames */ +- getcontext (&expr_dummy_uc); ++ CALL_UTIL (getcontext) (&expr_dummy_uc); + SETFUNCTIONCONTEXT (&expr_dummy_uc, NULL); + + /* initialize dummy context for "out-of-range" frames */ +- getcontext (&expr_out_of_range_uc); ++ CALL_UTIL (getcontext) (&expr_out_of_range_uc); + SETFUNCTIONCONTEXT (&expr_out_of_range_uc, &__collector_hwcs_out_of_range); + + /* initialize dummy context for "frozen" frames */ +- getcontext (&expr_frozen_uc); ++ CALL_UTIL (getcontext) (&expr_frozen_uc); + SETFUNCTIONCONTEXT (&expr_frozen_uc, &__collector_hwcs_frozen); + + /* initialize dummy context for non-program-related frames */ +- getcontext (&expr_nopc_uc); ++ CALL_UTIL (getcontext) (&expr_nopc_uc); + SETFUNCTIONCONTEXT (&expr_nopc_uc, &__collector_not_program_related); + + /* initialize dummy context for lost-counts-related frames */ +- getcontext (&expr_lostcounts_uc); ++ CALL_UTIL (getcontext) (&expr_lostcounts_uc); + SETFUNCTIONCONTEXT (&expr_lostcounts_uc, &__collector_hwc_samples_lost); + } + /* initialize the signal handler */ +diff --git a/gprofng/libcollector/iolib.c b/gprofng/libcollector/iolib.c +index 6881f02fd30..861843c183d 100644 +--- a/gprofng/libcollector/iolib.c ++++ b/gprofng/libcollector/iolib.c +@@ -243,16 +243,14 @@ __collector_create_handle (char *descp) + { + /* allocate our buffers in virtual memory */ + /* later, we will remap buffers individually to the file */ +- uint8_t *memory = (uint8_t*) CALL_UTIL (mmap64)(0, +- (size_t) (NBUFS * blksz), +- PROT_READ | PROT_WRITE, ++ uint8_t *memory = (uint8_t*) CALL_UTIL (mmap64_) (0, ++ (size_t) (NBUFS * blksz), PROT_READ | PROT_WRITE, + #if ARCH(SPARC) + MAP_SHARED | MAP_ANON, + #else + MAP_PRIVATE | MAP_ANON, + #endif +- -1, +- (off64_t) 0); ++ -1, (off64_t) 0); + if (memory == MAP_FAILED) + { + TprintfT (0, "create_handle: can't mmap MAP_ANON (for %s): %s\n", hndl->fname, CALL_UTIL (strerror)(errno)); +@@ -516,9 +514,8 @@ allocateChunk (DataHandle *hndl, unsigned ichunk) + if (__collector_cas_ptr (&hndl->chunks[ichunk], NULL, CHUNK_BUSY) == NULL) + { + /* allocate virtual memory */ +- uint8_t *newchunk = (uint8_t*) CALL_UTIL (mmap64)(0, +- (size_t) (blksz * hndl->nflow), +- PROT_READ | PROT_WRITE, ++ uint8_t *newchunk = (uint8_t*) CALL_UTIL (mmap64_) (0, ++ (size_t) (blksz * hndl->nflow), PROT_READ | PROT_WRITE, + #if ARCH(SPARC) + MAP_SHARED | MAP_ANON, + #else +@@ -611,8 +608,10 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk) + char errmsg[MAXPATHLEN + 50]; + hrtime_t teo = __collector_gethrtime (); + double deltato = (double) (teo - tso) / 1000000.; +- (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), " t=%d, %s: open-retries-failed = %d, %3.6f ms.; remap", +- __collector_thr_self (), hndl->fname, iter, deltato); ++ (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), ++ " t=%lu, %s: open-retries-failed=%d, %3.6f ms.; remap\n", ++ (unsigned long) __collector_thr_self (), hndl->fname, ++ iter, deltato); + __collector_log_write ("%s\n", + SP_JCMD_COMMENT, COL_COMMENT_NONE, errmsg); + rc = 1; +@@ -623,9 +622,9 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk) + } + deleteHandle (hndl); + TprintfT (0, "remapBlock: can't open file: %s: %s\n", hndl->fname, STR (CALL_UTIL (strerror)(errno))); +- __collector_log_write ("t=%llu, %s: remap \n", ++ __collector_log_write ("t=%lu, %s: remap \n", + SP_JCMD_CERROR, COL_ERROR_FILEOPN, errno, +- (unsigned long long) __collector_thr_self (), ++ (unsigned long) __collector_thr_self (), + hndl->fname); + rc = 1; + goto exit; +@@ -640,15 +639,18 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk) + char errmsg[MAXPATHLEN + 50]; + hrtime_t teo = __collector_gethrtime (); + double deltato = (double) (teo - tso) / 1000000.; +- (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), " t=%d, %s: open-retries = %d, %3.6f ms.; remap", +- __collector_thr_self (), hndl->fname, iter, deltato); ++ (void) CALL_UTIL (snprintf) (errmsg, sizeof (errmsg), ++ " t=%d, %s: open-retries=%lu, %3.6f ms.; remap\n", ++ (unsigned long) __collector_thr_self (), hndl->fname, ++ iter, deltato); + __collector_log_write ("%s\n", + SP_JCMD_COMMENT, COL_COMMENT_NONE, errmsg); + } + + /* Ensure disk space is allocated and the block offset is 0 */ + uint32_t zero = 0; +- int n = CALL_UTIL (pwrite64)(fd, &zero, sizeof (zero), (off64_t) (offset + blksz - sizeof (zero))); ++ int n = CALL_UTIL (pwrite64_) (fd, &zero, sizeof (zero), ++ (off64_t) (offset + blksz - sizeof (zero))); + if (n <= 0) + { + deleteHandle (hndl); +@@ -663,13 +665,9 @@ remapBlock (DataHandle *hndl, unsigned iflow, unsigned ichunk) + + /* Map block to file */ + uint8_t *bptr = getBlock (hndl, iflow, ichunk); +- uint8_t *vaddr = (uint8_t *) CALL_UTIL (mmap64)( +- (void*) bptr, +- (size_t) blksz, +- PROT_READ | PROT_WRITE, +- MAP_SHARED | MAP_FIXED, +- fd, +- offset); ++ uint8_t *vaddr = (uint8_t *) CALL_UTIL (mmap64_) ((void*) bptr, ++ (size_t) blksz, PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, ++ fd, offset); + + if (vaddr != bptr) + { +@@ -784,8 +782,9 @@ __collector_write_packet (DataHandle *hndl, CM_Packet *pckt) + TprintfT (0, "collector_write_packet: packet too long: %d (max %ld)\n", recsz, blksz); + return 1; + } +- unsigned tid = (__collector_no_threads ? __collector_lwp_self () : __collector_thr_self ()); +- unsigned iflow = tid % hndl->nflow; ++ collector_thread_t tid = __collector_no_threads ? __collector_lwp_self () ++ : __collector_thr_self (); ++ unsigned iflow = (unsigned) (((unsigned long) tid) % hndl->nflow); + + /* Acquire block */ + uint32_t *sptr = &hndl->blkstate[iflow * NCHUNKS]; +@@ -925,7 +924,8 @@ mapBuffer (char *fname, Buffer *buf, off64_t foff) + + /* ensure disk space is allocated */ + char nl = '\n'; +- int n = CALL_UTIL (pwrite64)(fd, &nl, sizeof (nl), (off64_t) (foff + blksz - sizeof (nl))); ++ int n = CALL_UTIL (pwrite64_) (fd, &nl, sizeof (nl), ++ (off64_t) (foff + blksz - sizeof (nl))); + if (n <= 0) + { + TprintfT (0, "mapBuffer ERROR: can't pwrite file %s at 0x%llx\n", fname, +@@ -937,7 +937,7 @@ mapBuffer (char *fname, Buffer *buf, off64_t foff) + goto exit; + } + /* mmap buf->vaddr to fname at foff */ +- uint8_t *vaddr = CALL_UTIL (mmap64)(buf->vaddr, (size_t) blksz, ++ uint8_t *vaddr = CALL_UTIL (mmap64_) (buf->vaddr, (size_t) blksz, + PROT_READ | PROT_WRITE, MAP_SHARED | MAP_FIXED, fd, foff); + if (vaddr != buf->vaddr) + { +diff --git a/gprofng/libcollector/iotrace.c b/gprofng/libcollector/iotrace.c +index 9b47724bab9..d94daefa89b 100644 +--- a/gprofng/libcollector/iotrace.c ++++ b/gprofng/libcollector/iotrace.c +@@ -34,7 +34,7 @@ + #include + + #include "gp-defs.h" +-#include "collector_module.h" ++#include "collector.h" + #include "gp-experiment.h" + #include "data_pckts.h" + #include "tsd.h" +@@ -999,6 +999,22 @@ init_io_intf () + return rc; + } + ++static void ++write_io_packet (int fd, ssize_t ret, hrtime_t reqt, int iotype) ++{ ++ IOTrace_packet iopkt; ++ collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); ++ iopkt.comm.tsize = sizeof (IOTrace_packet); ++ iopkt.comm.tstamp = gethrtime (); ++ iopkt.requested = reqt; ++ iopkt.iotype = iotype; ++ iopkt.fd = fd; ++ iopkt.nbyte = ret; ++ iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, ++ iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); ++ collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); ++} ++ + /*------------------------------------------------------------- open */ + int + open (const char *path, int oflag, ...) +@@ -2412,162 +2428,147 @@ pread (int fildes, void *buf, size_t nbyte, off_t offset) + } + + /*------------------------------------------------------------- pwrite */ +-#if ARCH(Intel) && WSIZE(32) ++ ++#if !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32) + // map interposed symbol versions +-static int +-__collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset); + + SYMVER_ATTRIBUTE (__collector_pwrite_2_2, pwrite@@GLIBC_2.2) + int + __collector_pwrite_2_2 (int fildes, const void *buf, size_t nbyte, off_t offset) + { +- TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", +- CALL_REAL (pwrite_2_2), fildes, buf, (long long) nbyte, (long long) offset); +- if (NULL_PTR (pwrite)) ++ int *guard; ++ if (NULL_PTR (pwrite_2_2)) + init_io_intf (); +- return __collector_pwrite_symver (CALL_REAL (pwrite_2_2), fildes, buf, nbyte, offset); ++ if (CHCK_REENTRANCE (guard)) ++ return CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset); ++ PUSH_REENTRANCE (guard); ++ hrtime_t reqt = gethrtime (); ++ ssize_t ret = CALL_REAL (pwrite_2_2)(fildes, buf, nbyte, offset); ++ if (RECHCK_REENTRANCE (guard)) ++ { ++ POP_REENTRANCE (guard); ++ return ret; ++ } ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); ++ POP_REENTRANCE (guard); ++ return ret; + } + + SYMVER_ATTRIBUTE (__collector_pwrite_2_1, pwrite@GLIBC_2.1) + int + __collector_pwrite_2_1 (int fildes, const void *buf, size_t nbyte, off_t offset) + { +- TprintfT (DBG_LTT, "iotrace: __collector_pwrite_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", +- CALL_REAL (pwrite_2_1), fildes, buf, (long long) nbyte, (long long) offset); +- if (NULL_PTR (pwrite)) ++ int *guard; ++ if (NULL_PTR (pwrite_2_1)) + init_io_intf (); +- return __collector_pwrite_symver (CALL_REAL (pwrite_2_1), fildes, buf, nbyte, offset); ++ if (CHCK_REENTRANCE (guard)) ++ return CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); ++ PUSH_REENTRANCE (guard); ++ hrtime_t reqt = gethrtime (); ++ ssize_t ret = CALL_REAL (pwrite_2_1)(fildes, buf, nbyte, offset); ++ if (RECHCK_REENTRANCE (guard)) ++ { ++ POP_REENTRANCE (guard); ++ return ret; ++ } ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); ++ POP_REENTRANCE (guard); ++ return ret; + } +- +-static int +-__collector_pwrite_symver (int(real_pwrite) (), int fildes, const void *buf, size_t nbyte, off_t offset) +-{ +-#else /* ^ARCH(Intel) && WSIZE(32) */ ++#endif /* !defined(__MUSL_LIBC) && ARCH(Intel) && WSIZE(32) */ + + ssize_t + pwrite (int fildes, const void *buf, size_t nbyte, off_t offset) + { +-#endif /* ^ARCH(Intel) && WSIZE(32) */ + int *guard; +- ssize_t ret; +- IOTrace_packet iopkt; + if (NULL_PTR (pwrite)) + init_io_intf (); + if (CHCK_REENTRANCE (guard)) +- { +-#if ARCH(Intel) && WSIZE(32) +- return (real_pwrite) (fildes, buf, nbyte, offset); +-#else +- return CALL_REAL (pwrite)(fildes, buf, nbyte, offset); +-#endif +- } ++ return CALL_REAL (pwrite)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt = gethrtime (); +-#if ARCH(Intel) && WSIZE(32) +- ret = (real_pwrite) (fildes, buf, nbyte, offset); +-#else +- ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset); +-#endif ++ ssize_t ret = CALL_REAL (pwrite)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } +- hrtime_t grnt = gethrtime (); +- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); +- iopkt.comm.tsize = sizeof ( IOTrace_packet); +- iopkt.comm.tstamp = grnt; +- iopkt.requested = reqt; +- if (ret >= 0) +- iopkt.iotype = WRITE_TRACE; +- else +- iopkt.iotype = WRITE_TRACE_ERROR; +- iopkt.fd = fildes; +- iopkt.nbyte = ret; +- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); +- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); + POP_REENTRANCE (guard); + return ret; + } + + /*------------------------------------------------------------- pwrite64 */ ++#if !defined(__MUSL_LIBC) + #if ARCH(Intel) && WSIZE(32) + // map interposed symbol versions +-static int +-__collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset); + + SYMVER_ATTRIBUTE (__collector_pwrite64_2_2, pwrite64@@GLIBC_2.2) +-int ++ssize_t + __collector_pwrite64_2_2 (int fildes, const void *buf, size_t nbyte, off64_t offset) + { +- TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_2@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", +- CALL_REAL (pwrite64_2_2), fildes, buf, (long long) nbyte, (long long) offset); +- if (NULL_PTR (pwrite64)) ++ int *guard; ++ if (NULL_PTR (pwrite64_2_2)) + init_io_intf (); +- return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_2), fildes, buf, nbyte, offset); ++ if (CHCK_REENTRANCE (guard)) ++ return CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset); ++ PUSH_REENTRANCE (guard); ++ hrtime_t reqt = gethrtime (); ++ ssize_t ret = CALL_REAL (pwrite64_2_2)(fildes, buf, nbyte, offset); ++ if (RECHCK_REENTRANCE (guard)) ++ { ++ POP_REENTRANCE (guard); ++ return ret; ++ } ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); ++ POP_REENTRANCE (guard); ++ return ret; + } + + SYMVER_ATTRIBUTE (__collector_pwrite64_2_1, pwrite64@GLIBC_2.1) + int + __collector_pwrite64_2_1 (int fildes, const void *buf, size_t nbyte, off64_t offset) + { +- TprintfT (DBG_LTT, "iotrace: __collector_pwrite64_2_1@%p(fildes=%d, buf=%p, nbyte=%lld, offset=%lld)\n", +- CALL_REAL (pwrite64_2_1), fildes, buf, (long long) nbyte, (long long) offset); +- if (NULL_PTR (pwrite64)) ++ int *guard; ++ if (NULL_PTR (pwrite64_2_1)) + init_io_intf (); +- return __collector_pwrite64_symver (CALL_REAL (pwrite64_2_1), fildes, buf, nbyte, offset); ++ if (CHCK_REENTRANCE (guard)) ++ return CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); ++ PUSH_REENTRANCE (guard); ++ hrtime_t reqt = gethrtime (); ++ ssize_t ret = CALL_REAL (pwrite64_2_1)(fildes, buf, nbyte, offset); ++ if (RECHCK_REENTRANCE (guard)) ++ { ++ POP_REENTRANCE (guard); ++ return ret; ++ } ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); ++ POP_REENTRANCE (guard); ++ return ret; + } +- +-static int +-__collector_pwrite64_symver (int(real_pwrite64) (), int fildes, const void *buf, size_t nbyte, off64_t offset) +-{ +-#else /* ^ARCH(Intel) && WSIZE(32) */ ++#endif + + ssize_t + pwrite64 (int fildes, const void *buf, size_t nbyte, off64_t offset) + { +-#endif /* ^ARCH(Intel) && WSIZE(32) */ + int *guard; +- ssize_t ret; +- IOTrace_packet iopkt; + if (NULL_PTR (pwrite64)) + init_io_intf (); + if (CHCK_REENTRANCE (guard)) +- { +-#if ARCH(Intel) && WSIZE(32) +- return (real_pwrite64) (fildes, buf, nbyte, offset); +-#else +- return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); +-#endif +- } ++ return CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); + PUSH_REENTRANCE (guard); + hrtime_t reqt = gethrtime (); +-#if ARCH(Intel) && WSIZE(32) +- ret = (real_pwrite64) (fildes, buf, nbyte, offset); +-#else +- ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); +-#endif ++ ssize_t ret = CALL_REAL (pwrite64)(fildes, buf, nbyte, offset); + if (RECHCK_REENTRANCE (guard)) + { + POP_REENTRANCE (guard); + return ret; + } +- hrtime_t grnt = gethrtime (); +- collector_memset (&iopkt, 0, sizeof ( IOTrace_packet)); +- iopkt.comm.tsize = sizeof ( IOTrace_packet); +- iopkt.comm.tstamp = grnt; +- iopkt.requested = reqt; +- if (ret >= 0) +- iopkt.iotype = WRITE_TRACE; +- else +- iopkt.iotype = WRITE_TRACE_ERROR; +- iopkt.fd = fildes; +- iopkt.nbyte = ret; +- iopkt.comm.frinfo = collector_interface->getFrameInfo (io_hndl, iopkt.comm.tstamp, FRINFO_FROM_STACK, &iopkt); +- collector_interface->writeDataRecord (io_hndl, (Common_packet*) & iopkt); ++ write_io_packet (fildes, ret, reqt, ret >= 0 ? WRITE_TRACE : WRITE_TRACE_ERROR); + POP_REENTRANCE (guard); + return ret; + } ++#endif + + /*------------------------------------------------------------- fgets */ + char* +diff --git a/gprofng/libcollector/jprofile.c b/gprofng/libcollector/jprofile.c +index 9daaa5a267e..52114066726 100644 +--- a/gprofng/libcollector/jprofile.c ++++ b/gprofng/libcollector/jprofile.c +@@ -285,12 +285,6 @@ __collector_jprofile_start_attach (void) + { + jthread thread; + (*jvmti)->GetCurrentThread (jvmti, &thread); +-#ifdef DEBUG +- collector_thread_t tid; +- tid = __collector_thr_self (); +- TprintfT (0, "jprofile attach: AttachCurrentThread: thread: %lu jni_env=%p jthread=%p\n", +- (unsigned long) tid, jni_env, thread); +-#endif /* DEBUG */ + jvmti_VMInit (jvmti, jni_env, thread); + (*jvmti)->GenerateEvents (jvmti, JVMTI_EVENT_COMPILED_METHOD_LOAD); + (*jvmti)->GenerateEvents (jvmti, JVMTI_EVENT_DYNAMIC_CODE_GENERATED); +diff --git a/gprofng/libcollector/libcol_util.c b/gprofng/libcollector/libcol_util.c +index c709b3c5ed1..d682aa0ab29 100644 +--- a/gprofng/libcollector/libcol_util.c ++++ b/gprofng/libcollector/libcol_util.c +@@ -1116,9 +1116,9 @@ __collector_util_init () + /* internal calls for mapping in libcollector call mmap64 */ + ptr = dlsym (libc, "mmap64"); + if (ptr) +- __collector_util_funcs.mmap64 = (void*(*)(void *, size_t, int, int, int, off_t))ptr; ++ __collector_util_funcs.mmap64_ = (void*(*)(void *, size_t, int, int, int, off_t))ptr; + else +- __collector_util_funcs.mmap64 = __collector_util_funcs.mmap; ++ __collector_util_funcs.mmap64_ = __collector_util_funcs.mmap; + + ptr = dlsym (libc, "munmap"); + if (ptr) +@@ -1214,16 +1214,16 @@ __collector_util_init () + #if ARCH(Intel) && WSIZE(32) + ptr = dlvsym (libc, "pwrite64", "GLIBC_2.2"); // it is in /lib/libpthread.so.0 + if (ptr) +- __collector_util_funcs.pwrite64 = (ssize_t (*)())ptr; ++ __collector_util_funcs.pwrite64_ = (ssize_t (*)())ptr; + else + { + Tprintf (DBG_LT0, "libcol_util: WARNING: dlvsym for %s@%s failed. Using dlsym() instead.", "pwrite64", "GLIBC_2.2"); + #endif /* ARCH(Intel) && WSIZE(32) */ + ptr = dlsym (libc, "pwrite64"); + if (ptr) +- __collector_util_funcs.pwrite64 = (ssize_t (*)())ptr; ++ __collector_util_funcs.pwrite64_ = (ssize_t (*)())ptr; + else +- __collector_util_funcs.pwrite64 = __collector_util_funcs.pwrite; ++ __collector_util_funcs.pwrite64_ = __collector_util_funcs.pwrite; + #if ARCH(Intel) && WSIZE(32) + } + #endif /* ARCH(Intel) && WSIZE(32) */ +@@ -1319,6 +1319,15 @@ __collector_util_init () + __collector_util_funcs.getcpuid = __collector_getcpuid; + __collector_util_funcs.memset = collector_memset; + ++ ptr = dlsym (libc, "getcontext"); ++ if (ptr) ++ __collector_util_funcs.getcontext = (int(*)())ptr; ++ else ++ { ++ CALL_UTIL (fprintf)(stderr, "collector_util_init COL_ERROR_UTIL_INIT getcontext: %s\n", dlerror ()); ++ err = COL_ERROR_UTIL_INIT; ++ } ++ + ptr = dlsym (libc, "malloc"); + if (ptr) + __collector_util_funcs.malloc = (void *(*)(size_t))ptr; +diff --git a/gprofng/libcollector/libcol_util.h b/gprofng/libcollector/libcol_util.h +index e13a02ea6d7..c32c76f091b 100644 +--- a/gprofng/libcollector/libcol_util.h ++++ b/gprofng/libcollector/libcol_util.h +@@ -59,12 +59,11 @@ extern int __collector_xml_snprintf (char *s, size_t n, const char *format, ...) + extern int __collector_xml_vsnprintf (char *s, size_t n, const char *format, va_list args); + + /* ------- collector_thread ----------------- */ +-pid_t __collector_gettid (); ++extern pid_t __collector_gettid (); + extern void __collector_ext_gettid_tsd_create_key (); +-#define collector_thread_t pthread_t // not using pid_t, since tid is defined as pthread_t in package structures, and other codes assume this type +-#define statvfs_t struct statvfs +-#define __collector_lwp_self() (collector_thread_t)__collector_gettid() // not using pthread_self() +-#define __collector_thr_self() (collector_thread_t)__collector_gettid() // not using pthread_self() ++typedef pthread_t collector_thread_t; ++#define __collector_lwp_self() ((collector_thread_t) ((unsigned long) __collector_gettid())) ++#define __collector_thr_self() ((collector_thread_t) ((unsigned long) __collector_gettid())) + + /* ------- collector_mutex ----------------- */ + /* +diff --git a/gprofng/libcollector/linetrace.c b/gprofng/libcollector/linetrace.c +index 978c5503e2e..a209308c767 100644 +--- a/gprofng/libcollector/linetrace.c ++++ b/gprofng/libcollector/linetrace.c +@@ -29,6 +29,8 @@ + #include + #include + #include ++#include ++ + + #include "descendants.h" + +@@ -360,7 +362,7 @@ check_fd_dynamic (int fd) + size_t sz = (size_t) 8192; /* one page should suffice */ + if (sz > off) + sz = off; +- char *p = CALL_UTIL (mmap64)((char *) 0, sz, PROT_READ, MAP_PRIVATE, fd, (off64_t) 0); ++ char *p = CALL_UTIL (mmap64_)((char *) 0, sz, PROT_READ, MAP_PRIVATE, fd, (off64_t) 0); + if (p == MAP_FAILED) + { + TprintfT (DBG_LT0, "check_fd_dynamic(): ERROR/WARNING: mmap failed for `%d'\n", fd); +diff --git a/gprofng/libcollector/memmgr.c b/gprofng/libcollector/memmgr.c +index 5ada421f3f4..aa13ea77852 100644 +--- a/gprofng/libcollector/memmgr.c ++++ b/gprofng/libcollector/memmgr.c +@@ -131,7 +131,7 @@ alloc_chunk (unsigned sz, int log) + if (log == 1) + Tprintf (DBG_LT2, "alloc_chunk mapping %u, rounded up from %u\n", (unsigned int) chunksz, sz); + /* mmap64 is only in 32-bits; this call goes to mmap in 64-bits */ +- ptr = (char*) CALL_UTIL (mmap64)(0, chunksz, PROT_READ | PROT_WRITE, ++ ptr = (char*) CALL_UTIL (mmap64_)(0, chunksz, PROT_READ | PROT_WRITE, + MAP_PRIVATE | MAP_ANON, (int) -1, (off64_t) 0); + if (ptr == MAP_FAILED) + { +diff --git a/gprofng/libcollector/mmaptrace.c b/gprofng/libcollector/mmaptrace.c +index ba5c9129f4c..bd299e6f64f 100644 +--- a/gprofng/libcollector/mmaptrace.c ++++ b/gprofng/libcollector/mmaptrace.c +@@ -441,13 +441,9 @@ checksum_mapname (MapInfo* map) + } + + +-#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) +-static void* +-dlopen_searchpath_symver (void*(real_dlopen) (), void* caller_addr, const char* basename, int mode) +-#else + static void* +-dlopen_searchpath (void* caller_addr, const char* basename, int mode) +-#endif ++dlopen_searchpath (void*(real_dlopen) (const char *, int), ++ void *caller_addr, const char *basename, int mode) + { + TprintfT (DBG_LT2, "dlopen_searchpath(%p, %s, %d)\n", caller_addr, basename, mode); + Dl_info dl_info; +@@ -458,7 +454,8 @@ dlopen_searchpath (void* caller_addr, const char* basename, int mode) + } + TprintfT (DBG_LT2, "dladdr(%p): %p fname=%s\n", + caller_addr, dl_info.dli_fbase, dl_info.dli_fname); +- int noload = RTLD_BINDING_MASK | RTLD_NOLOAD; //XXXX why RTLD_BINDING_MASK? ++ int noload = RTLD_LAZY | RTLD_NOW | RTLD_NOLOAD; ++ void *caller_hndl = NULL; + #define WORKAROUND_RTLD_BUG 1 + #ifdef WORKAROUND_RTLD_BUG + // A dynamic linker dlopen bug can result in corruption/closure of open streams +@@ -470,29 +467,20 @@ dlopen_searchpath (void* caller_addr, const char* basename, int mode) + #endif + const char* tmp_path = + (dl_info.dli_fbase == (void*) MAINBASE) ? NULL : dl_info.dli_fname; +- void* caller_hndl = NULL; +-#if ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) +- caller_hndl = (real_dlopen) (tmp_path, noload); +-#else +- caller_hndl = CALL_REAL (dlopen)(tmp_path, noload); +-#endif ++ caller_hndl = real_dlopen (tmp_path, noload); + + #else //XXXX workaround should be removed once linker patches are all available + +- void* caller_hndl = NULL; +-#if (ARCH(Intel) && WSIZE(32) || ARCH(SPARC) +- caller_hndl = (real_dlopen) (dl_info.dli_fname, noload); +-#else +- caller_hndl = CALL_REAL (dlopen)(dl_info.dli_fname, noload); +-#endif ++ caller_hndl = real_dlopen (dl_info.dli_fname, noload); + + #endif //XXXX workaround should be removed once linker patches are all available + + if (!caller_hndl) + { + TprintfT (0, "ERROR: dlopen(%s,NOLOAD): %s\n", dl_info.dli_fname, dlerror ()); +- return 0; ++ return NULL; + } ++#if !defined(__MUSL_LIBC) + Dl_serinfo _info, *info = &_info; + Dl_serpath *path; + +@@ -546,7 +534,7 @@ dlopen_searchpath (void* caller_addr, const char* basename, int mode) + I have already confirmed with our user that the workaround + is working with his real application. Additionally, + the dlopen_searchpath() function is called only by the +- libcorrector init() function when the experiment is started. ++ libcollector init() function when the experiment is started. + Therefore, allocating some extra bytes on the stack which + is local to this routine is harmless. + */ +@@ -575,7 +563,8 @@ dlopen_searchpath (void* caller_addr, const char* basename, int mode) + if (ret) + return ret; // success! + } +- return 0; ++#endif ++ return NULL; + } + + static void +@@ -1550,40 +1539,9 @@ munmap (void *start, size_t length) + + + /*------------------------------------------------------------- dlopen */ +-// map interposed symbol versions +-#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) +- +-static void * +-__collector_dlopen_symver (void*(real_dlopen) (), void *caller, const char *pathname, int mode); +- +-SYMVER_ATTRIBUTE (__collector_dlopen_2_1, dlopen@@GLIBC_2.1) +-void * +-__collector_dlopen_2_1 (const char *pathname, int mode) +-{ +- if (NULL_PTR (dlopen)) +- init_mmap_intf (); +- void *caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion +- return __collector_dlopen_symver (CALL_REAL (dlopen_2_1), caller, pathname, mode); +-} +- +-SYMVER_ATTRIBUTE (__collector_dlopen_2_0, dlopen@GLIBC_2.0) +-void * +-__collector_dlopen_2_0 (const char *pathname, int mode) +-{ +- if (NULL_PTR (dlopen)) +- init_mmap_intf (); +- void* caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion +- return __collector_dlopen_symver (CALL_REAL (dlopen_2_0), caller, pathname, mode); +-} +-#endif +- +-#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) + static void * +-__collector_dlopen_symver (void*(real_dlopen) (), void *caller, const char *pathname, int mode) +-#else +-void * +-dlopen (const char *pathname, int mode) +-#endif ++__collector_dlopen_symver (void*(real_dlopen) (const char *, int), ++ void *caller, const char *pathname, int mode) + { + const char * real_pathname = pathname; + char new_pathname[MAXPATHLEN]; +@@ -1595,10 +1553,6 @@ dlopen (const char *pathname, int mode) + origin_offset = 10; + if (origin_offset) + { +-#if ! ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) +- // 'caller' is not passed as an argument +- void * caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion +-#endif + Dl_info dl_info; + if (caller && dladdr (caller, &dl_info) != 0) + { +@@ -1619,37 +1573,18 @@ dlopen (const char *pathname, int mode) + init_mmap_intf (); + TprintfT (DBG_LT2, "libcollector.dlopen(%s,%d) interposing\n", + pathname ? pathname : "", mode); +- void* ret = NULL; ++ void *ret = NULL; + + // set guard for duration of handling dlopen, since want to ensure + // new mappings are resolved after the actual dlopen has occurred + PUSH_REENTRANCE; + hrtime_t hrt = GETRELTIME (); + +- if (real_pathname && !__collector_strchr (real_pathname, '/')) +- { // got an unqualified name +- // get caller and use its searchpath +-#if ! ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) +- void* caller = __builtin_return_address (0); // must be called inside dlopen +-#endif +- if (caller) +- { +-#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) +- ret = dlopen_searchpath_symver (real_dlopen, caller, real_pathname, mode); +-#else +- ret = dlopen_searchpath (caller, real_pathname, mode); +-#endif +- } +- } ++ if (caller && real_pathname && !__collector_strchr (real_pathname, '/')) ++ ret = dlopen_searchpath (real_dlopen, caller, real_pathname, mode); + + if (!ret) +- { +-#if (ARCH(Intel) && WSIZE(32)) || ARCH(SPARC) +- ret = (real_dlopen) (real_pathname, mode); +-#else +- ret = CALL_REAL (dlopen)(real_pathname, mode); +-#endif +- } ++ ret = real_dlopen (real_pathname, mode); + TprintfT (DBG_LT2, "libcollector -- dlopen(%s) returning %p\n", pathname, ret); + + /* Don't call update if dlopen failed: preserve dlerror() */ +@@ -1660,6 +1595,39 @@ dlopen (const char *pathname, int mode) + return ret; + } + ++void * ++dlopen (const char *pathname, int mode) ++{ ++ if (NULL_PTR (dlopen)) ++ init_mmap_intf (); ++ void* caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion ++ return __collector_dlopen_symver (CALL_REAL (dlopen), caller, pathname, mode); ++} ++ ++#if !defined(__MUSL_LIBC) && ((ARCH(Intel) && WSIZE(32)) || ARCH(SPARC)) ++// map interposed symbol versions ++ ++SYMVER_ATTRIBUTE (__collector_dlopen_2_1, dlopen@@GLIBC_2.1) ++void * ++__collector_dlopen_2_1 (const char *pathname, int mode) ++{ ++ if (NULL_PTR (dlopen_2_1)) ++ init_mmap_intf (); ++ void *caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion ++ return __collector_dlopen_symver (CALL_REAL (dlopen_2_1), caller, pathname, mode); ++} ++ ++SYMVER_ATTRIBUTE (__collector_dlopen_2_0, dlopen@GLIBC_2.0) ++void * ++__collector_dlopen_2_0 (const char *pathname, int mode) ++{ ++ if (NULL_PTR (dlopen_2_0)) ++ init_mmap_intf (); ++ void* caller = __builtin_return_address (0); // must be called inside dlopen first layer interpostion ++ return __collector_dlopen_symver (CALL_REAL (dlopen_2_0), caller, pathname, mode); ++} ++#endif ++ + /*------------------------------------------------------------- dlclose */ + int + dlclose (void *handle) +diff --git a/gprofng/libcollector/profile.c b/gprofng/libcollector/profile.c +index 996d3f09198..ee9fb7d3b0c 100644 +--- a/gprofng/libcollector/profile.c ++++ b/gprofng/libcollector/profile.c +@@ -268,7 +268,7 @@ __collector_ext_profile_handler (siginfo_t *info, ucontext_t *context) + /* assume this case is rare, and accept overhead of creating dummy_uc */ + TprintfT (0, "collector_profile_handler: ERROR: got NULL context!\n"); + context = &uctxmem; +- getcontext (context); /* initialize dummy context */ ++ CALL_UTIL (getcontext) (context); /* initialize dummy context */ + SETFUNCTIONCONTEXT (context, &__collector_lost_profile_context); + } + ClockPacket pckt; +diff --git a/gprofng/libcollector/synctrace.c b/gprofng/libcollector/synctrace.c +index 492ef9993f7..d48aeaa2d2d 100644 +--- a/gprofng/libcollector/synctrace.c ++++ b/gprofng/libcollector/synctrace.c +@@ -32,10 +32,9 @@ + #include + + #include "gp-defs.h" +-#include "collector_module.h" ++#include "collector.h" + #include "gp-experiment.h" + #include "data_pckts.h" +-#include "i18n.h" + #include "tsd.h" + #include "cc_libcollector.h" + +diff --git a/gprofng/libcollector/unwind.c b/gprofng/libcollector/unwind.c +index f8e11823c81..009b5ab8456 100644 +--- a/gprofng/libcollector/unwind.c ++++ b/gprofng/libcollector/unwind.c +@@ -232,7 +232,7 @@ memory_error_func (int status ATTRIBUTE_UNUSED, bfd_vma addr ATTRIBUTE_UNUSED, + + #elif ARCH(Aarch64) + #define FILL_CONTEXT(context) \ +- { getcontext(context); \ ++ { CALL_UTIL (getcontext) (context); \ + context->uc_mcontext.sp = (__u64) __builtin_frame_address(0); \ + } + +diff --git a/gprofng/src/Experiment.cc b/gprofng/src/Experiment.cc +index c797724af07..98aae9714ac 100644 +--- a/gprofng/src/Experiment.cc ++++ b/gprofng/src/Experiment.cc +@@ -6466,7 +6466,7 @@ int + Experiment::copy_file_to_archive (const char *name, const char *aname, int hide_msg) + { + errno = 0; +- int fd_w = open64 (aname, O_WRONLY | O_CREAT | O_EXCL, 0644); ++ int fd_w = ::open64 (aname, O_WRONLY | O_CREAT | O_EXCL, 0644); + if (fd_w == -1) + { + if (errno == EEXIST) +@@ -6484,7 +6484,7 @@ Experiment::copy_file_to_archive (const char *name, const char *aname, int hide_ + return 1; + } + +- int fd_r = open64 (name, O_RDONLY); ++ int fd_r = ::open64 (name, O_RDONLY); + if (fd_r == -1) + { + fprintf (stderr, GTXT ("er_archive: unable to open `%s': %s\n"), +diff --git a/gprofng/src/Print.cc b/gprofng/src/Print.cc +index d415d591e1e..03932530956 100644 +--- a/gprofng/src/Print.cc ++++ b/gprofng/src/Print.cc +@@ -2209,14 +2209,14 @@ print_anno_file (char *name, const char *sel, const char *srcFile, + { + fitem = func->getDefSrc (); + found = (func->line_first > 0) +- && strcmp (basename (srcFile), +- basename (fitem->get_name ())) == 0; ++ && strcmp (get_basename (srcFile), ++ get_basename (fitem->get_name ())) == 0; + } + else + { + Vec_loop (SourceFile*, sources, index, fitem) + { +- if (strcmp (basename (srcFile), basename (fitem->get_name ())) == 0) ++ if (strcmp (get_basename (srcFile), get_basename (fitem->get_name ())) == 0) + { + found = true; + break; +diff --git a/gprofng/src/collector_module.h b/gprofng/src/collector_module.h +index f608dab5831..6cf53d5b27f 100644 +--- a/gprofng/src/collector_module.h ++++ b/gprofng/src/collector_module.h +@@ -25,6 +25,7 @@ + #include + #include + #include ++#include + #include + + #include "gp-defs.h" +@@ -55,6 +56,7 @@ typedef struct CollectorUtilFuncs + int (*fprintf)(FILE *stream, const char *format, ...); + void (*free)(void *ptr); + int (*fstat)(int fd, struct stat *buf); ++ int (*getcontext)(ucontext_t *ucp); + int (*getcpuid)(); + char *(*getcwd)(char *buf, size_t size); + char *(*getenv)(const char *name); +@@ -66,7 +68,7 @@ typedef struct CollectorUtilFuncs + int (*mkdir)(); + time_t (*mktime)(struct tm *timeptr); + void *(*mmap)(void *, size_t, int, int, int, off_t); +- void *(*mmap64)(); ++ void *(*mmap64_)(); + int (*munmap)(); + int (*open)(const char *, int, ...); + int (*open_bare)(const char *, int, ...); +@@ -75,7 +77,7 @@ typedef struct CollectorUtilFuncs + FILE *(*popen)(const char *command, const char *mode); + int (*putenv)(char *string); + ssize_t (*pwrite)(); +- ssize_t (*pwrite64)(); ++ ssize_t (*pwrite64_)(); + ssize_t (*read)(); + int (*setenv)(const char *name, const char *value, int overwrite); + int (*sigfillset)(sigset_t *set); +-- +2.37.2 + diff --git a/tools/7z/patches/0001-C-Threads-use-pthread_setaffinity-portable-variant.patch b/tools/7z/patches/0001-C-Threads-use-pthread_setaffinity-portable-variant.patch new file mode 100644 index 00000000000000..b2cee4be1e9411 --- /dev/null +++ b/tools/7z/patches/0001-C-Threads-use-pthread_setaffinity-portable-variant.patch @@ -0,0 +1,66 @@ +From 585d5fe3b20213215cac4dc5a1a2b336f4a7a2a9 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Wed, 11 Jan 2023 01:06:43 +0100 +Subject: [PATCH 1/2] C: Threads: use pthread_setaffinity portable variant + +Musl libc doesn't have pthread_attr_setaffinity_np. Use the +pthread_setaffinity_np variant that is more portable and compatible with +glibc and musl libc. + +Signed-off-by: Christian Marangi +--- + C/Threads.c | 11 +++++++---- + 1 file changed, 7 insertions(+), 4 deletions(-) + +diff --git a/C/Threads.c b/C/Threads.c +index 6eb45b08..a6abe4b2 100644 +--- a/C/Threads.c ++++ b/C/Threads.c +@@ -234,10 +234,11 @@ WRes Thread_Create_With_CpuSet(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, + + if (!ret) + { ++ /* + if (cpuSet) + { + #ifdef _7ZIP_AFFINITY_SUPPORTED +- ++ */ + /* + printf("\n affinity :"); + unsigned i; +@@ -255,26 +256,28 @@ WRes Thread_Create_With_CpuSet(CThread *p, THREAD_FUNC_TYPE func, LPVOID param, + } + printf("\n"); + */ +- ++ /* + // ret2 = + pthread_attr_setaffinity_np(&attr, sizeof(*cpuSet), cpuSet); + // if (ret2) ret = ret2; + #endif + } ++ */ + + ret = pthread_create(&p->_tid, &attr, func, param); + + if (!ret) + { + p->_created = 1; +- /* + if (cpuSet) + { ++ #ifdef _7ZIP_AFFINITY_SUPPORTED ++ + // ret2 = + pthread_setaffinity_np(p->_tid, sizeof(*cpuSet), cpuSet); + // if (ret2) ret = ret2; ++ #endif + } +- */ + } + } + // ret2 = +-- +2.37.2 + diff --git a/tools/7z/patches/0002-C-Threads-define-_GNU_SOURCE-in-Threads.h.patch b/tools/7z/patches/0002-C-Threads-define-_GNU_SOURCE-in-Threads.h.patch new file mode 100644 index 00000000000000..ad313add391e0d --- /dev/null +++ b/tools/7z/patches/0002-C-Threads-define-_GNU_SOURCE-in-Threads.h.patch @@ -0,0 +1,56 @@ +From 8bdad09663ee40ee8566ed04991b8a31d6c6c8c3 Mon Sep 17 00:00:00 2001 +From: Christian Marangi +Date: Wed, 11 Jan 2023 01:17:37 +0100 +Subject: [PATCH 2/2] C: Threads: define _GNU_SOURCE in Threads.h + +Move _GNU_SOURCE from Threads.c to Threads.h as it's also used by MtDec.h and +cause compilation error for unknown type name 'cpu_set_t' with musl +libc. + +Signed-off-by: Christian Marangi +--- + C/Threads.c | 12 ++++++------ + C/Threads.h | 4 +++- + 2 files changed, 9 insertions(+), 7 deletions(-) + +diff --git a/C/Threads.c b/C/Threads.c +index a6abe4b2..0f58c3cf 100644 +--- a/C/Threads.c ++++ b/C/Threads.c +@@ -192,12 +192,12 @@ WRes CriticalSection_Init(CCriticalSection *p) + + // ---------- POSIX ---------- + +-#ifndef __APPLE__ +-#ifndef _7ZIP_AFFINITY_DISABLE +-// _GNU_SOURCE can be required for pthread_setaffinity_np() / CPU_ZERO / CPU_SET +-#define _GNU_SOURCE +-#endif +-#endif ++// #ifndef __APPLE__ ++// #ifndef _7ZIP_AFFINITY_DISABLE ++// // _GNU_SOURCE can be required for pthread_setaffinity_np() / CPU_ZERO / CPU_SET ++// #define _GNU_SOURCE ++// #endif ++// #endif + + #include "Threads.h" + +diff --git a/C/Threads.h b/C/Threads.h +index e9493aff..92d8e50b 100644 +--- a/C/Threads.h ++++ b/C/Threads.h +@@ -13,7 +13,9 @@ + #ifndef _7ZIP_AFFINITY_DISABLE + #define _7ZIP_AFFINITY_SUPPORTED + // #pragma message(" ==== _7ZIP_AFFINITY_SUPPORTED") +-// #define _GNU_SOURCE ++#ifndef _GNU_SOURCE ++#define _GNU_SOURCE ++#endif + #endif + #endif + #endif +-- +2.37.2 +