Enable `EHCONT` for some DLLs and for PGO instrumentation (#55942)
authorKoundinya Veluri <kouvel@users.noreply.github.com>
Thu, 22 Jul 2021 16:25:22 +0000 (09:25 -0700)
committerGitHub <noreply@github.com>
Thu, 22 Jul 2021 16:25:22 +0000 (09:25 -0700)
* 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

eng/native/configurecompiler.cmake
src/coreclr/pgosupport.cmake
src/libraries/Native/Windows/CMakeLists.txt

index 92a715f..39460f3 100644 (file)
@@ -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.
index c0791c4..6f07f1c 100644 (file)
@@ -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)
index e96ec87..9d69ca8 100644 (file)
@@ -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.