From b5b18faddc0f457623eef93bad362851cd3fcd19 Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Wed, 16 Mar 2016 15:02:28 -0700 Subject: [PATCH 1/5] Update clang for the Dockerfile used in tsan tests --- .../tools/dockerfile/clang_update.include | 32 ++++++++++++++++++ .../test/cxx_jessie_x64/Dockerfile.template | 2 +- .../dockerfile/test/cxx_jessie_x64/Dockerfile | 33 +++++++++++++++++++ 3 files changed, 66 insertions(+), 1 deletion(-) create mode 100644 templates/tools/dockerfile/clang_update.include diff --git a/templates/tools/dockerfile/clang_update.include b/templates/tools/dockerfile/clang_update.include new file mode 100644 index 00000000000..83ab3e0bbbf --- /dev/null +++ b/templates/tools/dockerfile/clang_update.include @@ -0,0 +1,32 @@ +#================= +# Update clang to a version with improved tsan + +RUN apt-get update && apt-get -y install python cmake && apt-get clean + +RUN git clone -n -b release_38 http://llvm.org/git/llvm.git && ${'\\'} + cd llvm && git checkout ad57503 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/clang.git && ${'\\'} + cd clang && git checkout ad2c56e && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/compiler-rt.git && ${'\\'} + cd compiler-rt && git checkout 3176922 && cd .. +RUN git clone -n -b release_38 ${'\\'} + http://llvm.org/git/clang-tools-extra.git && cd clang-tools-extra && ${'\\'} + git checkout c288525 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/libcxx.git && ${'\\'} + cd libcxx && git checkout fda3549 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/libcxxabi.git && ${'\\'} + cd libcxxabi && git checkout 8d4e51d && cd .. + +RUN mv clang llvm/tools +RUN mv compiler-rt llvm/projects +RUN mv clang-tools-extra llvm/tools/clang/tools +RUN mv libcxx llvm/projects +RUN mv libcxxabi llvm/projects + +RUN mkdir llvm-build +RUN cd llvm-build && cmake ${'\\'} + -DCMAKE_BUILD_TYPE:STRING=Release ${'\\'} + -DCMAKE_INSTALL_PREFIX:STRING=/usr ${'\\'} + -DLLVM_TARGETS_TO_BUILD:STRING=X86 ${'\\'} + ../llvm +RUN make -C llvm-build && make -C llvm-build install && rm -rf llvm-build diff --git a/templates/tools/dockerfile/test/cxx_jessie_x64/Dockerfile.template b/templates/tools/dockerfile/test/cxx_jessie_x64/Dockerfile.template index 842c5348050..eb11ce352c8 100644 --- a/templates/tools/dockerfile/test/cxx_jessie_x64/Dockerfile.template +++ b/templates/tools/dockerfile/test/cxx_jessie_x64/Dockerfile.template @@ -33,7 +33,7 @@ <%include file="../../apt_get_basic.include"/> <%include file="../../cxx_deps.include"/> + <%include file="../../clang_update.include"/> <%include file="../../run_tests_addons.include"/> # Define the default command. CMD ["bash"] - \ No newline at end of file diff --git a/tools/dockerfile/test/cxx_jessie_x64/Dockerfile b/tools/dockerfile/test/cxx_jessie_x64/Dockerfile index e3ed39dfe6c..b848f233b70 100644 --- a/tools/dockerfile/test/cxx_jessie_x64/Dockerfile +++ b/tools/dockerfile/test/cxx_jessie_x64/Dockerfile @@ -67,6 +67,39 @@ RUN apt-get update && apt-get install -y time && apt-get clean # C++ dependencies RUN apt-get update && apt-get -y install libgflags-dev libgtest-dev libc++-dev clang && apt-get clean +#================= +# Update clang to a version with improved tsan + +RUN apt-get update && apt-get -y install python cmake && apt-get clean + +RUN git clone -n -b release_38 http://llvm.org/git/llvm.git && \ + cd llvm && git checkout ad57503 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/clang.git && \ + cd clang && git checkout ad2c56e && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/compiler-rt.git && \ + cd compiler-rt && git checkout 3176922 && cd .. +RUN git clone -n -b release_38 \ + http://llvm.org/git/clang-tools-extra.git && cd clang-tools-extra && \ + git checkout c288525 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/libcxx.git && \ + cd libcxx && git checkout fda3549 && cd .. +RUN git clone -n -b release_38 http://llvm.org/git/libcxxabi.git && \ + cd libcxxabi && git checkout 8d4e51d && cd .. + +RUN mv clang llvm/tools +RUN mv compiler-rt llvm/projects +RUN mv clang-tools-extra llvm/tools/clang/tools +RUN mv libcxx llvm/projects +RUN mv libcxxabi llvm/projects + +RUN mkdir llvm-build +RUN cd llvm-build && cmake \ + -DCMAKE_BUILD_TYPE:STRING=Release \ + -DCMAKE_INSTALL_PREFIX:STRING=/usr \ + -DLLVM_TARGETS_TO_BUILD:STRING=X86 \ + ../llvm +RUN make -C llvm-build && make -C llvm-build install && rm -rf llvm-build + # Prepare ccache RUN ln -s /usr/bin/ccache /usr/local/bin/gcc RUN ln -s /usr/bin/ccache /usr/local/bin/g++ From 112923f75ea169a36cd1883897f78f918d6a80ac Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Thu, 17 Mar 2016 08:16:47 -0700 Subject: [PATCH 2/5] Remove JENKINS_BUILD specific options from tsan --- Makefile | 4 ++-- build.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 01d8922f376..6b93dee7e60 100644 --- a/Makefile +++ b/Makefile @@ -189,7 +189,7 @@ CXX_tsan = clang++ LD_tsan = clang LDXX_tsan = clang++ CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_tsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +LDFLAGS_tsan = -fsanitize=thread -fPIE -pie DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 VALID_CONFIG_stapprof = 1 @@ -226,7 +226,7 @@ CXX_etsan = clang++ LD_etsan = clang LDXX_etsan = clang++ CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_etsan = -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) +LDFLAGS_etsan = -fsanitize=thread -fPIE -pie DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 diff --git a/build.yaml b/build.yaml index 1f010244134..73f5ac4e4ad 100644 --- a/build.yaml +++ b/build.yaml @@ -2769,7 +2769,7 @@ configs: CXX: clang++ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER LD: clang - LDFLAGS: -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) + LDFLAGS: -fsanitize=thread -fPIE -pie LDXX: clang++ compile_the_world: true test_environ: @@ -2824,7 +2824,7 @@ configs: -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS CXX: clang++ LD: clang - LDFLAGS: -fsanitize=thread -fPIE -pie $(if $(JENKINS_BUILD),-Wl$(comma)-Ttext-segment=0x7e0000000000,) + LDFLAGS: -fsanitize=thread -fPIE -pie LDXX: clang++ compile_the_world: true test_environ: From 5bda4d46d168a764ef5ea69e7527fec65a7e473f Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Thu, 17 Mar 2016 17:27:11 -0700 Subject: [PATCH 3/5] Disable PIE --- Makefile | 8 ++++---- build.yaml | 8 ++++---- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/Makefile b/Makefile index 6b93dee7e60..6b9e50736e5 100644 --- a/Makefile +++ b/Makefile @@ -188,8 +188,8 @@ CC_tsan = clang CXX_tsan = clang++ LD_tsan = clang LDXX_tsan = clang++ -CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_tsan = -fsanitize=thread -fPIE -pie +CPPFLAGS_tsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_tsan = -fsanitize=thread DEFINES_tsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 VALID_CONFIG_stapprof = 1 @@ -225,8 +225,8 @@ CC_etsan = clang CXX_etsan = clang++ LD_etsan = clang LDXX_etsan = clang++ -CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS -LDFLAGS_etsan = -fsanitize=thread -fPIE -pie +CPPFLAGS_etsan = -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument -DGPR_NO_DIRECT_SYSCALLS +LDFLAGS_etsan = -fsanitize=thread DEFINES_etsan = _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER DEFINES_etsan += GRPC_TEST_SLOWDOWN_BUILD_FACTOR=5 diff --git a/build.yaml b/build.yaml index 73f5ac4e4ad..02a83441e51 100644 --- a/build.yaml +++ b/build.yaml @@ -2765,11 +2765,11 @@ configs: etsan: CC: clang CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument - -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS + -DGPR_NO_DIRECT_SYSCALLS CXX: clang++ DEFINES: _DEBUG DEBUG GRPC_EXECUTION_CONTEXT_SANITIZER LD: clang - LDFLAGS: -fsanitize=thread -fPIE -pie + LDFLAGS: -fsanitize=thread LDXX: clang++ compile_the_world: true test_environ: @@ -2821,10 +2821,10 @@ configs: tsan: CC: clang CPPFLAGS: -O0 -fsanitize=thread -fno-omit-frame-pointer -Wno-unused-command-line-argument - -fPIE -pie -DGPR_NO_DIRECT_SYSCALLS + -DGPR_NO_DIRECT_SYSCALLS CXX: clang++ LD: clang - LDFLAGS: -fsanitize=thread -fPIE -pie + LDFLAGS: -fsanitize=thread LDXX: clang++ compile_the_world: true test_environ: From 4ce09cf760db8771f9c9b222d6f06df61c058ff7 Mon Sep 17 00:00:00 2001 From: vjpai Date: Fri, 18 Mar 2016 23:09:15 -0700 Subject: [PATCH 4/5] Reorder a release store after the operations it protects. --- src/core/iomgr/fd_posix.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/core/iomgr/fd_posix.c b/src/core/iomgr/fd_posix.c index 4ba7c5df943..3edafa0b070 100644 --- a/src/core/iomgr/fd_posix.c +++ b/src/core/iomgr/fd_posix.c @@ -72,6 +72,9 @@ static grpc_fd *fd_freelist = NULL; static gpr_mu fd_freelist_mu; static void freelist_fd(grpc_fd *fd) { + // Note that this function must be called after a release store (or + // full-barrier operation) on refst so that prior actions on the fd are + // ordered before the fd becomes visible to the freelist gpr_mu_lock(&fd_freelist_mu); fd->freelist_next = fd_freelist; fd_freelist = fd; @@ -92,7 +95,6 @@ static grpc_fd *alloc_fd(int fd) { gpr_mu_init(&r->mu); } - gpr_atm_rel_store(&r->refst, 1); r->shutdown = 0; r->read_closure = CLOSURE_NOT_READY; r->write_closure = CLOSURE_NOT_READY; @@ -104,6 +106,11 @@ static grpc_fd *alloc_fd(int fd) { r->on_done_closure = NULL; r->closed = 0; r->released = 0; + // The last operation on r before returning it should be a release-store + // so that all the above fields are globally visible before the value of + // r could escape to another thread. Our refcount itself needs a release-store + // so use this + gpr_atm_rel_store(&r->refst, 1); return r; } From c0e3952d274a1e262dcf2ad313271775cd360c1c Mon Sep 17 00:00:00 2001 From: Vijay Pai Date: Sat, 19 Mar 2016 05:53:21 -0700 Subject: [PATCH 5/5] Re-enable tsan for qps tests --- build.yaml | 4 ---- tools/run_tests/tests.json | 8 ++------ 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/build.yaml b/build.yaml index fc13d04264a..5f61e18c0aa 100644 --- a/build.yaml +++ b/build.yaml @@ -2452,8 +2452,6 @@ targets: - gpr_test_util - gpr - grpc++_test_config - exclude_configs: - - tsan platforms: - mac - linux @@ -2473,8 +2471,6 @@ targets: - gpr_test_util - gpr - grpc++_test_config - exclude_configs: - - tsan platforms: - mac - linux diff --git a/tools/run_tests/tests.json b/tools/run_tests/tests.json index 099a516709c..2be7d8a48a8 100644 --- a/tools/run_tests/tests.json +++ b/tools/run_tests/tests.json @@ -2296,9 +2296,7 @@ "posix" ], "cpu_cost": 10, - "exclude_configs": [ - "tsan" - ], + "exclude_configs": [], "flaky": false, "gtest": false, "language": "c++", @@ -2317,9 +2315,7 @@ "posix" ], "cpu_cost": 10, - "exclude_configs": [ - "tsan" - ], + "exclude_configs": [], "flaky": false, "gtest": false, "language": "c++",