Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 1 | set(SANITIZER_GEN_DYNAMIC_LIST |
| 2 | ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/gen_dynamic_list.py) |
| 3 | |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 4 | set(SANITIZER_LINT_SCRIPT |
| 5 | ${COMPILER_RT_SOURCE_DIR}/lib/sanitizer_common/scripts/check_lint.sh) |
| 6 | |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 7 | # Create a target "<name>-<arch>-symbols" that would generate the list of |
| 8 | # symbols that need to be exported from sanitizer runtime "<name>". Function |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 9 | # interceptors are exported automatically, user can also provide files with |
| 10 | # symbol names that should be exported as well. |
Chris Bieneman | 15b5750 | 2015-08-26 23:12:25 +0000 | [diff] [blame] | 11 | # add_sanitizer_rt_symbols(<name> |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 12 | # ARCHS <architectures> |
Chris Bieneman | 69c3a3e | 2015-08-27 18:27:33 +0000 | [diff] [blame] | 13 | # PARENT_TARGET <convenience parent target> |
Chris Bieneman | 15b5750 | 2015-08-26 23:12:25 +0000 | [diff] [blame] | 14 | # EXTRA <files with extra symbols to export>) |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 15 | macro(add_sanitizer_rt_symbols name) |
Chris Bieneman | 15b5750 | 2015-08-26 23:12:25 +0000 | [diff] [blame] | 16 | cmake_parse_arguments(ARG |
| 17 | "" |
Chris Bieneman | 69c3a3e | 2015-08-27 18:27:33 +0000 | [diff] [blame] | 18 | "PARENT_TARGET" |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 19 | "ARCHS;EXTRA" |
Chris Bieneman | 15b5750 | 2015-08-26 23:12:25 +0000 | [diff] [blame] | 20 | ${ARGN}) |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 21 | foreach(arch ${ARG_ARCHS}) |
| 22 | set(target_name ${name}-${arch}) |
| 23 | set(stamp ${CMAKE_CURRENT_BINARY_DIR}/${target_name}.syms-stamp) |
| 24 | set(extra_args) |
| 25 | foreach(arg ${ARG_EXTRA}) |
| 26 | list(APPEND extra_args "--extra" ${arg}) |
| 27 | endforeach() |
| 28 | add_custom_command(OUTPUT ${stamp} |
| 29 | COMMAND ${PYTHON_EXECUTABLE} |
| 30 | ${SANITIZER_GEN_DYNAMIC_LIST} ${extra_args} $<TARGET_FILE:${target_name}> |
| 31 | > $<TARGET_FILE:${target_name}>.syms |
| 32 | COMMAND ${CMAKE_COMMAND} -E touch ${stamp} |
| 33 | DEPENDS ${target_name} ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} |
| 34 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 35 | COMMENT "Generating exported symbols for ${target_name}" |
| 36 | VERBATIM) |
| 37 | add_custom_target(${target_name}-symbols ALL |
| 38 | DEPENDS ${stamp} |
| 39 | SOURCES ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA}) |
Alexey Samsonov | cbac3e4 | 2014-03-04 08:28:43 +0000 | [diff] [blame] | 40 | |
Chris Bieneman | c2cae06 | 2016-06-09 21:35:37 +0000 | [diff] [blame] | 41 | install(FILES $<TARGET_FILE:${target_name}>.syms |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 42 | DESTINATION ${COMPILER_RT_LIBRARY_INSTALL_DIR}) |
Chris Bieneman | 0d4ac15 | 2015-08-27 20:07:54 +0000 | [diff] [blame] | 43 | if(ARG_PARENT_TARGET) |
| 44 | add_dependencies(${ARG_PARENT_TARGET} ${target_name}-symbols) |
| 45 | endif() |
| 46 | endforeach() |
Alexey Samsonov | e5fa243 | 2013-08-27 15:08:02 +0000 | [diff] [blame] | 47 | endmacro() |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 48 | |
Francis Ricci | ae4b880 | 2017-01-09 03:51:42 +0000 | [diff] [blame] | 49 | # This function is only used on Darwin, where undefined symbols must be specified |
| 50 | # in the linker invocation. |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 51 | function(add_weak_symbols libname link_flags) |
Francis Ricci | ae4b880 | 2017-01-09 03:51:42 +0000 | [diff] [blame] | 52 | file(STRINGS "${COMPILER_RT_SOURCE_DIR}/lib/${libname}/weak_symbols.txt" WEAK_SYMBOLS) |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 53 | set(local_link_flags ${${link_flags}}) |
Francis Ricci | ae4b880 | 2017-01-09 03:51:42 +0000 | [diff] [blame] | 54 | foreach(SYMBOL ${WEAK_SYMBOLS}) |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 55 | set(local_link_flags ${local_link_flags} -Wl,-U,${SYMBOL}) |
Francis Ricci | ae4b880 | 2017-01-09 03:51:42 +0000 | [diff] [blame] | 56 | endforeach() |
Francis Ricci | 9f93113 | 2017-01-10 04:33:04 +0000 | [diff] [blame] | 57 | set(${link_flags} ${local_link_flags} PARENT_SCOPE) |
Francis Ricci | ae4b880 | 2017-01-09 03:51:42 +0000 | [diff] [blame] | 58 | endfunction() |
| 59 | |
Evgeniy Stepanov | 0683241 | 2015-05-05 22:51:35 +0000 | [diff] [blame] | 60 | macro(add_sanitizer_rt_version_list name) |
| 61 | set(vers ${CMAKE_CURRENT_BINARY_DIR}/${name}.vers) |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 62 | cmake_parse_arguments(ARG "" "" "LIBS;EXTRA" ${ARGN}) |
Evgeniy Stepanov | 0683241 | 2015-05-05 22:51:35 +0000 | [diff] [blame] | 63 | set(args) |
| 64 | foreach(arg ${ARG_EXTRA}) |
| 65 | list(APPEND args "--extra" ${arg}) |
| 66 | endforeach() |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 67 | foreach(arg ${ARG_LIBS}) |
Evgeniy Stepanov | 0683241 | 2015-05-05 22:51:35 +0000 | [diff] [blame] | 68 | list(APPEND args "$<TARGET_FILE:${arg}>") |
| 69 | endforeach() |
| 70 | add_custom_command(OUTPUT ${vers} |
| 71 | COMMAND ${PYTHON_EXECUTABLE} |
| 72 | ${SANITIZER_GEN_DYNAMIC_LIST} --version-list ${args} |
| 73 | > ${vers} |
Filipe Cabecinhas | c309de7 | 2015-06-19 03:39:24 +0000 | [diff] [blame] | 74 | DEPENDS ${SANITIZER_GEN_DYNAMIC_LIST} ${ARG_EXTRA} ${ARG_LIBS} |
Evgeniy Stepanov | 0683241 | 2015-05-05 22:51:35 +0000 | [diff] [blame] | 75 | WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} |
| 76 | COMMENT "Generating version list for ${name}" |
| 77 | VERBATIM) |
| 78 | |
| 79 | add_custom_target(${name}-version-list ALL |
| 80 | DEPENDS ${vers}) |
| 81 | endmacro() |
| 82 | |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 83 | # Add target to check code style for sanitizer runtimes. |
Sean Silva | 621dec4 | 2016-04-06 20:19:31 +0000 | [diff] [blame] | 84 | if(CMAKE_HOST_UNIX) |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 85 | add_custom_target(SanitizerLintCheck |
Alexey Samsonov | 61d4798 | 2016-03-17 21:41:08 +0000 | [diff] [blame] | 86 | COMMAND env LLVM_CHECKOUT=${LLVM_MAIN_SRC_DIR} SILENT=1 TMPDIR= |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 87 | PYTHON_EXECUTABLE=${PYTHON_EXECUTABLE} |
Greg Fitzgerald | a6bfd8d | 2014-03-21 00:45:21 +0000 | [diff] [blame] | 88 | COMPILER_RT=${COMPILER_RT_SOURCE_DIR} |
Alexey Samsonov | 38a61aa | 2013-08-29 10:49:04 +0000 | [diff] [blame] | 89 | ${SANITIZER_LINT_SCRIPT} |
| 90 | DEPENDS ${SANITIZER_LINT_SCRIPT} |
| 91 | COMMENT "Running lint check for sanitizer sources..." |
| 92 | VERBATIM) |
| 93 | endif() |
| 94 | |