Skip to content
This repository was archived by the owner on Nov 1, 2020. It is now read-only.

Commit 407f544

Browse files
committed
Use LLVM libunwind for stack unwinding on Unix
This change replaces external libunwind usage on Unix by a copy of the LLVM libunwind. It also modifies libunwind to support reporting register location and implements the unw_get_save_loc API to get this location. For now, only memory locations are supported (register locations are not).
1 parent 661166e commit 407f544

File tree

15 files changed

+451
-144
lines changed

15 files changed

+451
-144
lines changed

THIRD-PARTY-NOTICES

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
.NET Core uses third-party libraries or other resources that may be
2+
distributed under licenses different than the .NET Core software.
3+
4+
Attributions and licence notices for test cases originally authored by
5+
third parties can be found in the respective test directories.
6+
7+
In the event that we accidentally failed to list a required notice, please
8+
bring it to our attention. Post an issue or email us:
9+
10+
11+
12+
The attached notices are provided for information only.
13+
14+
License notice for The LLVM Compiler Infrastructure
15+
---------------------------------------------------
16+
==============================================================================
17+
LLVM Release License
18+
==============================================================================
19+
University of Illinois/NCSA
20+
Open Source License
21+
22+
Copyright (c) 2003-2015 University of Illinois at Urbana-Champaign.
23+
All rights reserved.
24+
25+
Developed by:
26+
27+
LLVM Team
28+
29+
University of Illinois at Urbana-Champaign
30+
31+
http://llvm.org
32+
33+
Permission is hereby granted, free of charge, to any person obtaining a copy of
34+
this software and associated documentation files (the "Software"), to deal with
35+
the Software without restriction, including without limitation the rights to
36+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
37+
of the Software, and to permit persons to whom the Software is furnished to do
38+
so, subject to the following conditions:
39+
40+
* Redistributions of source code must retain the above copyright notice,
41+
this list of conditions and the following disclaimers.
42+
43+
* Redistributions in binary form must reproduce the above copyright notice,
44+
this list of conditions and the following disclaimers in the
45+
documentation and/or other materials provided with the distribution.
46+
47+
* Neither the names of the LLVM Team, University of Illinois at
48+
Urbana-Champaign, nor the names of its contributors may be used to
49+
endorse or promote products derived from this Software without specific
50+
prior written permission.
51+
52+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
53+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
54+
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
55+
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
56+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
57+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
58+
SOFTWARE.
59+

src/Native/Runtime/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,12 @@ else()
9393
include_directories(unix)
9494
include_directories(../libunwind/include)
9595

96+
# Disable building _Unwind_XXX style APIs of libunwind, since we don't use them.
97+
add_definitions(-D_LIBUNWIND_DISABLE_ZERO_COST_APIS=1)
98+
99+
# Compile unwinding only for the current compilation target architecture
100+
add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY)
101+
96102
list(APPEND COMMON_RUNTIME_SOURCES
97103
unix/PalRedhawkUnix.cpp
98104
)
@@ -105,6 +111,12 @@ else()
105111
../libunwind/src/libunwind.cpp
106112
)
107113

114+
if(CLR_CMAKE_PLATFORM_DARWIN)
115+
list(APPEND FULL_RUNTIME_SOURCES
116+
../libunwind/src/Unwind_AppleExtras.cpp
117+
)
118+
endif()
119+
108120
if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
109121
set(ARCH_SOURCES_DIR amd64)
110122
set(ASM_SUFFIX S)
@@ -117,8 +129,8 @@ else()
117129
endif()
118130

119131
list(APPEND RUNTIME_SOURCES_ARCH_ASM
120-
../libunwind/src/UnwindRegistersRestore.${ASM_SUFFIX}
121-
../libunwind/src/UnwindRegistersSave.${ASM_SUFFIX}
132+
../libunwind/src/UnwindRegistersRestore.S
133+
../libunwind/src/UnwindRegistersSave.S
122134
)
123135
endif()
124136

src/Native/Runtime/startup.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -70,15 +70,13 @@ bool InitDLL(HANDLE hPalInstance)
7070
if (!RestrictedCallouts::Initialize())
7171
return false;
7272

73-
#ifndef USE_PORTABLE_HELPERS
74-
#ifndef APP_LOCAL_RUNTIME
73+
#if !defined(APP_LOCAL_RUNTIME) && !defined(USE_PORTABLE_HELPERS)
7574
#ifndef PLATFORM_UNIX
7675
PalAddVectoredExceptionHandler(1, RhpVectoredExceptionHandler);
7776
#else
7877
PalSetHardwareExceptionHandler(RhpHardwareExceptionHandler);
7978
#endif
80-
#endif
81-
#endif
79+
#endif // !APP_LOCAL_RUNTIME && !USE_PORTABLE_HELPERS
8280

8381
//
8482
// init per-instance state

src/Native/Runtime/unix/PalRedhawkUnix.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -443,12 +443,12 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit()
443443
{
444444
return false;
445445
}
446-
#ifndef USE_PORTABLE_HELPERS
446+
#ifndef USE_PORTABLE_HELPERS
447447
if (!InitializeHardwareExceptionHandling())
448448
{
449449
return false;
450450
}
451-
#endif
451+
#endif // !USE_PORTABLE_HELPERS
452452
int status = pthread_key_create(&g_threadKey, TlsObjectDestructor);
453453
if (status != 0)
454454
{

src/Native/Runtime/unix/UnixContext.cpp

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@
1111
#include "regdisplay.h"
1212
#include "config.h"
1313

14-
#if !HAVE_LIBUNWIND_H
15-
#error Don't know how to unwind on this platform
16-
#endif
17-
1814
#include <libunwind.h>
1915

2016
#if HAVE_UCONTEXT_T

src/Native/Runtime/unix/config.h.in

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
#cmakedefine01 HAVE_SYS_VMPARAM_H
55
#cmakedefine01 HAVE_MACH_VM_TYPES_H
66
#cmakedefine01 HAVE_MACH_VM_PARAM_H
7-
#cmakedefine01 HAVE_LIBUNWIND_H
87

98
#cmakedefine01 HAVE_PTHREAD_ATTR_GET_NP
109
#cmakedefine01 HAVE_PTHREAD_GETATTR_NP

src/Native/Runtime/unix/configure.cmake

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64)
1818
check_include_files(sys/vmparam.h HAVE_SYS_VMPARAM_H)
1919
check_include_files(mach/vm_types.h HAVE_MACH_VM_TYPES_H)
2020
check_include_files(mach/vm_param.h HAVE_MACH_VM_PARAM_H)
21-
check_include_files(libunwind.h HAVE_LIBUNWIND_H)
2221

2322
check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
2423
check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
@@ -106,9 +105,4 @@ int main()
106105
exit(ret);
107106
}" HAVE_MACH_ABSOLUTE_TIME)
108107

109-
if(NOT HAVE_LIBUNWIND_H)
110-
unset(HAVE_LIBUNWIND_H CACHE)
111-
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8 and libunwind8-dev (or the appropriate packages for your platform)")
112-
endif()
113-
114108
configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)

src/Native/libunwind/include/__libunwind_config.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@
2525
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 9
2626
# elif defined(__x86_64__)
2727
# define _LIBUNWIND_TARGET_X86_64 1
28-
# define _LIBUNWIND_CONTEXT_SIZE 21
29-
# define _LIBUNWIND_CURSOR_SIZE 33
28+
# define _LIBUNWIND_CONTEXT_SIZE 42
29+
# define _LIBUNWIND_CURSOR_SIZE 54
3030
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 17
3131
# elif defined(__ppc__)
3232
# define _LIBUNWIND_TARGET_PPC 1

src/Native/libunwind/include/libunwind.h

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,26 @@ struct unw_proc_info_t {
9595
};
9696
typedef struct unw_proc_info_t unw_proc_info_t;
9797

98+
enum unw_save_loc_type_t
99+
{
100+
UNW_SLT_NONE, /* register is not saved ("not an l-value") */
101+
UNW_SLT_MEMORY, /* register has been saved in memory */
102+
UNW_SLT_REG /* register has been saved in (another) register */
103+
};
104+
typedef enum unw_save_loc_type_t unw_save_loc_type_t;
105+
106+
struct unw_save_loc_t
107+
{
108+
unw_save_loc_type_t type;
109+
union
110+
{
111+
unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
112+
unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
113+
}
114+
u;
115+
};
116+
typedef struct unw_save_loc_t unw_save_loc_t;
117+
98118
#ifdef __cplusplus
99119
extern "C" {
100120
#endif
@@ -119,7 +139,7 @@ extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
119139
extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
120140
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
121141
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
122-
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
142+
extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
123143

124144
extern unw_addr_space_t unw_local_addr_space;
125145

0 commit comments

Comments
 (0)