diff --git a/BUILD b/BUILD index c40ee518bba..92d0e699785 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 631fff805ee..9e8b116528e 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 \ @@ -3886,15 +3887,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 133f8f48624..0e4181cc06b 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 2a9dc3824b0..2fbca377cb6 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 @@ -874,6 +875,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 30b278798a1..70e33edfc9d 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 585d3ec9090..13e79d5005a 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 0a3440e6e4c..f47a3631408 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 01e91808543..2f73e94c458 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 00000000000..cb59cc7e50e --- /dev/null +++ b/src/core/support/wrap_memcpy.c @@ -0,0 +1,48 @@ +/* + * + * 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 + +/* 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. + */ + +#ifdef __linux__ +__asm__(".symver memcpy,memcpy@GLIBC_2.2.5"); + +void *__wrap_memcpy(void *destination, const void *source, size_t num) { + return memcpy(destination, source, num); +} +#endif diff --git a/src/python/grpcio/grpc_core_dependencies.py b/src/python/grpcio/grpc_core_dependencies.py index 708091df9f1..ad4714da217 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 018353ce5d8..b13dd6c76d2 100644 --- a/src/ruby/ext/grpc/extconf.rb +++ b/src/ruby/ext/grpc/extconf.rb @@ -1,4 +1,4 @@ -# Copyright 2015, Google Inc. +# Copyright 2015-2016, Google Inc. # All rights reserved. # # Redistribution and use in source and binary forms, with or without @@ -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 1770d0f3663..a3d37804492 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 a913585240d..31c9f8c96cf 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 cd49a1980dc..17603802e07 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 172385675f2..75eb95f13d8 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 b20d6ff77f5..2d081240f90 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj @@ -293,6 +293,8 @@ + + diff --git a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters index 85d8ec86729..1480f339d7d 100644 --- a/vsprojects/vcxproj/gpr/gpr.vcxproj.filters +++ b/vsprojects/vcxproj/gpr/gpr.vcxproj.filters @@ -127,6 +127,9 @@ src\core\support + + src\core\support +