Skip to content

Commit b83635a

Browse files
committed
Re-enable system libunwind support
This includes a backport of dotnet/runtime#42689
1 parent b5a7ad0 commit b83635a

File tree

3 files changed

+112
-2
lines changed

3 files changed

+112
-2
lines changed

Directory.Build.props

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@
2727
no longer be passed in. -->
2828
<BuildPortableRuntime Condition="'$(BuildPortableRuntime)' == ''">false</BuildPortableRuntime>
2929
<BuildPortableSdk Condition="'$(BuildPortableSdk)' == ''">false</BuildPortableSdk>
30+
<UseSystemLibraries Condition="'$(UseSystemLibraries)' == '' AND '$(PortableRuntime)' != 'true'">true</UseSystemLibraries>
31+
<UseSystemLibraries Condition="'$(UseSystemLibraries)' == ''">false</UseSystemLibraries>
3032
</PropertyGroup>
3133

3234
<!-- This repo's projects are entirely infrastructure and do not ship. -->

patches/runtime/42689.patch

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
From 333b6b50efa909e396b525087d9ba5d8fecd7e3a Mon Sep 17 00:00:00 2001
2+
From: Omair Majid <omajid@redhat.com>
3+
Date: Thu, 24 Sep 2020 12:23:56 -0400
4+
Subject: [PATCH] Re-enable support for using the system libunwind
5+
6+
You can now build runtime against the system libunwind using:
7+
8+
./build.sh -cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND
9+
10+
This allows Linux distributions that already ship a compatible version
11+
of libunwind library to use that instead of carrying a duplicate in
12+
.NET. This provides some benefits to them, including smaller build
13+
sizes, slightly faster builds and fewer places to fix any
14+
vulnerabilities
15+
16+
This functionality was already supported in .NET Core 3.1 and has
17+
regressed since.
18+
19+
CoreCLR already handles `-DCLR_CMAKE_USE_SYSTEM_LIBUNWIND`, so no
20+
changes are needed there.
21+
22+
The libraries build doesn't care about this cmake varibale, but cmake
23+
itself fails if the variable is not used:
24+
25+
EXEC : CMake error : [runtime/src/libraries/Native/build-native.proj]
26+
Manually-specified variables were not used by the project:
27+
28+
CLR_CMAKE_USE_SYSTEM_LIBUNWIND
29+
30+
So libraries just needs to check and ignore this variable.
31+
32+
The singlefilehost needs to link against libunwind too. Otherwise the
33+
linker fails to resolve symbols, making the build fail:
34+
35+
/usr/bin/ld: runtime/artifacts/bin/coreclr/Linux.x64.Debug//lib/libcoreclrpal.a(seh.cpp.o): in function `UnwindContextToWinContext(unw_cursor*, _CONTEXT*)':
36+
dotnet/runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:176: undefined reference to `_ULx86_64_get_reg'
37+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:177: undefined reference to `_ULx86_64_get_reg'
38+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:178: undefined reference to `_ULx86_64_get_reg'
39+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:179: undefined reference to `_ULx86_64_get_reg'
40+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:180: undefined reference to `_ULx86_64_get_reg'
41+
/usr/bin/ld: runtime/artifacts/bin/coreclr/Linux.x64.Debug//lib/libcoreclrpal.a(seh.cpp.o): runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:181: more undefined references to `_ULx86_64_get_reg' follow
42+
/usr/bin/ld: runtime/artifacts/bin/coreclr/Linux.x64.Debug//lib/libcoreclrpal.a(seh.cpp.o): in function `GetContextPointer(unw_cursor*, ucontext_t*, int, unsigned long**)':
43+
runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:227: undefined reference to `_ULx86_64_get_save_loc'
44+
/usr/bin/ld: runtime/artifacts/bin/coreclr/Linux.x64.Debug//lib/libcoreclrpal.a(seh.cpp.o): in function `PAL_VirtualUnwind':
45+
runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:340: undefined reference to `_ULx86_64_init_local'
46+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:351: undefined reference to `_ULx86_64_step'
47+
/usr/bin/ld: runtime/src/coreclr/src/pal/src/exception/seh-unwind.cpp:360: undefined reference to `_ULx86_64_is_signal_frame'
48+
clang-10: error: linker command failed with exit code 1 (use -v to see invocation)
49+
50+
Fixes: #42661
51+
---
52+
.../corehost/cli/apphost/static/CMakeLists.txt | 14 +++++++++-----
53+
src/libraries/Native/Unix/configure.cmake | 6 ++++++
54+
2 files changed, 15 insertions(+), 5 deletions(-)
55+
56+
diff --git a/src/installer/corehost/cli/apphost/static/CMakeLists.txt b/src/installer/corehost/cli/apphost/static/CMakeLists.txt
57+
index fd2508ea0f9b..d115b93a27b3 100644
58+
--- a/src/installer/corehost/cli/apphost/static/CMakeLists.txt
59+
+++ b/src/installer/corehost/cli/apphost/static/CMakeLists.txt
60+
@@ -109,11 +109,6 @@ elseif(CLR_CMAKE_TARGET_LINUX)
61+
#
62+
# # On OSX and *BSD, we use the libunwind that's part of the OS
63+
# if(CLR_CMAKE_TARGET_FREEBSD)
64+
- # find_unwind_libs(UNWIND_LIBS)
65+
- #
66+
- # LIST(APPEND CORECLR_LIBRARIES
67+
- # ${UNWIND_LIBS}
68+
- # )
69+
# endif(CLR_CMAKE_TARGET_FREEBSD)
70+
#
71+
# if(CLR_CMAKE_TARGET_NETBSD)
72+
@@ -129,6 +124,15 @@ endif(CLR_CMAKE_TARGET_WIN32)
73+
set(NATIVE_LIBS_LOCATION "${NATIVE_LIBS_ARTIFACTS}")
74+
message ("Looking for native libs at location: '${NATIVE_LIBS_LOCATION}'.")
75+
76+
+# This needs to be the default for BSD and OSX
77+
+if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
78+
+ find_unwind_libs(UNWIND_LIBS)
79+
+
80+
+ LIST(APPEND CORECLR_LIBRARIES
81+
+ ${UNWIND_LIBS}
82+
+ )
83+
+endif()
84+
+
85+
if(NOT CLR_CMAKE_TARGET_LINUX)
86+
set(NATIVE_LIBS
87+
# Native libs linked into singlefilehost is supported only on Linux for now.
88+
diff --git a/src/libraries/Native/Unix/configure.cmake b/src/libraries/Native/Unix/configure.cmake
89+
index 6c7e49fc975b..84d787e19eac 100644
90+
--- a/src/libraries/Native/Unix/configure.cmake
91+
+++ b/src/libraries/Native/Unix/configure.cmake
92+
@@ -42,6 +42,12 @@ else ()
93+
message(FATAL_ERROR "Unknown platform. Cannot define PAL_UNIX_NAME, used by RuntimeInformation.")
94+
endif ()
95+
96+
+if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
97+
+ # This option can be passed to cmake and used by the coreclr and installer
98+
+ # builds. Libraries doesn't need it, but not using it makes the build fail.
99+
+ # So just check and igore the flag.
100+
+endif()
101+
+
102+
# We compile with -Werror, so we need to make sure these code fragments compile without warnings.
103+
# Older CMake versions (3.8) do not assign the result of their tests, causing unused-value errors
104+
# which are not distinguished from the test failing. So no error for that one.

repos/runtime.common.props

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212
<OverrideTargetRid Condition="'$(TargetOS)' == 'FreeBSD'">freebsd-x64</OverrideTargetRid>
1313
<OverrideTargetRid Condition="'$(TargetOS)' == 'Windows_NT'">win-x64</OverrideTargetRid>
1414
<OverrideTargetRid Condition="'$(TargetOS)' == 'Linux' and ('$(PortableBuild)' == 'true' or '$(BuildingPortableRuntime)' == 'true')">linux-$(Platform)</OverrideTargetRid>
15+
16+
<UseSystemLibunwind Condition="'$(UseSystemLibunwind)' == '' AND '$(OS)' == 'Windows_NT'">false</UseSystemLibunwind>
17+
<UseSystemLibunwind Condition="'$(UseSystemLibunwind)' == '' AND '$(TargetOS)' == 'OSX'">false</UseSystemLibunwind>
18+
<UseSystemLibunwind Condition="'$(UseSystemLibunwind)' == ''">$(UseSystemLibraries)</UseSystemLibunwind>
1519
</PropertyGroup>
1620

1721
<!-- Build arguments -->
@@ -21,8 +25,7 @@
2125
<LogVerbosityOptOut>true</LogVerbosityOptOut>
2226

2327
<!-- coreclr -->
24-
<!-- coreclr build fails when passing this flag after this PR https://github.com/dotnet/coreclr/pull/26082 -->
25-
<!-- <CoreClrBuildArguments Condition="'$(UseSystemLibraries)' == 'true' AND '$(OS)' != 'Windows_NT'">$(CoreClrBuildArguments) cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=TRUE</CoreClrBuildArguments> -->
28+
<CoreClrBuildArguments Condition="'$(UseSystemLibunwind)' == 'true'">$(CoreClrBuildArguments) -cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=TRUE</CoreClrBuildArguments>
2629
<CoreClrBuildArguments Condition="$(Platform.Contains('arm')) AND '$(BuildArchitecture)' != 'arm64' ">$(CoreClrBuildArguments) skipnuget cross -skiprestore cmakeargs -DFEATURE_GDBJIT=TRUE</CoreClrBuildArguments>
2730
<CoreClrBuildArguments Condition="'$(TargetOS)' == 'FreeBSD'">$(CoreClrBuildArguments) -clang6.0 /p:PortableBuild=true</CoreClrBuildArguments>
2831

@@ -64,6 +67,7 @@
6467
<InstallerBuildArguments>$(FlagParameterPrefix)restore $(FlagParameterPrefix)build</InstallerBuildArguments>
6568
<InstallerBuildArguments>$(InstallerBuildArguments) /p:PortableBuild=$(OverridePortableBuild)</InstallerBuildArguments>
6669
<InstallerBuildArguments>$(InstallerBuildArguments) /p:KeepNativeSymbols=true</InstallerBuildArguments>
70+
<InstallerBuildArguments Condition="'$(UseSystemLibunwind)' == 'true'">$(InstallerBuildArguments) -cmakeargs -DCLR_CMAKE_USE_SYSTEM_LIBUNWIND=TRUE</InstallerBuildArguments>
6771
<InstallerBuildArguments Condition="$(Platform.Contains('arm')) AND '$(BuildArchitecture)' != 'arm64'">$(InstallerBuildArguments) /p:TargetArchitecture=$(Platform) /p:DisableCrossgen=true /p:CrossBuild=true</InstallerBuildArguments>
6872
<InstallerBuildArguments>$(InstallerBuildArguments) /p:BuildDebPackage=false</InstallerBuildArguments>
6973
<InstallerBuildArguments>$(InstallerBuildArguments) /p:BuildAllPackages=true</InstallerBuildArguments>

0 commit comments

Comments
 (0)