From cbdefcda3438afd6cff61e2cbae84c0cda508b20 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Fri, 16 Jun 2023 06:17:32 -0500 Subject: [PATCH 1/4] Add support for libunwind in CMake build This adds an option that defaults to ON: ENABLE_UNWIND. On Linux, CMake will look for the library and link it globally if it is found. On other OSs, CMake will skip the check, because libunwind is only available on Linux. --- CMakeLists.txt | 7 ++++ cmake/Findunwind.cmake | 49 ++++++++++++++++++++++++++++ include/tscore/ink_config.h.cmake.in | 1 + 3 files changed, 57 insertions(+) create mode 100644 cmake/Findunwind.cmake diff --git a/CMakeLists.txt b/CMakeLists.txt index 1dafffdbe15..5648f84067d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,7 @@ option(ENABLE_POSIX_CAP ) option(ENABLE_PROFILER "Use gperftools profiler (default OFF)") option(ENABLE_TCMALLOC "Use TCMalloc (default OFF)") +option(ENABLE_UNWIND "Use libunwind; Linux only (default ON)" ON) set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)") set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)") set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)") @@ -150,6 +151,12 @@ if(TSMallocReplacement_FOUND) link_libraries(ts::TSMallocReplacement) endif() +if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND ENABLE_UNWIND) + find_package(unwind REQUIRED) + link_libraries(unwind::unwind) + set(TS_USE_REMOTE_UNWINDING TRUE) +endif() + find_package(ZLIB REQUIRED) include(Check128BitCas) diff --git a/cmake/Findunwind.cmake b/cmake/Findunwind.cmake new file mode 100644 index 00000000000..42d356a01bf --- /dev/null +++ b/cmake/Findunwind.cmake @@ -0,0 +1,49 @@ +####################### +# +# Licensed to the Apache Software Foundation (ASF) under one or more contributor license +# agreements. See the NOTICE file distributed with this work for additional information regarding +# copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 +# (the "License"); you may not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software distributed under the License +# is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express +# or implied. See the License for the specific language governing permissions and limitations under +# the License. +# +####################### + +# Findunwind.cmake +# +# This will define the following variables +# +# unwind_FOUND +# unwind_LIBRARY +# unwind_INCLUDE_DIRS +# +# and the following imported targets +# +# unwind::unwind +# + +find_library(unwind_LIBRARY NAMES unwind) +find_path(unwind_INCLUDE_DIR NAMES unwind.h) + +mark_as_advanced(unwind_FOUND unwind_LIBRARY unwind_INCLUDE_DIR) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(unwind + REQUIRED_VARS unwind_LIBRARY unwind_INCLUDE_DIR +) + +if(unwind_FOUND) + set(unwind_INCLUDE_DIRS ${unwind_INCLUDE_DIR}) +endif() + +if(unwind_FOUND AND NOT TARGET unwind::unwind) + add_library(unwind::unwind INTERFACE IMPORTED) + target_include_directories(unwind::unwind INTERFACE ${unwind_INCLUDE_DIRS}) + target_link_libraries(unwind::unwind INTERFACE "${unwind_LIBRARY}") +endif() diff --git a/include/tscore/ink_config.h.cmake.in b/include/tscore/ink_config.h.cmake.in index cc0446822d1..ffb2eb49de6 100644 --- a/include/tscore/ink_config.h.cmake.in +++ b/include/tscore/ink_config.h.cmake.in @@ -125,6 +125,7 @@ const int DEFAULT_STACKSIZE = @DEFAULT_STACK_SIZE@; #cmakedefine01 TS_USE_LINUX_IO_URING #cmakedefine01 TS_USE_LINUX_NATIVE_AIO #cmakedefine01 TS_USE_POSIX_CAP +#cmakedefine01 TS_USE_REMOTE_UNWINDING #cmakedefine01 TS_USE_SET_RBIO #cmakedefine01 TS_USE_TLS13 From 4bce0f122556b28ae7af486e03a53dca07f67213 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Fri, 16 Jun 2023 11:25:25 -0500 Subject: [PATCH 2/4] Move find_package(unwind) to Linux build section This consolidates the Linux-specific settings. --- CMakeLists.txt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 5648f84067d..bf4d8c73948 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -151,12 +151,6 @@ if(TSMallocReplacement_FOUND) link_libraries(ts::TSMallocReplacement) endif() -if(CMAKE_SYSTEM_NAME STREQUAL "Linux" AND ENABLE_UNWIND) - find_package(unwind REQUIRED) - link_libraries(unwind::unwind) - set(TS_USE_REMOTE_UNWINDING TRUE) -endif() - find_package(ZLIB REQUIRED) include(Check128BitCas) @@ -218,6 +212,12 @@ include(CTest) message("Configuring for ${HOST_OS}") if(HOST_OS STREQUAL "linux") + if(ENABLE_UNWIND) + find_package(unwind REQUIRED) + link_libraries(unwind::unwind) + set(TS_USE_REMOTE_UNWINDING TRUE) + endif() + set(CMAKE_THREAD_LIBS_INIT "-lpthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") set(CMAKE_HAVE_THREADS_LIBRARY 1) From acf023fe0840592510c58c1b4e57ec0f4d521d86 Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Fri, 16 Jun 2023 12:13:18 -0500 Subject: [PATCH 3/4] Do not REQUIRE libunwind --- CMakeLists.txt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bf4d8c73948..42b2d1cd4d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ option(ENABLE_POSIX_CAP ) option(ENABLE_PROFILER "Use gperftools profiler (default OFF)") option(ENABLE_TCMALLOC "Use TCMalloc (default OFF)") -option(ENABLE_UNWIND "Use libunwind; Linux only (default ON)" ON) +option(ENABLE_UNWIND "Use libunwind if available; Linux only (default ON)" ON) set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)") set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)") set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)") @@ -213,9 +213,11 @@ message("Configuring for ${HOST_OS}") if(HOST_OS STREQUAL "linux") if(ENABLE_UNWIND) - find_package(unwind REQUIRED) - link_libraries(unwind::unwind) - set(TS_USE_REMOTE_UNWINDING TRUE) + find_package(unwind) + if(unwind_FOUND) + link_libraries(unwind::unwind) + endif() + set(TS_USE_REMOTE_UNWINDING ${unwind_FOUND}) endif() set(CMAKE_THREAD_LIBS_INIT "-lpthread") From a9166539c31625896081f65b16afaaa3fd036d7e Mon Sep 17 00:00:00 2001 From: Josiah VanderZee Date: Fri, 16 Jun 2023 12:21:18 -0500 Subject: [PATCH 4/4] Move find_package(unwind) back with other packages libunwind is also available on Mac, and since we don't fail if it's not found, there's no reason to look for it only on some operating systems. --- CMakeLists.txt | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 42b2d1cd4d2..7676058a243 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,7 +47,7 @@ option(ENABLE_POSIX_CAP ) option(ENABLE_PROFILER "Use gperftools profiler (default OFF)") option(ENABLE_TCMALLOC "Use TCMalloc (default OFF)") -option(ENABLE_UNWIND "Use libunwind if available; Linux only (default ON)" ON) +option(ENABLE_UNWIND "Use libunwind if found on system (default ON)" ON) set(TS_MAX_HOST_NAME_LEN 256 CACHE STRING "Max host name length (default 256)") set(TS_USE_SET_RBIO 1 CACHE STRING "Use openssl set_rbio (default 1)") set(TS_USE_DIAGS 1 CACHE STRING "Use diags (default 1)") @@ -151,6 +151,14 @@ if(TSMallocReplacement_FOUND) link_libraries(ts::TSMallocReplacement) endif() +if(ENABLE_UNWIND) + find_package(unwind) + if(unwind_FOUND) + link_libraries(unwind::unwind) + endif() + set(TS_USE_REMOTE_UNWINDING ${unwind_FOUND}) +endif() + find_package(ZLIB REQUIRED) include(Check128BitCas) @@ -212,14 +220,6 @@ include(CTest) message("Configuring for ${HOST_OS}") if(HOST_OS STREQUAL "linux") - if(ENABLE_UNWIND) - find_package(unwind) - if(unwind_FOUND) - link_libraries(unwind::unwind) - endif() - set(TS_USE_REMOTE_UNWINDING ${unwind_FOUND}) - endif() - set(CMAKE_THREAD_LIBS_INIT "-lpthread") set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread") set(CMAKE_HAVE_THREADS_LIBRARY 1)