From 4c51b2dbbdd9bdf23552a9d26ad08a78ce1523cc Mon Sep 17 00:00:00 2001 From: Tomas Weinfurt Date: Tue, 19 Jun 2018 13:54:41 -0700 Subject: [PATCH] fixes for sos on FreeBSD (#18479) * fixes for sos on FreeBSD * refactore unwind detection to common block for BSD and Linux * missing newline * do not do libunwind detection for OSX --- src/pal/src/CMakeLists.txt | 67 ++++++++++++++---------------- src/pal/src/include/pal/thread.hpp | 7 ++++ 2 files changed, 39 insertions(+), 35 deletions(-) diff --git a/src/pal/src/CMakeLists.txt b/src/pal/src/CMakeLists.txt index 130e06ed4b..a3cc603e18 100644 --- a/src/pal/src/CMakeLists.txt +++ b/src/pal/src/CMakeLists.txt @@ -16,8 +16,37 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) include_directories(${CMAKE_CURRENT_BINARY_DIR}/libunwind/include/tdep) add_subdirectory(libunwind) -endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) +elseif(NOT CMAKE_SYSTEM_NAME STREQUAL Darwin) + 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(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) + set(UNWIND_LIBS ${UNWIND_ARCH}) + endif() + find_library(UNWIND_GENERIC NAMES unwind-generic) + + if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) + set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND_GENERIC}) + endif() + + find_library(UNWIND NAMES unwind) + + if(UNWIND STREQUAL UNWIND-NOTFOUND) + message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.") + endif() + + set(UNWIND_LIBS ${UNWIND_LIBS} ${UNWIND}) +endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND) include(configure.cmake) project(coreclrpal) @@ -275,14 +304,11 @@ if(CMAKE_SYSTEM_NAME STREQUAL Darwin) endif(CMAKE_SYSTEM_NAME STREQUAL Darwin) if(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) - if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) - find_library(UNWIND unwind) - endif() find_library(INTL intl) target_link_libraries(coreclrpal pthread rt - ${UNWIND} + ${UNWIND_LIBS} ${INTL} ) endif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD) @@ -342,36 +368,7 @@ if(CMAKE_SYSTEM_NAME STREQUAL Linux) endif(NOT INTL STREQUAL INTL-NOTFOUND) if(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) - 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(NOT UNWIND_ARCH STREQUAL UNWIND_ARCH-NOTFOUND) - target_link_libraries(coreclrpal ${UNWIND_ARCH}) - endif() - - find_library(UNWIND_GENERIC NAMES unwind-generic) - - if(NOT UNWIND_GENERIC STREQUAL UNWIND_GENERIC-NOTFOUND) - target_link_libraries(coreclrpal ${UNWIND_GENERIC}) - endif() - - find_library(UNWIND NAMES unwind) - - if(UNWIND STREQUAL UNWIND-NOTFOUND) - message(FATAL_ERROR "Cannot find libunwind. Try installing libunwind8-dev or libunwind-devel.") - endif() - - target_link_libraries(coreclrpal ${UNWIND}) - + target_link_libraries(coreclrpal ${UNWIND_LIBS}) endif(CLR_CMAKE_USE_SYSTEM_LIBUNWIND) endif(CMAKE_SYSTEM_NAME STREQUAL Linux) diff --git a/src/pal/src/include/pal/thread.hpp b/src/pal/src/include/pal/thread.hpp index ddacfb9039..2a03bcfdd4 100644 --- a/src/pal/src/include/pal/thread.hpp +++ b/src/pal/src/include/pal/thread.hpp @@ -810,6 +810,13 @@ inline SIZE_T THREADSilentGetCurrentThreadId() { pthread_threadid_np(pthread_self(), &tid); return (SIZE_T)tid; } +#elif defined(__FreeBSD__) +#include +inline SIZE_T THREADSilentGetCurrentThreadId() { + long tid; + thr_self(&tid); + return (SIZE_T)tid; +} #elif defined(__NetBSD__) #include #define THREADSilentGetCurrentThreadId() (SIZE_T)_lwp_self() -- 2.34.1