Bug 1514965 - Part 2: Enable clang -ftrivial-auto-var-init to initialize local variables with 0xAA in debug builds. r=froydnj
authorChris Peterson <cpeterson@mozilla.com>
Wed, 21 Aug 2019 07:08:29 +0000
changeset 489138 5babe33486a1407d9af695351b8a857d1702cc7f
parent 489137 5ad6f4f0edeb8b9dff2c53d7b3fee508501390cd
child 489139 eaa150b76520436278334337b869f22634faccdc
push id36465
push userdvarga@mozilla.com
push dateWed, 21 Aug 2019 16:47:43 +0000
treeherdermozilla-central@4ab60925635c [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj
bugs1514965
milestone70.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1514965 - Part 2: Enable clang -ftrivial-auto-var-init to initialize local variables with 0xAA in debug builds. r=froydnj Disable -ftrivial-auto-var-init for DllBLocklistWin.cpp with clang-cl because the file's interceptions happen so early in the main process that the loader hasn't yet resolved the import of memset (used by -ftrivial-auto-var-init) from vcruntime140.dll. Disable -ftrivial-auto-var-init on Linux32 because it causes some xpcshell test failures. Differential Revision: https://phabricator.services.mozilla.com/D42273
browser/app/winlauncher/moz.build
build/moz.configure/toolchain.configure
--- a/browser/app/winlauncher/moz.build
+++ b/browser/app/winlauncher/moz.build
@@ -27,16 +27,29 @@ SOURCES['DllBlocklistWin.cpp'].no_pgo = 
 # DllBlocklistWin.cpp should be compiled in a freestanding environment, as
 # our patched NtMapViewOfSection must not assume that it has access to any
 # runtime libraries.
 if CONFIG['CC_TYPE'] == 'clang-cl':
     SOURCES['DllBlocklistWin.cpp'].flags += ['-Xclang', '-ffreestanding']
 else:
     SOURCES['DllBlocklistWin.cpp'].flags += ['-ffreestanding']
 
+# Disable -ftrivial-auto-var-init=pattern for DllBlocklistWin.cpp because
+# the file's interceptions happen so early in the main process that the
+# loader hasn't yet resolved the import of memset (used by
+# -ftrivial-auto-var-init) from vcruntime140.dll.
+if CONFIG['CC_TYPE'] == 'clang-cl':
+    SOURCES['DllBlocklistWin.cpp'].flags += [
+        '-Xclang', '-ftrivial-auto-var-init=uninitialized',
+    ]
+else:
+    SOURCES['DllBlocklistWin.cpp'].flags += [
+        '-ftrivial-auto-var-init=uninitialized',
+    ]
+
 OS_LIBS += [
     'ntdll',
     'oleaut32',
     'ole32',
     'rpcrt4',
     'version',
 ]
 
--- a/build/moz.configure/toolchain.configure
+++ b/build/moz.configure/toolchain.configure
@@ -1540,18 +1540,19 @@ option('--enable-hardening', env='MOZ_SE
 # is passed, and if no flag is passed.
 #
 # At time of this comment writing, all flags are actually added in the
 # default no-flag case; making --enable-hardening the same as omitting the
 # flag. --disable-hardening will omit the security flags. (However, not all
 # possible security flags will be omitted by --disable-hardening, as many are
 # compiler-default options we do not explicitly enable.)
 @depends('--enable-hardening', '--enable-address-sanitizer',
-         '--enable-optimize', c_compiler, target)
-def security_hardening_cflags(hardening_flag, asan, optimize, c_compiler, target):
+         '--enable-debug', '--enable-optimize', c_compiler, target)
+def security_hardening_cflags(hardening_flag, asan, debug, optimize, c_compiler,
+                              target):
     compiler_is_gccish = c_compiler.type in ('gcc', 'clang')
 
     flags = []
     ldflags = []
     js_flags = []
     js_ldflags = []
 
     # ----------------------------------------------------------
@@ -1575,16 +1576,28 @@ def security_hardening_cflags(hardening_
         mingw_clang = c_compiler.type == 'clang' and target.os == 'WINNT'
         if compiler_is_gccish and not asan:
             if not mingw_clang:
                 flags.append("-fstack-protector-strong")
                 ldflags.append("-fstack-protector-strong")
                 js_flags.append("-fstack-protector-strong")
                 js_ldflags.append("-fstack-protector-strong")
 
+        # ftrivial-auto-var-init ------------------------------
+        # Initialize local variables with a 0xAA pattern in clang debug builds.
+        # Linux32 fails some xpcshell tests with -ftrivial-auto-var-init
+        linux32 = target.kernel == 'Linux' and target.cpu == 'x86'
+        if (c_compiler.type == 'clang' or c_compiler.type == 'clang-cl') and \
+            c_compiler.version >= '8' and debug and not linux32:
+            if c_compiler.type == 'clang-cl':
+                flags.append('-Xclang')
+                js_flags.append('-Xclang')
+            flags.append('-ftrivial-auto-var-init=pattern')
+            js_flags.append('-ftrivial-auto-var-init=pattern')
+
         # ASLR ------------------------------------------------
         # ASLR (dynamicbase) is enabled by default in clang-cl; but the
         # mingw-clang build requires it to be explicitly enabled
         if mingw_clang:
             ldflags.append("-Wl,--dynamicbase")
             js_ldflags.append("-Wl,--dynamicbase")
 
         # Control Flow Guard (CFG) ----------------------------