Skip to content

Commit 9873eb7

Browse files
committed
add tsan-enabled builds
The gcc implementation of tsan currently doesn't support atomic_thread_fence so we leave it disabled in the CI and instead only test clang builds. Signed-off-by: Christian Mazakas <[email protected]>
1 parent 03b5110 commit 9873eb7

File tree

5 files changed

+57
-1
lines changed

5 files changed

+57
-1
lines changed

.github/workflows/ci.yml

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ jobs:
4646
cc: x86_64-linux-gnu-gcc
4747
cxx: x86_64-linux-gnu-g++
4848
sanitize: 0
49+
tsan: 0
4950

5051
# x86-64 gcc asan
5152
- arch: x86_64
@@ -54,6 +55,7 @@ jobs:
5455
cc: x86_64-linux-gnu-gcc
5556
cxx: x86_64-linux-gnu-g++
5657
sanitize: 1
58+
tsan: 0
5759

5860
# x86-64 clang asan
5961
- arch: x86_64
@@ -62,6 +64,16 @@ jobs:
6264
cc: clang
6365
cxx: clang++
6466
sanitize: 1
67+
tsan: 0
68+
69+
# x86-64 clang tsan
70+
- arch: x86_64
71+
cc_pkg: clang
72+
cxx_pkg: clang
73+
cc: clang
74+
cxx: clang++
75+
sanitize: 0
76+
tsan: 1
6577

6678
# x86-64 clang
6779
- arch: x86_64
@@ -72,6 +84,7 @@ jobs:
7284
liburing_extra_flags: -Wshorten-64-to-32
7385
extra_flags: -Wmissing-prototypes -Wstrict-prototypes -Wunreachable-code-loop-increment -Wunreachable-code -Wmissing-variable-declarations -Wextra-semi-stmt
7486
sanitize: 0
87+
tsan: 0
7588

7689
# x86 (32-bit) gcc
7790
- arch: i686
@@ -80,6 +93,7 @@ jobs:
8093
cc: i686-linux-gnu-gcc
8194
cxx: i686-linux-gnu-g++
8295
sanitize: 0
96+
tsan: 0
8397

8498
# aarch64 gcc
8599
- arch: aarch64
@@ -88,6 +102,7 @@ jobs:
88102
cc: aarch64-linux-gnu-gcc
89103
cxx: aarch64-linux-gnu-g++
90104
sanitize: 0
105+
tsan: 0
91106

92107
# arm (32-bit) gcc
93108
- arch: arm
@@ -96,6 +111,7 @@ jobs:
96111
cc: arm-linux-gnueabi-gcc
97112
cxx: arm-linux-gnueabi-g++
98113
sanitize: 0
114+
tsan: 0
99115

100116
# riscv64
101117
- arch: riscv64
@@ -104,6 +120,7 @@ jobs:
104120
cc: riscv64-linux-gnu-gcc
105121
cxx: riscv64-linux-gnu-g++
106122
sanitize: 0
123+
tsan: 0
107124

108125
# powerpc64
109126
- arch: powerpc64
@@ -112,6 +129,7 @@ jobs:
112129
cc: powerpc64-linux-gnu-gcc
113130
cxx: powerpc64-linux-gnu-g++
114131
sanitize: 0
132+
tsan: 0
115133

116134
# powerpc
117135
- arch: powerpc
@@ -120,6 +138,7 @@ jobs:
120138
cc: powerpc-linux-gnu-gcc
121139
cxx: powerpc-linux-gnu-g++
122140
sanitize: 0
141+
tsan: 0
123142

124143
# alpha
125144
- arch: alpha
@@ -128,6 +147,7 @@ jobs:
128147
cc: alpha-linux-gnu-gcc
129148
cxx: alpha-linux-gnu-g++
130149
sanitize: 0
150+
tsan: 0
131151

132152
# mips64
133153
- arch: mips64
@@ -136,6 +156,7 @@ jobs:
136156
cc: mips64-linux-gnuabi64-gcc
137157
cxx: mips64-linux-gnuabi64-g++
138158
sanitize: 0
159+
tsan: 0
139160

140161
# mips
141162
- arch: mips
@@ -144,6 +165,7 @@ jobs:
144165
cc: mips-linux-gnu-gcc
145166
cxx: mips-linux-gnu-g++
146167
sanitize: 0
168+
tsan: 0
147169

148170
# hppa
149171
- arch: hppa
@@ -152,10 +174,12 @@ jobs:
152174
cc: hppa-linux-gnu-gcc
153175
cxx: hppa-linux-gnu-g++
154176
sanitize: 0
177+
tsan: 0
155178

156179
env:
157180
FLAGS: -g -O3 -Wall -Wextra -Werror -Wno-sign-compare ${{matrix.build_args.extra_flags}}
158181
SANITIZE: ${{matrix.build_args.sanitize}}
182+
THREAD_SANITIZE: ${{matrix.build_args.tsan}}
159183

