Skip to content

Commit

Permalink
Make debuginfod configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
cvonelm committed Nov 7, 2024
1 parent eda8d33 commit 66f9ff8
Show file tree
Hide file tree
Showing 2 changed files with 72 additions and 9 deletions.
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ IfUpdatedUnsetAll(lo2s_USE_STATIC_LIBS
X86Adapt_STATIC
x86_energy_STATIC
CUDA_USE_STATIC_LIBS
Debuginfod_USE_STATIC_LIBS
)

if(lo2s_USE_STATIC_LIBS STREQUAL "OFF")
Expand All @@ -47,6 +48,7 @@ if(lo2s_USE_STATIC_LIBS STREQUAL "OFF")
set(Sensors_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS OFF CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS OFF CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS OFF CACHE BOOL "")
endif()

if(lo2s_USE_STATIC_LIBS STREQUAL "MOSTLY")
Expand All @@ -59,6 +61,7 @@ if(lo2s_USE_STATIC_LIBS STREQUAL "MOSTLY")
set(Sensors_USE_STATIC_LIBS ON CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS ON CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS ON CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS ON CACHE BOOL "")
set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -static-libstdc++ -static-libgcc")
endif()

Expand All @@ -72,6 +75,7 @@ if(lo2s_USE_STATIC_LIBS STREQUAL "ALL")
set(Sensors_USE_STATIC_LIBS ON CACHE BOOL "")
set(Libpfm_USE_STATIC_LIBS ON CACHE BOOL "")
set(CUDA_USE_STATIC_LIBS ON CACHE BOOL "")
set(Debuginfod_USE_STATIC_LIBS ON CACHE BOOL "")

# Doesn't seem to work with clang, even though it should,
# but at least it doesn't complain about it either
Expand Down Expand Up @@ -112,6 +116,7 @@ find_package(Libpfm)
find_package(PkgConfig)
find_package(CUDAToolkit)
find_package(LibElf REQUIRED)
find_package(Debuginfod)

if(PkgConfig_FOUND)
pkg_check_modules(Audit audit)
Expand All @@ -136,6 +141,8 @@ CMAKE_DEPENDENT_OPTION(USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsu
add_feature_info("USE_VEOSINFO" USE_VEOSINFO "Use libveosinfo to sample NEC SX-Aurora Tsubasa cards.")
CMAKE_DEPENDENT_OPTION(USE_CUPTI "Use CUPTI to record CUDA activity." ON "CUDAToolkit_FOUND" OFF)
add_feature_info("USE_CUPTI" USE_CUPTI "Use CUPTI to record CUDA activity.")
CMAKE_DEPENDENT_OPTION(USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand." ON "Debuginfod_FOUND" OFF)
add_feature_info("USE_DEBUGINFOD" USE_DEBUGINFOD "Use Debuginfod to download debug information on-demand.")
# system configuration checks
CHECK_INCLUDE_FILES(linux/hw_breakpoint.h HAVE_HW_BREAKPOINT_H)
CHECK_STRUCT_HAS_MEMBER("struct perf_event_attr" clockid linux/perf_event.h HAVE_PERF_EVENT_ATTR_CLOCKID)
Expand Down Expand Up @@ -231,17 +238,8 @@ target_link_libraries(lo2s
std::filesystem
LibElf::LibElf
LibElf::LibDw
debuginfod
)

find_path(DEBUGINFOD_INCLUDE_DIRS elfutils/debuginfod.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(DEBUGINFOD_INCLUDE_DIRS)
target_compile_definitions(lo2s PUBLIC HAVE_DEBUGINFOD)
endif()

# old glibc versions require -lrt for clock_gettime()
if(NOT CLOCK_GETTIME_FOUND)
if(CLOCK_GETTIME_FOUND_WITH_RT)
Expand Down Expand Up @@ -321,6 +319,15 @@ if (USE_VEOSINFO)
endif()
endif()

if (USE_DEBUGINFOD)
if (Debuginfod_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_DEBUGINFOD)
target_link_libraries(lo2s PRIVATE Debuginfod::Debuginfod)
else()
message(SEND_ERROR "Debuginfod not found but requested")
endif()
endif()

if (USE_LIBPFM)
if (Libpfm_FOUND)
target_compile_definitions(lo2s PUBLIC HAVE_LIBPFM)
Expand Down
56 changes: 56 additions & 0 deletions cmake/FindDebuginfod.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Copyright (c) 2022, Technische Universität Dresden, Germany
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification, are permitted
# provided that the following conditions are met:
#
# 1. Redistributions of source code must retain the above copyright notice, this list of conditions
# and the following disclaimer.
#
# 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions
# and the following disclaimer in the documentation and/or other materials provided with the
# distribution.
#
# 3. Neither the name of the copyright holder nor the names of its contributors may be used to endorse
# or promote products derived from this software without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
# FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR
# CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
# IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
# THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

include(${CMAKE_CURRENT_LIST_DIR}/UnsetIfUpdated.cmake)

# Linking libelf isn't a great default because it produces warnings
option(Debuginfod_USE_STATIC_LIBS "Link debuginfod statically." OFF)

UnsetIfUpdated(Debuginfod_LIBRARY Debuginfod_USE_STATIC_LIBS)

find_path(Debuginfod_INCLUDE_DIRS libelf.h
PATHS ENV C_INCLUDE_PATH ENV CPATH
PATH_SUFFIXES include)

if(Debuginfod_USE_STATIC_LIBS)
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.a
HINTS ENV LIBRARY_PATH)
else()
find_library(Debuginfod_LIBRARY NAMES libdebuginfod.so
HINTS ENV LIBRARY_PATH LD_LIBRARY_PATH)
endif()

include (FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(Debuginfod DEFAULT_MSG
Debuginfod_LIBRARY
Debuginfod_INCLUDE_DIRS)

if(Debuginfod_FOUND)
add_library(Debuginfod::Debuginfod UNKNOWN IMPORTED)
set_property(TARGET Debuginfod::Debuginfod PROPERTY IMPORTED_LOCATION ${Debuginfod_LIBRARY})
target_include_directories(Debuginfod::Debuginfod INTERFACE ${Debuginfod_INCLUDE_DIRS})
endif()

mark_as_advanced(Debuginfod_LIBRARY Debuginfod_INCLUDE_DIRS)

0 comments on commit 66f9ff8

Please sign in to comment.