Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Trial PR] Add ThreadSanitizer support #22

Closed
wants to merge 16 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .depend
Original file line number Diff line number Diff line change
Expand Up @@ -2381,6 +2381,7 @@ asmcomp/asmlibrarian.cmx : \
asmcomp/asmlibrarian.cmi
asmcomp/asmlibrarian.cmi :
asmcomp/asmlink.cmo : \
asmcomp/thread_sanitizer.cmi \
lambda/runtimedef.cmi \
utils/profile.cmi \
utils/misc.cmi \
Expand All @@ -2399,6 +2400,7 @@ asmcomp/asmlink.cmo : \
asmcomp/asmgen.cmi \
asmcomp/asmlink.cmi
asmcomp/asmlink.cmx : \
asmcomp/thread_sanitizer.cmx \
lambda/runtimedef.cmx \
utils/profile.cmx \
utils/misc.cmx \
Expand Down Expand Up @@ -2583,6 +2585,7 @@ asmcomp/cmm_invariants.cmi : \
asmcomp/cmm.cmi
asmcomp/cmmgen.cmo : \
typing/types.cmi \
asmcomp/thread_sanitizer.cmi \
middle_end/printclambda_primitives.cmi \
typing/primitive.cmi \
utils/misc.cmi \
Expand All @@ -2602,6 +2605,7 @@ asmcomp/cmmgen.cmo : \
asmcomp/cmmgen.cmi
asmcomp/cmmgen.cmx : \
typing/types.cmx \
asmcomp/thread_sanitizer.cmx \
middle_end/printclambda_primitives.cmx \
typing/primitive.cmx \
utils/misc.cmx \
Expand Down Expand Up @@ -3170,6 +3174,22 @@ asmcomp/strmatch.cmx : \
asmcomp/strmatch.cmi : \
lambda/debuginfo.cmi \
asmcomp/cmm.cmi
asmcomp/thread_sanitizer.cmo : \
lambda/debuginfo.cmi \
asmcomp/cmm_helpers.cmi \
asmcomp/cmm.cmi \
middle_end/backend_var.cmi \
parsing/asttypes.cmi \
asmcomp/thread_sanitizer.cmi
asmcomp/thread_sanitizer.cmx : \
lambda/debuginfo.cmx \
asmcomp/cmm_helpers.cmx \
asmcomp/cmm.cmx \
middle_end/backend_var.cmx \
parsing/asttypes.cmi \
asmcomp/thread_sanitizer.cmi
asmcomp/thread_sanitizer.cmi : \
asmcomp/cmm.cmi
asmcomp/x86_ast.cmi :
asmcomp/x86_dsl.cmo : \
asmcomp/x86_proc.cmi \
Expand Down
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ Working version
functor leads to new warning 73.
(Frederic Bour and Richard Eisenberg, review by Florian Angeletti)

- #12114: Add ThreadSanitizer support
(Fabrice Buoro and Olivier Nicole, based on an initial work by Anmol Sahoo,
review by ???)

### Runtime system:

- #12001: Fix book keeping for last finalisers during the minor cycle
Expand Down
41 changes: 23 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -474,9 +474,9 @@ ocamlc_LIBRARIES = $(addprefix compilerlibs/,ocamlcommon ocamlbytecomp)

ocamlc_MODULES = driver/main

ocamlc$(EXE): OC_BYTECODE_LDFLAGS += -compat-32 -g
ocamlc$(EXE): OC_BYTECODE_LINKFLAGS += -compat-32 -g

ocamlc.opt$(EXE): OC_NATIVE_LDFLAGS += $(addprefix -cclib ,$(BYTECCLIBS))
ocamlc.opt$(EXE): OC_NATIVE_LINKFLAGS += $(addprefix -cclib ,$(BYTECCLIBS))

partialclean::
rm -f ocamlc ocamlc.exe ocamlc.opt ocamlc.opt.exe
Expand All @@ -487,7 +487,7 @@ ocamlopt_LIBRARIES = $(addprefix compilerlibs/,ocamlcommon ocamloptcomp)

ocamlopt_MODULES = driver/optmain

ocamlopt$(EXE): OC_BYTECODE_LDFLAGS += -g
ocamlopt$(EXE): OC_BYTECODE_LINKFLAGS += -g

