summaryrefslogtreecommitdiff
path: root/SConstruct
diff options
context:
space:
mode:
authorAndrew Morrow <acm@mongodb.com>2019-02-24 15:40:59 -0500
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2021-01-28 03:34:44 +0000
commit5a5a75e4149faae8f1b6e95d60b84cc7f33d4e2b (patch)
tree0886b94186afaad368320d712729b0626222f27c /SConstruct
parent82fad519d9bd7374a85fc5dc973a4479e15eb13c (diff)
downloadmongo-5a5a75e4149faae8f1b6e95d60b84cc7f33d4e2b.tar.gz
SERVER-39786 Set defaults for debug info compression
We default to assembler off and linker off. Also a drive-by to fix an errant distro setting for the RHEL 8 builder
Diffstat (limited to 'SConstruct')
-rw-r--r--SConstruct80
1 files changed, 80 insertions, 0 deletions
diff --git a/SConstruct b/SConstruct
index 06fae013fd1..d70e0a7e6b2 100644
--- a/SConstruct
+++ b/SConstruct
@@ -271,6 +271,13 @@ add_option('opt',
type='choice',
)
+add_option('debug-compress',
+ action="append",
+ choices=["off", "as", "ld"],
+ default=["auto"],
+ help="Compress debug sections",
+)
+
add_option('sanitize',
help='enable selected sanitizers',
metavar='san1,san2,...sanN',
@@ -3479,6 +3486,79 @@ def doConfigure(myenv):
# If possible with the current linker, mark relocations as read-only.
AddToLINKFLAGSIfSupported(myenv, "-Wl,-z,relro")
+ # As far as we know these flags only apply on posix-y systems,
+ # and not on Darwin.
+ if env.TargetOSIs("posix") and not env.TargetOSIs("darwin"):
+
+ # Disable debug compression in both the assembler and linker
+ # by default. If the user requested compression, only allow
+ # the zlib-gabi form.
+ debug_compress = get_option("debug-compress")
+
+ # If a value was provided on the command line for --debug-compress, it should
+ # inhibit the application of auto, so strip it out.
+ if "auto" in debug_compress and len(debug_compress) > 1:
+ debug_compress = debug_compress[1:]
+
+ # Disallow saying --debug-compress=off --debug-compress=ld and similar
+ if "off" in debug_compress and len(debug_compress) > 1:
+ env.FatalError("Cannot combine 'off' for --debug-compress with other values")
+
+ # Transform the 'auto' argument into a real value.
+ if "auto" in debug_compress:
+ debug_compress = []
+
+ # We only automatically enable ld compression for
+ # dynamic builds because it seems to use enormous
+ # amounts of memory in static builds.
+ if link_model.startswith("dynamic"):
+ debug_compress.append("ld")
+
+ compress_type="zlib-gabi"
+ compress_flag="compress-debug-sections"
+
+ AddToCCFLAGSIfSupported(
+ myenv,
+ f"-Wa,--{compress_flag}={compress_type}" if "as" in debug_compress else f"-Wa,--no{compress_flag}")
+
+ # We shouldn't enable debug compression in the linker
+ # (meaning our final binaries contain compressed debug
+ # info) unless our local elf environment appears to at
+ # least be aware of SHF_COMPRESSED. This seems like a
+ # necessary precondition, but is it sufficient?
+ #
+ # https://gnu.wildebeest.org/blog/mjw/2016/01/13/elf-libelf-compressed-sections-and-elfutils/
+
+ def CheckElfHForSHF_COMPRESSED(context):
+
+ test_body = """
+ #include <elf.h>
+ #if !defined(SHF_COMPRESSED)
+ #error
+ #endif
+ """
+
+ context.Message('Checking elf.h for SHF_COMPRESSED... ')
+ ret = context.TryCompile(textwrap.dedent(test_body), ".c")
+ context.Result(ret)
+ return ret
+
+ conf = Configure(myenv, help=False, custom_tests = {
+ 'CheckElfHForSHF_COMPRESSED' : CheckElfHForSHF_COMPRESSED,
+ })
+
+ have_shf_compressed = conf.CheckElfHForSHF_COMPRESSED()
+ conf.Finish()
+
+ if have_shf_compressed and 'ld' in debug_compress:
+ AddToLINKFLAGSIfSupported(
+ myenv,
+ f"-Wl,--{compress_flag}={compress_type}")
+ else:
+ AddToLINKFLAGSIfSupported(
+ myenv,
+ f"-Wl,--{compress_flag}=none")
+
# Avoid deduping symbols on OS X debug builds, as it takes a long time.
if not optBuild and myenv.ToolchainIs('clang') and env.TargetOSIs('darwin'):
AddToLINKFLAGSIfSupported(myenv, "-Wl,-no_deduplicate")