selftest: enable undefined behaviour sanitizer
authorGary Lockyer <gary@catalyst.net.nz>
Mon, 13 May 2019 23:25:07 +0000 (11:25 +1200)
committerAndrew Bartlett <abartlet@samba.org>
Tue, 14 May 2019 07:20:28 +0000 (07:20 +0000)
Add a --undefined-sanitizer option to configure, this causes the tests
to be run with the undefined behaviout sanitizer enabled.

Errors can be suppressed by adding entries to selftest/ubsan.supp

Signed-off-by: Gary Lockyer <gary@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Tue May 14 07:20:28 UTC 2019 on sn-devel-184

buildtools/wafsamba/samba_autoconf.py
buildtools/wafsamba/wscript
selftest/ubsan.supp [new file with mode: 0644]
selftest/wscript

index 0dbfd54..be179d8 100644 (file)
@@ -793,10 +793,17 @@ int main(void) {
     if Options.options.pedantic:
         conf.ADD_CFLAGS('-W', testflags=True)
 
+    if (Options.options.address_sanitizer or
+        Options.options.undefined_sanitizer):
+        conf.ADD_CFLAGS('-fno-omit-frame-pointer -O1', testflags=True)
     if Options.options.address_sanitizer:
-        conf.ADD_CFLAGS('-fno-omit-frame-pointer -O1 -fsanitize=address', testflags=True)
+        conf.ADD_CFLAGS('-fsanitize=address', testflags=True)
         conf.ADD_LDFLAGS('-fsanitize=address', testflags=True)
         conf.env['ADDRESS_SANITIZER'] = True
+    if Options.options.undefined_sanitizer:
+        conf.ADD_CFLAGS('-fsanitize=undefined', testflags=True)
+        conf.ADD_LDFLAGS('-fsanitize=undefined', testflags=True)
+        conf.env['UNDEFINED_SANITIZER'] = True
 
 
     # Let people pass an additional ADDITIONAL_{CFLAGS,LDFLAGS}
index 2e14a32..8014716 100644 (file)
@@ -128,6 +128,11 @@ def options(opt):
     gr.add_option('--address-sanitizer',
                    help=("Enable address sanitizer compile and linker flags"),
                    action="store_true", dest='address_sanitizer', default=False)
+    gr.add_option('--undefined-sanitizer',
+        help=("Enable undefined behaviour sanitizer compile and linker flags"),
+        action="store_true",
+        dest='undefined_sanitizer',
+        default=False)
 
     gr.add_option('--abi-check',
                   help=("Check ABI signatures for libraries"),
diff --git a/selftest/ubsan.supp b/selftest/ubsan.supp
new file mode 100644 (file)
index 0000000..423e083
--- /dev/null
@@ -0,0 +1,6 @@
+# Suppress the
+# "left shift of x by y places cannot be represented in type 'int'"
+# in the heimdal code for now.
+shift-base:../../source4/heimdal/lib/hcrypto/des.c
+shift-base:../../source4/heimdal/lib/krb5/crypto.c
+
index 5116d7e..5c864eb 100644 (file)
@@ -265,8 +265,9 @@ def cmd_testonly(opt):
 
     if env.ADDRESS_SANITIZER:
         # We try to find the correct libasan automatically
-        libasan = Utils.cmd_output('ldd bin/texpect | grep libasan| cut -f 3 -d \ ',
-                                   silent=True).strip()
+        libasan = Utils.cmd_output(
+            'ldd bin/texpect | grep libasan| cut -f 3 -d \ ',
+            silent=True).strip()
         libasan = libasan.decode('utf8')
 
         # Have the selftest.pl LD_PRELOAD libasan in the right spot
@@ -290,6 +291,12 @@ def cmd_testonly(opt):
         env.FILTER_OPTIONS = asan_envs + env.FILTER_OPTIONS
         env.SUBUNIT_FORMATTER = asan_envs + env.SUBUNIT_FORMATTER
 
+    if env.UNDEFINED_SANITIZER:
+        # print a stack trace with the error.
+        print_stack_trace = "UBSAN_OPTIONS=print_stacktrace=1"
+        print_stack_trace += ",suppressions=${srcdir}/selftest/ubsan.supp"
+        env.CORE_COMMAND = print_stack_trace + " " + env.CORE_COMMAND
+
     if Options.options.LIST:
         cmd = '${CORE_COMMAND} --list'
     else: