Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Remove dependency on libunwind (#17094)
Browse files Browse the repository at this point in the history
* Add original source of libunwind 1.3-stable

Taken from:
https://github.com/libunwind/libunwind/tree/v1.3-stable

* Enable building of libunwind

This change enables building libunwind and removes
dependency on the libunwind package for all Unixes
except OSX. In OSX the libunwind is part of the OS
and also has support for compact unwind info that
is OSX specific, so we keep using that one.

* Disable warnings in code we don't execute
  • Loading branch information
janvorli authored Mar 22, 2018
1 parent 0822457 commit d104270
Show file tree
Hide file tree
Showing 778 changed files with 78,715 additions and 77 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@ syntax: glob
[Dd]ebugPublic/
[Rr]elease/
[Rr]eleases/
x64/
x86/
build/
bld/
[Bb]in/
Expand Down Expand Up @@ -54,7 +52,6 @@ dlldata.c

*_i.c
*_p.c
*_i.h
*.ilk
*.meta
*.obj
Expand Down
51 changes: 13 additions & 38 deletions src/pal/src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
cmake_minimum_required(VERSION 2.8.12.2)

include_directories(SYSTEM /usr/local/include)
include_directories(libunwind/include)

add_compile_options(-fPIC)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
add_subdirectory(libunwind)
endif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)

include(configure.cmake)

Expand Down Expand Up @@ -109,8 +116,6 @@ endif(CLR_CMAKE_PLATFORM_ALPINE_LINUX)
# turn off capability to remove unused functions (which was enabled in debug build with sanitizers)
set(CMAKE_SHARED_LINKER_FLAGS_DEBUG "${CMAKE_SHARED_LINKER_FLAGS_DEBUG} -Wl,--no-gc-sections")

add_compile_options(-fPIC)

set(ARCH_SOURCES
arch/${PAL_ARCH_SOURCES_DIR}/context2.S
arch/${PAL_ARCH_SOURCES_DIR}/debugbreak.S
Expand Down Expand Up @@ -235,11 +240,17 @@ set(SOURCES
thread/tls.cpp
)

if(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)
# On OSX, we use the libunwind that's part of the OS
set(LIBUNWIND_OBJECTS $<TARGET_OBJECTS:libunwind>)
endif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin)

add_library(coreclrpal
STATIC
${SOURCES}
${ARCH_SOURCES}
${PLATFORM_SOURCES}
${LIBUNWIND_OBJECTS}
)

if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
Expand All @@ -256,29 +267,15 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
endif(CMAKE_SYSTEM_NAME STREQUAL Darwin)

if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
find_library(UNWIND unwind)
find_library(INTL intl)
target_link_libraries(coreclrpal
pthread
rt
${UNWIND}
${INTL}
)
endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)

if(CMAKE_SYSTEM_NAME STREQUAL Linux)
if(PAL_CMAKE_PLATFORM_ARCH_ARM)
find_library(UNWIND_ARCH NAMES unwind-arm)
endif()

if(PAL_CMAKE_PLATFORM_ARCH_ARM64)
find_library(UNWIND_ARCH NAMES unwind-aarch64)
endif()

if(PAL_CMAKE_PLATFORM_ARCH_AMD64)
find_library(UNWIND_ARCH NAMES unwind-x86_64)
endif()

if(CLR_CMAKE_PLATFORM_ALPINE_LINUX OR CLR_CMAKE_PLATFORM_ANDROID)
find_library(INTL intl)
endif()
Expand Down Expand Up @@ -306,23 +303,12 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
${LZMA})
endif()

find_library(UNWIND NAMES unwind)

if(UNWIND STREQUAL UNWIND-NOTFOUND)
message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev and libunwind8.")
endif(UNWIND STREQUAL UNWIND-NOTFOUND)

target_link_libraries(coreclrpal ${UNWIND})

if(CLR_MAKE_PLATFORM_ANDROID)
find_library(ANDROID_SUPPORT NAMES android-support)
find_library(ANDROID_GLOB NAMES android-glob)
find_library(INTL NAMES intl)

if(UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
message(FATAL_ERROR "Cannot find libunwind.")
endif()

if(ANDROID_SUPPORT STREQUAL ANDROID_SUPPORT-NOTFOUND)
message(FATAL_ERROR "Cannot find android-support.")
endif()
Expand All @@ -336,19 +322,10 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux)
endif()
endif()

find_library(UNWIND_GENERIC NAMES unwind-generic)

target_link_libraries(coreclrpal
dl
)

if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)
target_link_libraries(coreclrpal ${UNWIND_GENERIC})
endif(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND)

if(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)
target_link_libraries(coreclrpal ${UNWIND_ARCH})
endif(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND)

