summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 12:53:16 +0000
committermark@chromium.org <mark@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-08-13 12:53:16 +0000
commit1bba09cc68b4f5335ecd335a4e52b74f221ef583 (patch)
treed3d7cbe9c9cfada1a901023b4c50245f559e5fe4
parentf3964daf023b2d10df1111248de367a0647d6392 (diff)
downloadchromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.zip
chromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.tar.gz
chromium_src-1bba09cc68b4f5335ecd335a4e52b74f221ef583.tar.bz2
Disable RTTI and C++ exceptions in the Mac build. Disable RTTI in the Linux
build, where C++ exceptions are already disabled. BUG=19094 12248 TEST=Mac release-mode Google Chrome.app should shrink by about 6MB. Mac disk image should shrink by about 1.5MB. Linux binary and package should shrink too. Review URL: http://codereview.chromium.org/165330 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@23304 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--base/file_path.h8
-rw-r--r--base/hash_tables.h131
-rw-r--r--breakpad/breakpad.gyp5
-rw-r--r--build/common.gypi13
-rw-r--r--chrome/browser/cocoa/nsimage_cache.h8
-rw-r--r--chrome/browser/cocoa/nsimage_cache.mm11
-rw-r--r--chrome/browser/profile.h4
-rw-r--r--testing/gtest.gyp23
8 files changed, 106 insertions, 97 deletions
diff --git a/base/file_path.h b/base/file_path.h
index 3d19c01..6bd2216 100644
--- a/base/file_path.h
+++ b/base/file_path.h
@@ -66,6 +66,7 @@
#define BASE_FILE_PATH_H_
#include <string>
+#include <vector>
#include "base/basictypes.h"
#include "base/compiler_specific.h"
@@ -257,14 +258,15 @@ class FilePath {
#define FILE_PATH_LITERAL(x) L ## x
#endif // OS_WIN
-// Implement hash function so that we can use FilePaths in hashsets and maps.
+// Provide a hash function so that hash_sets and maps can contain FilePath
+// objects.
#if defined(COMPILER_GCC)
namespace __gnu_cxx {
template<>
struct hash<FilePath> {
- size_t operator()(const FilePath& f) const {
- return std::tr1::hash<FilePath::StringType>()(f.value());
+ std::size_t operator()(const FilePath& f) const {
+ return hash<FilePath::StringType>()(f.value());
}
};
diff --git a/base/hash_tables.h b/base/hash_tables.h
index 3f701f0..c2dcde5 100644
--- a/base/hash_tables.h
+++ b/base/hash_tables.h
@@ -12,8 +12,8 @@
// base::hash_set<int> my_set;
//
-#ifndef BASE_HASH_TABLES_H__
-#define BASE_HASH_TABLES_H__
+#ifndef BASE_HASH_TABLES_H_
+#define BASE_HASH_TABLES_H_
#include "build/build_config.h"
@@ -37,99 +37,68 @@ using stdext::hash_set;
#include <ext/hash_map>
#include <ext/hash_set>
+#include <string>
#ifdef CHROME_OLD__DEPRECATED
#define __DEPRECATED CHROME_OLD__DEPRECATED
#undef CHROME_OLD__DEPRECATED
#endif
-#include <tr1/functional>
namespace base {
using __gnu_cxx::hash_map;
using __gnu_cxx::hash_set;
-}
+} // namespace base
-// Implement string hash functions so that strings of various flavors can
-// be used as keys in STL maps and sets.
namespace __gnu_cxx {
-template<>
-struct hash<wchar_t*> {
- size_t operator()(const wchar_t* s) const {
- return std::tr1::hash<const wchar_t*>()(s);
- }
-};
-
-template<>
-struct hash<const wchar_t*> {
- size_t operator()(const wchar_t* s) const {
- return std::tr1::hash<const wchar_t*>()(s);
- }
-};
-
-template<>
-struct hash<std::wstring> {
- size_t operator()(const std::wstring& s) const {
- return std::tr1::hash<std::wstring>()(s);
- }
-};
-
-template<>
-struct hash<const std::wstring> {
- size_t operator()(const std::wstring& s) const {
- return std::tr1::hash<std::wstring>()(s);
- }
-};
-
-template<>
-struct hash<std::string> {
- size_t operator()(const std::string& s) const {
- return std::tr1::hash<std::string>()(s);
- }
-};
-
-template<>
-struct hash<const std::string> {
- size_t operator()(const std::string& s) const {
- return std::tr1::hash<std::string>()(s);
- }
-};
-
-template<>
-struct hash<long long> {
- size_t operator()(long long i) const {
- return std::tr1::hash<long>()((long) i);
- }
-};
+// The GNU C++ library provides identiy hash functions for many integral types,
+// but not for |long long|. This hash function will truncate if |size_t| is
+// narrower than |long long|. This is probably good enough for what we will
+// use it for.
+
+#define DEFINE_TRIVIAL_HASH(integral_type) \
+ template<> \
+ struct hash<integral_type> { \
+ std::size_t operator()(integral_type value) const { \
+ return static_cast<std::size_t>(value); \
+ } \
+ }
+
+DEFINE_TRIVIAL_HASH(long long);
+DEFINE_TRIVIAL_HASH(unsigned long long);
+
+#undef DEFINE_TRIVIAL_HASH
+
+// Implement string hash functions so that strings of various flavors can
+// be used as keys in STL maps and sets. The hash algorithm comes from the
+// GNU C++ library, in <tr1/functional>. It is duplicated here because GCC
+// versions prior to 4.3.2 are unable to compile <tr1/functional> when RTTI
+// is disabled, as it is in our build.
+
+#define DEFINE_STRING_HASH(string_type) \
+ template<> \
+ struct hash<string_type> { \
+ std::size_t operator()(const string_type& s) const { \
+ std::size_t result = 0; \
+ for (string_type::const_iterator i = s.begin(); i != s.end(); ++i) \
+ result = (result * 131) + *i; \
+ return result; \
+ } \
+ }
+
+DEFINE_STRING_HASH(std::string);
+DEFINE_STRING_HASH(std::wstring);
#if defined(WCHAR_T_IS_UTF32)
-template<>
-struct hash<string16> {
- size_t operator()(const string16& s) const {
- // This comes from GNU libstdc++, but the types have been changed to
- // make it compile. The lib only defines the hash for string and wstring.
- std::size_t result = 0;
- for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
- result = (result * 131) + *i;
- return result;
- }
-};
-
-template<>
-struct hash<const string16> {
- size_t operator()(const string16& s) const {
- // This comes from GNU libstdc++, but the types have been changed to
- // make it compile. The lib only defines the hash for string and wstring.
- std::size_t result = 0;
- for (string16::const_iterator i = s.begin(); i != s.end(); ++i)
- result = (result * 131) + *i;
- return result;
- }
-};
-#endif
+// If string16 and std::wstring are not the same type, provide a
+// specialization for string16.
+DEFINE_STRING_HASH(string16);
+#endif // WCHAR_T_IS_UTF32
-}
+#undef DEFINE_STRING_HASH
-#endif
+} // namespace __gnu_cxx
+
+#endif // COMPILER
-#endif // BASE_HASH_TABLES_H__
+#endif // BASE_HASH_TABLES_H_
diff --git a/breakpad/breakpad.gyp b/breakpad/breakpad.gyp
index 7fac254..334bcd1 100644
--- a/breakpad/breakpad.gyp
+++ b/breakpad/breakpad.gyp
@@ -144,6 +144,11 @@
'src/client/mac/Framework/Breakpad.mm',
'src/client/mac/Framework/OnDemandServer.mm',
],
+ 'xcode_settings': {
+ # The Mac Breakpad framework uses C++ exceptions internally, but
+ # is careful to not propagate them to callers.
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'YES',
+ },
},
],
}],
diff --git a/build/common.gypi b/build/common.gypi
index d9d35dc..8ff4fb3 100644
--- a/build/common.gypi
+++ b/build/common.gypi
@@ -356,13 +356,14 @@
'werror%': '-Werror',
},
'cflags': [
- '<(werror)', # See note above about the werror variable.
- '-pthread',
- '-fno-exceptions',
- '-Wall',
- '-D_FILE_OFFSET_BITS=64',
+ '<(werror)', # See note above about the werror variable.
+ '-pthread',
+ '-fno-exceptions',
+ '-Wall',
+ '-D_FILE_OFFSET_BITS=64',
],
'cflags_cc': [
+ '-fno-rtti',
'-fno-threadsafe-statics',
],
'ldflags': [
@@ -558,6 +559,8 @@
'GCC_C_LANGUAGE_STANDARD': 'c99',
'GCC_CW_ASM_SYNTAX': 'NO',
'GCC_DYNAMIC_NO_PIC': 'NO',
+ 'GCC_ENABLE_CPP_EXCEPTIONS': 'NO',
+ 'GCC_ENABLE_CPP_RTTI': 'NO',
'GCC_ENABLE_PASCAL_STRINGS': 'NO',
'GCC_INLINES_ARE_PRIVATE_EXTERN': 'YES',
'GCC_OBJC_CALL_CXX_CDTORS': 'YES',
diff --git a/chrome/browser/cocoa/nsimage_cache.h b/chrome/browser/cocoa/nsimage_cache.h
index 2d2511e..7085eef 100644
--- a/chrome/browser/cocoa/nsimage_cache.h
+++ b/chrome/browser/cocoa/nsimage_cache.h
@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#ifndef CHROME_BROWSER_COCOA_IMAGE_CACHE_H_
-#define CHROME_BROWSER_COCOA_IMAGE_CACHE_H_
+#ifndef CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_
+#define CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_
#import <Cocoa/Cocoa.h>
@@ -21,6 +21,6 @@ NSImage *ImageNamed(NSString* name);
// Clears the cache.
void Clear(void);
-}
+} // namespace nsimage_cache
-#endif // CHROME_BROWSER_COCOA_IMAGE_CACHE_H_
+#endif // CHROME_BROWSER_COCOA_NSIMAGE_CACHE_H_
diff --git a/chrome/browser/cocoa/nsimage_cache.mm b/chrome/browser/cocoa/nsimage_cache.mm
index 05957ea6..feb0376 100644
--- a/chrome/browser/cocoa/nsimage_cache.mm
+++ b/chrome/browser/cocoa/nsimage_cache.mm
@@ -7,6 +7,15 @@
#include "base/logging.h"
#include "base/mac_util.h"
+// When C++ exceptions are disabled, the C++ library defines |try| and
+// |catch| so as to allow exception-expecting C++ code to build properly when
+// language support for exceptions is not present. These macros interfere
+// with the use of |@try| and |@catch| in Objective-C files such as this one.
+// Undefine these macros here, after everything has been #included, since
+// there will be no C++ uses and only Objective-C uses from this point on.
+#undef try
+#undef catch
+
namespace nsimage_cache {
static NSMutableDictionary *image_cache = nil;
@@ -53,4 +62,4 @@ void Clear(void) {
[image_cache removeAllObjects];
}
-} // nsimage_cache
+} // namespace nsimage_cache
diff --git a/chrome/browser/profile.h b/chrome/browser/profile.h
index 3f3a127..a305888 100644
--- a/chrome/browser/profile.h
+++ b/chrome/browser/profile.h
@@ -487,8 +487,8 @@ namespace __gnu_cxx {
template<>
struct hash<Profile*> {
- size_t operator()(Profile* const& p) const {
- return std::tr1::hash<long>()(reinterpret_cast<long>(p));
+ std::size_t operator()(Profile* const& p) const {
+ return reinterpret_cast<std::size_t>(p);
}
};
diff --git a/testing/gtest.gyp b/testing/gtest.gyp
index e9d15f5..581d37a 100644
--- a/testing/gtest.gyp
+++ b/testing/gtest.gyp
@@ -52,7 +52,28 @@
'gtest/include',
],
'conditions': [
- [ 'OS == "mac"', { 'sources': [ 'platform_test_mac.mm' ] } ],
+ ['OS == "mac"', {
+ 'sources': [
+ 'platform_test_mac.mm'
+ ],
+ }],
+ ['OS == "mac" or OS == "linux"', {
+ 'defines': [
+ # gtest isn't able to figure out when RTTI is disabled for gcc
+ # versions older than 4.3.2, and assumes it's enabled. Our Mac
+ # and Linux builds disable RTTI, and cannot guarantee that the
+ # compiler will be 4.3.2. or newer. The Mac, for example, uses
+ # 4.2.1 as that is the latest available on that platform. gtest
+ # must be instructed that RTTI is disabled here, and for any
+ # direct dependents that might include gtest headers.
+ 'GTEST_HAS_RTTI=0',
+ ],
+ 'direct_dependent_settings': {
+ 'defines': [
+ 'GTEST_HAS_RTTI=0',
+ ],
+ },
+ }],
],
'direct_dependent_settings': {
'defines': [