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

Commit

Permalink
Use LLVM libunwind for stack unwinding on Unix
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
janvorli committed Dec 1, 2016
1 parent 9317993 commit 60f4ebf
Show file tree
Hide file tree
Showing 15 changed files with 451 additions and 144 deletions.
59 changes: 59 additions & 0 deletions THIRD-PARTY-NOTICES
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
.NET Core uses third-party libraries or other resources that may be
distributed under licenses different than the .NET Core software.

Attributions and licence notices for test cases originally authored by
third parties can be found in the respective test directories.

In the event that we accidentally failed to list a required notice, please
bring it to our attention. Post an issue or email us:

[email protected]

The attached notices are provided for information only.

License notice for The LLVM Compiler Infrastructure
---------------------------------------------------
==============================================================================
LLVM Release License
==============================================================================
University of Illinois/NCSA
Open Source License

Copyright (c) 2003-2015 University of Illinois at Urbana-Champaign.
All rights reserved.

Developed by:

LLVM Team

University of Illinois at Urbana-Champaign

http://llvm.org

Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal with
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:

* Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimers.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimers in the
documentation and/or other materials provided with the distribution.

* Neither the names of the LLVM Team, University of Illinois at
Urbana-Champaign, nor the names of its contributors may be used to
endorse or promote products derived from this Software without specific
prior written permission.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS WITH THE
SOFTWARE.

16 changes: 14 additions & 2 deletions src/Native/Runtime/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ else()
include_directories(unix)
include_directories(../libunwind/include)

# Disable building _Unwind_XXX style APIs of libunwind, since we don't use them.
add_definitions(-D_LIBUNWIND_DISABLE_ZERO_COST_APIS=1)

# Compile unwinding only for the current compilation target architecture
add_definitions(-D_LIBUNWIND_IS_NATIVE_ONLY)

list(APPEND COMMON_RUNTIME_SOURCES
unix/PalRedhawkUnix.cpp
)
Expand All @@ -105,6 +111,12 @@ else()
../libunwind/src/libunwind.cpp
)

if(CLR_CMAKE_PLATFORM_DARWIN)
list(APPEND FULL_RUNTIME_SOURCES
../libunwind/src/Unwind_AppleExtras.cpp
)
endif()

if(CLR_CMAKE_PLATFORM_ARCH_AMD64)
set(ARCH_SOURCES_DIR amd64)
set(ASM_SUFFIX S)
Expand All @@ -117,8 +129,8 @@ else()
endif()

list(APPEND RUNTIME_SOURCES_ARCH_ASM
../libunwind/src/UnwindRegistersRestore.${ASM_SUFFIX}
../libunwind/src/UnwindRegistersSave.${ASM_SUFFIX}
../libunwind/src/UnwindRegistersRestore.S
../libunwind/src/UnwindRegistersSave.S
)
endif()

Expand Down
6 changes: 2 additions & 4 deletions src/Native/Runtime/startup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,13 @@ bool InitDLL(HANDLE hPalInstance)
if (!RestrictedCallouts::Initialize())
return false;

#ifndef USE_PORTABLE_HELPERS
#ifndef APP_LOCAL_RUNTIME
#if !defined(APP_LOCAL_RUNTIME) && !defined(USE_PORTABLE_HELPERS)
#ifndef PLATFORM_UNIX
PalAddVectoredExceptionHandler(1, RhpVectoredExceptionHandler);
#else
PalSetHardwareExceptionHandler(RhpHardwareExceptionHandler);
#endif
#endif
#endif
#endif // !APP_LOCAL_RUNTIME && !USE_PORTABLE_HELPERS

