Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang,lld: enable some CFI and PEHeaders flags to match MSVC UWP default behavior #558

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions cmake/toolchain_check.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ if(TARGET_CPU STREQUAL "x86_64")
set(crt_lib "--disable-lib32 --enable-lib64")
set(LIBOMP_ASMFLAGS_M64 "-DLIBOMP_ASMFLAGS=-m64")
set(M_TUNE "generic")
set(cfi "-mguard=cf")
set(clang_cfi "-mguard=cf -fcf-protection=full -Xclang -ehcontguard")
set(lld_cfi "-Xlink=-guard:cf,longjmp,ehcont -Xlink=-cetcompat")
if (GCC_ARCH STREQUAL "x86-64")
unset(cfi)
unset(opt)
endif()
elseif(TARGET_CPU STREQUAL "i686")
Expand All @@ -24,5 +24,6 @@ elseif(TARGET_CPU STREQUAL "i686")
elseif(TARGET_CPU STREQUAL "aarch64")
set(crt_lib "--disable-lib32 --disable-lib64 --enable-libarm64")
set(M_TUNE "generic")
set(cfi "-mguard=cf")
set(clang_cfi "-mguard=cf -Xclang -ehcontguard")
set(lld_cfi "-Xlink=-guard:cf,longjmp,ehcont")
endif()
1 change: 1 addition & 0 deletions toolchain/llvm/llvm-compiler-rt-builtin.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ ExternalProject_Add(llvm-compiler-rt-builtin
-DCOMPILER_RT_DEFAULT_TARGET_ONLY=TRUE
-DCOMPILER_RT_USE_BUILTINS_LIBRARY=TRUE
-DCOMPILER_RT_BUILD_BUILTINS=TRUE
-DCOMPILER_RT_ENABLE_CET=TRUE
-DLLVM_CONFIG_PATH=""
-DCMAKE_FIND_ROOT_PATH=${MINGW_INSTALL_PREFIX}
-DCMAKE_FIND_ROOT_PATH_MODE_INCLUDE=ONLY
Expand Down
5 changes: 3 additions & 2 deletions toolchain/llvm/llvm-compiler.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ TARGET=@TARGET_ARCH@
FLAGS="$FLAGS -target $TARGET -march=@GCC_ARCH@ -mtune=@M_TUNE@"
FLAGS="$FLAGS @driver_mode@ --sysroot @MINGW_INSTALL_PREFIX@"
FLAGS="$FLAGS -fuse-ld=lld --ld-path=@TARGET_ARCH@-ld"
FLAGS="$FLAGS @cfi@ @opt@"
FLAGS="$FLAGS @clang_cfi@ @opt@"
FLAGS="$FLAGS -gcodeview"
FLAGS="$FLAGS -Wno-unused-command-line-argument"
FLAGS="$FLAGS -Wno-unused-command-line-argument -Wno-macro-redefined"
FLAGS="$FLAGS -D_WIN32_WINNT=0x0A00 -DWINVER=0x0A00"

if [ "$LTO" != "0" ] && [ "@CLANG_PACKAGES_LTO@" = "ON" ]; then
LTO_FLAGS="-flto=thin"
Expand Down
2 changes: 2 additions & 0 deletions toolchain/llvm/llvm-ld.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ PROG=@CMAKE_INSTALL_PREFIX@/bin/ld.lld
TARGET=@TARGET_ARCH@
POLICY="cache_size_bytes=1g:prune_interval=1m"
FLAGS="-m @ld_m_flag@"
FLAGS="$FLAGS @lld_cfi@"
FLAGS="$FLAGS --pdb= --thinlto-cache-dir=@MINGW_INSTALL_PREFIX@/thinlto -Xlink=-lldltocachepolicy:$POLICY"
FLAGS="$FLAGS -O3 -Xlink=-opt:lldlto=3 -Xlink=-opt:lldltocgo=3"
FLAGS="$FLAGS --no-insert-timestamp --major-os-version=10 --major-subsystem-version=6 --minor-subsystem-version=2 --file-alignment=4096"

if [ "$CONF" == "1" ]; then
SKIP_OPT="-O0 -Xlink=-opt:lldlto=0 -Xlink=-opt:lldltocgo=0 --no-gc-sections --no-guard-cf"
Expand Down
3 changes: 3 additions & 0 deletions toolchain/llvm/llvm-libcxx.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ ExternalProject_Add(llvm-libcxx
-DLIBUNWIND_USE_COMPILER_RT=TRUE
-DLIBUNWIND_ENABLE_SHARED=OFF
-DLIBUNWIND_ENABLE_STATIC=ON
-DLIBUNWIND_ENABLE_CET=ON
-DCXX_SUPPORTS_FCF_PROTECTION_EQ_FULL_FLAG=ON
-DCXX_SUPPORTS_MSHSTK_FLAG=ON
-DLIBCXX_USE_COMPILER_RT=ON
-DLIBCXX_ENABLE_SHARED=OFF
-DLIBCXX_ENABLE_STATIC=ON
Expand Down