waf: added --ubsan and --ubsan-abort options

This commit is contained in:
Andrew Tridgell 2022-07-11 09:10:05 +10:00
parent 3385d3ae62
commit acf56204f2
2 changed files with 23 additions and 0 deletions

View File

@ -582,6 +582,14 @@ Address Sanitizer support llvm-symbolizer is required to be on the PATH.
This option is only supported on macOS versions of clang.
''')
g.add_option('--ubsan',
action='store_true',
help='''Build using the gcc undefined behaviour sanitizer''')
g.add_option('--ubsan-abort',
action='store_true',
help='''Build using the gcc undefined behaviour sanitizer and abort on error''')
def build(bld):
bld.add_pre_fun(_process_build_command)
bld.add_pre_fun(_select_programs_from_group)

View File

@ -557,6 +557,21 @@ class sitl(Board):
'-Werror=float-equal'
]
if cfg.options.ubsan or cfg.options.ubsan_abort:
env.CXXFLAGS += [
"-fsanitize=undefined",
"-fsanitize=float-cast-overflow",
]
env.LINKFLAGS += [
"-fsanitize=undefined",
"-lubsan",
]
if cfg.options.ubsan_abort:
env.CXXFLAGS += [
"-fno-sanitize-recover"
]
if not cfg.env.DEBUG:
env.CXXFLAGS += [
'-O3',