From 5a5a75e4149faae8f1b6e95d60b84cc7f33d4e2b Mon Sep 17 00:00:00 2001 From: Andrew Morrow Date: Sun, 24 Feb 2019 15:40:59 -0500 Subject: 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 --- SConstruct | 80 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 80 insertions(+) (limited to 'SConstruct') 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 + #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") -- cgit v1.2.1