scons: Move some compiler flag setting code to the SConstruct.
authorGabe Black <gabeblack@google.com>
Tue, 21 Nov 2017 02:21:19 +0000 (18:21 -0800)
committerGabe Black <gabeblack@google.com>
Mon, 27 Nov 2017 22:10:05 +0000 (22:10 +0000)
These settings are invariant, so there's no reason to apply them over
and over again for the child environments used for various build
products.

Change-Id: Icb4053105e4f1c43008f2422ba30c7206b7ff365
Reviewed-on: https://gem5-review.googlesource.com/5981
Reviewed-by: Andreas Sandberg <andreas.sandberg@arm.com>
Reviewed-by: Nikos Nikoleris <nikos.nikoleris@arm.com>
Maintainer: Andreas Sandberg <andreas.sandberg@arm.com>

SConstruct
src/SConscript

index 095b58be43fa5a746e82e89c5ef030803a938dbd..36db2162cedbea27de74a9163fa575ac9983f3e8 100755 (executable)
@@ -473,6 +473,25 @@ if main['GCC']:
     if compareVersions(gcc_version, "5.0") > 0:
         main.Append(CCFLAGS=['-Wno-error=suggest-override'])
 
+    # The address sanitizer is available for gcc >= 4.8
+    if GetOption('with_asan'):
+        if GetOption('with_ubsan') and \
+                compareVersions(env['GCC_VERSION'], '4.9') >= 0:
+            env.Append(CCFLAGS=['-fsanitize=address,undefined',
+                                '-fno-omit-frame-pointer'],
+                       LINKFLAGS='-fsanitize=address,undefined')
+        else:
+            env.Append(CCFLAGS=['-fsanitize=address',
+                                '-fno-omit-frame-pointer'],
+                       LINKFLAGS='-fsanitize=address')
+    # Only gcc >= 4.9 supports UBSan, so check both the version
+    # and the command-line option before adding the compiler and
+    # linker flags.
+    elif GetOption('with_ubsan') and \
+            compareVersions(env['GCC_VERSION'], '4.9') >= 0:
+        env.Append(CCFLAGS='-fsanitize=undefined')
+        env.Append(LINKFLAGS='-fsanitize=undefined')
+
 elif main['CLANG']:
     # Check for a supported version of clang, >= 3.1 is needed to
     # support similar features as gcc 4.8. See
@@ -513,6 +532,22 @@ elif main['CLANG']:
     if sys.platform.startswith('freebsd'):
         main.Append(LIBS=['thr'])
 
+    # We require clang >= 3.1, so there is no need to check any
+    # versions here.
+    if GetOption('with_ubsan'):
+        if GetOption('with_asan'):
+            env.Append(CCFLAGS=['-fsanitize=address,undefined',
+                                '-fno-omit-frame-pointer'],
+                       LINKFLAGS='-fsanitize=address,undefined')
+        else:
+            env.Append(CCFLAGS='-fsanitize=undefined',
+                       LINKFLAGS='-fsanitize=undefined')
+
+    elif GetOption('with_asan'):
+        env.Append(CCFLAGS=['-fsanitize=address',
+                            '-fno-omit-frame-pointer'],
+                   LINKFLAGS='-fsanitize=address')
+
 else:
     print termcap.Yellow + termcap.Bold + 'Error' + termcap.Normal,
     print "Don't know what compiler options to use for your compiler."
index f9560afbcf701d9e4337cd5127ddc1d945eaa9fe..a40955b68c97a40720e85246783fd2d421d2f392 100755 (executable)
@@ -952,44 +952,6 @@ def makeEnv(env, label, objsfx, strip=False, disable_partial=False, **kwargs):
     new_env.Label = label
     new_env.Append(**kwargs)
 
-    if env['GCC']:
-        # The address sanitizer is available for gcc >= 4.8
-        if GetOption('with_asan'):
-            if GetOption('with_ubsan') and \
-                    compareVersions(env['GCC_VERSION'], '4.9') >= 0:
-                new_env.Append(CCFLAGS=['-fsanitize=address,undefined',
-                                        '-fno-omit-frame-pointer'])
-                new_env.Append(LINKFLAGS='-fsanitize=address,undefined')
-            else:
-                new_env.Append(CCFLAGS=['-fsanitize=address',
-                                        '-fno-omit-frame-pointer'])
-                new_env.Append(LINKFLAGS='-fsanitize=address')
-        # Only gcc >= 4.9 supports UBSan, so check both the version
-        # and the command-line option before adding the compiler and
-        # linker flags.
-        elif GetOption('with_ubsan') and \
-                compareVersions(env['GCC_VERSION'], '4.9') >= 0:
-            new_env.Append(CCFLAGS='-fsanitize=undefined')
-            new_env.Append(LINKFLAGS='-fsanitize=undefined')
-
-
-    if env['CLANG']:
-        # We require clang >= 3.1, so there is no need to check any
-        # versions here.
-        if GetOption('with_ubsan'):
-            if GetOption('with_asan'):
-                new_env.Append(CCFLAGS=['-fsanitize=address,undefined',
-                                        '-fno-omit-frame-pointer'])
-                new_env.Append(LINKFLAGS='-fsanitize=address,undefined')
-            else:
-                new_env.Append(CCFLAGS='-fsanitize=undefined')
-                new_env.Append(LINKFLAGS='-fsanitize=undefined')
-
-        elif GetOption('with_asan'):
-            new_env.Append(CCFLAGS=['-fsanitize=address',
-                                    '-fno-omit-frame-pointer'])
-            new_env.Append(LINKFLAGS='-fsanitize=address')
-
     werror_env = new_env.Clone()
     # Treat warnings as errors but white list some warnings that we
     # want to allow (e.g., deprecation warnings).