Skip to content

Commit

Permalink
Build omnitrace-rt library (ROCm#355)
Browse files Browse the repository at this point in the history
* Build omnitrace-rt library

- Explicitly build dyninstAPI_RT as omnitrace-rt so that the SONAME in the ELF is omnitrace-rt instead of dyninstAPI_RT
- Create symbolic link lib/omnitrace/libdyninstAPI_RT.so which points to lib/libomnitrace-rt.so
- Simplify build tree location of libomnitrace-rt.so since it is ../lib from the bin directory even in the build tree
- Update dyninst submodule with minor tweaks to dyninstAPI_RT/CMakeLists.txt

* Update source/lib/omnitrace-rt/cmake/platform.cmake

* Use ftpmirror.gnu.org instead of ftp.gnu.org

- in timemory and dyninst submodules
- minor .clang-tidy tweak
  • Loading branch information
jrmadsen authored and samjwu committed Jul 29, 2024
1 parent 5e3df5e commit c49051c
Show file tree
Hide file tree
Showing 57 changed files with 7,652 additions and 81 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ performance-*,\
readability-*,\
-readability-function-size,\
-readability-identifier-naming,\
-readability-identifier-length,\
-readability-implicit-bool-cast,\
-readability-inconsistent-declaration-parameter-name,\
-readability-named-parameter,\
Expand Down
41 changes: 1 addition & 40 deletions cmake/Packages.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,7 @@ if(OMNITRACE_BUILD_DYNINST)

set(DYNINST_OPTION_PREFIX ON)
set(DYNINST_BUILD_DOCS OFF)
set(DYNINST_BUILD_RTLIB OFF)
set(DYNINST_QUIET_CONFIG
ON
CACHE BOOL "Suppress dyninst cmake messages")
Expand Down Expand Up @@ -344,7 +345,6 @@ if(OMNITRACE_BUILD_DYNINST)
dynDwarf
dynElf
dyninstAPI
dyninstAPI_RT
instructionAPI
parseAPI
patchAPI
Expand All @@ -360,9 +360,6 @@ if(OMNITRACE_BUILD_DYNINST)
endif()
endforeach()

omnitrace_install_tpl(dyninstAPI_RT omnitrace-rt
"${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}" core)

# for packaging
install(
DIRECTORY ${DYNINST_TPL_STAGING_PREFIX}/lib/
Expand All @@ -373,35 +370,11 @@ if(OMNITRACE_BUILD_DYNINST)

target_link_libraries(omnitrace-dyninst INTERFACE Dyninst::Dyninst)

set(OMNITRACE_DYNINST_API_RT
${PROJECT_BINARY_DIR}/external/dyninst/dyninstAPI_RT/libdyninstAPI_RT${CMAKE_SHARED_LIBRARY_SUFFIX}
)

if(OMNITRACE_DYNINST_API_RT)
omnitrace_target_compile_definitions(
omnitrace-dyninst
INTERFACE
DYNINST_API_RT="${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}:$<TARGET_FILE_DIR:Dyninst::dyninstAPI_RT>:${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}/$<TARGET_FILE_NAME:Dyninst::dyninstAPI_RT>:$<TARGET_FILE:Dyninst::dyninstAPI_RT>"
)
endif()

else()
find_package(Dyninst ${omnitrace_FIND_QUIETLY} REQUIRED
COMPONENTS dyninstAPI parseAPI instructionAPI symtabAPI)

if(TARGET Dyninst::Dyninst) # updated Dyninst CMake system was found
# useful for defining the location of the runtime API
find_library(
OMNITRACE_DYNINST_API_RT dyninstAPI_RT
HINTS ${Dyninst_ROOT_DIR} ${Dyninst_DIR}
PATHS ${Dyninst_ROOT_DIR} ${Dyninst_DIR}
PATH_SUFFIXES lib NO_CACHE)

if(OMNITRACE_DYNINST_API_RT)
omnitrace_target_compile_definitions(
omnitrace-dyninst INTERFACE DYNINST_API_RT="${OMNITRACE_DYNINST_API_RT}")
endif()

target_link_libraries(omnitrace-dyninst INTERFACE Dyninst::Dyninst)
else() # updated Dyninst CMake system was not found
set(_BOOST_COMPONENTS atomic system thread date_time)
Expand All @@ -424,13 +397,6 @@ else()
PATH_SUFFIXES include)
endif()

# useful for defining the location of the runtime API
find_library(
OMNITRACE_DYNINST_API_RT dyninstAPI_RT
HINTS ${Dyninst_ROOT_DIR} ${Dyninst_DIR}
PATHS ${Dyninst_ROOT_DIR} ${Dyninst_DIR}
PATH_SUFFIXES lib)

# try to find TBB
find_package(TBB QUIET)

Expand All @@ -447,11 +413,6 @@ else()
PATH_SUFFIXES include)
endif()

