Index: auto.def ================================================================== --- auto.def +++ auto.def @@ -9,10 +9,11 @@ with-zlib:path|auto|tree => {Look for zlib in the given path, automatically, or in the source tree} with-exec-rel-paths=0 => {Enable relative paths for external diff/gdiff} with-legacy-mv-rm=1 => {Enable legacy behavior for mv/rm (skip checkout files)} + with-sanitizer: => {Build with C compiler's -fsanitize=LIST; e.g. address,enum,null,undefined} with-th1-docs=0 => {Enable TH1 for embedded documentation pages} with-th1-hooks=0 => {Enable TH1 hooks for commands and web pages} with-tcl:path => {Enable Tcl integration, with Tcl in the specified path} with-tcl-stubs=0 => {Enable Tcl integration via stubs library mechanism} with-tcl-private-stubs=0 @@ -589,10 +590,24 @@ define FOSSIL_HAVE_FUSEFS 1 define-append LIBS -lfuse msg-result "FuseFS support enabled" } } + +# Add -fsanitize compile and link options late: we don't want the C +# checks above to run with those sanitizers enabled. It can not only +# be pointless, it can actually break correct tests. +set fsan [opt-val with-sanitizer] +if {[string length $fsan]} { + define-append EXTRA_CFLAGS -fsanitize=$fsan + define-append EXTRA_LDFLAGS -fsanitize=$fsan + if {[string first "undefined" $fsan] != -1} { + # We need to link with libubsan if we're compiling under + # GCC with -fsanitize=undefined. + cc-check-function-in-lib __ubsan_handle_add_overflow ubsan + } +} # Finally, append -ldl to make sure it's the last in the list. # The library order matters in case of static linking. if {[check-function-in-lib dlopen dl]} { # Some platforms (*BSD) have the dl functions already in libc and no libdl.