From 27d31f33cdac30302b8413bfad0efb949af974e4 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 16 Jun 2025 15:45:35 +0200 Subject: [PATCH 1/6] Add UBSan to GHA build --- .github/workflows/build.yml | 8 ++++ .github/workflows/reusable-ubsan.yml | 71 ++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 .github/workflows/reusable-ubsan.yml diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 54ebc914b46821..c6171571857af6 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -527,6 +527,14 @@ jobs: config_hash: ${{ needs.build-context.outputs.config-hash }} free-threading: ${{ matrix.free-threading }} + build-ubsan: + name: Undefined behavior sanitizer + needs: build-context + if: needs.build-context.outputs.run-tests == 'true' + uses: ./.github/workflows/reusable-ubsan.yml + with: + config_hash: ${{ needs.build-context.outputs.config-hash }} + cross-build-linux: name: Cross build Linux runs-on: ubuntu-latest diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml new file mode 100644 index 00000000000000..9daea7caf5352d --- /dev/null +++ b/.github/workflows/reusable-ubsan.yml @@ -0,0 +1,71 @@ +name: Reusable Undefined Behavior Sanitizer + +on: + workflow_call: + inputs: + config_hash: + required: true + type: string + +env: + FORCE_COLOR: 1 + +jobs: + build-ubsan-reusable: + name: 'Undefined Behavior sanitizer' + runs-on: ubuntu-24.04 + timeout-minutes: 60 + steps: + - uses: actions/checkout@v4 + with: + persist-credentials: false + - name: Runner image version + run: echo "IMAGE_OS_VERSION=${ImageOS}-${ImageVersion}" >> "$GITHUB_ENV" + - name: Restore config.cache + uses: actions/cache@v4 + with: + path: config.cache + key: ${{ github.job }}-${{ env.IMAGE_OS_VERSION }}-${{ inputs.config_hash }} + - name: Install dependencies + run: | + sudo ./.github/workflows/posix-deps-apt.sh + # Install clang-20 + wget https://apt.llvm.org/llvm.sh + chmod +x llvm.sh + sudo ./llvm.sh 20 + - name: UBSAN option setup + run: | + echo "UBSAN_OPTIONS=log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" + echo "CC=clang" >> "$GITHUB_ENV" + echo "CXX=clang++" >> "$GITHUB_ENV" + - name: Add ccache to PATH + run: | + echo "PATH=/usr/lib/ccache:$PATH" >> "$GITHUB_ENV" + - name: Configure ccache action + uses: hendrikmuhs/ccache-action@v1.2 + with: + save: ${{ github.event_name == 'push' }} + max-size: "200M" + - name: Configure CPython + run: >- + ./configure + --config-cache + --with-undefined-behavior-sanitizer + --with-pydebug + - name: Build CPython + run: make -j4 + - name: Display build info + run: make pythoninfo + - name: Tests + run: ./python -m test -j4 + - name: Display TSAN logs + if: always() + run: find "${GITHUB_WORKSPACE}" -name 'ubsan_log.*' | xargs head -n 1000 + - name: Archive TSAN logs + if: always() + uses: actions/upload-artifact@v4 + with: + name: >- + tsan-logs + path: tsan_log.* + if-no-files-found: ignore From b38afc97b727a3f633d6c8041f17c12bf366c216 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Mon, 16 Jun 2025 16:18:00 +0200 Subject: [PATCH 2/6] Don't recover --- .github/workflows/reusable-ubsan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml index 9daea7caf5352d..b90906c0fca9f8 100644 --- a/.github/workflows/reusable-ubsan.yml +++ b/.github/workflows/reusable-ubsan.yml @@ -36,7 +36,7 @@ jobs: - name: UBSAN option setup run: | echo "UBSAN_OPTIONS=log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" - echo "CC=clang" >> "$GITHUB_ENV" + echo "CC=clang -fno-sanitize-recover=all" >> "$GITHUB_ENV" echo "CXX=clang++" >> "$GITHUB_ENV" - name: Add ccache to PATH run: | From 5bc492b854c6cad238dd21572cf3496e65ae63ff Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 17 Jun 2025 08:46:11 +0200 Subject: [PATCH 3/6] UBSan, not TSan --- .github/workflows/reusable-ubsan.yml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml index b90906c0fca9f8..3c64d22fa1a516 100644 --- a/.github/workflows/reusable-ubsan.yml +++ b/.github/workflows/reusable-ubsan.yml @@ -58,14 +58,14 @@ jobs: run: make pythoninfo - name: Tests run: ./python -m test -j4 - - name: Display TSAN logs + - name: Display UBSAN logs if: always() run: find "${GITHUB_WORKSPACE}" -name 'ubsan_log.*' | xargs head -n 1000 - - name: Archive TSAN logs + - name: Archive UBSAN logs if: always() uses: actions/upload-artifact@v4 with: name: >- - tsan-logs - path: tsan_log.* + ubsan-logs + path: ubsan_log.* if-no-files-found: ignore From 53d49aae089e588b145f49a5ceb12f49a2f73d89 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 17 Jun 2025 08:46:55 +0200 Subject: [PATCH 4/6] Use UBSAN_OPTIONS --- .github/workflows/reusable-ubsan.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml index 3c64d22fa1a516..f8fe7b324de34e 100644 --- a/.github/workflows/reusable-ubsan.yml +++ b/.github/workflows/reusable-ubsan.yml @@ -35,8 +35,8 @@ jobs: sudo ./llvm.sh 20 - name: UBSAN option setup run: | - echo "UBSAN_OPTIONS=log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" - echo "CC=clang -fno-sanitize-recover=all" >> "$GITHUB_ENV" + echo "UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1:log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" + echo "CC=clang" >> "$GITHUB_ENV" echo "CXX=clang++" >> "$GITHUB_ENV" - name: Add ccache to PATH run: | From 34b644ceac59dd0a536305e6fc76f70a91cb9df5 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 17 Jun 2025 11:12:22 +0200 Subject: [PATCH 5/6] Activate UBSan log after configuration --- .github/workflows/reusable-ubsan.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml index f8fe7b324de34e..75dabb80b2d2cf 100644 --- a/.github/workflows/reusable-ubsan.yml +++ b/.github/workflows/reusable-ubsan.yml @@ -35,7 +35,7 @@ jobs: sudo ./llvm.sh 20 - name: UBSAN option setup run: | - echo "UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1:log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" + echo "UBSAN_OPTIONS=halt_on_error=1:abort_on_error=1:print_summary=1:print_stacktrace=1" >> "$GITHUB_ENV" echo "CC=clang" >> "$GITHUB_ENV" echo "CXX=clang++" >> "$GITHUB_ENV" - name: Add ccache to PATH @@ -52,6 +52,9 @@ jobs: --config-cache --with-undefined-behavior-sanitizer --with-pydebug + - name: Set up UBSAN log after configuration + run: | + echo "UBSAN_OPTIONS=${UBSAN_OPTIONS}:log_path=${GITHUB_WORKSPACE}/ubsan_log" >> "$GITHUB_ENV" - name: Build CPython run: make -j4 - name: Display build info From 57678461cc89cb5234d8147b1c8a4230f26f1510 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Tue, 17 Jun 2025 14:12:23 +0200 Subject: [PATCH 6/6] Update .github/workflows/reusable-ubsan.yml Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- .github/workflows/reusable-ubsan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/reusable-ubsan.yml b/.github/workflows/reusable-ubsan.yml index 75dabb80b2d2cf..cf93932f13b827 100644 --- a/.github/workflows/reusable-ubsan.yml +++ b/.github/workflows/reusable-ubsan.yml @@ -12,7 +12,7 @@ env: jobs: build-ubsan-reusable: - name: 'Undefined Behavior sanitizer' + name: 'Undefined behavior sanitizer' runs-on: ubuntu-24.04 timeout-minutes: 60 steps: