|
| 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. |
0 commit comments