Skip to content

Commit 889d514

Browse files
authored
[cDAC] Statically link in native dependencies (#113627)
* Statically link cDAC unwinder libraries * Revert INSTALL_ALL_ARTIFACTS implementation * Creates cdac CMAKEcomponent for native cdac dependencies which is built with tools.cdacreader
1 parent c200ad6 commit 889d514

File tree

12 files changed

+89
-56
lines changed

12 files changed

+89
-56
lines changed

eng/Subsets.props

+4
Original file line numberDiff line numberDiff line change
@@ -307,6 +307,10 @@
307307
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrILToolsSubset=true</ClrRuntimeBuildSubsets>
308308
</PropertyGroup>
309309

310+
<PropertyGroup Condition="$(_subset.Contains('+tools.cdacreader+'))">
311+
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrCdacSubset=true</ClrRuntimeBuildSubsets>
312+
</PropertyGroup>
313+
310314
<PropertyGroup Condition="$(_subset.Contains('+clr.nativeaotruntime+')) and '$(NativeAotSupported)' == 'true'">
311315
<ClrRuntimeBuildSubsets>$(ClrRuntimeBuildSubsets);ClrNativeAotSubset=true</ClrRuntimeBuildSubsets>
312316
</PropertyGroup>

eng/native/functions.cmake

+5-10
Original file line numberDiff line numberDiff line change
@@ -554,11 +554,11 @@ function(install_static_library targetName destination component)
554554
endif()
555555
endfunction()
556556

557-
# install_clr(TARGETS targetName [targetName2 ...] [DESTINATIONS destination [destination2 ...]] [COMPONENT componentName] [INSTALL_ALL_ARTIFACTS])
557+
# install_clr(TARGETS targetName [targetName2 ...] [DESTINATIONS destination [destination2 ...]] [COMPONENT componentName])
558558
function(install_clr)
559559
set(multiValueArgs TARGETS DESTINATIONS)
560560
set(singleValueArgs COMPONENT)
561-
set(options INSTALL_ALL_ARTIFACTS)
561+
set(options "")
562562
cmake_parse_arguments(INSTALL_CLR "${options}" "${singleValueArgs}" "${multiValueArgs}" ${ARGV})
563563

564564
if ("${INSTALL_CLR_TARGETS}" STREQUAL "")
@@ -594,14 +594,9 @@ function(install_clr)
594594
endif()
595595

596596
foreach(destination ${destinations})
597-
# Install the export libraries for static libraries.
598-
if (${INSTALL_CLR_INSTALL_ALL_ARTIFACTS})
599-
install(TARGETS ${targetName} DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
600-
else()
601-
# We don't need to install the export libraries for our DLLs
602-
# since they won't be directly linked against.
603-
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
604-
endif()
597+
# We don't need to install the export libraries for our DLLs
598+
# since they won't be directly linked against.
599+
install(PROGRAMS $<TARGET_FILE:${targetName}> DESTINATION ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
605600
if (NOT "${symbolFile}" STREQUAL "")
606601
install_symbol_file(${symbolFile} ${destination} COMPONENT ${INSTALL_CLR_COMPONENT})
607602
endif()

src/coreclr/components.cmake

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ add_component(iltools)
88
add_component(nativeaot)
99
add_component(spmi)
1010
add_component(debug)
11+
add_component(cdac)
1112

1213
# Define coreclr_all as the fallback component and make every component depend on this component.
1314
# iltools and paltests should be minimal subsets, so don't add a dependency on coreclr_misc

src/coreclr/debug/daccess/cdac.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -26,14 +26,7 @@ namespace
2626
path.Truncate(iter);
2727
path.Append(CDAC_LIB_NAME);
2828

29-
#ifdef HOST_WINDOWS
30-
// LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR tells the native windows loader to load dependencies
31-
// from the same directory as cdacreader.dll. Once the native portions of the cDAC
32-
// are statically linked, this won't be required.
33-
*phCDAC = CLRLoadLibraryEx(path.GetUnicode(), NULL, LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR);
34-
#else // !HOST_WINDOWS
3529
*phCDAC = CLRLoadLibrary(path.GetUnicode());
36-
#endif // HOST_WINDOWS
3730
if (*phCDAC == NULL)
3831
return false;
3932

src/coreclr/runtime.proj

+3-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
<_CoreClrBuildArg Condition="'$(ClrSpmiSubset)' == 'true'" Include="-component spmi" />
7878
<_CoreClrBuildArg Condition="'$(ClrCrossComponentsSubset)' == 'true'" Include="-component crosscomponents" />
7979
<_CoreClrBuildArg Condition="'$(ClrDebugSubset)' == 'true'" Include="-component debug" />
80+
<_CoreClrBuildArg Condition="'$(ClrCdacSubset)' == 'true'" Include= "-component cdac" />
8081
</ItemGroup>
8182

8283
<PropertyGroup Condition="('$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and '$(HostCrossOS)' == '' and '$(ANDROID_NDK_ROOT)' != ''">
@@ -85,8 +86,8 @@
8586

8687
<ItemGroup Condition="('$(TargetsAndroid)' == 'true' or '$(TargetsLinuxBionic)' == 'true') and '$(HostCrossOS)' == '' and '$(ANDROID_NDK_ROOT)' != ''">
8788
<_CoreClrBuildArg Include="-cmakeargs &quot;-DANDROID_STL=c++_static&quot;"/>
88-
89-
<!--
89+
90+
<!--
9091
Only apply this setting on non-windows builds. Our windows build has a hard
9192
time with a value that has spaces in it.
9293
-->

src/coreclr/unwinder/CMakeLists.txt

+54-14
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,33 @@ add_dependencies(unwinder_dac eventing_headers)
3030
set_target_properties(unwinder_dac PROPERTIES DAC_COMPONENT TRUE)
3131
target_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.
3461
function(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)
74103
endfunction()
75104

76-
# TODO: Support building cDAC unwinders on other platforms
77-
# https://github.com/dotnet/runtime/issues/112272#issue-2838611496
78105
if(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)
81108
endif(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+

src/coreclr/unwinder/amd64/unwinder.h

+6-6
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
#include "baseunwinder.h"
1010

1111
#ifdef FEATURE_CDAC_UNWINDER
12-
EXTERN_C __declspec(dllexport) BOOL amd64Unwind(void* pContext,
13-
ReadFromTarget readFromTarget,
14-
GetAllocatedBuffer getAllocatedBuffer,
15-
GetStackWalkInfo getStackWalkInfo,
16-
UnwinderFail unwinderFail,
17-
void* callbackContext);
12+
EXTERN_C BOOL amd64Unwind(void* pContext,
13+
ReadFromTarget readFromTarget,
14+
GetAllocatedBuffer getAllocatedBuffer,
15+
GetStackWalkInfo getStackWalkInfo,
16+
UnwinderFail unwinderFail,
17+
void* callbackContext);
1818
#endif // FEATURE_CDAC_UNWINDER
1919

2020
//---------------------------------------------------------------------------------------

src/coreclr/unwinder/arm64/unwinder.h

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@
99
#include "baseunwinder.h"
1010

1111
#ifdef FEATURE_CDAC_UNWINDER
12-
EXTERN_C __declspec(dllexport) BOOL arm64Unwind(void* pContext, ReadFromTarget readFromTarget,
13-
GetAllocatedBuffer getAllocatedBuffer,
14-
GetStackWalkInfo getStackWalkInfo,
15-
UnwinderFail unwinderFail,
16-
void* callbackContext);
12+
EXTERN_C BOOL arm64Unwind(void* pContext, ReadFromTarget readFromTarget,
13+
GetAllocatedBuffer getAllocatedBuffer,
14+
GetStackWalkInfo getStackWalkInfo,
15+
UnwinderFail unwinderFail,
16+
void* callbackContext);
1717
#endif // FEATURE_CDAC_UNWINDER
1818

1919
//---------------------------------------------------------------------------------------

src/coreclr/unwinder/baseunwinder.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,12 @@ HRESULT OOPStackUnwinder::GetFunctionEntry( DWORD64 addres
6060
_Out_writes_(cbBuffer) PVOID pBuffer,
6161
DWORD cbBuffer)
6262
{
63+
#ifndef FEATURE_CDAC_UNWINDER
6364
if (cbBuffer < sizeof(T_RUNTIME_FUNCTION))
6465
{
6566
return E_INVALIDARG;
6667
}
68+
#endif // FEATURE_CDAC_UNWINDER
6769

6870
PVOID pFuncEntry = NULL;
6971
#ifndef FEATURE_CDAC_UNWINDER

src/libraries/externals.csproj

-2
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,6 @@
9292
TODO: [cdac] Remove once cdacreader is added to shipping shared framework -->
9393
<RuntimeFiles Include="$(CoreCLRArtifactsPath)\*cdacreader*" />
9494
<RuntimeFiles Include="$(CoreCLRArtifactsPath)\PDB\*cdacreader*" />
95-
<RuntimeFiles Include="$(CoreCLRArtifactsPath)\cdaclibs\*unwinder_cdac*" />
96-
<RuntimeFiles Include="$(CoreCLRArtifactsPath)\cdaclibs\PDB\*unwinder_cdac*" />
9795
</ItemGroup>
9896
<!-- If the build has native sanitizers, copy over the non-sanitized diagnostic binaries so they can be loaded by a debugger -->
9997
<ItemGroup Condition="'$(EnableNativeSanitizers)' != ''">

src/native/managed/cdacreader/src/cdacreader.csproj

+9-6
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,15 @@
3232
</ItemGroup>
3333

3434
<ItemGroup>
35-
<!-- TODO: Link libraries on non-windows platforms. -->
36-
<!-- https://github.com/dotnet/runtime/issues/112416 -->
37-
<DirectPInvoke Include="unwinder_cdac_amd64" Condition="'$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64'"/>
38-
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\unwinder_cdac_amd64.lib" Condition="'$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64'" />
39-
<DirectPInvoke Include="unwinder_cdac_arm64" Condition="'$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64'"/>
40-
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\unwinder_cdac_arm64.lib" Condition="'$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64'" />
35+
<DirectPInvoke Include="unwinder_cdac_amd64" Condition="'$(TargetArchitecture)' == 'x64'" />
36+
<DirectPInvoke Include="unwinder_cdac_arm64" Condition="'$(TargetArchitecture)' == 'arm64' or ('$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64')" />
37+
38+
<!-- unwinder_cdac_base is supported on all platforms -->
39+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\$(LibPrefix)unwinder_cdac_base$(StaticLibSuffix)" />
40+
41+
<!-- amd64 and arm64 are supported on windows x64, or on their native platform -->
42+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\$(LibPrefix)unwinder_cdac_amd64$(StaticLibSuffix)" Condition="'$(TargetArchitecture)' == 'x64'" />
43+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\$(LibPrefix)unwinder_cdac_arm64$(StaticLibSuffix)" Condition="'$(TargetArchitecture)' == 'arm64' or ('$(TargetsWindows)' == 'true' and '$(TargetArchitecture)' == 'x64')" />
4144
</ItemGroup>
4245

4346
<ItemGroup>

src/tests/Common/Directory.Build.targets

-4
Original file line numberDiff line numberDiff line change
@@ -122,10 +122,6 @@
122122
<IncludeSubFolders>True</IncludeSubFolders>
123123
</RunTimeArtifactsIncludeFolders>
124124

125-
<RuntimeArtifactsIncludeFolders Include="cdaclibs/" TargetDir="/">
126-
<IncludeSubFolders>True</IncludeSubFolders>
127-
</RuntimeArtifactsIncludeFolders>
128-
129125
<!-- XUnit runner harness assemblies that we don't want to mix in with the framework in Core_Root -->
130126
<RunTimeArtifactsIncludeFolders Include="xunit/" TargetDir="xunit/" />
131127
</ItemGroup>

0 commit comments

Comments
 (0)