//
// init per-instance state
Expand Down
4 changes: 2 additions & 2 deletions src/Native/Runtime/unix/PalRedhawkUnix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -443,12 +443,12 @@ REDHAWK_PALEXPORT bool REDHAWK_PALAPI PalInit()
{
return false;
}
#ifndef USE_PORTABLE_HELPERS
#ifndef USE_PORTABLE_HELPERS
if (!InitializeHardwareExceptionHandling())
{
return false;
}
#endif
#endif // !USE_PORTABLE_HELPERS
int status = pthread_key_create(&g_threadKey, TlsObjectDestructor);
if (status != 0)
{
Expand Down
4 changes: 0 additions & 4 deletions src/Native/Runtime/unix/UnixContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@
#include "regdisplay.h"
#include "config.h"

#if !HAVE_LIBUNWIND_H
#error Don't know how to unwind on this platform
#endif

#include <libunwind.h>

#if HAVE_UCONTEXT_T
Expand Down
1 change: 0 additions & 1 deletion src/Native/Runtime/unix/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
#cmakedefine01 HAVE_SYS_VMPARAM_H
#cmakedefine01 HAVE_MACH_VM_TYPES_H
#cmakedefine01 HAVE_MACH_VM_PARAM_H
#cmakedefine01 HAVE_LIBUNWIND_H

#cmakedefine01 HAVE_PTHREAD_ATTR_GET_NP
#cmakedefine01 HAVE_PTHREAD_GETATTR_NP
Expand Down
6 changes: 0 additions & 6 deletions src/Native/Runtime/unix/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ list(APPEND CMAKE_REQUIRED_DEFINITIONS -D_FILE_OFFSET_BITS=64)
check_include_files(sys/vmparam.h HAVE_SYS_VMPARAM_H)
check_include_files(mach/vm_types.h HAVE_MACH_VM_TYPES_H)
check_include_files(mach/vm_param.h HAVE_MACH_VM_PARAM_H)
check_include_files(libunwind.h HAVE_LIBUNWIND_H)

check_library_exists(pthread pthread_attr_get_np "" HAVE_PTHREAD_ATTR_GET_NP)
check_library_exists(pthread pthread_getattr_np "" HAVE_PTHREAD_GETATTR_NP)
Expand Down Expand Up @@ -106,9 +105,4 @@ int main()
exit(ret);
}" HAVE_MACH_ABSOLUTE_TIME)

if(NOT HAVE_LIBUNWIND_H)
unset(HAVE_LIBUNWIND_H CACHE)
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8 and libunwind8-dev (or the appropriate packages for your platform)")
endif()

configure_file(${CMAKE_CURRENT_LIST_DIR}/config.h.in ${CMAKE_CURRENT_BINARY_DIR}/config.h)
4 changes: 2 additions & 2 deletions src/Native/libunwind/include/__libunwind_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 9
# elif defined(__x86_64__)
# define _LIBUNWIND_TARGET_X86_64 1
# define _LIBUNWIND_CONTEXT_SIZE 21
# define _LIBUNWIND_CURSOR_SIZE 33
# define _LIBUNWIND_CONTEXT_SIZE 42
# define _LIBUNWIND_CURSOR_SIZE 54
# define _LIBUNWIND_HIGHEST_DWARF_REGISTER 17
# elif defined(__ppc__)
# define _LIBUNWIND_TARGET_PPC 1
Expand Down
22 changes: 21 additions & 1 deletion src/Native/libunwind/include/libunwind.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,26 @@ struct unw_proc_info_t {
};
typedef struct unw_proc_info_t unw_proc_info_t;

enum unw_save_loc_type_t
{
UNW_SLT_NONE, /* register is not saved ("not an l-value") */
UNW_SLT_MEMORY, /* register has been saved in memory */
UNW_SLT_REG /* register has been saved in (another) register */
};
typedef enum unw_save_loc_type_t unw_save_loc_type_t;

struct unw_save_loc_t
{
unw_save_loc_type_t type;
union
{
unw_word_t addr; /* valid if type==UNW_SLT_MEMORY */
unw_regnum_t regnum; /* valid if type==UNW_SLT_REG */
}
u;
};
typedef struct unw_save_loc_t unw_save_loc_t;

#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -119,7 +139,7 @@ extern int unw_get_proc_info(unw_cursor_t *, unw_proc_info_t *) LIBUNWIND_AVAIL;
extern int unw_is_fpreg(unw_cursor_t *, unw_regnum_t) LIBUNWIND_AVAIL;
extern int unw_is_signal_frame(unw_cursor_t *) LIBUNWIND_AVAIL;
extern int unw_get_proc_name(unw_cursor_t *, char *, size_t, unw_word_t *) LIBUNWIND_AVAIL;
//extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);
extern int unw_get_save_loc(unw_cursor_t*, int, unw_save_loc_t*);

extern unw_addr_space_t unw_local_addr_space;

Expand Down
Loading

0 comments on commit 60f4ebf

Please sign in to comment.