diff options
author | Andrew Morrow <acm@mongodb.com> | 2016-09-27 14:41:39 -0400 |
---|---|---|
committer | Andrew Morrow <acm@mongodb.com> | 2016-10-10 16:38:53 -0400 |
commit | bdb8bfe3b57e7db11d0b47d80993e7ba5081d794 (patch) | |
tree | d68e685a21c916a36724ac3deb3d7ec73059f27d | |
parent | 27b771a1805871c1a87fab70d38e44b072b22c7f (diff) | |
download | mongo-bdb8bfe3b57e7db11d0b47d80993e7ba5081d794.tar.gz |
SERVER-26276 Enable thin static linking on binutils platforms
-rw-r--r-- | SConstruct | 9 | ||||
-rw-r--r-- | etc/evergreen.yml | 2 | ||||
-rw-r--r-- | site_scons/site_tools/thin_archive.py | 83 |
3 files changed, 90 insertions, 4 deletions
diff --git a/SConstruct b/SConstruct index d4b09f2d087..c4c508701d6 100644 --- a/SConstruct +++ b/SConstruct @@ -562,11 +562,11 @@ def variable_arch_converter(val): def decide_platform_tools(): if is_running_os('windows'): # we only support MS toolchain on windows - return ['msvc', 'mslink', 'mslib'] + return ['msvc', 'mslink', 'mslib', 'masm'] elif is_running_os('linux', 'solaris'): - return ['gcc', 'g++', 'gnulink', 'ar'] + return ['gcc', 'g++', 'gnulink', 'ar', 'gas'] elif is_running_os('osx'): - return ['gcc', 'g++', 'applelink', 'ar'] + return ['gcc', 'g++', 'applelink', 'ar', 'as'] else: return ["default"] @@ -1332,6 +1332,9 @@ if env['_LIBDEPS'] == '$_LIBDEPS_OBJS': env['ARCOMSTR'] = 'Generating placeholder library $TARGET' env['RANLIBCOM'] = noop_action env['RANLIBCOMSTR'] = 'Skipping ranlib for $TARGET' +elif env['_LIBDEPS'] == '$_LIBDEPS_LIBS': + env.Tool('thin_archive') + libdeps.setup_environment(env, emitting_shared=(link_model.startswith("dynamic"))) diff --git a/etc/evergreen.yml b/etc/evergreen.yml index e86fa739bec..4e0d7f48484 100644 --- a/etc/evergreen.yml +++ b/etc/evergreen.yml @@ -7484,7 +7484,7 @@ buildvariants: expansions: gorootvars: PATH=/opt/mongodbtoolchain/v2/bin:$PATH tooltags: -gccgoflags "$(pkg-config --libs --cflags libssl libsasl2)" -tags 'sasl ssl' - compile_flags: --dbg=on --opt=on --ssl MONGO_DISTMOD=rhel72 -j3 CCFLAGS="-march=z196 -mtune=zEC12" CC=/opt/mongodbtoolchain/v2/bin/gcc CXX=/opt/mongodbtoolchain/v2/bin/g++ OBJCOPY=/opt/mongodbtoolchain/v2/bin/objcopy + compile_flags: --dbg=on --opt=on --ssl --link-model=static MONGO_DISTMOD=rhel72 -j3 CCFLAGS="-march=z196 -mtune=zEC12" CC=/opt/mongodbtoolchain/v2/bin/gcc CXX=/opt/mongodbtoolchain/v2/bin/g++ OBJCOPY=/opt/mongodbtoolchain/v2/bin/objcopy num_jobs_available: 2 test_flags: --storageEngine=inMemory --excludeWithAnyTags=requires_persistence,requires_mmapv1,requires_journaling build_mongoreplay: true diff --git a/site_scons/site_tools/thin_archive.py b/site_scons/site_tools/thin_archive.py new file mode 100644 index 00000000000..05ff702142b --- /dev/null +++ b/site_scons/site_tools/thin_archive.py @@ -0,0 +1,83 @@ +# Copyright 2016 MongoDB Inc. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import SCons + +import re +import subprocess + +def exists(env): + if not 'AR' in env: + return False + + ar = env.subst(env['AR']) + if not ar: + return False + + # If the user has done anything confusing with ARFLAGS, bail out. We want to find + # an item in ARFLAGS of the exact form 'rc'. + if not "rc" in env['ARFLAGS']: + return False + + pipe = SCons.Action._subproc(env, SCons.Util.CLVar(ar) + ['--version'], + stdin = 'devnull', + stderr = 'devnull', + stdout = subprocess.PIPE) + if pipe.wait() != 0: + return False + + isgnu = False + for line in pipe.stdout: + if isgnu: + continue # consume all data + isgnu = re.search(r'^GNU ar', line) + + return bool(isgnu) + + +def generate(env): + if not exists(env): + return + + class ThinArchiveNode(SCons.Node.FS.File): + def __init__(self, name, directory, fs): + SCons.Node.FS.File.__init__(self, name, directory, fs) + + def get_contents(self): + child_sigs = sorted([child.get_csig() for child in self.children()]) + return ''.join(child_sigs) + + def get_content_hash(self): + return SCons.Util.MD5signature(self.get_contents()) + + + def _ThinArchiveNode(env, name, directory = None, create = 1): + return env.fs._lookup(env.subst(name), directory, ThinArchiveNode, create) + + env.AddMethod(_ThinArchiveNode, 'ThinArchiveNode') + + def archive_target_factory(arg): + return env.ThinArchiveNode(arg) + + env['BUILDERS']['Library'].target_factory = archive_target_factory + env['BUILDERS']['StaticLibrary'].target_factory = archive_target_factory + + env['ARFLAGS'] = SCons.Util.CLVar([arflag if arflag != "rc" else "rcsTD" for arflag in env['ARFLAGS']]) + + def noop_action(env, target, source): + pass + + # Disable running ranlib, since we added 's' above + env['RANLIBCOM'] = noop_action + env['RANLIBCOMSTR'] = 'Skipping ranlib for thin archive $TARGET' |