SERVER-27675 Make all targets depend on the allocator shim to topsort it last

This commit is contained in:
Andrew Morrow
2020-02-21 08:04:47 -05:00
committed by Evergreen Agent
parent 65814eb597
commit 82cf48411f
4 changed files with 57 additions and 13 deletions

View File

@@ -1,5 +1,7 @@
# -*- mode: python -*-
import SCons
import libdeps
import json
@@ -208,6 +210,42 @@ def injectThirdParty(thisEnv, libraries=[], parts=[]):
env.AddMethod(injectThirdParty, 'InjectThirdParty')
# In a dynamic build, force everything to depend on shim_allocator, so
# that it topsorts to the end of the list. We are totally relying on
# the fact that we are altering the env from src/SConscript
if get_option('link-model').startswith("dynamic"):
for builder_name in ('Program', 'SharedLibrary', 'LoadableModule', 'StaticLibrary'):
builder = env['BUILDERS'][builder_name]
base_emitter = builder.emitter
def add_shim_allocator_hack(target, source, env):
# If we allowed conftests to become dependent, any TryLink
# that happened after we made the below modifications would
# cause the configure steps to try to compile tcmalloc and any
# of its dependencies. Oops!
if any('conftest' in str(t) for t in target):
return target, source
# It is possible that 'env' isn't a unique
# OverrideEnvironment, since if you didn't pass any kw args
# into your builder call, you just reuse the env you were
# called with. That could mean that we see the same
# envirnoment here multiple times. But that is really OK,
# since the operation we are performing would be performed on
# all of them anyway. The flag serves as a way to disable the
# auto-injection for the handful of libraries where we must do
# so to avoid forming a cycle.
if not env.get('DISABLE_ALLOCATOR_SHIM_INJECTION', False):
lds = env.get('LIBDEPS', [])
lds.append('$BUILD_DIR/third_party/shim_allocator')
env['LIBDEPS'] = lds
return target, source
builder.emitter = SCons.Builder.ListEmitter([add_shim_allocator_hack, base_emitter])
env = env.Clone()
murmurEnv = env.Clone()
@@ -249,7 +287,12 @@ if use_libunwind:
target="shim_unwind",
source=[
'shim_unwind.cpp',
])
],
# We don't want the shim_allocator hack to apply to this library, since
# otherwise we would create a loop, since tcmalloc might use us. That should
# be OK, unless libunwind had static initializers that invoked malloc.
DISABLE_ALLOCATOR_SHIM_INJECTION=True,
)
if use_system_version_of_library("fmt"):
fmtEnv = env.Clone(
@@ -493,7 +536,9 @@ gperftoolsEnv.Library(
target="shim_allocator",
source=[
"shim_allocator.cpp",
])
],
DISABLE_ALLOCATOR_SHIM_INJECTION=True,
)
if use_system_version_of_library("stemmer"):