Skip to content

Commit 21667f2

Browse files
author
Max Charlamb
committed
statically link cdac unwinder libraries
1 parent 4631ece commit 21667f2

File tree

6 files changed

+81
-40
lines changed

6 files changed

+81
-40
lines changed

src/coreclr/debug/daccess/cdac.cpp

Lines changed: 0 additions & 7 deletions
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/unwinder/CMakeLists.txt

Lines changed: 53 additions & 13 deletions
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 debug)
59+
3360
# Helper function for platform specific cDAC uwninder builds.
3461
function(create_platform_unwinder)
3562
set(oneValueArgs TARGET ARCH)
@@ -48,21 +75,23 @@ 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
6897
install_clr(TARGETS ${TARGETDETAILS_TARGET} DESTINATIONS ${TARGETDETAILS_DESTINATIONS} COMPONENT debug INSTALL_ALL_ARTIFACTS)
@@ -73,9 +102,20 @@ function(create_platform_unwinder)
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(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(CLR_CMAKE_TARGET_WIN32 AND CLR_CMAKE_TARGET_ARCH_ARM64)
121+

src/coreclr/unwinder/amd64/unwinder.h

Lines changed: 6 additions & 6 deletions
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

Lines changed: 5 additions & 5 deletions
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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ HRESULT OOPStackUnwinder::GetFunctionEntry( DWORD64 addres
6060
_Out_writes_(cbBuffer) PVOID pBuffer,
6161
DWORD cbBuffer)
6262
{
63-
if (cbBuffer < sizeof(T_RUNTIME_FUNCTION))
64-
{
65-
return E_INVALIDARG;
66-
}
63+
// if (cbBuffer < sizeof(T_RUNTIME_FUNCTION))
64+
// {
65+
// return E_INVALIDARG;
66+
// }
6767

6868
PVOID pFuncEntry = NULL;
6969
#ifndef FEATURE_CDAC_UNWINDER

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

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,20 @@
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'"/>
35+
<DirectPInvoke Include="unwinder_cdac_amd64" />
36+
<DirectPInvoke Include="unwinder_cdac_arm64" />
37+
38+
<!-- unwinder_cdac_base is supported on all platforms -->
39+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\unwinder_cdac_base.lib" Condition="'$(TargetsWindows)' == 'true'"/>
40+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\libunwinder_cdac_base.a" Condition="'$(TargetsWindows)' != 'true'" />
41+
42+
<!-- amd64 and arm64 are supported on windows x64, or on their native platform -->
3843
<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'" />
44+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\unwinder_cdac_arm64.lib" Condition="'$(TargetsWindows)' == 'true' and ('$(TargetArchitecture)' == 'x64' or '$(TargetArchitecture)' == 'arm64')" />
45+
46+
<!-- non-windows, load only the platform native unwinders -->
47+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\libunwinder_cdac_amd64.a" Condition="'$(TargetsWindows)' != 'true' and '$(TargetArchitecture)' == 'x64'" />
48+
<NativeLibrary Include="$(CoreCLRArtifactsPath)cdaclibs\libunwinder_cdac_arm64.a" Condition="'$(TargetsWindows)' != 'true' and '$(TargetArchitecture)' == 'arm64'" />
4149
</ItemGroup>
4250

4351
<ItemGroup>

0 commit comments

Comments
 (0)