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 0dbfd54393f4a897b1fc5ec95cca880897252254..be179d8b29bae8e0fb39d59a7fb29a52cc3d150b 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 2e14a326cb8273f4d8a9b0838e5a9eacc20a71af..8014716e64e49178d65632b836fecaff429f3dda 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 5116d7ee31b0f2b47495d5caeef5ed394a190e6d..5c864ebed96c5ce1d72970f5a1789bb84ad87901 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: