diff --git a/BUILD b/BUILD index c40ee518bba3007c7becc9c3e6f2781f68f9c09a..92d0e699785fd151c37c8cdabb4b8cfac6fddbec 100644 --- a/BUILD +++ b/BUILD @@ -96,6 +96,7 @@ cc_library( "src/core/support/time_precise.c", "src/core/support/time_win32.c", "src/core/support/tls_pthread.c", + "src/core/support/wrap_memcpy.c", ], hdrs = [ "include/grpc/support/alloc.h", @@ -1171,6 +1172,7 @@ objc_library( "src/core/support/time_precise.c", "src/core/support/time_win32.c", "src/core/support/tls_pthread.c", + "src/core/support/wrap_memcpy.c", ], hdrs = [ "include/grpc/support/alloc.h", diff --git a/Makefile b/Makefile index 794778dae480681fcfa9999661d5dcf27c2bc0b6..53974d1ef0004b26d007f0a1b36d06b0f077f1b9 100644 --- a/Makefile +++ b/Makefile @@ -2247,6 +2247,7 @@ LIBGPR_SRC = \ src/core/support/time_precise.c \ src/core/support/time_win32.c \ src/core/support/tls_pthread.c \ + src/core/support/wrap_memcpy.c \ PUBLIC_HEADERS_C += \ include/grpc/support/alloc.h \ @@ -3884,15 +3885,15 @@ ifeq ($(SYSTEM),MINGW32) $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT): $(LIBGRPC_CSHARP_EXT_OBJS) $(ZLIB_DEP) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_DEP) $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc_csharp_ext.def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a -o $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -Wl,-wrap,memcpy -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=$(LIBDIR)/$(CONFIG)/grpc_csharp_ext.def -Wl,--out-implib=$(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext-imp.a -o $(LIBDIR)/$(CONFIG)/grpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) else $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT): $(LIBGRPC_CSHARP_EXT_OBJS) $(ZLIB_DEP) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(OPENSSL_DEP) $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name libgrpc_csharp_ext.$(SHARED_EXT) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -Wl,-wrap,memcpy -L$(LIBDIR)/$(CONFIG) -install_name libgrpc_csharp_ext.$(SHARED_EXT) -dynamiclib -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) else - $(Q) $(LD) $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.0 -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) + $(Q) $(LD) $(LDFLAGS) -Wl,-wrap,memcpy -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,libgrpc_csharp_ext.so.0 -o $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.$(SHARED_EXT) $(LIBGRPC_CSHARP_EXT_OBJS) $(LDLIBS) $(LIBDIR)/$(CONFIG)/libgrpc.a $(LIBDIR)/$(CONFIG)/libgpr.a $(ZLIB_MERGE_LIBS) $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.so.0 $(Q) ln -sf libgrpc_csharp_ext.$(SHARED_EXT) $(LIBDIR)/$(CONFIG)/libgrpc_csharp_ext.so endif diff --git a/binding.gyp b/binding.gyp index 133f8f48624570eb5ca6bca9b2bd199cea293bf6..0e4181cc06b0c5c3039d1abd534d62059eedf1e4 100644 --- a/binding.gyp +++ b/binding.gyp @@ -528,6 +528,7 @@ 'src/core/support/time_precise.c', 'src/core/support/time_win32.c', 'src/core/support/tls_pthread.c', + 'src/core/support/wrap_memcpy.c', ], "conditions": [ ['OS == "mac"', { @@ -743,6 +744,11 @@ "boringssl", "z", ] + }], + ['OS=="linux"', { + 'ldflags': [ + '-Wl,-wrap,memcpy' + ] }] ], "target_name": "grpc_node", diff --git a/build.yaml b/build.yaml index f8d18fbb9a681cf7f725f0f821e920a9459a91f7..41b09aa19e06d63f11a64bd0b09964ca3e4a3703 100644 --- a/build.yaml +++ b/build.yaml @@ -511,6 +511,7 @@ libs: - src/core/support/time_precise.c - src/core/support/time_win32.c - src/core/support/tls_pthread.c + - src/core/support/wrap_memcpy.c filegroups: - grpc_codegen secure: false @@ -872,6 +873,7 @@ libs: deps: - grpc - gpr + LDFLAGS: -Wl,-wrap,memcpy deps_linkage: static dll: only vs_config_type: DynamicLibrary diff --git a/gRPC.podspec b/gRPC.podspec index 30b278798a1d0b3c8876c8bda798a72d330eb09d..70e33edfc9d293baf85b00968204b5a009c7e5bf 100644 --- a/gRPC.podspec +++ b/gRPC.podspec @@ -163,6 +163,7 @@ Pod::Spec.new do |s| 'src/core/support/time_precise.c', 'src/core/support/time_win32.c', 'src/core/support/tls_pthread.c', + 'src/core/support/wrap_memcpy.c', 'src/core/security/auth_filters.h', 'src/core/security/base64.h', 'src/core/security/credentials.h', diff --git a/grpc.gemspec b/grpc.gemspec index 585d3ec9090d613950f96fb93a469b433a6e92a1..13e79d5005a5fcbb4b6b57660e9a749c95aaceb3 100755 --- a/grpc.gemspec +++ b/grpc.gemspec @@ -146,6 +146,7 @@ Gem::Specification.new do |s| s.files += %w( src/core/support/time_precise.c ) s.files += %w( src/core/support/time_win32.c ) s.files += %w( src/core/support/tls_pthread.c ) + s.files += %w( src/core/support/wrap_memcpy.c ) s.files += %w( include/grpc/grpc_security.h ) s.files += %w( include/grpc/byte_buffer.h ) s.files += %w( include/grpc/byte_buffer_reader.h ) diff --git a/package.json b/package.json index 0a3440e6e4cf20668bdb07dc74458dffecd3734c..f47a363140895a44c9888af487aee188bfef18c1 100644 --- a/package.json +++ b/package.json @@ -503,6 +503,7 @@ "src/core/support/time_precise.c", "src/core/support/time_win32.c", "src/core/support/tls_pthread.c", + "src/core/support/wrap_memcpy.c", "third_party/boringssl/crypto/aes/internal.h", "third_party/boringssl/crypto/asn1/asn1_locl.h", "third_party/boringssl/crypto/bio/internal.h", diff --git a/setup.py b/setup.py index 01e91808543760675f8b550488a76f72b56851d0..6699263ab1136504eee1782a84e58de7e36b1d50 100644 --- a/setup.py +++ b/setup.py @@ -80,10 +80,19 @@ EXTENSION_INCLUDE_DIRECTORIES = ( EXTENSION_LIBRARIES = ('m',) if not "darwin" in sys.platform: - EXTENSION_LIBRARIES += ('rt',) + EXTENSION_LIBRARIES += ('rt',) DEFINE_MACROS = (('OPENSSL_NO_ASM', 1),) +CFLAGS = (,) +LDFLAGS = (,) +if "linux" in sys.platform: + LDFLAGS += ('-Wl,-wrap,memcpy',) +if "linux" in sys.platform or "darwin" in sys.platform: + CFLAGS += ('-fvisibility=hidden',) + DEFINE_MACROS += (('PyMODINIT_FUNC', '__attribute__((visibility ("default"))) void'),) + + def cython_extensions(package_names, module_names, include_dirs, libraries, define_macros, build_with_cython=False): if ENABLE_CYTHON_TRACING: diff --git a/src/core/support/wrap_memcpy.c b/src/core/support/wrap_memcpy.c new file mode 100644 index 0000000000000000000000000000000000000000..b191d0396be5637d05ca17a01ef0da9b5b653911 --- /dev/null +++ b/src/core/support/wrap_memcpy.c @@ -0,0 +1,46 @@ +/* +* +* Copyright 2016, 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. +* +*/ + +#include <string.h> + +/* Provide a wrapped memcpy for targets that need to be backwards + * compatible with older libc's. + * + * Enable by setting LDFLAGS=-Wl,-wrap,memcpy when linking. + */ + +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); + +void *__wrap_memcpy(void *destination, const void *source, size_t num) { + return memcpy(destination, source, num); +} diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 708091df9f1eba11a7f2a5219a81aec6deb4875d..ad4714da2176fea0eb6ca142c3a4df7aee247902 100644 --- a/src/python/grpcio/grpc_core_dependencies.py +++ b/src/python/grpcio/grpc_core_dependencies.py @@ -72,6 +72,7 @@ CORE_SOURCE_FILES = [ 'src/core/support/time_precise.c', 'src/core/support/time_win32.c', 'src/core/support/tls_pthread.c', + 'src/core/support/wrap_memcpy.c', 'src/core/httpcli/httpcli_security_connector.c', 'src/core/security/base64.c', 'src/core/security/client_auth_filter.c', diff --git a/src/ruby/ext/grpc/extconf.rb b/src/ruby/ext/grpc/extconf.rb index 018353ce5d8053c8bf549150f5af5dcab3c72e89..3d809856cc0c4e7ab1f7370aa6ffad8acc47f8b9 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -80,6 +80,8 @@ if grpc_config == 'gcov' $LDFLAGS << ' -fprofile-arcs -ftest-coverage -rdynamic' end +$LDFLAGS << ' -Wl,-wrap,memcpy' + $CFLAGS << ' -std=c99 ' $CFLAGS << ' -Wall ' $CFLAGS << ' -Wextra ' diff --git a/templates/Makefile.template b/templates/Makefile.template index 1770d0f366356415c166dcd107e88b916c010ea3..a3d37804492c05efd5617746e2e556fb37198484 100644 --- a/templates/Makefile.template +++ b/templates/Makefile.template @@ -1598,6 +1598,10 @@ if lib.language == 'c++': common = common + ' $(LDLIBSXX) $(LDLIBS_PROTOBUF)' + + ldflags = '$(LDFLAGS)' + if lib.get('LDFLAGS', None): + ldflags += ' ' + lib['LDFLAGS'] %> % if lib.build == "all": @@ -1605,15 +1609,15 @@ ${out_base}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${mingw_lib_deps} $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs} + $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,--output-def=${out_base}.def -Wl,--out-implib=${out_libbase}-imp.a -o ${out_base}.$(SHARED_EXT) ${common}${mingw_libs} else ${out_libbase}.$(SHARED_EXT): $(LIB${lib.name.upper()}_OBJS) ${lib_deps} $(E) "[LD] Linking $@" $(Q) mkdir -p `dirname $@` ifeq ($(SYSTEM),Darwin) - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} + $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -install_name lib${lib.name}.$(SHARED_EXT) -dynamiclib -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} else - $(Q) ${ld} $(LDFLAGS) -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} + $(Q) ${ld} ${ldflags} -L$(LIBDIR)/$(CONFIG) -shared -Wl,-soname,lib${lib.name}.so.${settings.version.major} -o ${out_libbase}.$(SHARED_EXT) ${common}${libs} $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so.${settings.version.major} $(Q) ln -sf lib${lib.name}.$(SHARED_EXT) ${out_libbase}.so endif diff --git a/templates/binding.gyp.template b/templates/binding.gyp.template index a913585240dc55fa072bb026fd71540e9076775e..31c9f8c96cf698cf92c50a08b779fc1e59f3c57a 100644 --- a/templates/binding.gyp.template +++ b/templates/binding.gyp.template @@ -230,6 +230,11 @@ % endif % endfor ] + }], + ['OS=="linux"', { + 'ldflags': [ + '-Wl,-wrap,memcpy' + ] }] ], "target_name": "${module.name}", diff --git a/tools/doxygen/Doxyfile.core.internal b/tools/doxygen/Doxyfile.core.internal index cd49a1980dc26e9e369affbf31551f0750f3861a..17603802e07d5789e116e15f24e70f430fca9bc7 100644 --- a/tools/doxygen/Doxyfile.core.internal +++ b/tools/doxygen/Doxyfile.core.internal @@ -1150,7 +1150,8 @@ src/core/support/time.c \ src/core/support/time_posix.c \ src/core/support/time_precise.c \ src/core/support/time_win32.c \ -src/core/support/tls_pthread.c +src/core/support/tls_pthread.c \ +src/core/support/wrap_memcpy.c # This tag can be used to specify the character encoding of the source files # that doxygen parses. Internally doxygen uses the UTF-8 encoding. Doxygen uses diff --git a/tools/run_tests/sources_and_headers.json b/tools/run_tests/sources_and_headers.json index aef0023a3e5c403ae697dfa488b94c101bc058c8..505385591dee9405889ea9bd4159cf0a3f44376a 100644 --- a/tools/run_tests/sources_and_headers.json +++ b/tools/run_tests/sources_and_headers.json @@ -2929,7 +2929,8 @@ "src/core/support/time_precise.c", "src/core/support/time_precise.h", "src/core/support/time_win32.c", - "src/core/support/tls_pthread.c" + "src/core/support/tls_pthread.c", + "src/core/support/wrap_memcpy.c" ] }, { diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj b/vsprojects/vcxproj/gpr/gpr.vcxproj index b20d6ff77f53946b541b3f957193514464325a7d..2d081240f90185e0694ebc1ebf416cf8338a961d 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj @@ -293,6 +293,8 @@ </ClCompile> <ClCompile Include="$(SolutionDir)\..\src\core\support\tls_pthread.c"> </ClCompile> + <ClCompile Include="$(SolutionDir)\..\src\core\support\wrap_memcpy.c"> + </ClCompile> </ItemGroup> <Import Project="$(VCTargetsPath)\Microsoft.Cpp.targets" /> <ImportGroup Label="ExtensionTargets"> diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters index 85d8ec8672952d438d48f34845f871e5e2e27f58..1480f339d7d8a1321ea2e685576b86a1bef8a5b9 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters @@ -127,6 +127,9 @@ <ClCompile Include="$(SolutionDir)\..\src\core\support\tls_pthread.c"> <Filter>src\core\support</Filter> </ClCompile> + <ClCompile Include="$(SolutionDir)\..\src\core\support\wrap_memcpy.c"> + <Filter>src\core\support</Filter> + </ClCompile> </ItemGroup> <ItemGroup> <ClInclude Include="$(SolutionDir)\..\include\grpc\support\alloc.h">