diff options
-rw-r--r-- | SConstruct | 38 | ||||
-rw-r--r-- | src/mongo/util/stacktrace_test.cpp | 2 | ||||
-rw-r--r-- | src/third_party/gperftools/SConscript | 6 | ||||
-rw-r--r-- | src/third_party/unwind/SConscript | 9 |
4 files changed, 43 insertions, 12 deletions
diff --git a/SConstruct b/SConstruct index 8b6cf40b90a..ffe2e9ba349 100644 --- a/SConstruct +++ b/SConstruct @@ -279,6 +279,7 @@ experimental_optimizations = [ 'sandybridge', 'tbaa', 'treevec', + 'vishidden', ] experimental_optimization_choices = ['*'] experimental_optimization_choices.extend("+" + opt for opt in experimental_optimizations) @@ -1649,13 +1650,6 @@ if link_model.startswith("dynamic"): SHCCFLAGS=[ '$MONGO_VISIBILITY_SHCCFLAGS_GENERATOR', ], - SHCXXFLAGS=[ - # TODO: This has broader implications and seems not to - # work right now at least on macOS. We should - # investigate further in the future. - # - # '-fvisibility-inlines-hidden' if not env.TargetOSIs('windows') else [], - ], ) def library(env, target, source, *args, **kwargs): @@ -2505,6 +2499,26 @@ if env.TargetOSIs('posix'): if not "tbaa" in selected_experimental_optimizations: env.Append(CCFLAGS=["-fno-strict-aliasing"]) + # The hidden visibility requires that we have libunwind in play. + if "vishidden" in selected_experimental_optimizations and use_libunwind: + if link_model.startswith('dynamic'): + # In dynamic mode, we can't make the default visibility + # hidden because not all libraries have export tags. But + # we can at least make inlines hidden. + env.Append(CXXFLAGS=["-fvisibility-inlines-hidden"]) + else: + # In static mode, we need an escape hatch for a few + # libraries that don't work correctly when built with + # hidden visiblity. + def conditional_visibility_generator(target, source, env, for_signature): + if 'DISALLOW_VISHIDDEN' in env: + return + return "-fvisibility=hidden" + env.Append( + CCFLAGS_VISIBILITY_HIDDEN_GENERATOR=conditional_visibility_generator, + CCFLAGS='$CCFLAGS_VISIBILITY_HIDDEN_GENERATOR', + ) + # env.Append( " -Wconversion" ) TODO: this doesn't really work yet env.Append( CXXFLAGS=["-Woverloaded-virtual"] ) @@ -2526,8 +2540,14 @@ if env.TargetOSIs('posix'): if env.TargetOSIs('macOS'): env.Append( LINKFLAGS=["-Wl,-bind_at_load"] ) else: - env.Append( LINKFLAGS=["-Wl,-z,now"] ) - env.Append( LINKFLAGS=["-rdynamic"] ) + env.Append( + LINKFLAGS=[ + "-Wl,-z,now", + ], + PROGLINKFLAGS=[ + "-rdynamic", + ] + ) env.Append( LIBS=[] ) diff --git a/src/mongo/util/stacktrace_test.cpp b/src/mongo/util/stacktrace_test.cpp index cb06e5e8ef8..feac7aa72aa 100644 --- a/src/mongo/util/stacktrace_test.cpp +++ b/src/mongo/util/stacktrace_test.cpp @@ -73,7 +73,7 @@ namespace mongo { namespace stack_trace_test_detail { /** Needs to have linkage so we can test metadata. */ -void testFunctionWithLinkage() { +MONGO_COMPILER_NOINLINE MONGO_COMPILER_API_EXPORT void testFunctionWithLinkage() { printf("..."); } diff --git a/src/third_party/gperftools/SConscript b/src/third_party/gperftools/SConscript index 4f12718d26c..74eb94b4d28 100644 --- a/src/third_party/gperftools/SConscript +++ b/src/third_party/gperftools/SConscript @@ -5,7 +5,11 @@ Import("has_option") Import("use_libunwind") Import("debugBuild") -env = env.Clone() +env = env.Clone( + # Building with hidden visibility interferes with intercepting the + # libc allocation functions. + DISALLOW_VISHIDDEN=True, +) if use_libunwind: env.Append( diff --git a/src/third_party/unwind/SConscript b/src/third_party/unwind/SConscript index 3372cdafe9b..ba49060607e 100644 --- a/src/third_party/unwind/SConscript +++ b/src/third_party/unwind/SConscript @@ -13,7 +13,14 @@ Import("debugBuild") # linux_x86_64 # linux_aarch64 -env = env.Clone() +env = env.Clone( + # Libunwind wants to interpose (for better or for worse) on the + # libc `backtrace`. Buidling with hidden visibility probably + # breaks that. It also seems to interfere with building with the + # sanitizers, which use linker maps that reference backtrace. This + # may be an ld.gold bug. + DISALLOW_VISHIDDEN=True, +) unwind_root = env.Dir(".").srcnode() unwind_platform = unwind_root.Dir("platform/${TARGET_OS}_${TARGET_ARCH}") |