Skip to content

Commit a7cf115

Browse files
scc-twscc
andauthored
Add libclang-rt and sanitizer verification workflow (#6)
* Add libclang-rt-${LLVM_VERSION}-dev to Dockerfiles for Clang versions 14-22 * Add sanitizer verification workflow for Clang and GCC * chore: Update license information in sanitizer verification workflow * chore: fix shell's pipefail command not found --------- Co-authored-by: scc <scc@sccdeMacBook-Air.local>
1 parent a1fa3cf commit a7cf115

File tree

10 files changed

+116
-0
lines changed

10 files changed

+116
-0
lines changed

.github/workflows/sanitizers.yml

Lines changed: 107 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
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

Dockerfile.clang14

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
clang-format-${LLVM_VERSION} \
1515
libc++-${LLVM_VERSION}-dev \
1616
libc++abi-${LLVM_VERSION}-dev \
17+
libclang-rt-${LLVM_VERSION}-dev \
1718
&& \
1819
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
1920
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \

Dockerfile.clang15

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
clang-format-${LLVM_VERSION} \
1515
libc++-${LLVM_VERSION}-dev \
1616
libc++abi-${LLVM_VERSION}-dev \
17+
libclang-rt-${LLVM_VERSION}-dev \
1718
&& \
1819
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
1920
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \

Dockerfile.clang16

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
clang-format-${LLVM_VERSION} \
1515
libc++-${LLVM_VERSION}-dev \
1616
libc++abi-${LLVM_VERSION}-dev \
17+
libclang-rt-${LLVM_VERSION}-dev \
1718
&& \
1819
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
1920
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \

Dockerfile.clang17

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
clang-format-${LLVM_VERSION} \
1515
libc++-${LLVM_VERSION}-dev \
1616
libc++abi-${LLVM_VERSION}-dev \
17+
libclang-rt-${LLVM_VERSION}-dev \
1718
&& \
1819
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
1920
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \

Dockerfile.clang18

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ RUN apt-get install -y --no-install-recommends \
1414
clang-format-${LLVM_VERSION} \
1515
libc++-${LLVM_VERSION}-dev \
1616
libc++abi-${LLVM_VERSION}-dev \
17+
libclang-rt-${LLVM_VERSION}-dev \
1718
&& \
1819
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
1920
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \

Dockerfile.clang19

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
1717
clang-format-${LLVM_VERSION} \
1818
libc++-${LLVM_VERSION}-dev \
1919
libc++abi-${LLVM_VERSION}-dev && \
20+
apt-get install -y --no-install-recommends libclang-rt-${LLVM_VERSION}-dev && \
2021
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
2122
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \
2223
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_VERSION} ${LLVM_VERSION}0 && \

Dockerfile.clang20

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
1717
clang-format-${LLVM_VERSION} \
1818
libc++-${LLVM_VERSION}-dev \
1919
libc++abi-${LLVM_VERSION}-dev && \
20+
apt-get install -y --no-install-recommends libclang-rt-${LLVM_VERSION}-dev && \
2021
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
2122
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \
2223
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_VERSION} ${LLVM_VERSION}0 && \

Dockerfile.clang21

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
1717
clang-format-${LLVM_VERSION} \
1818
libc++-${LLVM_VERSION}-dev \
1919
libc++abi-${LLVM_VERSION}-dev && \
20+
apt-get install -y --no-install-recommends libclang-rt-${LLVM_VERSION}-dev && \
2021
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
2122
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \
2223
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_VERSION} ${LLVM_VERSION}0 && \

Dockerfile.clang22

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUN wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key|apt-key add - && \
1717
clang-format-${LLVM_VERSION} \
1818
libc++-${LLVM_VERSION}-dev \
1919
libc++abi-${LLVM_VERSION}-dev && \
20+
apt-get install -y --no-install-recommends libclang-rt-${LLVM_VERSION}-dev && \
2021
update-alternatives --install /usr/bin/clang clang /usr/bin/clang-${LLVM_VERSION} ${LLVM_VERSION}0 \
2122
--slave /usr/bin/clang++ clang++ /usr/bin/clang++-${LLVM_VERSION} && \
2223
update-alternatives --install /usr/bin/clang-tidy clang-tidy /usr/bin/clang-tidy-${LLVM_VERSION} ${LLVM_VERSION}0 && \

0 commit comments

Comments
 (0)