Skip to content

Commit 227cb67

Browse files
committed
added thread sanitizer target to Makefile
1 parent 91a5fce commit 227cb67

1 file changed

Lines changed: 13 additions & 5 deletions

File tree

Makefile

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,30 @@ ifneq (,$(filter %release %static, $(MAKECMDGOALS)))
7171
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O3)
7272
CXXFLAGS += -DNDEBUG $(BASEFLAGS)
7373
else
74-
ifneq (,$(filter %memcheck %memdebug, $(MAKECMDGOALS)))
74+
ifneq (,$(filter %memcheck %memdebug %tsan %tcheck %thrcheck, $(MAKECMDGOALS)))
7575
#use sanitizer in gcc 4.9+
76-
MEMCHECK_BUILD=1
7776
GCCVER49 := $(shell expr `${CXX} -dumpversion | cut -f1,2 -d.` \>= 4.9)
7877
ifeq "$(GCCVER49)" "0"
7978
$(error gcc version 4.9 or greater is required for this build target)
8079
endif
8180
CXXFLAGS := $(if $(CXXFLAGS),$(CXXFLAGS),-g -O0)
82-
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address $(BASEFLAGS)
81+
SANLIBS :=
82+
ifneq (,$(filter %tsan %tcheck %thrcheck, $(MAKECMDGOALS)))
83+
# thread sanitizer only (incompatible with address sanitizer)
84+
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=thread -fsanitize=undefined $(BASEFLAGS)
85+
SANLIBS := -ltsan
86+
else
87+
# address sanitizer
88+
CXXFLAGS += -fno-omit-frame-pointer -fsanitize=undefined -fsanitize=address $(BASEFLAGS)
89+
SANLIBS := -lasan
90+
endif
8391
ifeq "$(GCCVER5)" "1"
8492
CXXFLAGS += -fsanitize=bounds -fsanitize=float-divide-by-zero -fsanitize=vptr
8593
CXXFLAGS += -fsanitize=float-cast-overflow -fsanitize=object-size
8694
#CXXFLAGS += -fcheck-pointer-bounds -mmpx
8795
endif
8896
CXXFLAGS += -DDEBUG -D_DEBUG -DGDEBUG -fno-common -fstack-protector
89-
LIBS := -lasan -lubsan -ldl $(LIBS)
97+
LIBS := ${SANLIBS} -lubsan -ldl ${LIBS}
9098
else
9199
#just plain debug build
92100
DEBUG_BUILD=1
@@ -133,7 +141,7 @@ endif
133141
OBJS += rlink.o tablemaker.o tmerge.o
134142

135143
all release static debug: stringtie${EXE}
136-
memcheck memdebug: stringtie${EXE}
144+
memcheck memdebug tsan tcheck thrcheck: stringtie${EXE}
137145
memuse memusage memtrace: stringtie${EXE}
138146
nothreads: stringtie${EXE}
139147

0 commit comments

Comments
 (0)