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

Commit 6ecb1ac

Browse files
authored
Fix build without libunwind installed (#17221)
* Fix build without libunwind installed I have removed libunwind dependency in a recent commit, but it turns out that the build was using incorrect include paths and it was still depending on the libunwind installation for the libunwind.h header. This change fixes it. * Fix clang warning The libunwind headers contain two empty structs and clang issues a warning since the size of such structs is 0 in C and 1 in C++. This is benign for our purposes, since the affected structs are not directly used by our code.
1 parent 4e9206c commit 6ecb1ac

File tree

5 files changed

+41
-27
lines changed

5 files changed

+41
-27
lines changed

src/pal/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ add_compile_options(-fPIC)
1111

1212
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
1313
include_directories(libunwind/include)
14+
include_directories(libunwind/include/tdep)
15+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/libunwind/include)
16+
include_directories(${CMAKE_CURRENT_BINARY_DIR}/libunwind/include/tdep)
17+
1418
add_subdirectory(libunwind)
1519
endif(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
1620

src/pal/src/configure.cmake

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -100,28 +100,6 @@ check_function_exists(semget HAS_SYSV_SEMAPHORES)
100100
check_function_exists(pthread_mutex_init HAS_PTHREAD_MUTEXES)
101101
check_function_exists(ttrace HAVE_TTRACE)
102102
check_function_exists(pipe2 HAVE_PIPE2)
103-
set(CMAKE_REQUIRED_LIBRARIES unwind unwind-generic)
104-
check_cxx_source_compiles("
105-
#include <libunwind.h>
106-
107-
int main(int argc, char **argv) {
108-
unw_cursor_t cursor;
109-
unw_save_loc_t saveLoc;
110-
int reg = UNW_REG_IP;
111-
unw_get_save_loc(&cursor, reg, &saveLoc);
112-
113-
return 0;
114-
}" HAVE_UNW_GET_SAVE_LOC)
115-
check_cxx_source_compiles("
116-
#include <libunwind.h>
117-
118-
int main(int argc, char **argv) {
119-
unw_addr_space_t as;
120-
unw_get_accessors(as);
121-
122-
return 0;
123-
}" HAVE_UNW_GET_ACCESSORS)
124-
set(CMAKE_REQUIRED_LIBRARIES)
125103

126104
check_cxx_source_compiles("
127105
#include <pthread_np.h>
@@ -982,6 +960,8 @@ if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
982960
list(INSERT CMAKE_REQUIRED_INCLUDES 0 ${CMAKE_CURRENT_SOURCE_DIR}/libunwind/include ${CMAKE_CURRENT_BINARY_DIR}/libunwind/include)
983961
endif()
984962

963+
set(CMAKE_REQUIRED_FLAGS "-c -Werror=implicit-function-declaration")
964+
985965
check_c_source_compiles("
986966
#include <libunwind.h>
987967
#include <ucontext.h>
@@ -993,6 +973,29 @@ int main(int argc, char **argv)
993973
return 0;
994974
}" UNWIND_CONTEXT_IS_UCONTEXT_T)
995975

976+
check_c_source_compiles("
977+
#include <libunwind.h>
978+
979+
int main(int argc, char **argv) {
980+
unw_cursor_t cursor;
981+
unw_save_loc_t saveLoc;
982+
int reg = UNW_REG_IP;
983+
unw_get_save_loc(&cursor, reg, &saveLoc);
984+
985+
return 0;
986+
}" HAVE_UNW_GET_SAVE_LOC)
987+
988+
check_c_source_compiles("
989+
#include <libunwind.h>
990+
991+
int main(int argc, char **argv) {
992+
unw_addr_space_t as;
993+
unw_get_accessors(as);
994+
995+
return 0;
996+
}" HAVE_UNW_GET_ACCESSORS)
997+
998+
set(CMAKE_REQUIRED_FLAGS)
996999
if(NOT CLR_CMAKE_USE_SYSTEM_LIBUNWIND)
9971000
list(REMOVE_AT CMAKE_REQUIRED_INCLUDES 0 1)
9981001
endif()

src/pal/src/exception/remote-unwind.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,13 @@ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
4949
#include <dlfcn.h>
5050

5151
#define UNW_LOCAL_ONLY
52+
// Sub-headers included from the libunwind.h contain an empty struct
53+
// and clang issues a warning. Until the libunwind is fixed, disable
54+
// the warning.
55+
#pragma clang diagnostic push
56+
#pragma clang diagnostic ignored "-Wextern-c-compat"
5257
#include <libunwind.h>
58+
#pragma clang diagnostic pop
5359

5460
SET_DEFAULT_DEBUG_CHANNEL(EXCEPT);
5561

src/pal/src/exception/seh-unwind.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,13 @@ Module Name:
2828
#include <dlfcn.h>
2929

3030
#define UNW_LOCAL_ONLY
31+
// Sub-headers included from the libunwind.h contain an empty struct
32+
// and clang issues a warning. Until the libunwind is fixed, disable
33+
// the warning.
34+
#pragma clang diagnostic push
35+
#pragma clang diagnostic ignored "-Wextern-c-compat"
3136
#include <libunwind.h>
37+
#pragma clang diagnostic pop
3238

3339
//----------------------------------------------------------------------
3440
// Virtual Unwinding

src/pal/src/libunwind/CMakeLists.txt

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include)
2-
include_directories(${CMAKE_CURRENT_BINARY_DIR}/include/tdep)
3-
include_directories(include)
4-
include_directories(include/tdep)
5-
61
add_subdirectory(src)
72

83
# define variables for the configure_file below

0 commit comments

Comments
 (0)