if(NOT INTL STREQUAL INTL-NOTFOUND)
target_link_libraries(coreclrpal ${INTL})
Expand All @@ -358,13 +335,11 @@ endif(CMAKE_SYSTEM_NAME STREQUAL Linux)

if(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
add_definitions(-D_KMEMUSER)
find_library(UNWIND unwind)
find_library(INTL intl)
find_library(KVM kvm)
target_link_libraries(coreclrpal
pthread
rt
${UNWIND}
${INTL}
${KVM}
)
Expand Down
3 changes: 1 addition & 2 deletions src/pal/src/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
#cmakedefine01 HAVE_PTHREAD_NP_H
#cmakedefine01 HAVE_SYS_LWP_H
#cmakedefine01 HAVE_LWP_H
#cmakedefine01 HAVE_LIBUNWIND_H
#cmakedefine01 HAVE_RUNETYPE_H
#cmakedefine01 HAVE_SYS_SYSCTL_H
#cmakedefine01 HAVE_GNU_LIBNAMES_H
Expand Down Expand Up @@ -99,6 +98,7 @@
#cmakedefine01 HAVE_BROKEN_FIFO_SELECT
#cmakedefine01 HAVE_BROKEN_FIFO_KEVENT
#cmakedefine01 HAS_FTRUNCATE_LENGTH_ISSUE
#cmakedefine01 UNWIND_CONTEXT_IS_UCONTEXT_T
#cmakedefine01 HAVE_SCHED_GET_PRIORITY
#cmakedefine01 HAVE_SCHED_GETCPU
#cmakedefine01 HAVE_WORKING_GETTIMEOFDAY
Expand Down Expand Up @@ -146,7 +146,6 @@
#cmakedefine01 SYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING
#cmakedefine01 ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS
#cmakedefine01 HAS_FTRUNCATE_LENGTH_ISSUE
#cmakedefine01 UNWIND_CONTEXT_IS_UCONTEXT_T
#cmakedefine01 HAVE_FULLY_FEATURED_PTHREAD_MUTEXES
#cmakedefine01 HAVE_FUNCTIONAL_PTHREAD_ROBUST_MUTEXES
#cmakedefine BSD_REGS_STYLE(reg, RR, rr) @BSD_REGS_STYLE@
Expand Down
26 changes: 5 additions & 21 deletions src/pal/src/configure.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ check_include_files(sys/time.h HAVE_SYS_TIME_H)
check_include_files(pthread_np.h HAVE_PTHREAD_NP_H)
check_include_files(sys/lwp.h HAVE_SYS_LWP_H)
check_include_files(lwp.h HAVE_LWP_H)
check_include_files(libunwind.h HAVE_LIBUNWIND_H)
check_include_files(runetype.h HAVE_RUNETYPE_H)
check_include_files(semaphore.h HAVE_SEMAPHORE_H)
check_include_files(sys/prctl.h HAVE_PRCTL_H)
Expand Down Expand Up @@ -975,24 +974,25 @@ int main()
return 1;
}" FILE_OPS_CHECK_FERROR_OF_PREVIOUS_CALL)
set(CMAKE_REQUIRED_DEFINITIONS)

set(SYNCHMGR_SUSPENSION_SAFE_CONDITION_SIGNALING 1)
set(ERROR_FUNC_FOR_GLOB_HAS_FIXED_PARAMS 1)

check_cxx_source_compiles("
list(INSERT CMAKE_REQUIRED_INCLUDES 0 ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include ${CMAKE_CURRENT_BINARY_DIR}/libunwind/include)

check_c_source_compiles("
#include <libunwind.h>
#include <ucontext.h>
int main(int argc, char **argv)
{
unw_context_t libUnwindContext;
ucontext_t uContext;
libUnwindContext = uContext;
return 0;
}" UNWIND_CONTEXT_IS_UCONTEXT_T)

list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0 1)

check_cxx_source_compiles("
#include <sys/param.h>
#include <sys/sysctl.h>
Expand Down Expand Up @@ -1272,10 +1272,6 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin)
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)

elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
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()
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
Expand All @@ -1286,10 +1282,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
set(BSD_REGS_STYLE "((reg).r_##rr)")
set(HAVE_SCHED_OTHER_ASSIGNABLE 1)
elseif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
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()
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (void*)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
Expand All @@ -1301,10 +1293,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL NetBSD)
set(HAVE_SCHED_OTHER_ASSIGNABLE 0)

