summaryrefslogtreecommitdiff
path: root/site_scons
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2018-10-17 22:21:05 -0400
committerAndrew Morrow <acm@mongodb.com>2018-10-30 13:01:30 -0400
commit6d475fdb5a76acab760ce4b6709b60a4c8c9aec6 (patch)
treeb0690e155382de9115a6b8b2daa36da0cef4e5ae /site_scons
parent27d6f6977113551e0e3444b4f76c646d94e75a49 (diff)
downloadmongo-6d475fdb5a76acab760ce4b6709b60a4c8c9aec6.tar.gz
SERVER-37488 SERVER-37596 Manage debug info and symbol maps info for embedded builds
Diffstat (limited to 'site_scons')
-rw-r--r--site_scons/site_tools/auto_install_binaries.py6
-rw-r--r--site_scons/site_tools/separate_debug.py143
2 files changed, 149 insertions, 0 deletions
diff --git a/site_scons/site_tools/auto_install_binaries.py b/site_scons/site_tools/auto_install_binaries.py
index 9f3de6166df..9a71b4919b7 100644
--- a/site_scons/site_tools/auto_install_binaries.py
+++ b/site_scons/site_tools/auto_install_binaries.py
@@ -10,6 +10,12 @@ def generate(env):
suffix_map = {
env.subst('$PROGSUFFIX') : 'bin',
'.dylib' : 'lib',
+ # TODO: These 'lib' answers are incorrect. The location for the debug info
+ # should be the same as the target itself, which might be bin or lib. We need
+ # a solution for that. When that is fixed, add 'Program' back into the list
+ # of separate debug targets in the separate_debug.py tool.
+ '.dSYM' : 'lib',
+ '.debug' : 'lib',
'.so' : 'lib',
'.dll' : 'bin',
'.lib' : 'lib',
diff --git a/site_scons/site_tools/separate_debug.py b/site_scons/site_tools/separate_debug.py
new file mode 100644
index 00000000000..3edd50518e1
--- /dev/null
+++ b/site_scons/site_tools/separate_debug.py
@@ -0,0 +1,143 @@
+# Copyright 2018 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
+
+def _update_builder(env, builder, bitcode):
+
+ old_scanner = builder.target_scanner
+ old_path_function = old_scanner.path_function
+
+ def new_scanner(node, env, path=()):
+ results = old_scanner.function(node, env, path)
+ origin = getattr(node.attributes, "debug_file_for", None)
+ if origin:
+ origin_results = old_scanner(origin, env, path)
+ for origin_result in origin_results:
+ origin_result_debug_file = getattr(origin_result.attributes, "separate_debug_file", None)
+ if origin_result_debug_file:
+ results.append(origin_result_debug_file)
+ # TODO: Do we need to do the same sort of drag along for bcsymbolmap files?
+ return results
+
+ builder.target_scanner = SCons.Scanner.Scanner(
+ function=new_scanner,
+ path_function=old_path_function,
+ )
+
+ base_action = builder.action
+ if not isinstance(base_action, SCons.Action.ListAction):
+ base_action = SCons.Action.ListAction([base_action])
+
+ # TODO: Make variables for dsymutil and strip, and for the action
+ # strings. We should really be running these tools as found by
+ # xcrun by default. We should achieve that by upgrading the
+ # site_scons/site_tools/xcode.py tool to search for these for
+ # us. We could then also remove a lot of the compiler and sysroot
+ # setup from the etc/scons/xcode_*.vars files, which would be a
+ # win as well.
+ if env.TargetOSIs('darwin'):
+ if bitcode:
+ base_action.list.append(
+ SCons.Action.Action(
+ "dsymutil $TARGET --symbol-map=${TARGET}.bcsymbolmap -o ${TARGET}.dSYM",
+ "Generating debug info for $TARGET into ${TARGET}.dSYM"
+ )
+ )
+
+ else:
+ base_action.list.append(
+ SCons.Action.Action(
+ "dsymutil $TARGET -o ${TARGET}.dSYM",
+ "Generating debug info for $TARGET into ${TARGET}.dSYM"
+ )
+ )
+ base_action.list.append(
+ SCons.Action.Action(
+ "strip -Sx ${TARGET}",
+ "Stripping ${TARGET}"
+ )
+ )
+ elif env.TargetOSIs('posix'):
+ base_action.list.extend([
+ SCons.Action.Action(
+ "${OBJCOPY} --only-keep-debug $TARGET ${TARGET}.debug",
+ "Generating debug info for $TARGET into ${TARGET}.debug"
+ ),
+ SCons.Action.Action(
+ "${OBJCOPY} --strip-debug --add-gnu-debuglink ${TARGET}.debug ${TARGET}",
+ "Stripping debug info from ${TARGET} and adding .gnu.debuglink to ${TARGET}.debug"
+ ),
+ ])
+ else:
+ pass
+
+ base_emitter = builder.emitter
+ def new_emitter(target, source, env):
+
+ bitcode_file = None
+ if env.TargetOSIs('darwin'):
+ debug_file = env.Dir(str(target[0]) + ".dSYM")
+ if bitcode:
+ bitcode_file = env.File(str(target[0]) + ".bcsymbolmap")
+ elif env.TargetOSIs('posix'):
+ debug_file = env.File(str(target[0]) + ".debug")
+ else:
+ pass
+
+ setattr(debug_file.attributes, "debug_file_for", target[0])
+ setattr(target[0].attributes, "separate_debug_file", debug_file)
+
+ target.append(debug_file)
+
+ if bitcode_file:
+ setattr(bitcode_file.attributes, "bcsymbolmap_file_for", target[0])
+ setattr(target[0].attributes, "bcsymbolmap_file", bitcode_file)
+ target.append(bitcode_file)
+
+ return (target, source)
+
+ new_emitter = SCons.Builder.ListEmitter([base_emitter, new_emitter])
+ builder.emitter = new_emitter
+
+def generate(env):
+ if not exists(env):
+ return
+
+ # If we are generating bitcode, add the magic linker flags that
+ # hide the bitcode symbols, and override the name of the bitcode
+ # symbol map file so that it is determinstically known to SCons
+ # rather than being a UUID. We need this so that we can install it
+ # under a well known name. We leave it to the evergreen
+ # postprocessing to rename to the correct name. I'd like to do
+ # this better, but struggled for a long time and decided that
+ # later was a better time to address this. We should also consider
+ # moving all bitcode setup into a separate tool.
+ bitcode = False
+ if env.TargetOSIs('darwin') and any(flag == "-fembed-bitcode" for flag in env['LINKFLAGS']):
+ bitcode = True
+ env.AppendUnique(LINKFLAGS=[
+ "-Wl,-bitcode_hide_symbols",
+ "-Wl,-bitcode_symbol_map,${TARGET}.bcsymbolmap",
+ ])
+
+
+ # TODO: For now, not doing this for programs. Need to update
+ # auto_install_binaries to understand to install the debug symbol
+ # for target X to the same target location as X.
+ for builder in ['SharedLibrary', 'LoadableModule']:
+ _update_builder(env, env['BUILDERS'][builder], bitcode)
+
+def exists(env):
+ return True