|
| 1 | + |
| 2 | +set(DISPATCH_USE_SANITIZER "" CACHE STRING |
| 3 | + "Define the sanitizer used to build binaries and tests.") |
| 4 | + |
| 5 | +if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND DISPATCH_USE_SANITIZER) |
| 6 | + message(FATAL_ERROR "building libdispatch with sanitization is not supported on Darwin") |
| 7 | +endif() |
| 8 | + |
| 9 | +if(DISPATCH_USE_SANITIZER) |
| 10 | + # TODO(compnerd) ensure that the compiler supports these options before adding |
| 11 | + # them. At the moment, assume that this will just be used with a GNU |
| 12 | + # compatible driver and that the options are spelt correctly in light of that. |
| 13 | + add_compile_options("-fno-omit-frame-pointer") |
| 14 | + if(CMAKE_BUILD_TYPE MATCHES "Debug") |
| 15 | + add_compile_options("-O1") |
| 16 | + elseif(NOT CMAKE_BUILD_TYPE MATCHES "Debug" AND |
| 17 | + NOT CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo") |
| 18 | + add_compile_options("-gline-tables-only") |
| 19 | + endif() |
| 20 | + |
| 21 | + if(LLVM_USE_SANITIZER STREQUAL "Address") |
| 22 | + add_compile_options("-fsanitize=address") |
| 23 | + elseif(DISPATCH_USE_SANITIZER MATCHES "Memory(WithOrigins)?") |
| 24 | + add_compile_options("-fsanitize=memory") |
| 25 | + if(DISPATCH_USE_SANITIZER STREQUAL "MemoryWithOrigins") |
| 26 | + add_compile_options("-fsanitize-memory-track-origins") |
| 27 | + endif() |
| 28 | + elseif(DISPATCH_USE_SANITIZER STREQUAL "Undefined") |
| 29 | + add_compile_options("-fsanitize=undefined") |
| 30 | + add_compile_options("-fno-sanitize=vptr,function") |
| 31 | + add_compile_options("-fno-sanitize-recover=all") |
| 32 | + elseif(DISPATCH_USE_SANITIZER STREQUAL "Thread") |
| 33 | + add_compile_options("-fsanitize=thread") |
| 34 | + elseif(DISPATCH_USE_SANITIZER STREQUAL "Address;Undefined" OR |
| 35 | + DISPATCH_USE_SANITIZER STREQUAL "Undefined;Address") |
| 36 | + add_compile_options("-fsanitize=address,undefined") |
| 37 | + add_compile_options("-fno-sanitize=vptr,function") |
| 38 | + add_compile_options("-fno-sanitize-recover=all") |
| 39 | + elseif(DISPATCH_USE_SANITIZER STREQUAL "Leaks") |
| 40 | + add_compile_options("-fsanitize=leak") |
| 41 | + else() |
| 42 | + message(FATAL_ERROR "unsupported value of DISPATCH_USE_SANITIZER: ${DISPATCH_USE_SANITIZER}") |
| 43 | + endif() |
| 44 | +endif() |
0 commit comments