1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-22 13:34:15 +03:00

selftest: enable undefined behaviour sanitizer

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
This commit is contained in:
Gary Lockyer 2019-05-14 11:25:07 +12:00 committed by Andrew Bartlett
parent b0cc6d2174
commit b1a32dd7f5
4 changed files with 28 additions and 3 deletions

View 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}

View 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"),

6
selftest/ubsan.supp Normal file
View File

@ -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

View 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: