DispatchSanitization.cmake 1.9 KB

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