changeset c0302ad57921 in /z/repo/gem5
details: http://repo.gem5.org/gem5?cmd=changeset;node=c0302ad57921
description:
        scons: Add Undefined Behavior Sanitizer (UBSan) option

        This patch adds the Undefined Behavior Sanitizer (UBSan) for clang and
        gcc >= 4.9. Due to the performance impact, the usage is guarded by a
        command-line option.

diffstat:

 SConstruct     |  11 +++++++++++
 src/SConscript |  15 +++++++++++++++
 2 files changed, 26 insertions(+), 0 deletions(-)

diffs (60 lines):

diff -r 1e2cf7b3e9d4 -r c0302ad57921 SConstruct
--- a/SConstruct        Mon Sep 22 14:37:23 2014 -0500
+++ b/SConstruct        Thu Oct 16 05:49:36 2014 -0400
@@ -189,6 +189,8 @@
 AddLocalOption('--without-tcmalloc', dest='without_tcmalloc',
                action='store_true',
                help='Disable linking against tcmalloc')
+AddLocalOption('--with-ubsan', dest='with_ubsan', action='store_true',
+               help='Build with Undefined Behavior Sanitizer if available')
 
 termcap = get_termcap(GetOption('use_colors'))
 
@@ -602,6 +604,15 @@
                 'binutils to 2.23.' + \
                 termcap.Normal
 
+    # Make sure we warn if the user has requested to compile with the
+    # Undefined Benahvior Sanitizer and this version of gcc does not
+    # support it.
+    if GetOption('with_ubsan') and \
+            compareVersions(gcc_version, '4.9') < 0:
+        print termcap.Yellow + termcap.Bold + \
+            'Warning: UBSan is only supported using gcc 4.9 and later.' + \
+            termcap.Normal
+
     # Add the appropriate Link-Time Optimization (LTO) flags
     # unless LTO is explicitly turned off. Note that these flags
     # are only used by the fast target.
diff -r 1e2cf7b3e9d4 -r c0302ad57921 src/SConscript
--- a/src/SConscript    Mon Sep 22 14:37:23 2014 -0500
+++ b/src/SConscript    Thu Oct 16 05:49:36 2014 -0400
@@ -953,6 +953,15 @@
         if compareVersions(env['GCC_VERSION'], '4.7') >= 0:
             new_env.Append(CXXFLAGS='-Wdelete-non-virtual-dtor')
             swig_env.Append(CCFLAGS='-Wno-maybe-uninitialized')
+
+        # 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 \
+                compareVersions(env['GCC_VERSION'], '4.9') >= 0:
+            new_env.Append(CCFLAGS='-fsanitize=undefined')
+            new_env.Append(LINKFLAGS='-fsanitize=undefined')
+
     if env['CLANG']:
         # Always enable the warning for deletion of derived classes
         # with non-virtual destructors
@@ -966,6 +975,12 @@
                 '-Wno-deprecated-register',
                 ])
 
+        # All supported clang versions have support for UBSan, so if
+        # asked to use it, append the compiler and linker flags.
+        if GetOption('with_ubsan'):
+            new_env.Append(CCFLAGS='-fsanitize=undefined')
+            new_env.Append(LINKFLAGS='-fsanitize=undefined')
+
     werror_env = new_env.Clone()
     werror_env.Append(CCFLAGS='-Werror')
 
_______________________________________________
gem5-dev mailing list
[email protected]
http://m5sim.org/mailman/listinfo/gem5-dev

Reply via email to