partialclean::
rm -f ocamlopt ocamlopt.exe ocamlopt.opt ocamlopt.opt.exe
Expand All @@ -500,7 +500,7 @@ ocaml_LIBRARIES = \
ocaml_MODULES = toplevel/topstart

.INTERMEDIATE: ocaml.tmp
ocaml.tmp: OC_BYTECODE_LDFLAGS += -I toplevel/byte -linkall -g
ocaml.tmp: OC_BYTECODE_LINKFLAGS += -I toplevel/byte -linkall -g
ocaml.tmp: $(ocaml_LIBRARIES:=.cma) $(ocaml_MODULES:=.cmo)
$(V_LINKC)$(LINK_BYTECODE_PROGRAM) -o $@ $^

Expand Down Expand Up @@ -680,7 +680,8 @@ runtime_NATIVE_ONLY_C_SOURCES = \
fail_nat \
frame_descriptors \
startup_nat \
signals_nat
signals_nat \
$(TSAN_NATIVE_RUNTIME_C_SOURCES)
runtime_NATIVE_C_SOURCES = \
$(runtime_COMMON_C_SOURCES:%=runtime/%.c) \
$(runtime_NATIVE_ONLY_C_SOURCES:%=runtime/%.c)
Expand Down Expand Up @@ -912,22 +913,24 @@ runtime/%.bi.$(O): OC_CPPFLAGS += $(ocamlruni_CPPFLAGS)
$(DEPDIR)/runtime/%.bi.$(D): OC_CPPFLAGS += $(ocamlruni_CPPFLAGS)

runtime/%.bpic.$(O): OC_CFLAGS += $(SHAREDLIB_CFLAGS)
$(DEPDIR)/runtime/%.bpic.$(D): OC_CFLAGS += $(SHAREDLIB_CFLAGS)

runtime/%.n.$(O): OC_CFLAGS += $(OC_NATIVE_CFLAGS)
runtime/%.n.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
$(DEPDIR)/runtime/%.n.$(D): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)

runtime/%.nd.$(O): OC_CFLAGS += $(OC_NATIVE_CFLAGS)
runtime/%.nd.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlrund_CPPFLAGS)
$(DEPDIR)/runtime/%.nd.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlrund_CPPFLAGS)

runtime/%.ni.$(O): OC_CFLAGS += $(OC_NATIVE_CFLAGS)
runtime/%.ni.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlruni_CPPFLAGS)
$(DEPDIR)/runtime/%.ni.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(ocamlruni_CPPFLAGS)

runtime/%.npic.$(O): OC_CFLAGS += $(OC_NATIVE_CPPFLAGS) $(SHAREDLIB_CFLAGS)
$(DEPDIR)/runtime/%.npic.$(D): \
OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS) $(SHAREDLIB_CFLAGS)
runtime/%.npic.$(O): OC_CFLAGS += $(OC_NATIVE_CFLAGS) $(SHAREDLIB_CFLAGS)
runtime/%.npic.$(O): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)
$(DEPDIR)/runtime/%.npic.$(D): OC_CPPFLAGS += $(OC_NATIVE_CPPFLAGS)

## Compilation of runtime C files

Expand Down Expand Up @@ -1120,7 +1123,7 @@ ocamllex: ocamlyacc
ocamllex.opt: ocamlopt
$(MAKE) lex-allopt

lex/ocamllex$(EXE): OC_BYTECODE_LDFLAGS += -compat-32
lex/ocamllex$(EXE): OC_BYTECODE_LINKFLAGS += -compat-32

