diff options
author | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 05:28:19 +0000 |
---|---|---|
committer | rsimha@chromium.org <rsimha@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-31 05:28:19 +0000 |
commit | 360ef9f95352c591a2c07b384f4b9cd9a8d6974a (patch) | |
tree | 2454d22631e27e68d7c299b3dcc0cffd9bddfa09 | |
parent | 10f4fe478efac05f256c45daec74227af0790c3d (diff) | |
download | chromium_src-360ef9f95352c591a2c07b384f4b9cd9a8d6974a.zip chromium_src-360ef9f95352c591a2c07b384f4b9cd9a8d6974a.tar.gz chromium_src-360ef9f95352c591a2c07b384f4b9cd9a8d6974a.tar.bz2 |
Componentize protobuf_lite
Several parts of chrome that use protobufs depend on the static library 'protobuf_lite' in third_party/protobuf. As more parts of chrome are pulled into their own components, we end up linking duplicate copies of protobuf_lite into each of them. This causes memory corruption errors due to protobuf's use of static variables to maintain state.
Componentizing protobuf_lite isn't as simple as changing its target type to '<(component)'. This is because there is a larger, more full-fledged version of protobuf in the target 'protobuf_full_do_not_use', which cannot be dynamically linked with the component protobuf_lite. This is because several classes declared in protobuf_lite are partially defined in protobuf_full_do_not_use, due to which we run into issues with dllexport/dllimport annotations.
The target 'protobuf_lite' is used as a dependency all over chrome, while the target 'protobuf_full_do_not_use' is used only in one place, where it is statically linked into the protobuf compiler executable 'protoc'.
This patch does the following:
1) Pulls out most of the target definitions of 'protobuf_lite' into a separate gypi file.
2) Defines protobuf export macros for all platforms in protobuf/stubs/common.h.
3) For the target 'protobuf_lite':
- Changes the target type to '<(component)'.
- Includes the contents of protobuf_lite.gypi.
- Exports symbols via the LIBPROTOBUF_EXPORT macro.
- Makes sure targets that consume it can import its symbols.
4) For the target 'protobuf_full_do_not_use':
- Retains the target type of 'static_library'.
- Includes the contents of protobuf_lite.gypi instead of depending on the target 'protobuf_lite'.
BUG=172800
TEST=Enable component builds and make sure all chrome targets build, and all tests run and pass.
Review URL: https://codereview.chromium.org/12090058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@179806 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | third_party/protobuf/README.chromium | 4 | ||||
-rw-r--r-- | third_party/protobuf/protobuf.gyp | 76 | ||||
-rw-r--r-- | third_party/protobuf/protobuf_lite.gypi | 69 | ||||
-rw-r--r-- | third_party/protobuf/src/google/protobuf/stubs/common.h | 37 | ||||
-rw-r--r-- | third_party/protobuf/src/google/protobuf/stubs/once.h | 3 |
5 files changed, 112 insertions, 77 deletions
diff --git a/third_party/protobuf/README.chromium b/third_party/protobuf/README.chromium index 7672411..4439bac 100644 --- a/third_party/protobuf/README.chromium +++ b/third_party/protobuf/README.chromium @@ -22,6 +22,10 @@ See r62331 for the patch. This code has been patched to ensure that files in the target protobuf_lite do not include headers from protobuf_full. See r173228 for the patch. +This code has been patched to make the target protobuf_lite a component so that +targets that depend on it can be componentized. See http://crbug.com/172800. +TODO(rsimha): Add revision number here after CL is committed. + Revisions r427 and r430 were cherry-picked from upstream. Cherry-pick patch from http://code.google.com/p/protobuf/issues/detail?id=425. diff --git a/third_party/protobuf/protobuf.gyp b/third_party/protobuf/protobuf.gyp index f9a624f..7c507c1 100644 --- a/third_party/protobuf/protobuf.gyp +++ b/third_party/protobuf/protobuf.gyp @@ -129,74 +129,23 @@ # to your .proto file. { 'target_name': 'protobuf_lite', - 'type': 'static_library', + 'type': '<(component)', 'toolsets': ['host', 'target'], - 'sources': [ - 'src/google/protobuf/stubs/atomicops.h', - 'src/google/protobuf/stubs/atomicops_internals_arm_gcc.h', - 'src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h', - 'src/google/protobuf/stubs/atomicops_internals_macosx.h', - 'src/google/protobuf/stubs/atomicops_internals_mips_gcc.h', - 'src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc', - 'src/google/protobuf/stubs/atomicops_internals_x86_gcc.h', - 'src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc', - 'src/google/protobuf/stubs/atomicops_internals_x86_msvc.h', - 'src/google/protobuf/stubs/common.h', - 'src/google/protobuf/stubs/once.h', - 'src/google/protobuf/stubs/platform_macros.h', - 'src/google/protobuf/extension_set.h', - 'src/google/protobuf/generated_message_util.h', - 'src/google/protobuf/message_lite.h', - 'src/google/protobuf/repeated_field.h', - 'src/google/protobuf/unknown_field_set.cc', - 'src/google/protobuf/unknown_field_set.h', - 'src/google/protobuf/wire_format_lite.h', - 'src/google/protobuf/wire_format_lite_inl.h', - 'src/google/protobuf/io/coded_stream.h', - 'src/google/protobuf/io/zero_copy_stream.h', - 'src/google/protobuf/io/zero_copy_stream_impl_lite.h', - - 'src/google/protobuf/stubs/common.cc', - 'src/google/protobuf/stubs/once.cc', - 'src/google/protobuf/stubs/hash.h', - 'src/google/protobuf/stubs/map-util.h', - 'src/google/protobuf/stubs/stl_util-inl.h', - 'src/google/protobuf/extension_set.cc', - 'src/google/protobuf/generated_message_util.cc', - 'src/google/protobuf/message_lite.cc', - 'src/google/protobuf/repeated_field.cc', - 'src/google/protobuf/wire_format_lite.cc', - 'src/google/protobuf/io/coded_stream.cc', - 'src/google/protobuf/io/coded_stream_inl.h', - 'src/google/protobuf/io/zero_copy_stream.cc', - 'src/google/protobuf/io/zero_copy_stream_impl_lite.cc', - '<(config_h_dir)/config.h', + 'includes': [ + 'protobuf_lite.gypi', ], - 'include_dirs': [ - '<(config_h_dir)', - 'src', - ], - # This macro must be defined to suppress the use of dynamic_cast<>, - # which requires RTTI. + # Required for component builds. See http://crbug.com/172800. 'defines': [ - 'GOOGLE_PROTOBUF_NO_RTTI', - 'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER', + 'LIBPROTOBUF_EXPORTS', + 'PROTOBUF_USE_DLLS', ], - 'direct_dependent_settings': { - 'include_dirs': [ - '<(config_h_dir)', - 'src', - ], 'defines': [ - 'GOOGLE_PROTOBUF_NO_RTTI', - 'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER', + 'PROTOBUF_USE_DLLS', ], - # TODO(jschuh): http://crbug.com/167187 size_t -> int. - 'msvs_disabled_warnings': [ 4267 ], }, }, - # This is the full, heavy protobuf lib that's needed for c++ .proto's + # This is the full, heavy protobuf lib that's needed for c++ .protos # that don't specify the LITE_RUNTIME option. The protocol # compiler itself (protoc) falls into that category. # @@ -205,6 +154,9 @@ 'target_name': 'protobuf_full_do_not_use', 'type': 'static_library', 'toolsets': ['host','target'], + 'includes': [ + 'protobuf_lite.gypi', + ], 'sources': [ 'src/google/protobuf/descriptor.h', 'src/google/protobuf/descriptor.pb.h', @@ -250,12 +202,6 @@ 'src/google/protobuf/compiler/importer.cc', 'src/google/protobuf/compiler/parser.cc', ], - 'dependencies': [ - 'protobuf_lite', - ], - 'export_dependent_settings': [ - 'protobuf_lite', - ], }, { 'target_name': 'protoc', diff --git a/third_party/protobuf/protobuf_lite.gypi b/third_party/protobuf/protobuf_lite.gypi new file mode 100644 index 0000000..e66d29f --- /dev/null +++ b/third_party/protobuf/protobuf_lite.gypi @@ -0,0 +1,69 @@ +# Copyright 2013 The Chromium Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + +{ + 'sources': [ + 'src/google/protobuf/stubs/atomicops.h', + 'src/google/protobuf/stubs/atomicops_internals_arm_gcc.h', + 'src/google/protobuf/stubs/atomicops_internals_atomicword_compat.h', + 'src/google/protobuf/stubs/atomicops_internals_macosx.h', + 'src/google/protobuf/stubs/atomicops_internals_mips_gcc.h', + 'src/google/protobuf/stubs/atomicops_internals_x86_gcc.cc', + 'src/google/protobuf/stubs/atomicops_internals_x86_gcc.h', + 'src/google/protobuf/stubs/atomicops_internals_x86_msvc.cc', + 'src/google/protobuf/stubs/atomicops_internals_x86_msvc.h', + 'src/google/protobuf/stubs/common.h', + 'src/google/protobuf/stubs/once.h', + 'src/google/protobuf/stubs/platform_macros.h', + 'src/google/protobuf/extension_set.h', + 'src/google/protobuf/generated_message_util.h', + 'src/google/protobuf/message_lite.h', + 'src/google/protobuf/repeated_field.h', + 'src/google/protobuf/unknown_field_set.cc', + 'src/google/protobuf/unknown_field_set.h', + 'src/google/protobuf/wire_format_lite.h', + 'src/google/protobuf/wire_format_lite_inl.h', + 'src/google/protobuf/io/coded_stream.h', + 'src/google/protobuf/io/zero_copy_stream.h', + 'src/google/protobuf/io/zero_copy_stream_impl_lite.h', + + 'src/google/protobuf/stubs/common.cc', + 'src/google/protobuf/stubs/once.cc', + 'src/google/protobuf/stubs/hash.h', + 'src/google/protobuf/stubs/map-util.h', + 'src/google/protobuf/stubs/stl_util-inl.h', + 'src/google/protobuf/extension_set.cc', + 'src/google/protobuf/generated_message_util.cc', + 'src/google/protobuf/message_lite.cc', + 'src/google/protobuf/repeated_field.cc', + 'src/google/protobuf/wire_format_lite.cc', + 'src/google/protobuf/io/coded_stream.cc', + 'src/google/protobuf/io/coded_stream_inl.h', + 'src/google/protobuf/io/zero_copy_stream.cc', + 'src/google/protobuf/io/zero_copy_stream_impl_lite.cc', + '<(config_h_dir)/config.h', + ], + 'include_dirs': [ + '<(config_h_dir)', + 'src', + ], + # This macro must be defined to suppress the use of dynamic_cast<>, + # which requires RTTI. + 'defines': [ + 'GOOGLE_PROTOBUF_NO_RTTI', + 'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER', + ], + 'direct_dependent_settings': { + 'include_dirs': [ + '<(config_h_dir)', + 'src', + ], + 'defines': [ + 'GOOGLE_PROTOBUF_NO_RTTI', + 'GOOGLE_PROTOBUF_NO_STATIC_INITIALIZER', + ], + # TODO(jschuh): http://crbug.com/167187 size_t -> int. + 'msvs_disabled_warnings': [ 4267 ], + }, +} diff --git a/third_party/protobuf/src/google/protobuf/stubs/common.h b/third_party/protobuf/src/google/protobuf/stubs/common.h index 00af41a..cad22fa 100644 --- a/third_party/protobuf/src/google/protobuf/stubs/common.h +++ b/third_party/protobuf/src/google/protobuf/stubs/common.h @@ -85,18 +85,33 @@ namespace protobuf { TypeName(const TypeName&); \ void operator=(const TypeName&) -#if defined(_MSC_VER) && defined(PROTOBUF_USE_DLLS) - #ifdef LIBPROTOBUF_EXPORTS - #define LIBPROTOBUF_EXPORT __declspec(dllexport) - #else - #define LIBPROTOBUF_EXPORT __declspec(dllimport) +// The macros defined below are required in order to make protobuf_lite a +// component on all platforms. See http://crbug.com/172800. +#if defined(COMPONENT_BUILD) && defined(PROTOBUF_USE_DLLS) + #if defined(_MSC_VER) + #ifdef LIBPROTOBUF_EXPORTS + #define LIBPROTOBUF_EXPORT __declspec(dllexport) + #else + #define LIBPROTOBUF_EXPORT __declspec(dllimport) + #endif + #ifdef LIBPROTOC_EXPORTS + #define LIBPROTOC_EXPORT __declspec(dllexport) + #else + #define LIBPROTOC_EXPORT __declspec(dllimport) + #endif + #else // defined(_MSC_VER) + #ifdef LIBPROTOBUF_EXPORTS + #define LIBPROTOBUF_EXPORT __attribute__((visibility("default"))) + #else + #define LIBPROTOBUF_EXPORT + #endif + #ifdef LIBPROTOC_EXPORTS + #define LIBPROTOC_EXPORT __attribute__((visibility("default"))) + #else + #define LIBPROTOC_EXPORT + #endif #endif - #ifdef LIBPROTOC_EXPORTS - #define LIBPROTOC_EXPORT __declspec(dllexport) - #else - #define LIBPROTOC_EXPORT __declspec(dllimport) - #endif -#else +#else // defined(COMPONENT_BUILD) && defined(PROTOBUF_USE_DLLS) #define LIBPROTOBUF_EXPORT #define LIBPROTOC_EXPORT #endif diff --git a/third_party/protobuf/src/google/protobuf/stubs/once.h b/third_party/protobuf/src/google/protobuf/stubs/once.h index c8cbe24..ead86fb 100644 --- a/third_party/protobuf/src/google/protobuf/stubs/once.h +++ b/third_party/protobuf/src/google/protobuf/stubs/once.h @@ -118,7 +118,8 @@ typedef internal::AtomicWord ProtobufOnceType; #define GOOGLE_PROTOBUF_ONCE_INIT ::google::protobuf::ONCE_STATE_UNINITIALIZED -void GoogleOnceInitImpl(ProtobufOnceType* once, Closure* closure); +LIBPROTOBUF_EXPORT void GoogleOnceInitImpl(ProtobufOnceType* once, + Closure* closure); inline void GoogleOnceInit(ProtobufOnceType* once, void (*init_func)()) { if (internal::Acquire_Load(once) != ONCE_STATE_DONE) { |