if(OMNITRACE_DYNINST_API_RT)
omnitrace_target_compile_definitions(
omnitrace-dyninst INTERFACE DYNINST_API_RT="${OMNITRACE_DYNINST_API_RT}")
endif()

target_link_libraries(omnitrace-dyninst INTERFACE ${DYNINST_LIBRARIES}
${Boost_LIBRARIES})
foreach(
Expand Down
2 changes: 1 addition & 1 deletion external/dyninst
2 changes: 1 addition & 1 deletion external/timemory
2 changes: 2 additions & 0 deletions source/bin/omnitrace-instrument/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ if(OMNITRACE_BUILD_DYNINST)
target_compile_definitions(omnitrace-instrument PRIVATE OMNITRACE_BUILD_DYNINST=1)
endif()

add_target_flag_if_avail(omnitrace-instrument "-Wno-deprecated-declarations")

omnitrace_strip_target(omnitrace-instrument)

if(CMAKE_BUILD_TYPE MATCHES "^(DEBUG|Debug)")
Expand Down
29 changes: 19 additions & 10 deletions source/bin/omnitrace-instrument/omnitrace-instrument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@

#include "omnitrace-instrument.hpp"
#include "common/defines.h"
#include "common/join.hpp"
#include "dl/dl.hpp"
#include "fwd.hpp"
#include "internal_libs.hpp"
Expand Down Expand Up @@ -187,18 +188,26 @@ strset_t print_formats = { "txt", "json
std::string modfunc_dump_dir = {};
auto regex_opts = std::regex_constants::egrep | std::regex_constants::optimize;

strvec_t lib_search_paths =
tim::delimit(JOIN(':', tim::get_env<std::string>("DYNINSTAPI_RT_LIB"),
tim::get_env<std::string>("DYNINST_REWRITER_PATHS"),
tim::get_env<std::string>("LD_LIBRARY_PATH")),
":");
std::string
get_internal_libpath()
{
auto _exe = std::string_view{ ::realpath("/proc/self/exe", nullptr) };
auto _pos = _exe.find_last_of('/');
auto _dir = std::string{ "./" };
if(_pos != std::string_view::npos) _dir = _exe.substr(0, _pos);
return omnitrace::common::join("/", _dir, "..", "lib");
}

strvec_t lib_search_paths = tim::delimit(
JOIN(':', get_internal_libpath(), tim::get_env<std::string>("DYNINSTAPI_RT_LIB"),
tim::get_env<std::string>("DYNINST_REWRITER_PATHS"),
tim::get_env<std::string>("LD_LIBRARY_PATH")),
":");
strvec_t bin_search_paths = tim::delimit(tim::get_env<std::string>("PATH"), ":");

#if defined(DYNINST_API_RT)
auto _dyn_api_rt_paths = tim::delimit(DYNINST_API_RT, ":");
#else
auto _dyn_api_rt_paths = std::vector<std::string>{};
#endif
auto _dyn_api_rt_paths = tim::delimit(
JOIN(":", get_internal_libpath(), JOIN("/", get_internal_libpath(), "omnitrace")),
":");

std::string
get_absolute_filepath(std::string _name, const strvec_t& _paths);
Expand Down
12 changes: 1 addition & 11 deletions source/bin/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,14 @@ function(OMNITRACE_ADD_BIN_TEST)
if(NOT TEST_WORKING_DIRECTORY)
set(TEST_WORKING_DIRECTORY ${PROJECT_BINARY_DIR})
endif()
if(NOT OMNITRACE_DYNINST_API_RT_DIR AND OMNITRACE_DYNINST_API_RT)
get_filename_component(OMNITRACE_DYNINST_API_RT_DIR "${OMNITRACE_DYNINST_API_RT}"
DIRECTORY)
endif()

if(OMNITRACE_BUILD_DYNINST)
set(OMNITRACE_DYNINST_API_RT_DIR
"${PROJECT_BINARY_DIR}/external/dyninst/dyninstAPI_RT:${PROJECT_BINARY_DIR}/external/dyninst/dyninstAPI"
)
endif()

if(NOT TEST_ENVIRONMENT)
set(TEST_ENVIRONMENT
"OMNITRACE_TRACE=ON"
"OMNITRACE_PROFILE=ON"
"OMNITRACE_USE_SAMPLING=ON"
"OMNITRACE_TIME_OUTPUT=OFF"
"LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}:${OMNITRACE_DYNINST_API_RT_DIR}:$ENV{LD_LIBRARY_PATH}"
"LD_LIBRARY_PATH=${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}:$ENV{LD_LIBRARY_PATH}"
)
endif()

Expand Down
1 change: 1 addition & 0 deletions source/lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,5 @@ add_subdirectory(binary)

add_subdirectory(omnitrace)
add_subdirectory(omnitrace-dl)
add_subdirectory(omnitrace-rt)
add_subdirectory(omnitrace-user)
138 changes: 138 additions & 0 deletions source/lib/omnitrace-rt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
#
# C extensions are required
#
set(CMAKE_C_STANDARD 11)
set(CMAKE_C_EXTENSIONS ON)
set(CMAKE_C_STANDARD_REQUIRED ON)

# ------------------------------------------------------------------------------#
# target sources
# ------------------------------------------------------------------------------#

include(cmake/platform.cmake)

set(SRC_LIST src/RTcommon.c src/RTmemEmulator.c)

if(PLATFORM MATCHES freebsd)
list(
APPEND
SRC_LIST
src/RTposix.c
src/RTfreebsd.c
src/RTheap.c
src/RTheap-freebsd.c
src/RTthread.c
src/RTspace.S
src/RTsignal.c)
elseif(PLATFORM MATCHES linux)
list(
APPEND
SRC_LIST
src/RTposix.c
src/RTlinux.c
src/RTheap.c
src/RTheap-linux.c
src/RTthread.c
src/RTspace.S
src/RTsignal.c)
list(APPEND RT_STATIC_ONLY_SRC_LIST src/RTstatic_ctors_dtors_begin.c
src/RTstatic_ctors_dtors_end.c)
elseif(PLATFORM MATCHES nt OR PLATFORM MATCHES windows)
list(APPEND SRC_LIST src/RTheap.c src/RTheap-win.c src/RTwinnt.c src/RTthread.c
src/RTthread-x86.c)
endif()

set(SRC_LIST_i386 src/RTthread-x86.c src/RTtlsgetaddr-x86.S)
set(RT_STATIC_ONLY_SRC_LIST_i386 src/RTstatic_ctors_dtors-x86.c)
set(SRC_LIST_x86_64 src/RTthread-x86-64.c src/RTtlsgetaddr-x86.S)
set(RT_STATIC_ONLY_SRC_LIST_x86_64 src/RTstatic_ctors_dtors-x86.c)
set(SRC_LIST_ppc32 src/RTthread-powerpc.c src/RTthread-powerpc-asm.S)
set(RT_STATIC_ONLY_SRC_LIST_ppc32 src/RTstatic_ctors_dtors-ppc32.c)
set(SRC_LIST_ppc64 src/RTthread-powerpc.c src/RTthread-powerpc-asm.S)
set(RT_STATIC_ONLY_SRC_LIST_ppc64 src/RTstatic_ctors_dtors-ppc64.c)
set(SRC_LIST_aarch64 src/RTthread-aarch64.c
# src/RTthread-aarch64-asm.S
)
set(RT_STATIC_ONLY_SRC_LIST_aarch64 src/RTstatic_ctors_dtors-aarch64.c)

# We use gcc to compile the various assembly files, but cmake doesn't default to knowing
# that gcc can handle .S.
enable_language(ASM)
file(GLOB SRC_ASSEMBLY "src/*.S")
if(NEED_NATIVE_ASSEMBER)
set_source_files_properties(${SRC_ASSEMBLY} PROPERTIES LANGUAGE ASM)
else()
set_source_files_properties(${SRC_ASSEMBLY} PROPERTIES LANGUAGE C)
endif()

# The arch-specific files other than RTthread-x86 are Unix-only.
if(UNIX)
if(PLATFORM MATCHES amd64 OR PLATFORM MATCHES x86_64)
set(SRC_LIST_mabi ${SRC_LIST} ${SRC_LIST_i386})
set(RT_STATIC_ONLY_SRC_LIST_mabi ${RT_STATIC_ONLY_SRC_LIST}
${RT_STATIC_ONLY_SRC_LIST_i386})
list(APPEND SRC_LIST ${SRC_LIST_x86_64})
list(APPEND RT_STATIC_ONLY_SRC_LIST ${RT_STATIC_ONLY_SRC_LIST_x86_64})
elseif(PLATFORM MATCHES ppc64)
set(SRC_LIST_mabi ${SRC_LIST} ${SRC_LIST_ppc32})
set(RT_STATIC_ONLY_SRC_LIST_mabi ${RT_STATIC_ONLY_SRC_LIST}
${RT_STATIC_ONLY_SRC_LIST_ppc32})
list(APPEND SRC_LIST ${SRC_LIST_ppc64})
list(APPEND RT_STATIC_ONLY_SRC_LIST ${RT_STATIC_ONLY_SRC_LIST_ppc64})
elseif(PLATFORM MATCHES i386)
list(APPEND SRC_LIST ${SRC_LIST_i386})
list(APPEND RT_STATIC_ONLY_SRC_LIST ${RT_STATIC_ONLY_SRC_LIST_i386})
elseif(PLATFORM MATCHES ppc32)
list(APPEND SRC_LIST ${SRC_LIST_ppc32})
list(APPEND RT_STATIC_ONLY_SRC_LIST ${RT_STATIC_ONLY_SRC_LIST_ppc32})
elseif(PLATFORM MATCHES aarch64)
list(APPEND SRC_LIST ${SRC_LIST_aarch64})
list(APPEND RT_STATIC_ONLY_SRC_LIST ${RT_STATIC_ONLY_SRC_LIST_aarch64})
endif()
endif()

add_library(omnitrace-rt-library SHARED)
add_library(omnitrace::omnitrace-rt-library ALIAS omnitrace-rt-library)

target_sources(omnitrace-rt-library PRIVATE ${SRC_LIST})
target_include_directories(
omnitrace-rt-library PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/h>)
target_compile_definitions(omnitrace-rt-library PRIVATE ${UNIFIED_DEFINES})
target_link_libraries(
omnitrace-rt-library
PUBLIC $<BUILD_INTERFACE:${dl_LIBRARY}>
PRIVATE omnitrace::omnitrace-threading)

add_target_cxx_flag_if_avail(omnitrace-rt-library "-g3")

set_target_properties(
omnitrace-rt-library
PROPERTIES OUTPUT_NAME omnitrace-rt
VERSION ${PROJECT_VERSION}
SOVERSION ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}
BUILD_RPATH "\$ORIGIN"
INSTALL_RPATH "\$ORIGIN")

omnitrace_strip_target(omnitrace-rt-library)

install(TARGETS omnitrace-rt-library DESTINATION ${CMAKE_INSTALL_LIBDIR})

if(NOT EXISTS ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
file(MAKE_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
endif()

add_custom_target(
omnitrace-rt-library-dyninstAPI_RT-symlink ALL
${CMAKE_COMMAND} -E create_symlink ../$<TARGET_FILE_NAME:omnitrace-rt-library>
${CMAKE_SHARED_LIBRARY_PREFIX}dyninstAPI_RT${CMAKE_SHARED_LIBRARY_SUFFIX}
WORKING_DIRECTORY ${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}
DEPENDS omnitrace-rt-library
COMMENT
"Creating ${CMAKE_SHARED_LIBRARY_PREFIX}dyninstAPI_RT${CMAKE_SHARED_LIBRARY_SUFFIX} to omnitrace-rt..."
)

install(
FILES
${PROJECT_BINARY_DIR}/${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME}/${CMAKE_SHARED_LIBRARY_PREFIX}dyninstAPI_RT${CMAKE_SHARED_LIBRARY_SUFFIX}
DESTINATION ${CMAKE_INSTALL_LIBDIR}/${PROJECT_NAME})
Loading

0 comments on commit c49051c

Please sign in to comment.