Skip to content

Commit

Permalink
fine tuning sanitizer flags
Browse files Browse the repository at this point in the history
  • Loading branch information
Neumann-A committed Jul 23, 2023
1 parent b438eca commit c4ad022
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 12 deletions.
9 changes: 6 additions & 3 deletions x64-win-llvm/extra_setup.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ if(DEFINED CURRENT_PORT_DIR AND
get_filename_component(LLVM_BIN_DIR "${CLANG-CL_EXECUTBALE}" DIRECTORY)
set(LLVM_PATH_BACKUP "$ENV{PATH}")
set(ENV{PATH} "${LLVM_BIN_DIR};$ENV{PATH}")
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)")
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)" AND NOT PORT MATCHES "(icu)") # icu is building and executable calling the linker with hardcoded linker flags -> so no sanitizer
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DVCPKG_USE_SANITIZERS:BOOL=TRUE"
)
file(READ "${CURRENT_PORT_DIR}/portfile.cmake" port_contents)
if(NOT PORT MATCHES "(openssl|boost)" AND NOT port_contents MATCHES "(vcpkg_configure_meson|_msbuild|_nmake)")
if(NOT PORT MATCHES "(openssl|boost|libpq)" AND NOT port_contents MATCHES "(vcpkg_configure_meson|_msbuild|_nmake)")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DVCPKG_USE_COMPILER_FOR_LINKAGE:BOOL=TRUE"
)
Expand All @@ -52,9 +52,12 @@ if(DEFINED CURRENT_PORT_DIR AND
set(clang_ver_path "${LLVM_BIN_DIR}/../lib/clang/$ENV{LLVMToolsVersion}")
endif()
cmake_path(NORMAL_PATH clang_ver_path)
set(ENV{PATH} "$ENV{PATH};${clang_ver_path}/lib/windows")
set(ENV{PATH} "${clang_ver_path}/lib/windows;$ENV{PATH}")
set(ENV{LINK} "/LIBPATH:\"${clang_ver_path}/lib/windows\"")
#set(ENV{PATH} "$ENV{VCToolsInstallDir}/bin/Hostx64/${VCPKG_TARGET_ARCHITECTURE};$ENV{PATH}") # Probably need to remove the VS sanitizer libs so they won't get picked up by accident!
endif()
else()
# This is just the detect compiler run!
if(CMAKE_PARENT_LIST_FILE MATCHES "-san(\\\.|-)")
list(APPEND VCPKG_CMAKE_CONFIGURE_OPTIONS
"-DVCPKG_USE_SANITIZERS:BOOL=TRUE"
Expand Down
1 change: 1 addition & 0 deletions x64-win-llvm/port_specialization.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ endif()
if(PORT MATCHES "^(re2)$")
set(VCPKG_LIBRARY_LINKAGE static)
endif()

# Note: All gn ports still use cl unless we figure out to pass it a toolchain somehow.
if(PORT MATCHES "^(arrow|akali|arb|cello|chakracore|flint|folly|glog|zydis|graphicsmagick|freerdp|gtk|irrlicht|libde265|llfio|mongo-c-driver|tcl|nvtt)$")
# akali -> typedef private void (T::*POnTimer)(void); -> error
Expand Down
19 changes: 10 additions & 9 deletions x64-win-llvm/x64-win-llvm.toolchain.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ set(std_c_flags "-std:c11 -D__STDC__=1 -Wno-implicit-function-declaration") #/Zc
# for read/open/access and clang 16 made that an error instead of a warning.

# Set C++ standard.
#set(CMAKE_CXX_STANDARD 14 CACHE STRING "")
#set(CMAKE_CXX_STANDARD 17 CACHE STRING "")
#set(CMAKE_CXX_STANDARD_REQUIRED ON CACHE STRING "")
#set(CMAKE_CXX_EXTENSIONS OFF CACHE STRING "")
# set(std_cxx_flags "/permissive- -std:c++20 /Zc:__cplusplus")
#set(std_cxx_flags "/permissive- -std:c++14 /Zc:__cplusplus")
#set(std_cxx_flags "/permissive- -std:c++17 /Zc:__cplusplus -Wno-register")

# Set Windows definitions:
set(windows_defs "/DWIN32")
Expand Down Expand Up @@ -129,18 +129,19 @@ if(VCPKG_USE_SANITIZERS)
if(VCPKG_CRT_LINKAGE STREQUAL "static")
string(APPEND sanitizers ",undefined")
endif()
string(APPEND CLANG_FLAGS_RELEASE "-fsanitize=${sanitizers} -fsanitize-stats /Oy- /GF-")
string(APPEND CLANG_FLAGS_RELEASE "-fsanitize=${sanitizers} /Oy- /GF-")
if(NOT DEFINED ENV{LLVMToolsVersion})
file(GLOB clang_ver_path LIST_DIRECTORIES true "${LLVM_BIN_DIR}/../lib/clang/*")
else()
set(clang_ver_path "${LLVM_BIN_DIR}/../lib/clang/$ENV{LLVMToolsVersion}")
endif()
set(ENV{PATH} "$ENV{PATH};${clang_ver_path}/lib/windows")
#set(ENV{PATH} "$ENV{PATH};${clang_ver_path}/lib/windows")

if(NOT VCPKG_USE_COMPILER_FOR_LINKAGE)
set(ENV{LINK} "$ENV{LINK} /LIBPATH:\"${clang_ver_path}/lib/windows\"")
#set(ENV{LINK} "$ENV{LINK} /LIBPATH:\"${clang_ver_path}/lib/windows\"")
#set(sanitizer_path "/LIBPATH:\\\\\"${clang_ver_path}/lib/windows\\\\\"" )
if(VCPKG_CRT_LINKAGE STREQUAL "dynamic")
set(sanitizer_libs_exe "clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib")
set(sanitizer_libs_exe "-include:__asan_seh_interceptor clang_rt.asan_dynamic-x86_64.lib clang_rt.asan_dynamic_runtime_thunk-x86_64.lib /wholearchive:clang_rt.asan_dynamic_runtime_thunk-x86_64.lib")
set(sanitizer_libs_dll "${sanitizer_libs_exe}")
else()
set(sanitizer_libs "clang_rt.ubsan_standalone-x86_64.lib clang_rt.ubsan_standalone_cxx-x86_64.lib")
Expand All @@ -154,9 +155,9 @@ endif()

set(CMAKE_C_FLAGS "${CMAKE_CL_NOLOGO} ${windows_defs} ${arch_flags} ${VCPKG_C_FLAGS} ${CLANG_FLAGS} ${CHARSET_FLAG} ${std_c_flags} ${ignore_werror}" CACHE STRING "")
set(CMAKE_C_FLAGS_DEBUG "/Od /Ob0 /GS /RTC1 /FC ${VCPKG_C_FLAGS_DEBUG} ${VCPKG_CRT_FLAG}d ${VCPKG_DBG_FLAG} /D_DEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_RELEASE "${CLANG_FLAGS_RELEASE} /O2 /Oi ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} ${VCPKG_DBG_FLAG} /DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_MINSIZEREL "${CLANG_FLAGS_RELEASE} /O1 /Oi /Ob1 /GS- ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} /DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "${CLANG_FLAGS_RELEASE} /O2 /Oi /Ob1 /GS- ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} ${VCPKG_DBG_FLAG} /DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_RELEASE "/O2 /Oi ${CLANG_FLAGS_RELEASE} ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} ${VCPKG_DBG_FLAG} /DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_MINSIZEREL "/O1 /Oi /Ob1 /GS- ${CLANG_FLAGS_RELEASE} ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} /DNDEBUG" CACHE STRING "")
set(CMAKE_C_FLAGS_RELWITHDEBINFO "/O2 /Oi /Ob1 /GS- ${CLANG_FLAGS_RELEASE} ${VCPKG_C_FLAGS_RELEASE} ${VCPKG_CRT_FLAG} ${CLANG_C_LTO_FLAGS} ${VCPKG_DBG_FLAG} /DNDEBUG" CACHE STRING "")

set(CMAKE_CXX_FLAGS "${CMAKE_CL_NOLOGO} /EHsc /GR ${windows_defs} ${arch_flags} ${VCPKG_CXX_FLAGS} ${CLANG_FLAGS} ${CHARSET_FLAG} ${std_cxx_flags} ${ignore_werror}" CACHE STRING "")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} /FC ${VCPKG_CXX_FLAGS_DEBUG}" CACHE STRING "")
Expand Down

0 comments on commit c4ad022

Please sign in to comment.