@@ -30,6 +30,33 @@ add_dependencies(unwinder_dac eventing_headers)
3030set_target_properties (unwinder_dac PROPERTIES DAC_COMPONENT TRUE )
3131target_compile_definitions (unwinder_dac PRIVATE FEATURE_NO_HOST)
3232
33+ ### cDAC Unwinders ####
34+
35+ set (BASE_UNWINDER_SOURCES baseunwinder.cpp)
36+ convert_to_absolute_path(BASE_UNWINDER_SOURCES ${BASE_UNWINDER_SOURCES} )
37+ add_library_clr(unwinder_cdac_base STATIC ${BASE_UNWINDER_SOURCES} )
38+
39+ target_include_directories (unwinder_cdac_base BEFORE PUBLIC ${VM_DIR} )
40+ target_include_directories (unwinder_cdac_base BEFORE PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} )
41+ target_include_directories (unwinder_cdac_base BEFORE PUBLIC ${CLR_DIR} /unwinder)
42+ target_include_directories (unwinder_cdac_base PUBLIC ${CLR_DIR} /debug/ee)
43+ target_include_directories (unwinder_cdac_base PUBLIC ${CLR_DIR} /gc)
44+ target_include_directories (unwinder_cdac_base PUBLIC ${CLR_DIR} /gcdump)
45+ target_include_directories (unwinder_cdac_base PUBLIC ${CLR_DIR} /debug/daccess)
46+ target_compile_definitions (unwinder_cdac_base PUBLIC FEATURE_NO_HOST FEATURE_CDAC_UNWINDER)
47+
48+ if (CLR_CMAKE_TARGET_WIN32)
49+ # cDAC unwinders are statically linked into the NativeAOT runtime which is built with
50+ # release version of the statically linked CRT. Therefore we do the same here.
51+ set_property (TARGET unwinder_cdac_base PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded)
52+
53+ # _DEBUG is always passed as a parameter if the build is a debug build.
54+ # This causes the debug CRT on MSVC to be used so we need to undefine it.
55+ target_compile_options (unwinder_cdac_base PRIVATE -U_DEBUG)
56+ endif ()
57+
58+ install_clr(TARGETS unwinder_cdac_base DESTINATIONS cdaclibs COMPONENT cdac)
59+
3360# Helper function for platform specific cDAC uwninder builds.
3461function (create_platform_unwinder)
3562 set (oneValueArgs TARGET ARCH)
@@ -48,34 +75,47 @@ function(create_platform_unwinder)
4875 clr_unknown_arch()
4976 endif ()
5077
51- set (UNWINDER_SOURCES
52- baseunwinder.cpp
53- ${ARCH_SOURCES_DIR} /unwinder.cpp
54- )
55-
78+ set (UNWINDER_SOURCES ${ARCH_SOURCES_DIR} /unwinder.cpp)
5679 convert_to_absolute_path(UNWINDER_SOURCES ${UNWINDER_SOURCES} )
80+ add_library_clr(${TARGETDETAILS_TARGET} STATIC ${UNWINDER_SOURCES} )
5781
58- add_library_clr(${TARGETDETAILS_TARGET}
59- SHARED
60- ${UNWINDER_SOURCES}
61- )
82+ target_include_directories (${TARGETDETAILS_TARGET} BEFORE PRIVATE ${VM_DIR} /${ARCH_SOURCES_DIR} )
83+ target_include_directories (${TARGETDETAILS_TARGET} PRIVATE ${ARCH_SOURCES_DIR} )
6284
63- add_unwinder_include_directories(${TARGETDETAILS_TARGET} )
85+ target_link_libraries (${TARGETDETAILS_TARGET} PRIVATE unwinder_cdac_base)
86+ if (CLR_CMAKE_TARGET_WIN32)
87+ # cDAC unwinders are statically linked into the NativeAOT runtime which is built with
88+ # release version of the statically linked CRT. Therefore we do the same here.
89+ set_property (TARGET ${TARGETDETAILS_TARGET} PROPERTY MSVC_RUNTIME_LIBRARY MultiThreaded)
6490
65- target_link_libraries (${TARGETDETAILS_TARGET} PRIVATE ${STATIC_MT_CRT_LIB} ${STATIC_MT_VCRT_LIB} )
91+ # _DEBUG is always passed as a parameter if the build is a debug build.
92+ # This causes the debug CRT on MSVC to be used so we need to undefine it.
93+ target_compile_options (${TARGETDETAILS_TARGET} PRIVATE -U_DEBUG)
94+ endif ()
6695
6796 # add the install targets
68- install_clr(TARGETS ${TARGETDETAILS_TARGET} DESTINATIONS ${TARGETDETAILS_DESTINATIONS} COMPONENT debug INSTALL_ALL_ARTIFACTS )
97+ install_clr(TARGETS ${TARGETDETAILS_TARGET} DESTINATIONS ${TARGETDETAILS_DESTINATIONS} COMPONENT cdac )
6998
7099 # Set the target to be built for the specified OS and ARCH
71100 set_target_definitions_to_custom_os_and_arch(TARGET ${TARGETDETAILS_TARGET} OS win ARCH ${TARGETDETAILS_ARCH} )
72101
73102 target_compile_definitions (${TARGETDETAILS_TARGET} PRIVATE FEATURE_NO_HOST FEATURE_CDAC_UNWINDER)
74103endfunction ()
75104
76- # TODO: Support building cDAC unwinders on other platforms
77- # https://github.com/dotnet/runtime/issues/112272#issue-2838611496
78105if (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)
79106 create_platform_unwinder(TARGET unwinder_cdac_amd64 ARCH x64 DESTINATIONS cdaclibs)
80107 create_platform_unwinder(TARGET unwinder_cdac_arm64 ARCH arm64 DESTINATIONS cdaclibs)
81108endif (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)
109+
110+ if (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
111+ create_platform_unwinder(TARGET unwinder_cdac_arm64 ARCH arm64 DESTINATIONS cdaclibs)
112+ endif (CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
113+
114+ if (NOT CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)
115+ create_platform_unwinder(TARGET unwinder_cdac_amd64 ARCH x64 DESTINATIONS cdaclibs)
116+ endif (NOT CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_AMD64)
117+
118+ if (NOT CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
119+ create_platform_unwinder(TARGET unwinder_cdac_arm64 ARCH arm64 DESTINATIONS cdaclibs)
120+ endif (NOT CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
121+
0 commit comments