File: DispatchSanitization.cmake

package info (click to toggle)
swiftlang 6.0.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,519,992 kB
  • sloc: cpp: 9,107,863; ansic: 2,040,022; asm: 1,135,751; python: 296,500; objc: 82,456; f90: 60,502; lisp: 34,951; pascal: 19,946; sh: 18,133; perl: 7,482; ml: 4,937; javascript: 4,117; makefile: 3,840; awk: 3,535; xml: 914; fortran: 619; cs: 573; ruby: 573
file content (44 lines) | stat: -rw-r--r-- 1,959 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44

set(DISPATCH_USE_SANITIZER "" CACHE STRING
    "Define the sanitizer used to build binaries and tests.")

if(CMAKE_SYSTEM_NAME STREQUAL Darwin AND DISPATCH_USE_SANITIZER)
  message(FATAL_ERROR "building libdispatch with sanitization is not supported on Darwin")
endif()

if(DISPATCH_USE_SANITIZER)
  # TODO(compnerd) ensure that the compiler supports these options before adding
  # them.  At the moment, assume that this will just be used with a GNU
  # compatible driver and that the options are spelt correctly in light of that.
  add_compile_options("-fno-omit-frame-pointer")
  if(CMAKE_BUILD_TYPE MATCHES "Debug")
    add_compile_options("-O1")
  elseif(NOT CMAKE_BUILD_TYPE MATCHES "Debug" AND
         NOT CMAKE_BUILD_TYPE MATCHES "RelWithDebInfo")
    add_compile_options("-gline-tables-only")
  endif()

  if(LLVM_USE_SANITIZER STREQUAL "Address")
    add_compile_options("-fsanitize=address")
  elseif(DISPATCH_USE_SANITIZER MATCHES "Memory(WithOrigins)?")
    add_compile_options("-fsanitize=memory")
    if(DISPATCH_USE_SANITIZER STREQUAL "MemoryWithOrigins")
    add_compile_options("-fsanitize-memory-track-origins")
    endif()
  elseif(DISPATCH_USE_SANITIZER STREQUAL "Undefined")
    add_compile_options("-fsanitize=undefined")
    add_compile_options("-fno-sanitize=vptr,function")
    add_compile_options("-fno-sanitize-recover=all")
  elseif(DISPATCH_USE_SANITIZER STREQUAL "Thread")
    add_compile_options("-fsanitize=thread")
  elseif(DISPATCH_USE_SANITIZER STREQUAL "Address;Undefined" OR
         DISPATCH_USE_SANITIZER STREQUAL "Undefined;Address")
    add_compile_options("-fsanitize=address,undefined")
    add_compile_options("-fno-sanitize=vptr,function")
    add_compile_options("-fno-sanitize-recover=all")
  elseif(DISPATCH_USE_SANITIZER STREQUAL "Leaks")
    add_compile_options("-fsanitize=leak")
  else()
    message(FATAL_ERROR "unsupported value of DISPATCH_USE_SANITIZER: ${DISPATCH_USE_SANITIZER}")
  endif()
endif()