160184
# Flags for building sources in src/ dir only.
161185
LIBURING_CFLAGS: ${{matrix.build_args.liburing_extra_flags}}
@@ -181,7 +205,7 @@ jobs:
181205
${{matrix.build_args.cxx}} --version;
182206
183207
- name: Build
184-
if: ${{matrix.build_args.sanitize == '0'}}
208+
if: ${{matrix.build_args.sanitize == '0' && matrix.build_args.tsan == '0'}}
185209
run: |
186210
./configure --cc=${{matrix.build_args.cc}} --cxx=${{matrix.build_args.cxx}};
187211
make -j$(nproc) V=1 CPPFLAGS="-Werror" CFLAGS="$FLAGS" CXXFLAGS="$FLAGS";
@@ -192,6 +216,12 @@ jobs:
192216
./configure --cc=${{matrix.build_args.cc}} --cxx=${{matrix.build_args.cxx}} --enable-sanitizer;
193217
make -j$(nproc) V=1 CPPFLAGS="-Werror" CFLAGS="$FLAGS" CXXFLAGS="$FLAGS";
194218
219+
- name: Build
220+
if: ${{matrix.build_args.tsan == '1'}}
221+
run: |
222+
./configure --cc=${{matrix.build_args.cc}} --cxx=${{matrix.build_args.cxx}} --enable-tsan;
223+
make -j$(nproc) V=1 CPPFLAGS="-Werror" CFLAGS="$FLAGS" CXXFLAGS="$FLAGS";
224+
195225
- name: Test install command
196226
run: |
197227
sudo make install;
@@ -201,6 +231,8 @@ jobs:
201231
export TEST_FILE=".github/workflows/test_build.c";
202232
if [ "$SANITIZE" -eq "1" ]; then
203233
export SANITIZE_FLAGS="-fsanitize=address,undefined";
234+
elif [ "$THREAD_SANITIZE" -eq "1" ]; then
235+
export SANITIZE_FLAGS="-fsanitize=thread";
204236
else
205237
export SANITIZE_FLAGS="";
206238
fi;

configure

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ for opt do
3030
;;
3131
--enable-sanitizer) use_sanitizer=yes
3232
;;
33+
--enable-tsan) use_tsan=yes
34+
;;
3335
*)
3436
echo "ERROR: unknown option $opt"
3537
echo "Try '$0 --help' for more information"
@@ -576,6 +578,12 @@ if test "$use_sanitizer" = "yes"; then
576578
else
577579
print_config "use sanitizer" "no"
578580
fi
581+
if test "$use_tsan" = "yes"; then
582+
output_sym "CONFIG_USE_TSAN"
583+
print_config "use tsan" "yes"
584+
else
585+
print_config "use tsan" "no"
586+
fi
579587

580588
echo "CC=$cc" >> $config_host_mak
581589
print_config "CC" "$cc"

examples/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ ifeq ($(CONFIG_USE_SANITIZER),y)
1919
override LDFLAGS += -fsanitize=address,undefined
2020
endif
2121

22+
ifeq ($(CONFIG_USE_TSAN),y)
23+
override CFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls
24+
override CPPFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls
25+
override LDFLAGS += -fsanitize=thread -ltsan
26+
endif
27+
2228
example_srcs := \
2329
io_uring-close-test.c \
2430
io_uring-cp.c \

src/Makefile

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,12 @@ ifeq ($(CONFIG_USE_SANITIZER),y)
6262
liburing_srcs += sanitize.c
6363
endif
6464

65+
ifeq ($(CONFIG_USE_TSAN),y)
66+
override CFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls
67+
override CPPFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls
68+
override LINK_FLAGS += -fsanitize=thread -ltsan
69+
endif
70+
6571
override CPPFLAGS += -MT "$@" -MMD -MP -MF "$@.d"
6672
liburing_objs := $(patsubst %.c,%.ol,$(liburing_srcs))
6773
liburing_sobjs := $(patsubst %.c,%.os,$(liburing_srcs))

test/Makefile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ ifeq ($(CONFIG_USE_SANITIZER),y)
3131
XCFLAGS += -fsanitize=address,undefined -fno-omit-frame-pointer -fno-optimize-sibling-calls
3232
endif
3333

34+
ifeq ($(CONFIG_USE_TSAN),y)
35+
XCFLAGS += -fsanitize=thread -fno-omit-frame-pointer -fno-optimize-sibling-calls
36+
endif
37+
3438
CXXFLAGS ?= $(CFLAGS)
3539
override CFLAGS += $(XCFLAGS) -DLIBURING_BUILD_TEST
3640
override CXXFLAGS += $(XCFLAGS) -std=c++11 -DLIBURING_BUILD_TEST

0 commit comments

Comments
 (0)