changeset 09f8fda798bc in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=09f8fda798bc
description:
        scons: fix sanitizer flags with multiple sanitizers

        There has been some problem when using address and undefined-behavior
        sanitizers at the same time. This patch will look for the special case
        where both are enabled at once and change the flags passed to the 
compiler
        to reflect this.

diffstat:

 src/SConscript |  30 +++++++++++++++++++++---------
 1 files changed, 21 insertions(+), 9 deletions(-)

diffs (55 lines):

diff -r 27622f94fdcc -r 09f8fda798bc src/SConscript
--- a/src/SConscript    Fri Nov 25 10:33:15 2016 +0000
+++ b/src/SConscript    Mon Nov 28 12:44:54 2016 -0500
@@ -1085,19 +1085,26 @@
                                  '-Wno-maybe-uninitialized',
                                  '-Wno-type-limits'])
 
+
+        # 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.
-        if GetOption('with_ubsan') and \
+        elif GetOption('with_ubsan') and \
                 compareVersions(env['GCC_VERSION'], '4.9') >= 0:
             new_env.Append(CCFLAGS='-fsanitize=undefined')
             new_env.Append(LINKFLAGS='-fsanitize=undefined')
 
-        # The address sanitizer is available for gcc >= 4.8
-        if GetOption('with_asan'):
-            new_env.Append(CCFLAGS=['-fsanitize=address',
-                                    '-fno-omit-frame-pointer'])
-            new_env.Append(LINKFLAGS='-fsanitize=address')
 
     if env['CLANG']:
         swig_env.Append(CCFLAGS=['-Wno-sometimes-uninitialized',
@@ -1107,10 +1114,15 @@
         # We require clang >= 3.1, so there is no need to check any
         # versions here.
         if GetOption('with_ubsan'):
-            new_env.Append(CCFLAGS='-fsanitize=undefined')
-            new_env.Append(LINKFLAGS='-fsanitize=undefined')
+            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')
 
-        if GetOption('with_asan'):
+        elif GetOption('with_asan'):
             new_env.Append(CCFLAGS=['-fsanitize=address',
                                     '-fno-omit-frame-pointer'])
             new_env.Append(LINKFLAGS='-fsanitize=address')
_______________________________________________
gem5-dev mailing list
gem5-dev@gem5.org
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to