From f7796e0b2f482b98586d9bf831eb356b11025102 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Mon, 10 Apr 2017 11:07:49 -0700 Subject: [PATCH 01/10] Get tests to pass for c++ --- setup.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 88dc54f8d0d..6ea79fc20a7 100644 --- a/setup.py +++ b/setup.py @@ -172,7 +172,7 @@ LDFLAGS = tuple(EXTRA_LINK_ARGS) CFLAGS = tuple(EXTRA_COMPILE_ARGS) if "linux" in sys.platform or "darwin" in sys.platform: pymodinit_type = 'PyObject*' if PY3 else 'void' - pymodinit = '__attribute__((visibility ("default"))) {}'.format(pymodinit_type) + pymodinit = 'extern "C" __attribute__((visibility ("default"))) {}'.format(pymodinit_type) DEFINE_MACROS += (('PyMODINIT_FUNC', pymodinit),) # By default, Python3 distutils enforces compatibility of From 1b6097cfac5ebaeac8ec5d91478812fd4bf70add Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 10 Apr 2017 13:28:45 -0700 Subject: [PATCH 02/10] Pass in -fno-exceptions because we dont need them --- Makefile | 2 ++ build.yaml | 2 ++ 2 files changed, 4 insertions(+) diff --git a/Makefile b/Makefile index a55e984efd3..26a1cc5eeeb 100644 --- a/Makefile +++ b/Makefile @@ -92,6 +92,7 @@ CC_opt = $(DEFAULT_CC) CXX_opt = $(DEFAULT_CXX) LD_opt = $(DEFAULT_CC) LDXX_opt = $(DEFAULT_CXX) +CXXFLAGS_opt = -fno-exceptions CPPFLAGS_opt = -O2 DEFINES_opt = NDEBUG @@ -109,6 +110,7 @@ CC_dbg = $(DEFAULT_CC) CXX_dbg = $(DEFAULT_CXX) LD_dbg = $(DEFAULT_CC) LDXX_dbg = $(DEFAULT_CXX) +CXXFLAGS_dbg = -fno-exceptions CPPFLAGS_dbg = -O0 DEFINES_dbg = _DEBUG DEBUG diff --git a/build.yaml b/build.yaml index f80c259606b..e26fa16968a 100644 --- a/build.yaml +++ b/build.yaml @@ -4326,6 +4326,7 @@ configs: DEFINES: NDEBUG dbg: CPPFLAGS: -O0 + CXXFLAGS: -fno-exceptions DEFINES: _DEBUG DEBUG gcov: CC: gcc @@ -4366,6 +4367,7 @@ configs: LDFLAGS: -rdynamic opt: CPPFLAGS: -O2 + CXXFLAGS: -fno-exceptions DEFINES: NDEBUG stapprof: CPPFLAGS: -O2 -DGRPC_STAP_PROFILER From f85aabf6597a8edc0a35c068f3506ca04e68d14d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 10 Apr 2017 14:06:15 -0700 Subject: [PATCH 03/10] Make ruby build debuggable --- src/ruby/ext/grpc/extconf.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 70679338321..4f5d77012b1 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -84,7 +84,7 @@ unless windows puts 'Building internal gRPC into ' + grpc_lib_dir nproc = 4 nproc = Etc.nprocessors * 2 if Etc.respond_to? :nprocessors - system("make -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config}") + system("make -j#{nproc} -C #{grpc_root} #{grpc_lib_dir}/libgrpc.a CONFIG=#{grpc_config} Q=") exit 1 unless $? == 0 end From 157c5696342c91bbeb2dbd7088f814864c752bc2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 10 Apr 2017 14:27:57 -0700 Subject: [PATCH 04/10] fix c# --- tools/run_tests/run_tests.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/run_tests/run_tests.py b/tools/run_tests/run_tests.py index 0b4f26ca440..a58a7e2f201 100755 --- a/tools/run_tests/run_tests.py +++ b/tools/run_tests/run_tests.py @@ -757,7 +757,7 @@ class CSharpLanguage(object): self._make_options = ['EMBED_OPENSSL=true'] if self.args.compiler != 'coreclr': # On Mac, official distribution of mono is 32bit. - self._make_options += ['CFLAGS=-m32', 'LDFLAGS=-m32'] + self._make_options += ['CFLAGS=-m32', 'CXXFLAGS=-m32', 'LDFLAGS=-m32'] else: self._make_options = ['EMBED_OPENSSL=true', 'EMBED_ZLIB=true'] From 9f3822c4a873f96c7d1766939cba79e9c73abf6d Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Mon, 10 Apr 2017 15:07:22 -0700 Subject: [PATCH 05/10] patch ruby stuff --- src/ruby/ext/grpc/extconf.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 4f5d77012b1..6c0486f1a8c 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -65,6 +65,7 @@ ENV['MACOSX_DEPLOYMENT_TARGET'] = '10.7' ENV['AR'] = RbConfig::CONFIG['AR'] + ' rcs' ENV['CC'] = RbConfig::CONFIG['CC'] +ENV['CXX'] = RbConfig::CONFIG['CXX'] ENV['LD'] = ENV['CC'] ENV['AR'] = 'libtool -o' if RUBY_PLATFORM =~ /darwin/ From 3b90055f2cd5a20d1f4ff2b4d1581795a4eef645 Mon Sep 17 00:00:00 2001 From: Ken Payson Date: Mon, 10 Apr 2017 15:53:17 -0700 Subject: [PATCH 06/10] Fix mac build --- src/python/grpcio/commands.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/python/grpcio/commands.py b/src/python/grpcio/commands.py index e50ccbe23e7..f196b028a76 100644 --- a/src/python/grpcio/commands.py +++ b/src/python/grpcio/commands.py @@ -260,7 +260,7 @@ class BuildExt(build_ext.build_ext): """Custom build_ext command to enable compiler-specific flags.""" C_OPTIONS = { - 'unix': ('-pthread', '-std=gnu99'), + 'unix': ('-pthread',), 'msvc': (), } LINK_OPTIONS = {} From 2d111bd2f994c771f8a260cffee9e1c49dc99931 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 09:18:14 -0700 Subject: [PATCH 07/10] sanity --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3e7d080334..008584a5a4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8982,7 +8982,7 @@ if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_POSIX) add_executable(bm_cq_multiple_threads test/cpp/microbenchmarks/bm_cq_multiple_threads.cc - third_party/googletest/src/gtest-all.cc + third_party/googletest/googletest/src/gtest-all.cc ) @@ -8999,8 +8999,8 @@ target_include_directories(bm_cq_multiple_threads PRIVATE ${CARES_PLATFORM_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include - PRIVATE third_party/googletest/include - PRIVATE third_party/googletest + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest PRIVATE ${_gRPC_PROTO_GENS_DIR} ) @@ -10739,7 +10739,7 @@ if (gRPC_BUILD_TESTS) add_executable(memory_test test/core/support/memory_test.cc - third_party/googletest/src/gtest-all.cc + third_party/googletest/googletest/src/gtest-all.cc ) @@ -10756,8 +10756,8 @@ target_include_directories(memory_test PRIVATE ${CARES_PLATFORM_INCLUDE_DIR} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/cares/cares PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/third_party/gflags/include - PRIVATE third_party/googletest/include - PRIVATE third_party/googletest + PRIVATE third_party/googletest/googletest/include + PRIVATE third_party/googletest/googletest PRIVATE ${_gRPC_PROTO_GENS_DIR} ) From 85db77951c29c3441cf37bf32980b6185a2d14d2 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 10:46:31 -0700 Subject: [PATCH 08/10] Work around atomics --- BUILD | 6 ++- build.yaml | 3 ++ include/grpc/impl/codegen/port_platform.h | 6 +++ src/core/lib/support/atomic.h | 45 ++++++++++++++++ src/core/lib/support/atomic_with_atm.h | 66 +++++++++++++++++++++++ src/core/lib/support/atomic_with_std.h | 48 +++++++++++++++++ src/core/lib/surface/lame_client.cc | 8 +-- 7 files changed, 178 insertions(+), 4 deletions(-) create mode 100644 src/core/lib/support/atomic.h create mode 100644 src/core/lib/support/atomic_with_atm.h create mode 100644 src/core/lib/support/atomic_with_std.h diff --git a/BUILD b/BUILD index 1991c867432..c78a991e271 100644 --- a/BUILD +++ b/BUILD @@ -366,6 +366,10 @@ grpc_cc_library( "src/core/lib/support/backoff.h", "src/core/lib/support/block_annotate.h", "src/core/lib/support/env.h", + "src/core/lib/support/memory.h" + "src/core/lib/support/atomic.h" + "src/core/lib/support/atomic_with_atm.h" + "src/core/lib/support/atomic_with_std.h" "src/core/lib/support/mpscq.h", "src/core/lib/support/murmur_hash.h", "src/core/lib/support/spinlock.h", @@ -537,7 +541,7 @@ grpc_cc_library( "src/core/lib/surface/completion_queue.c", "src/core/lib/surface/completion_queue_factory.c", "src/core/lib/surface/event_string.c", - "src/core/lib/surface/lame_client.c", + "src/core/lib/surface/lame_client.cc", "src/core/lib/surface/metadata_array.c", "src/core/lib/surface/server.c", "src/core/lib/surface/validate_metadata.c", diff --git a/build.yaml b/build.yaml index e26fa16968a..483f950cb79 100644 --- a/build.yaml +++ b/build.yaml @@ -90,6 +90,9 @@ filegroups: - src/core/lib/support/block_annotate.h - src/core/lib/support/env.h - src/core/lib/support/memory.h + - src/core/lib/support/atomic.h + - src/core/lib/support/atomic_with_atm.h + - src/core/lib/support/atomic_with_std.h - src/core/lib/support/mpscq.h - src/core/lib/support/murmur_hash.h - src/core/lib/support/spinlock.h diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index 813e08b86e3..bac409e514d 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -290,6 +290,12 @@ #endif #endif /* GPR_NO_AUTODETECT_PLATFORM */ +#if defined(__has_include) +#if __has_include() +#define GRPC_HAS_CXX11_ATOMIC +#endif // __has_include() +#endif // defined(__has_include) + #ifndef GPR_PLATFORM_STRING #warning "GPR_PLATFORM_STRING not auto-detected" #define GPR_PLATFORM_STRING "unknown" diff --git a/src/core/lib/support/atomic.h b/src/core/lib/support/atomic.h new file mode 100644 index 00000000000..7cb495a0202 --- /dev/null +++ b/src/core/lib/support/atomic.h @@ -0,0 +1,45 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_LIB_SUPPORT_ATOMIC_H +#define GRPC_CORE_LIB_SUPPORT_ATOMIC_H + +#include + +#ifdef GPR_HAS_CXX11_ATOMIC +#include "atomic_with_std.h" +#else +#include "atomic_with_atm.h" +#endif + +#endif /* GRPC_CORE_LIB_SUPPORT_ATOMIC_H */ diff --git a/src/core/lib/support/atomic_with_atm.h b/src/core/lib/support/atomic_with_atm.h new file mode 100644 index 00000000000..6ad375736f9 --- /dev/null +++ b/src/core/lib/support/atomic_with_atm.h @@ -0,0 +1,66 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_LIB_SUPPORT_ATOMIC_WITH_ATM_H +#define GRPC_CORE_LIB_SUPPORT_ATOMIC_WITH_ATM_H + +#include + +namespace grpc_core { + +enum MemoryOrderRelaxed { memory_order_relaxed }; + +template +class atomic { + public: + static_assert(sizeof(T) <= sizeof(gpr_atm), + "Atomics of size > sizeof(gpr_atm) are not supported"); + atomic() { gpr_atm_no_barrier_store(&x_, static_cast(T())); } + + bool compare_exchange_strong(T& expected, T update, MemoryOrderRelaxed, + MemoryOrderRelaxed) { + if (!gpr_atm_no_barrier_cas(&x_, static_cast(expected), + static_cast(update))) { + expected = static_cast(gpr_atm_no_barrier_load(&x_)); + return false; + } + return true; + } + + private: + gpr_atm x_; +}; + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_SUPPORT_ATOMIC_H */ diff --git a/src/core/lib/support/atomic_with_std.h b/src/core/lib/support/atomic_with_std.h new file mode 100644 index 00000000000..7e9c19efe8a --- /dev/null +++ b/src/core/lib/support/atomic_with_std.h @@ -0,0 +1,48 @@ +/* + * + * Copyright 2017, Google Inc. + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are + * met: + * + * * Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * * Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following disclaimer + * in the documentation and/or other materials provided with the + * distribution. + * * Neither the name of Google Inc. nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS + * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT + * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR + * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT + * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT + * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + * + */ + +#ifndef GRPC_CORE_LIB_SUPPORT_ATOMIC_WITH_STD_H +#define GRPC_CORE_LIB_SUPPORT_ATOMIC_WITH_STD_H + +#include + +namespace grpc_core { + +template +using atomic = std::atomic; + +typedef std::memory_order memory_order; + +} // namespace grpc_core + +#endif /* GRPC_CORE_LIB_SUPPORT_ATOMIC_WITH_STD_H */ diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 4616fc58300..7a64726edb2 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -39,6 +39,8 @@ #include #include +#include "src/core/lib/support/atomic.h" + extern "C" { #include "src/core/lib/channel/channel_stack.h" #include "src/core/lib/support/string.h" @@ -56,7 +58,7 @@ namespace { struct CallData { grpc_linked_mdelem status; grpc_linked_mdelem details; - std::atomic filled_metadata; + grpc_core::atomic filled_metadata; }; struct ChannelData { @@ -69,8 +71,8 @@ static void fill_metadata(grpc_exec_ctx *exec_ctx, grpc_call_element *elem, CallData *calld = static_cast(elem->call_data); bool expected = false; if (!calld->filled_metadata.compare_exchange_strong( - expected, true, std::memory_order_relaxed, - std::memory_order_relaxed)) { + expected, true, grpc_core::memory_order_relaxed, + grpc_core::memory_order_relaxed)) { return; } ChannelData *chand = static_cast(elem->channel_data); From c611e60da200ee7ee1b8c5b54ab41c8386284a7e Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 19:03:42 -0700 Subject: [PATCH 09/10] Fix include --- src/core/lib/surface/lame_client.cc | 1 - 1 file changed, 1 deletion(-) diff --git a/src/core/lib/surface/lame_client.cc b/src/core/lib/surface/lame_client.cc index 7a64726edb2..88f4eaac08f 100644 --- a/src/core/lib/surface/lame_client.cc +++ b/src/core/lib/surface/lame_client.cc @@ -34,7 +34,6 @@ #include #include -#include #include #include From a566685f99d423f34c69678b2b7cbca85d974210 Mon Sep 17 00:00:00 2001 From: Craig Tiller Date: Tue, 11 Apr 2017 22:20:22 -0700 Subject: [PATCH 10/10] Public headers must be c89 --- include/grpc/impl/codegen/port_platform.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/include/grpc/impl/codegen/port_platform.h b/include/grpc/impl/codegen/port_platform.h index bac409e514d..a828f6c188f 100644 --- a/include/grpc/impl/codegen/port_platform.h +++ b/include/grpc/impl/codegen/port_platform.h @@ -293,8 +293,8 @@ #if defined(__has_include) #if __has_include() #define GRPC_HAS_CXX11_ATOMIC -#endif // __has_include() -#endif // defined(__has_include) +#endif /* __has_include() */ +#endif /* defined(__has_include) */ #ifndef GPR_PLATFORM_STRING #warning "GPR_PLATFORM_STRING not auto-detected"