Home | History | Annotate | Download | only in tsan
      1 SVN_ROOT=..
      2 OPT=1
      3 
      4 include ../common.mk
      5 
      6 OUTDIR=bin
      7 VALGRIND_ROOT=../third_party/valgrind
      8 VALGRIND_INST_ROOT=../tsan_inst
      9 STLPORT_ROOT=../third_party/stlport
     10 GTEST_ROOT=../third_party/googletest
     11 OFFLINE=1
     12 
     13 TS_VERSION=$(shell svnversion)
     14 
     15 COPT=-O -fno-omit-frame-pointer
     16 CWARN=-Wall -Wmissing-prototypes -Wshadow -Wpointer-arith -Wstrict-prototypes \
     17       -Wmissing-declarations -Wno-format-zero-length \
     18       -fno-strict-aliasing -Wno-long-long -Wno-pointer-sign \
     19       -Wdeclaration-after-statement
     20 CFLAGS=-g $(COPT) $(CWARN) -fno-strict-aliasing -fno-stack-protector -fpic
     21 CXXOPT=-O2
     22 CXXFLAGS=$(CXXOPT) -g -Wall -Wno-deprecated -fno-exceptions # -Wvla
     23 LDFLAGS=
     24 
     25 OFFLINE_DEFINES=-DTS_OFFLINE=1
     26 
     27 VG_CXXFLAGS=-fno-rtti -fno-stack-protector
     28 VG_DEFINES=-DVGA_$(ARCH)=1 -DVGO_$(OS)=1 -DVGP_$(ARCH_OS)=1 -D_STLP_NO_IOSTREAMS=1 -DTS_VALGRIND=1
     29 VG_INCLUDES=-I$(VALGRIND_ROOT) -I$(VALGRIND_ROOT)/include -I$(VALGRIND_ROOT)/VEX/pub -I$(STLPORT_ROOT)
     30 
     31 PIN_CXXFLAGS_L=-fPIC
     32 PIN_DEFINES=-DBIGARRAY_MULTIPLIER=1 -DUSING_XED -DTARGET_$(PIN_ARCH2)  -DHOST_$(PIN_ARCH2)   -DTARGET_LINUX -DTS_PIN=1
     33 PIN_INCLUDES=-I$(PIN_ROOT)/source/include -I$(PIN_ROOT)/source/include/gen \
     34              -I$(PIN_ROOT)/extras/xed2-$(PIN_ARCH)/include -I$(PIN_ROOT)/extras/components/include
     35 PIN_LIBPATHS=-L$(PIN_ROOT)/extras/xed2-$(PIN_ARCH)/lib -L$(PIN_ROOT)/$(PIN_ARCH)/lib -L$(PIN_ROOT)/$(PIN_ARCH)/lib-ext
     36 PIN_LDFLAGS=-g -shared -Wl,-Bsymbolic -Wl,--version-script=$(PIN_ROOT)/source/include/pintool.ver
     37 PIN_LIBS= -lpin -lxed -ldwarf -lelf -ldl -lpthread
     38 
     39 DR_CXXFLAGS=-fPIC -fno-rtti -fno-stack-protector
     40 DR_DEFINES=-D$(DR_OS) -D$(DR_ARCH)
     41 DR_INCLUDES=-I$(DYNAMORIO_ROOT)/include
     42 DR_LDFLAGS=-shared -nostartfiles -nodefaultlibs -lgcc
     43 DR_LIBS=
     44 
     45 OS=   # linux, darwin
     46 ARCH= # x86, amd64
     47 D=    # <empty>, -debug
     48 ARCHOS=$(ARCH)-$(OS)
     49 ARCH_OS=$(ARCH)_$(OS)
     50 
     51 # prefix of binary files
     52 P=$(OUTDIR)/$(ARCHOS)$(D)-
     53 OFF=$(P)off-
     54 VGP=$(P)vg-
     55 PINP=$(P)pin-
     56 PINMTP=$(P)pinmp-
     57 DRP=$(P)dr-
     58 
     59 STRIP=strip
     60 
     61 INCLUDES=-I../dynamic_annotations
     62 DEFINES=-DTS_VERSION=\"$(TS_VERSION)\"
     63 
     64 ifeq ($(DEBUG), 1)
     65   D=-debug
     66   DEFINES+=-DDEBUG=1
     67 else
     68   D=
     69 endif
     70 
     71 ifeq ($(ARCH), x86)
     72   PIN_ARCH=ia32
     73   PIN_ARCH2=IA32
     74   DR_ARCH=X86_32
     75 else ifeq ($(ARCH), amd64)
     76   PIN_ARCH=intel64
     77   PIN_ARCH2=IA32E
     78   DR_ARCH=X86_64
     79   DR_LD_SCRIPT=-Xlinker -T -Xlinker ./dr64_ldscript # TODO(kcc) this is too hackish...
     80 endif
     81 
     82 ifeq ($(OS), linux)
     83   PIN_CXXFLAGS=$(PIN_CXXFLAGS_L)
     84   VG_LD_FLAGS=-Wl,--build-id=none -Wl,-Ttext=0x38000000 -static -nodefaultlibs -nostartfiles -u _start 
     85   VG_LD_PRELOAD_FLAGS= -nodefaultlibs -shared -Wl,-z,interpose,-z,initfirst
     86   DR_OS=LINUX
     87   STRIP=strip -g  # keep some symbols for profiling.
     88 else ifeq ($(OS), darwin)
     89 ifeq ($(ARCH), x86)
     90   VG_LD_FLAGS=-Wl,-u,__start -Wl,-e,__start -Wl,-bind_at_load /usr/lib/dyld -arch i386 \
     91       -Wl,-seg1addr,0xf0080000 -Wl,-stack_addr,0xf0080000 -Wl,-stack_size,0x80000 -Wl,-pagezero_size,0xf0000000 \
     92       -nodefaultlibs -nostartfiles
     93   VG_LD_PRELOAD_FLAGS=-arch i386 -dynamic -dynamiclib -all_load
     94 endif
     95 ifeq ($(ARCH), amd64)
     96   VG_LD_FLAGS=-Wl,-u,__start -Wl,-e,__start -Wl,-bind_at_load /usr/lib/dyld -arch x86_64 \
     97       -Wl,-seg1addr,0xf0080000 -Wl,-stack_addr,0xf0080000 -Wl,-stack_size,0x80000 -Wl,-pagezero_size,0xf0000000 \
     98       -nodefaultlibs -nostartfiles
     99   VG_LD_PRELOAD_FLAGS=-arch x86_64 -dynamic -dynamiclib -all_load
    100 endif
    101   VG_CXXFLAGS+=-fno-weak -bind_at_load -fno-PIC
    102 else ifeq ($(OS), windows)
    103   VALGRIND_ROOT= # no valgrind on windows :(
    104   CXXFLAGS=/c /Zi /MT /EHs- /EHa- /wd4530 /D_CRT_SECURE_NO_DEPRECATE /D_SECURE_SCL=0 /D_HAS_ITERATOR_DEBUGGING=0 /nologo /Gy /Ox /GL
    105   PIN_DEFINES=/DTARGET_WINDOWS /DBIGARRAY_MULTIPLIER=1 /DUSING_XED /DTARGET_IA32 /DHOST_IA32a /D_SECURE_SCL=0 -DTS_PIN=1
    106   PIN_INCLUDES=/I$(PIN_ROOT)/source/include /I$(PIN_ROOT)/source/include/gen /I$(PIN_ROOT)/extras/xed2-ia32/include
    107   PIN_LDFLAGS=/LTCG /DEBUG /DLL /EXPORT:main /NODEFAULTLIB /NOLOGO /INCREMENTAL:NO /OPT:REF /MACHINE:x86 /ENTRY:Ptrace_DllMainCRTStartup@12 /BASE:0x55000000
    108   LDFLAGS=/LTCG
    109   PIN_LIBPATHS= /LIBPATH:$(PIN_ROOT)/ia32/lib /LIBPATH:$(PIN_ROOT)/ia32/lib-ext /LIBPATH:$(PIN_ROOT)/extras/xed2-ia32/lib
    110   PIN_LIBS=pin.lib libxed.lib libcpmt.lib libcmt.lib pinvm.lib kernel32.lib ntdll-32.lib winmm.lib
    111   DR_OS=WINDOWS
    112 else
    113   OS=UNKNOWN_OS
    114 endif
    115 
    116 
    117 
    118 VALGRIND_LIBS=$(VALGRIND_ROOT)/coregrind/libcoregrind-$(ARCHOS).a \
    119 		  $(VALGRIND_ROOT)/VEX/libvex-$(ARCHOS).a
    120 
    121 all: TS_valgrind TS_pin TS_offline TS_dynamorio test
    122 
    123 l: l32 l64
    124 lo: l32o l64o
    125 ld: l32d l64d
    126 l32: l32d l32o
    127 l64: l64d l64o
    128 
    129 
    130 l64d:
    131 	$(MAKE) all OS=linux ARCH=amd64 DEBUG=1
    132 l64o:
    133 	$(MAKE) all OS=linux ARCH=amd64 DEBUG=0
    134 l32d:
    135 	$(MAKE) all OS=linux ARCH=x86 DEBUG=1
    136 l32o:
    137 	$(MAKE) all OS=linux ARCH=x86 DEBUG=0
    138 la:
    139 	$(MAKE) all OS=linux ARCH=arm DEBUG=0
    140 
    141 w: w32
    142 w32: w32o w32d
    143 
    144 w32d:
    145 	$(MAKE) all OS=windows ARCH=x86 DEBUG=1
    146 
    147 w32o:
    148 	$(MAKE) all OS=windows ARCH=x86 DEBUG=0
    149 
    150 m: m32 m64
    151 m32: m32o m32d
    152 m64: m64o m64d
    153 
    154 m32o:
    155 	$(MAKE) all OS=darwin ARCH=x86 DEBUG=0
    156 m32d:
    157 	$(MAKE) all OS=darwin ARCH=x86 DEBUG=1
    158 m64o:
    159 	$(MAKE) all OS=darwin ARCH=amd64 DEBUG=0
    160 m64d:
    161 	$(MAKE) all OS=darwin ARCH=amd64 DEBUG=1
    162 
    163 install:
    164 	@echo The 'install' target is deprecated.
    165 
    166 self-contained: TS_valgrind
    167 	./mk-self-contained-valgrind.sh $(VALGRIND_INST_ROOT) tsan$(D) $(OUTDIR)/tsan-$(ARCHOS)$(D)-self-contained.sh
    168 self-contained-stripped: TS_valgrind
    169 	$(STRIP) $(OUTDIR)/tsan-*$(OS)
    170 	./mk-self-contained-valgrind.sh $(VALGRIND_INST_ROOT) tsan$(D) $(OUTDIR)/tsan-$(ARCHOS)$(D)-self-contained.sh
    171 
    172 TSAN_SFX_DIR=tsan-$(ARCHOS)
    173 sfx:
    174 	rm -rf $(TSAN_SFX_DIR)
    175 	mkdir -p $(TSAN_SFX_DIR)
    176 	cp -r $(PIN_ROOT)/ia32 \
    177 			bin/$(ARCHOS)-debug-ts_pin.dll bin/$(ARCHOS)-ts_pin.dll \
    178 			bin/$(ARCHOS)-ts_pinmt.dll \
    179 		  tsan.bat tsan-debug.bat tsan_mt.bat $(TSAN_SFX_DIR)
    180 	cp license_for_windows.txt $(TSAN_SFX_DIR)/LICENSE
    181 	7z a -sfx tsan-$(ARCHOS)-sfx.exe $(TSAN_SFX_DIR)
    182 	rm -rf $(TSAN_SFX_DIR)
    183 
    184 w32-sfx: w32o w32d
    185 	$(MAKE) sfx OS=windows ARCH=x86
    186 
    187 ifeq ($(VALGRIND_ROOT), )
    188 TS_valgrind:
    189 	@echo VALGRIND_ROOT is not set. Not building the Valgrind-based variant.
    190 else
    191 TS_valgrind:  $(OUTDIR)/tsan$D-$(ARCHOS) $(OUTDIR)/vgpreload_tsan$D-$(ARCHOS).so
    192 endif
    193 
    194 ifeq ($(PIN_ROOT), )
    195 TS_pin:
    196 	@echo PIN_ROOT is not set. Not building the PIN-based variant.
    197 else
    198 TS_pin: $(P)ts_pinmt.$(SO) $(P)ts_pin.$(SO)
    199 endif
    200 
    201 ifeq ($(DYNAMORIO_ROOT), )
    202 TS_dynamorio:
    203 	@echo DYNAMORIO_ROOT is not set. Not building the DynamoRio-based variant.
    204 else
    205 TS_dynamorio: $(P)ts_dynamorio.$(SO)
    206 endif
    207 
    208 
    209 ifeq ($(OFFLINE), 1)
    210 TS_offline: $(P)ts_offline$(EXE)
    211 else
    212 TS_offline:
    213 endif
    214 
    215 ifeq ($(GTEST_ROOT), )
    216 test:
    217 	@echo GTEST_ROOT is not set. Not building GTEST-based tests.
    218 else
    219 test: $(P)suppressions_test$(EXE) $(P)thread_sanitizer_test$(EXE)
    220 endif
    221 
    222 $(OUTDIR):
    223 	mkdir -p $(OUTDIR)
    224 
    225 TS_HEADERS=thread_sanitizer.h ts_util.h suppressions.h ignore.h ts_replace.h ts_heap_info.h \
    226 	   ts_simple_cache.h ts_stats.h ts_lock.h ts_events.h ts_event_names.h \
    227 	   ts_trace_info.h ts_race_verifier.h dense_multimap.h \
    228            ts_atomic.h ts_atomic_int.h \
    229 	   ../dynamic_annotations/dynamic_annotations.h
    230 ts_event_names.h: ts_events.h
    231 	sed -n '/^enum/,/^};/ {s/enum EventType/static const char *kEventNames[] = /; s/^  \([A-Z_][A-Z_]*\)/  "\1"/g; p;}' $< > $@
    232 TS_VG_HEADERS=ts_valgrind.h ts_valgrind_client_requests.h
    233 
    234 TS_VG_OBJECTS=$(VGP)thread_sanitizer.o $(VGP)ts_valgrind.o $(VGP)ts_valgrind_libc.o $(VGP)ts_util.o $(VGP)suppressions.o $(VGP)ignore.o $(VGP)common_util.o $(VGP)ts_race_verifier.o $(VGP)ts_atomic.o
    235 TS_PIN_OBJECTS=$(PINP)ts_pin.$(OBJ) $(PINP)ts_util.$(OBJ) $(PINP)thread_sanitizer.$(OBJ) $(PINP)suppressions.$(OBJ) $(PINP)ignore.$(OBJ) $(PINP)common_util.$(OBJ) $(PINP)ts_race_verifier.$(OBJ) $(PINP)ts_atomic.$(OBJ)
    236 TS_PINMT_OBJECTS=$(PINMTP)ts_pin.$(OBJ) $(PINMTP)ts_util.$(OBJ) $(PINMTP)thread_sanitizer.$(OBJ) $(PINMTP)suppressions.$(OBJ) $(PINMTP)ignore.$(OBJ) $(PINMTP)common_util.$(OBJ) $(PINMTP)ts_race_verifier.$(OBJ) $(PINMTP)ts_atomic.$(OBJ)
    237 TS_OFFLINE_OBJECTS=$(OFF)ts_offline.$(OBJ) $(OFF)thread_sanitizer.$(OBJ) $(OFF)ts_util.$(OBJ) $(OFF)suppressions.$(OBJ) $(OFF)ignore.$(OBJ) $(OFF)common_util.$(OBJ) $(OFF)ts_atomic.$(OBJ)
    238 TS_DR_OBJECTS=$(DRP)ts_dynamorio.$(OBJ) $(DRP)ts_util.$(OBJ)
    239 
    240 $(P)%.$(OBJ): %.cc $(TS_HEADERS) | $(OUTDIR)
    241 	$(CXX) $(CXXFLAGS) $(ARCHFLAGS) $(O)$@ -c $< $(DEFINES) $(INCLUDES)
    242 
    243 $(OFF)%.$(OBJ): %.cc $(TS_HEADERS) | $(OUTDIR)
    244 	$(CXX) $(CXXFLAGS) $(ARCHFLAGS) $(OFFLINE_DEFINES) $(O)$@ -c $< $(DEFINES) $(INCLUDES)
    245 
    246 $(VGP)%.o: %.cc $(TS_HEADERS) $(TS_VG_HEADERS) | $(OUTDIR)
    247 	$(CXX) $(CXXFLAGS) $(VG_CXXFLAGS) $(ARCHFLAGS) $(VG_INCLUDES) $(VG_DEFINES) -o $@ -c $< $(DEFINES) $(INCLUDES)
    248 
    249 $(PINP)%.$(OBJ): %.cc $(TS_HEADERS) $(TS_PIN_HEADERS) | $(OUTDIR)
    250 	$(CXX) $(CXXFLAGS) $(PIN_CXXFLAGS) $(ARCHFLAGS) $(PIN_INCLUDES) $(PIN_DEFINES) $(O)$@ -c $< $(DEFINES) $(INCLUDES)
    251 
    252 $(PINMTP)%.$(OBJ): %.cc $(TS_HEADERS) $(TS_PIN_HEADERS) | $(OUTDIR)
    253 	$(CXX) $(CXXFLAGS) $(PIN_CXXFLAGS) $(ARCHFLAGS) $(PIN_INCLUDES) $(PIN_DEFINES) $(O)$@ -c $< $(DEFINES) $(INCLUDES) -DTS_SERIALIZED=0
    254 
    255 $(DRP)%.$(OBJ): %.cc $(TS_HEADERS) $(TS_DR_HEADERS) | $(OUTDIR)
    256 	$(CXX) $(CXXFLAGS) $(DR_CXXFLAGS) $(ARCHFLAGS) $(DR_INCLUDES) $(DR_DEFINES) $(O)$@ -c $< $(DEFINES) $(INCLUDES)
    257 
    258 $(P)gtest-%.$(OBJ): %.cc $(TS_HEADERS) | $(OUTDIR)
    259 	$(CXX) $(CXXFLAGS) $(ARCHFLAGS) -I$(GTEST_ROOT)/include $(O)$@ -c $<
    260 
    261 $(P)preload-%.o: %.c $(TS_HEADERS) $(TS_VG_HEADERS) | $(OUTDIR)
    262 	$(CC) $(CFLAGS) $(ARCHFLAGS) $(VG_INCLUDES) $(VG_DEFINES) -o $@ -c $<
    263 
    264 $(OUTDIR)/tsan$(D)-$(ARCHOS): $(TS_VG_OBJECTS)
    265 	$(LTLD) $(LDFLAGS) $(ARCHFLAGS) $(VG_LD_FLAGS) -o $@ $^ $(VALGRIND_LIBS) -lgcc
    266 	ln -sf `pwd`/$@ $(VALGRIND_INST_ROOT)/lib/valgrind/  # install the symlink into the valgrind inst dir.
    267 
    268 $(OUTDIR)/vgpreload_tsan$(D)-$(ARCHOS).so: $(P)preload-ts_valgrind_intercepts.o
    269 	$(LD) $(LDFLAGS)  $(ARCHFLAGS) $(VG_LD_PRELOAD_FLAGS) -o $@  $<
    270 	ln -sf `pwd`/$@  $(VALGRIND_INST_ROOT)/lib/valgrind/  # install the symlink into the valgrind inst dir.
    271 
    272 $(P)ts_offline$(EXE): $(TS_OFFLINE_OBJECTS)
    273 	$(LD) $(LDFLAGS) $(ARCHFLAGS) $(LINKO)$@ $^
    274 
    275 $(P)suppressions_test$(EXE): $(P)gtest-suppressions_test.$(OBJ) $(P)suppressions.$(OBJ) $(P)common_util.$(OBJ) $(P)ts_util.$(OBJ) $(GTEST_LIB)
    276 	$(LD) $(LDFLAGS) $(ARCHFLAGS) $(LINKO)$@ $^
    277 
    278 $(P)thread_sanitizer_test$(EXE): $(P)gtest-thread_sanitizer_test.$(OBJ) $(P)ts_util.$(OBJ) $(GTEST_LIB)
    279 	$(LD) $(LDFLAGS) $(ARCHFLAGS) $(LINKO)$@ $^
    280 
    281 $(P)ts_pin.so: $(TS_PIN_OBJECTS)
    282 	$(LD) $(ARCHFLAGS) $(PIN_LDFLAGS) $(PIN_LIBPATHS) -o $@ $^  $(PIN_LIBS)
    283 
    284 $(P)ts_pinmt.so: $(TS_PINMT_OBJECTS)
    285 	$(LD) $(ARCHFLAGS) $(PIN_LDFLAGS) $(PIN_LIBPATHS) -o $@ $^  $(PIN_LIBS)
    286 
    287 $(P)ts_pin.dll: $(TS_PIN_OBJECTS)
    288 	$(LD) $(ARCHFLAGS) $(PIN_LDFLAGS) $(PIN_LIBPATHS)  /IMPLIB:$(PINP)ts_pin.lib /PDB:$(PINP)ts_pin.pdb /OUT:$@  $^  $(PIN_LIBS)
    289 
    290 $(P)ts_pinmt.dll: $(TS_PINMT_OBJECTS)
    291 	$(LD) $(ARCHFLAGS) $(PIN_LDFLAGS) $(PIN_LIBPATHS)  /IMPLIB:$(PINMTP)ts_pin.lib /PDB:$(PINMTP)ts_pin.pdb /OUT:$@  $^  $(PIN_LIBS)
    292 
    293 $(P)ts_dynamorio.so: $(TS_DR_OBJECTS)
    294 	$(LD) $(ARCHFLAGS) $(DR_LDFLAGS) $(DR_LIBPATHS) -o $@ $^  $(DR_LIBS) $(DR_LD_SCRIPT)
    295 
    296 clean: GTEST_CLEAN
    297 	rm -rfv $(OUTDIR) ts_event_names.h core* pintool.log* pin.log $(VALGRIND_INST_ROOT)/lib/valgrind/*tsan*
    298