partialclean::
rm -f lex/*.cm* lex/*.o lex/*.obj
Expand Down Expand Up @@ -1365,7 +1368,7 @@ partialclean::
ocamldep_LIBRARIES = $(addprefix compilerlibs/,ocamlcommon ocamlbytecomp)
ocamldep_MODULES = tools/ocamldep

tools/ocamldep$(EXE): OC_BYTECODE_LDFLAGS += -compat-32
tools/ocamldep$(EXE): OC_BYTECODE_LINKFLAGS += -compat-32

# The profiler

Expand Down Expand Up @@ -1457,10 +1460,10 @@ ocamltex_MODULES = tools/ocamltex
# Note: the following definitions apply to all the prerequisites
# of ocamltex.
$(ocamltex): CAMLC = $(OCAMLRUN) $(ROOTDIR)/ocamlc$(EXE) $(STDLIBFLAGS)
$(ocamltex): OC_COMMON_LDFLAGS += -linkall
$(ocamltex): OC_COMMON_LINKFLAGS += -linkall
$(ocamltex): VPATH += $(addprefix otherlibs/,str unix)

tools/ocamltex.cmo: OC_COMMON_CFLAGS += -no-alias-deps
tools/ocamltex.cmo: OC_COMMON_COMPFLAGS += -no-alias-deps

# we need str and unix which depend on the bytecode version of other tools
# thus we use the othertools target
Expand Down Expand Up @@ -1507,13 +1510,15 @@ ocamlnat_LIBRARIES = \

ocamlnat_MODULES = $(ocaml_MODULES)

ocamlnat$(EXE): OC_NATIVE_LDFLAGS += -linkall -I toplevel/native
ocamlnat$(EXE): OC_NATIVE_LINKFLAGS += -linkall -I toplevel/native

COMPILE_NATIVE_MODULE = \
$(CAMLOPT_CMD) $(OC_COMMON_CFLAGS) -I $(@D) $(INCLUDES) $(OC_NATIVE_CFLAGS)
$(CAMLOPT_CMD) $(OC_COMMON_COMPFLAGS) -I $(@D) $(INCLUDES) \
$(OC_NATIVE_COMPFLAGS)


toplevel/topdirs.cmx toplevel/toploop.cmx $(ocamlnat_MODULES:=.cmx): \
OC_NATIVE_CFLAGS += -I toplevel/native
OC_NATIVE_COMPFLAGS += -I toplevel/native

toplevel/toploop.cmx: toplevel/native/topeval.cmx

Expand Down Expand Up @@ -1545,10 +1550,10 @@ endif
# Default rules

%.cmo: %.ml
$(V_OCAMLC)$(CAMLC) $(OC_COMMON_CFLAGS) -I $(@D) $(INCLUDES) -c $<
$(V_OCAMLC)$(CAMLC) $(OC_COMMON_COMPFLAGS) -I $(@D) $(INCLUDES) -c $<

%.cmi: %.mli
$(V_OCAMLC)$(CAMLC) $(OC_COMMON_CFLAGS) -I $(@D) $(INCLUDES) -c $<
$(V_OCAMLC)$(CAMLC) $(OC_COMMON_COMPFLAGS) -I $(@D) $(INCLUDES) -c $<

%.cmx: %.ml
$(V_OCAMLOPT)$(COMPILE_NATIVE_MODULE) -c $<
Expand Down
56 changes: 44 additions & 12 deletions Makefile.build_config.in
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,34 @@ INSTALL_OCAMLNAT = @install_ocamlnat@
DEP_CC=@DEP_CC@ -MM
COMPUTE_DEPS=@compute_deps@

# Build-system flags to use to compile C files
OC_CFLAGS=@oc_cflags@
OC_CPPFLAGS=-I$(ROOTDIR)/runtime @oc_cppflags@

# The following variable defines flags to be passed to the C preprocessor
# when compiling C files to be linked with native code. This includes
# the native runtime itself and can also include the stub code around
# C libraries when it needs to be different from the one used to
# link with bytecode.

# These flags should be passed *in addition* to those in OC_CPPFLAGS, they
# should not replace them.

OC_NATIVE_CPPFLAGS=-DNATIVE_CODE @native_cppflags@

# Same as above, for CFLAGS
OC_NATIVE_CFLAGS=@native_cflags@

# Additional link-time options
# To support dynamic loading of shared libraries (they need to look at
# our own symbols):
OC_LDFLAGS=@oc_ldflags@
OC_DLL_LDFLAGS=@oc_dll_ldflags@
OC_EXE_LDFLAGS=@oc_exe_ldflags@

MKEXE_VIA_CC=\
$(CC) $(OC_EXE_LDFLAGS) $(OC_CFLAGS) $(CFLAGS) @mkexe_via_cc_ldflags@

# Which tool to use to display differences between files
DIFF=@DIFF@
# Which flags to pass to the diff tool
Expand Down Expand Up @@ -89,32 +117,32 @@ DEFAULT_BUILD_TARGET = @default_build_target@

# The names of the variables below take the form XXX_YYY_ZZZ where
#
# XXX is one of OC, OCAML or the name of a module. The OC prefix
# XXX is one of OC, OCAML or the lower-case name of a module. The OC prefix
# is for private variables (i.e. reserved by the compiler's build system),
# the OCAML prefix is used for variables the user can define to add their
# the OCAML prefix is used for variables users can define to add their
# own flags and the module-name prefix is for flags that apply only
# to one module.
#
# YYY refers to the backend. At the moment, it can take the values
# COMMON for the flags shared by all the backends, BYTECODE or NATIVE
# (other backends may be added in the future).
#
# ZZZ is either CFLAGS (compile-time flags) or LDFLAGS (link-time flags).
# However, contrary to what is done for C compilers, the flags in the
# CFLAGS category are not passed at link time, so if a flag is needed
# at both stages, like e.g. -g, it should be added to both XXX_YYY_CFLAGS and
# XXX_YYY_LDFLAGS.
# ZZZ is either COMPFLAGS (compile-time flags) or LINKFLAGS (link-time flags).
# Countrary to the C convention wrt. CFLAGS and LDFLAGS, the flags in the
# COMPFLAGS category are not passed at link time, so if a flag is needed
# at both stages, like e.g. -g, it should be added to both
# XXX_YYY_COMPFLAGS and XXX_YYY_LINKFLAGS.

OC_COMMON_CFLAGS = -g -strict-sequence -principal -absname \
OC_COMMON_COMPFLAGS = -g -strict-sequence -principal -absname \
-w +a-4-9-40-41-42-44-45-48 -warn-error +a -bin-annot \
-strict-formats
OC_COMMON_LDFLAGS = $(INCLUDES)
OC_COMMON_LINKFLAGS = $(INCLUDES)

OC_BYTECODE_LDFLAGS =
OC_BYTECODE_LINKFLAGS =

OC_NATIVE_CFLAGS = @oc_native_cflags@
OC_NATIVE_COMPFLAGS = @oc_native_compflags@

OC_NATIVE_LDFLAGS = -g
OC_NATIVE_LINKFLAGS = -g

# Platform-dependent command to create symbolic links
LN = @ln@
Expand All @@ -124,3 +152,7 @@ runtime_ASM_OBJECTS = $(addprefix runtime/,@runtime_asm_objects@)

# Platform-dependent module for ocamlyacc
ocamlyacc_WSTR_MODULE = @ocamlyacc_wstr_module@

# Contains TSan-specific runtime files, or nothing if TSan support is
# disabled
TSAN_NATIVE_RUNTIME_C_SOURCES = @tsan_native_runtime_c_sources@
13 changes: 3 additions & 10 deletions Makefile.common
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,8 @@ endif # ifeq "$(BOOTSTRAPPING_FLEXDLL)" "false"
# List of other libraries
ALL_OTHERLIBS = dynlink str systhreads unix runtime_events

# The following variable defines flags to be passed to the C preprocessor
# when compiling C files for the native runtime.
# These flags should be passed *in addition* to those in OC_CPPFLAGS, they
# should not replace them.
OC_NATIVE_CPPFLAGS=\
-DNATIVE_CODE -DTARGET_$(ARCH) -DMODEL_$(MODEL) -DSYS_$(SYSTEM)

# Flags to pass to the C preprocessor when preprocessing assembly files
OC_ASPPFLAGS=-I $(ROOTDIR)/runtime $(OC_NATIVE_CPPFLAGS)
OC_ASPPFLAGS=$(OC_CPPFLAGS) $(OC_NATIVE_CPPFLAGS)

OPTCOMPFLAGS=
ifeq "$(FUNCTION_SECTIONS)" "true"
Expand Down Expand Up @@ -254,7 +247,7 @@ MERGEMANIFESTEXE = $(call if_file_exists, $(1).manifest, \
.SECONDEXPANSION:

LINK_BYTECODE_PROGRAM =\
$(CAMLC) $(OC_COMMON_LDFLAGS) $(OC_BYTECODE_LDFLAGS)
$(CAMLC) $(OC_COMMON_LINKFLAGS) $(OC_BYTECODE_LINKFLAGS)

define OCAML_BYTECODE_PROGRAM
$(eval $(call PROGRAM_SYNONYM,$(1)))
Expand All @@ -265,7 +258,7 @@ $(1)$(EXE): \
endef # OCAML_BYTECODE_PROGRAM

LINK_NATIVE_PROGRAM =\
$(CAMLOPT_CMD) $(OC_COMMON_LDFLAGS) $(OC_NATIVE_LDFLAGS)
$(CAMLOPT_CMD) $(OC_COMMON_LINKFLAGS) $(OC_NATIVE_LINKFLAGS)

define OCAML_NATIVE_PROGRAM
$(eval $(call PROGRAM_SYNONYM,$(1)))
Expand Down
15 changes: 1 addition & 14 deletions Makefile.config.in
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ CC=@CC@
CC_HAS_DEBUG_PREFIX_MAP=@cc_has_debug_prefix_map@
AS_HAS_DEBUG_PREFIX_MAP=@as_has_debug_prefix_map@

### Additional link-time options
# To support dynamic loading of shared libraries (they need to look at
# our own symbols):
OC_LDFLAGS=@oc_ldflags@
OC_DLL_LDFLAGS=@oc_dll_ldflags@
OC_EXE_LDFLAGS=@oc_exe_ldflags@

LDFLAGS?=@LDFLAGS@

### How to invoke the C preprocessor through the C compiler
Expand Down Expand Up @@ -175,9 +168,7 @@ OTHERLIBRARIES=@otherlibraries@
UNIX_OR_WIN32=@unix_or_win32@
INSTALL_SOURCE_ARTIFACTS=@install_source_artifacts@

OC_CFLAGS=@oc_cflags@
CFLAGS=@CFLAGS@
OC_CPPFLAGS=-I$(ROOTDIR)/runtime @oc_cppflags@
CPPFLAGS=@CPPFLAGS@
OCAMLC_CFLAGS=@ocamlc_cflags@

Expand Down Expand Up @@ -214,8 +205,6 @@ MKEXE=@mkexe@
MKDLL=@mkdll@
MKMAINDLL=@mkmaindll@
MKEXEDEBUGFLAG=@mkexedebugflag@
MKEXE_VIA_CC=\
$(CC) $(OC_EXE_LDFLAGS) $(OC_CFLAGS) $(CFLAGS) @mkexe_via_cc_ldflags@

RUNTIMED=@debug_runtime@
INSTRUMENTED_RUNTIME=@instrumented_runtime@
Expand All @@ -225,10 +214,8 @@ WITH_OCAMLDOC=@ocamldoc@
WITH_OCAMLTEST=@ocamltest@
ASM_CFI_SUPPORTED=@asm_cfi_supported@
WITH_FRAME_POINTERS=@frame_pointers@
WITH_TSAN=@tsan@
HEADER_RESERVED_BITS=@reserved_header_bits@
LIBUNWIND_AVAILABLE=@libunwind_available@
LIBUNWIND_INCLUDE_FLAGS=@libunwind_include_flags@
LIBUNWIND_LINK_FLAGS=@libunwind_link_flags@
WITH_FPIC=@fpic@
TARGET=@target@
HOST=@host@
Expand Down
2 changes: 1 addition & 1 deletion Makefile.menhir
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ MENHIRBASICFLAGS := \
MENHIRFLAGS := \
$(MENHIRBASICFLAGS) \
--infer \
--ocamlc "$(CAMLC) $(OC_COMMON_CFLAGS) $(INCLUDES)" \
--ocamlc "$(CAMLC) $(OC_COMMON_COMPFLAGS) $(INCLUDES)" \
--fixed-exception \
--table \
--strategy simplified \
Expand Down
8 changes: 4 additions & 4 deletions aclocal.m4
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ int main (int argc, char *argv[]){
])

AC_DEFUN([OCAML_CHECK_LIBUNWIND], [
SAVED_CFLAGS="$CFLAGS"
SAVED_CPPFLAGS="$CPPFLAGS"
SAVED_LDFLAGS="$LDFLAGS"
CFLAGS="$CFLAGS $libunwind_include_flags"
LDFLAGS="$LDFLAGS $libunwind_link_flags"
CPPFLAGS="$CPPFLAGS $libunwind_cppflags"
LDFLAGS="$LDFLAGS $libunwind_ldflags"
AC_CHECK_HEADER([libunwind.h],
[AC_DEFINE([HAS_LIBUNWIND])
libunwind_available=true],
[libunwind_available=false])
LDFLAGS="$SAVED_LDFLAGS"
CFLAGS="$SAVED_CFLAGS"
CPPFLAGS="$SAVED_CPPFLAGS"
])

AC_DEFUN([OCAML_TEST_FLEXLINK], [
Expand Down
Loading