elseif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
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()
set(DEADLOCK_WHEN_THREAD_IS_SUSPENDED_WHILE_BLOCKED_ON_MUTEX 0)
set(PAL_PTRACE "ptrace((cmd), (pid), (caddr_t)(addr), (data))")
set(PAL_PT_ATTACH PT_ATTACH)
Expand All @@ -1313,10 +1301,6 @@ elseif(CMAKE_SYSTEM_NAME STREQUAL SunOS)
set(PAL_PT_WRITE_D PT_WRITE_D)
set(HAS_FTRUNCATE_LENGTH_ISSUE 0)
else() # Anything else is Linux
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()
if(NOT HAVE_LTTNG_TRACEPOINT_H AND FEATURE_EVENT_TRACE)
unset(HAVE_LTTNG_TRACEPOINT_H CACHE)
message(FATAL_ERROR "Cannot find liblttng-ust-dev. Try installing liblttng-ust-dev (or the appropriate packages for your platform)")
Expand Down
4 changes: 0 additions & 4 deletions src/pal/src/exception/remote-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,8 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#include "pal.h"
#include <dlfcn.h>

#if HAVE_LIBUNWIND_H
#ifndef __linux__
#define UNW_LOCAL_ONLY
#endif // !__linux__
#include <libunwind.h>
#endif // HAVE_LIBUNWIND_H

SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);

Expand Down
9 changes: 0 additions & 9 deletions src/pal/src/exception/seh-unwind.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,13 @@ Module Name:
#include "pal.h"
#include <dlfcn.h>

#if HAVE_LIBUNWIND_H
#ifndef __linux__
#define UNW_LOCAL_ONLY
#endif // !__linux__
#include <libunwind.h>
#endif // HAVE_LIBUNWIND_H

//----------------------------------------------------------------------
// Virtual Unwinding
//----------------------------------------------------------------------

#if HAVE_LIBUNWIND_H
#if UNWIND_CONTEXT_IS_UCONTEXT_T

#if defined(_AMD64_)
Expand Down Expand Up @@ -347,10 +342,6 @@ BOOL PAL_VirtualUnwind(CONTEXT *context, KNONVOLATILE_CONTEXT_POINTERS *contextP
return TRUE;
}

#else
#error don't know how to unwind on this platform
#endif

struct ExceptionRecords
{
CONTEXT ContextRecord;
Expand Down
79 changes: 79 additions & 0 deletions src/pal/src/libunwind/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
*.la
*.a
*.o
*.lo
*~
*.pc

.libs/
.deps/

.dirstamp
Makefile
Makefile.in

INSTALL
aclocal.m4
autom4te.cache/
config.log
config.status
config/
configure
libtool

doc/common.tex

src/[GL]cursor_i.h
src/mk_[GL]cursor_i.s

include/config.h
include/config.h.in
include/libunwind-common.h
include/stamp-h1
include/libunwind.h
include/tdep/libunwind_i.h

tests/[GL]test-bt
tests/[GL]test-concurrent
tests/[GL]test-dyn1
tests/[GL]test-exc
tests/[GL]test-init
tests/[GL]test-resume-sig
tests/[GL]test-resume-sig-rt
tests/[GL]perf-simple
tests/Ltest-nomalloc
tests/Ltest-nocalloc
tests/Lperf-simple
tests/Lrs-race
tests/Ltest-varargs
tests/check-namespace.sh
tests/crasher
tests/forker
tests/mapper
tests/rs-race
tests/test-async-sig
tests/test-coredump-unwind
tests/test-flush-cache
tests/test-init-remote
tests/test-mem
tests/test-ptrace
tests/test-setjmp
tests/test-strerror
tests/test-proc-info
tests/test-ptrace-misc
tests/test-reg-state
tests/test-varargs
tests/test-static-link
tests/[GL]test-trace
tests/[GL]perf-trace
tests/Ltest-cxx-exceptions
tests/Ltest-init-local-signal
tests/Ltest-mem-validate
tests/[GL]ia64-test-nat
tests/[GL]ia64-test-rbs
tests/[GL]ia64-test-readonly
tests/[GL]ia64-test-stack
tests/ia64-test-dyn1
tests/ia64-test-sig
tests/*.log
tests/*.trs
18 changes: 18 additions & 0 deletions src/pal/src/libunwind/.travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
sudo: required
language: c
compiler: gcc
env:
- TARGET=x86_64-linux-gnu
- TARGET=x86-linux-gnu
- TARGET=arm-linux-gnueabihf
- TARGET=aarch64-linux-gnu
- TARGET=mipsel-unknown-linux-gnu
# Currently experiencing build failures here
#- TARGET=powerpc64-linux-gnu
script:
- ./autogen.sh
- ./configure --target=$TARGET --host=$HOST
- make -j32
- sudo bash -c 'echo core.%p.%p > /proc/sys/kernel/core_pattern'
- ulimit -c unlimited
- if [ $TARGET == 'x86_64-linux-gnu' ]; then make check -j32; fi
1 change: 1 addition & 0 deletions src/pal/src/libunwind/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
David Mosberger <dmosberger@gmail.org>
Loading

0 comments on commit d104270

Please sign in to comment.