Use an interface target when building a static library.
Static linking disregards module initializers. This breaks clocks and the API table. The patch adds an interface target during static build that wraps the archive in --whole-archive to avoid incomplete initialization. Change-Id: Id32afbf969c1f3f16a191e5b2b66847669165fb7
Этот коммит содержится в:
@@ -43,8 +43,8 @@
|
|||||||
cmake_minimum_required ( VERSION 3.5.0 )
|
cmake_minimum_required ( VERSION 3.5.0 )
|
||||||
|
|
||||||
## Set core runtime module name and project name.
|
## Set core runtime module name and project name.
|
||||||
set ( CORE_RUNTIME_NAME "hsa-runtime" )
|
set ( CORE_RUNTIME_NAME "hsa-runtime64" )
|
||||||
set ( CORE_RUNTIME_TARGET "${CORE_RUNTIME_NAME}64" )
|
set ( CORE_RUNTIME_TARGET "${CORE_RUNTIME_NAME}" )
|
||||||
set ( CORE_RUNTIME_LIBRARY "lib${CORE_RUNTIME_TARGET}" )
|
set ( CORE_RUNTIME_LIBRARY "lib${CORE_RUNTIME_TARGET}" )
|
||||||
|
|
||||||
## Set project name
|
## Set project name
|
||||||
@@ -62,6 +62,12 @@ if ( NOT DEFINED BUILD_SHARED_LIBS )
|
|||||||
endif()
|
endif()
|
||||||
set ( BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Build shared library (.so) or not.")
|
set ( BUILD_SHARED_LIBS ${BUILD_SHARED_LIBS} CACHE BOOL "Build shared library (.so) or not.")
|
||||||
|
|
||||||
|
## Adjust target name for static builds
|
||||||
|
## Original name will be an interface target that adds --whole-archive linker options around the target.
|
||||||
|
if( NOT ${BUILD_SHARED_LIBS} )
|
||||||
|
set ( CORE_RUNTIME_TARGET "${CORE_RUNTIME_TARGET}_static" )
|
||||||
|
endif()
|
||||||
|
|
||||||
# Optionally, build HSA Runtime with ccache.
|
# Optionally, build HSA Runtime with ccache.
|
||||||
set(ROCM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
|
set(ROCM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build")
|
||||||
if (ROCM_CCACHE_BUILD)
|
if (ROCM_CCACHE_BUILD)
|
||||||
@@ -256,10 +262,17 @@ endif()
|
|||||||
## Set install information
|
## Set install information
|
||||||
# Installs binaries and exports the library usage data to ${HSAKMT_TARGET}Targets
|
# Installs binaries and exports the library usage data to ${HSAKMT_TARGET}Targets
|
||||||
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
||||||
install ( TARGETS ${CORE_RUNTIME_TARGET} EXPORT ${CORE_RUNTIME_TARGET}Targets
|
install ( TARGETS ${CORE_RUNTIME_TARGET} EXPORT ${CORE_RUNTIME_NAME}Targets
|
||||||
ARCHIVE DESTINATION lib COMPONENT binary
|
ARCHIVE DESTINATION lib COMPONENT binary
|
||||||
LIBRARY DESTINATION lib COMPONENT binary )
|
LIBRARY DESTINATION lib COMPONENT binary )
|
||||||
|
|
||||||
|
## Add the wrapper interface export target if doing a static build.
|
||||||
|
if( NOT ${BUILD_SHARED_LIBS} )
|
||||||
|
add_library(${CORE_RUNTIME_NAME} INTERFACE)
|
||||||
|
target_link_libraries(${CORE_RUNTIME_NAME} INTERFACE -Wl,--whole-archive ${CORE_RUNTIME_NAME}::${CORE_RUNTIME_TARGET} -Wl,--no-whole-archive)
|
||||||
|
install ( TARGETS ${CORE_RUNTIME_NAME} EXPORT ${CORE_RUNTIME_NAME}Targets )
|
||||||
|
endif()
|
||||||
|
|
||||||
# Install license
|
# Install license
|
||||||
#install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT binary )
|
#install ( FILES ${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT binary )
|
||||||
|
|
||||||
@@ -279,10 +292,10 @@ endif ()
|
|||||||
## Configure and install package config file
|
## Configure and install package config file
|
||||||
# Record our usage data for clients find_package calls.
|
# Record our usage data for clients find_package calls.
|
||||||
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
||||||
install ( EXPORT ${CORE_RUNTIME_TARGET}Targets
|
install ( EXPORT ${CORE_RUNTIME_NAME}Targets
|
||||||
FILE ${CORE_RUNTIME_TARGET}Targets.cmake
|
FILE ${CORE_RUNTIME_NAME}Targets.cmake
|
||||||
NAMESPACE ${CORE_RUNTIME_TARGET}::
|
NAMESPACE ${CORE_RUNTIME_NAME}::
|
||||||
DESTINATION lib/cmake/${CORE_RUNTIME_TARGET}
|
DESTINATION lib/cmake/${CORE_RUNTIME_NAME}
|
||||||
COMPONENT dev)
|
COMPONENT dev)
|
||||||
|
|
||||||
# Adds the target alias hsa-runtime64::hsa-runtime64 to the local cmake cache.
|
# Adds the target alias hsa-runtime64::hsa-runtime64 to the local cmake cache.
|
||||||
@@ -291,28 +304,30 @@ install ( EXPORT ${CORE_RUNTIME_TARGET}Targets
|
|||||||
# in some other project's cmake file. It allows uniform use of find_package
|
# in some other project's cmake file. It allows uniform use of find_package
|
||||||
# and target_link_library() without regard to whether a target is external or
|
# and target_link_library() without regard to whether a target is external or
|
||||||
# a subdirectory of the current build.
|
# a subdirectory of the current build.
|
||||||
add_library( ${CORE_RUNTIME_TARGET}::${CORE_RUNTIME_TARGET} ALIAS ${CORE_RUNTIME_TARGET} )
|
add_library( ${CORE_RUNTIME_NAME}::${CORE_RUNTIME_NAME} ALIAS ${CORE_RUNTIME_NAME} )
|
||||||
|
|
||||||
# Create cmake configuration files
|
# Create cmake configuration files
|
||||||
include(CMakePackageConfigHelpers)
|
include(CMakePackageConfigHelpers)
|
||||||
|
|
||||||
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
||||||
configure_package_config_file(${CORE_RUNTIME_TARGET}-config.cmake.in
|
configure_package_config_file(${CORE_RUNTIME_NAME}-config.cmake.in
|
||||||
${CORE_RUNTIME_TARGET}-config.cmake
|
${CORE_RUNTIME_NAME}-config.cmake
|
||||||
INSTALL_DESTINATION lib/cmake/${CORE_RUNTIME_TARGET} )
|
INSTALL_DESTINATION lib/cmake/${CORE_RUNTIME_NAME} )
|
||||||
|
|
||||||
write_basic_package_version_file(${CORE_RUNTIME_TARGET}-config-version.cmake
|
write_basic_package_version_file(${CORE_RUNTIME_NAME}-config-version.cmake
|
||||||
VERSION ${SO_VERSION_STRING} COMPATIBILITY AnyNewerVersion )
|
VERSION ${SO_VERSION_STRING} COMPATIBILITY AnyNewerVersion )
|
||||||
|
|
||||||
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
# TODO: Fix me for flat directory layout. Should be ${CMAKE_INSTALL_LIBDIR}
|
||||||
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_TARGET}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_TARGET}-config-version.cmake
|
install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_NAME}-config.cmake ${CMAKE_CURRENT_BINARY_DIR}/${CORE_RUNTIME_NAME}-config-version.cmake
|
||||||
DESTINATION lib/cmake/${CORE_RUNTIME_TARGET}
|
DESTINATION lib/cmake/${CORE_RUNTIME_NAME}
|
||||||
COMPONENT dev)
|
COMPONENT dev)
|
||||||
|
|
||||||
# Install the libelf find module
|
# Install the libelf find module if rocr is a static lib
|
||||||
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindLibElf.cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/COPYING-CMAKE-SCRIPTS
|
if( NOT ${BUILD_SHARED_LIBS} )
|
||||||
DESTINATION lib/cmake/${CORE_RUNTIME_TARGET}
|
install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/FindLibElf.cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules/COPYING-CMAKE-SCRIPTS
|
||||||
COMPONENT dev)
|
DESTINATION lib/cmake/${CORE_RUNTIME_NAME}
|
||||||
|
COMPONENT dev)
|
||||||
|
endif()
|
||||||
|
|
||||||
# Optionally record the package's find module in the user's package cache.
|
# Optionally record the package's find module in the user's package cache.
|
||||||
if ( NOT DEFINED EXPORT_TO_USER_PACKAGE_REGISTRY )
|
if ( NOT DEFINED EXPORT_TO_USER_PACKAGE_REGISTRY )
|
||||||
@@ -323,9 +338,9 @@ if(${EXPORT_TO_USER_PACKAGE_REGISTRY})
|
|||||||
# Enable writing to the registry
|
# Enable writing to the registry
|
||||||
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
|
set(CMAKE_EXPORT_PACKAGE_REGISTRY ON)
|
||||||
# Generate a target file for the build
|
# Generate a target file for the build
|
||||||
export(TARGETS ${CORE_RUNTIME_TARGET} NAMESPACE ${CORE_RUNTIME_TARGET}:: FILE ${CORE_RUNTIME_TARGET}Targets.cmake)
|
export(TARGETS ${CORE_RUNTIME_NAME} NAMESPACE ${CORE_RUNTIME_NAME}:: FILE ${CORE_RUNTIME_NAME}Targets.cmake)
|
||||||
# Record the package in the user's cache.
|
# Record the package in the user's cache.
|
||||||
export(PACKAGE ${CORE_RUNTIME_TARGET})
|
export(PACKAGE ${CORE_RUNTIME_NAME})
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
## Packaging directives
|
## Packaging directives
|
||||||
|
|||||||
@@ -44,7 +44,14 @@
|
|||||||
|
|
||||||
include( CMakeFindDependencyMacro )
|
include( CMakeFindDependencyMacro )
|
||||||
|
|
||||||
find_dependency(hsakmt 1.0)
|
# Client apps only need our private dependencies if rocr is a static lib.
|
||||||
find_dependency(elf::elf)
|
if( NOT @BUILD_SHARED_LIBS@ )
|
||||||
|
|
||||||
include( "${CMAKE_CURRENT_LIST_DIR}/@CORE_RUNTIME_TARGET@Targets.cmake" )
|
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_CURRENT_LIST_DIR}")
|
||||||
|
|
||||||
|
find_dependency(hsakmt 1.0)
|
||||||
|
find_dependency(LibElf)
|
||||||
|
|
||||||
|
endif()
|
||||||
|
|
||||||
|
include( "${CMAKE_CURRENT_LIST_DIR}/@CORE_RUNTIME_NAME@Targets.cmake" )
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user