|
| 1 | +# SPDX-FileCopyrightText: 2025 scc <scc@scc.tw> |
| 2 | +# SPDX-License-Identifier: CC0-1.0 |
| 3 | +# Sanitizer verification workflow |
| 4 | +# Runs after build-base workflow completes successfully. |
| 5 | + |
| 6 | +name: Sanitizers Availability |
| 7 | + |
| 8 | +on: |
| 9 | + workflow_run: |
| 10 | + workflows: ["Build Images from packages"] |
| 11 | + types: |
| 12 | + - completed |
| 13 | + |
| 14 | +jobs: |
| 15 | + sanitizers: |
| 16 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 17 | + runs-on: ubuntu-latest |
| 18 | + strategy: |
| 19 | + fail-fast: false |
| 20 | + matrix: |
| 21 | + image: [clang14, clang15, clang16, clang17, clang18, clang19, clang20, clang21, clang22] |
| 22 | + container: |
| 23 | + image: ghcr.io/${{ github.repository }}/${{ matrix.image }} |
| 24 | + steps: |
| 25 | + - name: Print clang version |
| 26 | + run: clang++ --version |
| 27 | + |
| 28 | + - name: Show resource dir and list sanitizer libs |
| 29 | + shell: bash |
| 30 | + run: | |
| 31 | + set -euo pipefail |
| 32 | + RD="$(clang++ -print-resource-dir)" || exit 1 |
| 33 | + echo "Resource dir: $RD" |
| 34 | + ls -1 "$RD/lib/linux" | grep -E 'asan|ubsan' || (echo 'Expected sanitizer runtimes missing' >&2; exit 1) |
| 35 | +
|
| 36 | + - name: Compile & link trivial program with ASan |
| 37 | + shell: bash |
| 38 | + run: | |
| 39 | + set -euo pipefail |
| 40 | + echo 'int main(){return 0;}' > t.cpp |
| 41 | + clang++ -O0 -g -fsanitize=address t.cpp -o t_asan |
| 42 | + ./t_asan |
| 43 | +
|
| 44 | + - name: Compile & link trivial program with combined ASan+UBSan |
| 45 | + shell: bash |
| 46 | + run: | |
| 47 | + set -euo pipefail |
| 48 | + echo 'int f(int*x){ return *x; } int main(){ int *p=nullptr; if(p) return f(p); return 0; }' > u.cpp |
| 49 | + clang++ -O0 -g -fsanitize=address,undefined u.cpp -o t_combined |
| 50 | + ./t_combined |
| 51 | +
|
| 52 | + - name: Negative test (expect failure when forcing ODR violation under UBSan) |
| 53 | + shell: bash |
| 54 | + run: | |
| 55 | + set -euo pipefail |
| 56 | + cat > o.cpp <<'EOF' |
| 57 | + int dup(); |
| 58 | + int main(){ return dup(); } |
| 59 | + EOF |
| 60 | + cat > p.cpp <<'EOF' |
| 61 | + int dup(){ return 0; } |
| 62 | + int dup(){ return 1; } |
| 63 | + EOF |
| 64 | + if clang++ -fsanitize=undefined o.cpp p.cpp -o odr 2>err.log; then |
| 65 | + echo 'Unexpected success; check if compiler failed to diagnose ODR.' |
| 66 | + else |
| 67 | + echo 'Compiler emitted diagnostics for ODR as expected.' |
| 68 | + fi |
| 69 | +
|
| 70 | + gcc-sanitizers: |
| 71 | + if: ${{ github.event.workflow_run.conclusion == 'success' }} |
| 72 | + needs: sanitizers |
| 73 | + runs-on: ubuntu-latest |
| 74 | + strategy: |
| 75 | + fail-fast: false |
| 76 | + matrix: |
| 77 | + image: [gcc9, gcc10, gcc11, gcc12, gcc13, gcc14] |
| 78 | + container: |
| 79 | + image: ghcr.io/${{ github.repository }}/${{ matrix.image }} |
| 80 | + steps: |
| 81 | + - name: Print gcc version |
| 82 | + run: gcc --version |
| 83 | + |
| 84 | + - name: Locate sanitizer libraries |
| 85 | + shell: bash |
| 86 | + run: | |
| 87 | + set -euo pipefail |
| 88 | + ASAN=$(gcc -print-file-name=libasan.so) |
| 89 | + UBSAN=$(gcc -print-file-name=libubsan.so) |
| 90 | + echo "libasan: $ASAN"; [ -f "$ASAN" ] |
| 91 | + echo "libubsan: $UBSAN"; [ -f "$UBSAN" ] |
| 92 | +
|
| 93 | + - name: Compile & link trivial program with ASan (GCC) |
| 94 | + shell: bash |
| 95 | + run: | |
| 96 | + set -euo pipefail |
| 97 | + echo 'int main(){return 0;}' > g.cpp |
| 98 | + g++ -O0 -g -fsanitize=address g.cpp -o g_asan |
| 99 | + ./g_asan |
| 100 | +
|
| 101 | + - name: Compile & link trivial program with ASan+UBSan (GCC) |
| 102 | + shell: bash |
| 103 | + run: | |
| 104 | + set -euo pipefail |
| 105 | + echo 'int f(int*x){ return *x; } int main(){ int *p=nullptr; if(p) return f(p); return 0; }' > gu.cpp |
| 106 | + g++ -O0 -g -fsanitize=address,undefined gu.cpp -o g_combined |
| 107 | + ./g_combined |
0 commit comments