Skip to content

Commit

Permalink
Enable EHCONT for some DLLs and for PGO instrumentation (#55942)
Browse files Browse the repository at this point in the history
* Enable `EHCONT` for some DLLs and for PGO instrumentation

- PGD files used for PGO optimziation need to be collected/produced against binaries with identical compiler features
- Enabled `/guard:ehcont` as a compiler option but not as a linker option
- Enabled `/guard:ehcont` and `/cetcompat` as a linker options for PGO instrumentation only for now
- Once new profile data is published, another PR would follow to enable `/guard:ehcont` and `/cetcompat` as linker options

* Fix build
  • Loading branch information
kouvel authored Jul 22, 2021
1 parent 17ada00 commit f28702c
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 11 deletions.
10 changes: 5 additions & 5 deletions eng/native/configurecompiler.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -574,11 +574,11 @@ if (MSVC)

# Enable EH-continuation table for native components for amd64 builds
# Added using variables instead of add_compile_options to let individual projects override it
#if (CLR_CMAKE_HOST_ARCH_AMD64)
# set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /guard:ehcont")
# set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:ehcont")
# set(CMAKE_ASM_MASM_FLAGS "${CMAKE_C_FLAGS} /guard:ehcont")
#endif (CLR_CMAKE_HOST_ARCH_AMD64)
if (CLR_CMAKE_HOST_ARCH_AMD64)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /guard:ehcont")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} /guard:ehcont")
set(CMAKE_ASM_MASM_FLAGS "${CMAKE_C_FLAGS} /guard:ehcont")
endif (CLR_CMAKE_HOST_ARCH_AMD64)

# Statically linked CRT (libcmt[d].lib, libvcruntime[d].lib and libucrt[d].lib) by default. This is done to avoid
# linking in VCRUNTIME140.DLL for a simplified xcopy experience by reducing the dependency on VC REDIST.
Expand Down
7 changes: 7 additions & 0 deletions src/coreclr/pgosupport.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,13 @@ function(add_pgo TargetName)
if(CLR_CMAKE_HOST_WIN32)
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /LTCG /GENPROFILE")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /LTCG /GENPROFILE")

if (CLR_CMAKE_HOST_ARCH_AMD64)
# The /guard:ehcont and /CETCOMPAT switches here are temporary and will be moved to a more global location once
# new profile data is published
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELEASE " /guard:ehcont /CETCOMPAT")
set_property(TARGET ${TargetName} APPEND_STRING PROPERTY LINK_FLAGS_RELWITHDEBINFO " /guard:ehcont /CETCOMPAT")
endif (CLR_CMAKE_HOST_ARCH_AMD64)
else(CLR_CMAKE_HOST_WIN32)
if(UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELEASE OR UPPERCASE_CMAKE_BUILD_TYPE STREQUAL RELWITHDEBINFO)
target_compile_options(${TargetName} PRIVATE -flto -fprofile-instr-generate)
Expand Down
12 changes: 6 additions & 6 deletions src/libraries/Native/Windows/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,12 @@ endif ()
add_compile_options(/guard:cf)
list(APPEND __SharedLinkArgs /guard:cf)

#if (${CLR_CMAKE_HOST_ARCH} STREQUAL "x86_64" OR ${CLR_CMAKE_HOST_ARCH} STREQUAL "amd64" OR ${CLR_CMAKE_HOST_ARCH} STREQUAL "x64")
# # Enable EH continuation table and CETCOMPAT for native components
# add_compile_options(/guard:ehcont)
# list(APPEND __SharedLinkArgs /guard:ehcont)
# list(APPEND __SharedLinkArgs /CETCOMPAT)
#endif ()
if (${CLR_CMAKE_HOST_ARCH} STREQUAL "x86_64" OR ${CLR_CMAKE_HOST_ARCH} STREQUAL "amd64" OR ${CLR_CMAKE_HOST_ARCH} STREQUAL "x64")
# Enable EH continuation table and CETCOMPAT for native components
add_compile_options(/guard:ehcont)
list(APPEND __SharedLinkArgs /guard:ehcont)
list(APPEND __SharedLinkArgs /CETCOMPAT)
endif ()

# Statically linked CRT (libcmt[d].lib, libvcruntime[d].lib and libucrt[d].lib) by default. This is done to avoid
# linking in VCRUNTIME140.DLL for a simplified xcopy experience by reducing the dependency on VC REDIST.
Expand Down

0 comments on commit f28702c

Please sign in to comment.