From e97c22d1ed6fc1905a1f44dfce415729634cf16a Mon Sep 17 00:00:00 2001 From: pbalcer Date: Tue, 18 Jul 2023 14:14:31 +0200 Subject: [PATCH] [adapters] only export get proc table symbols in adapters This adds a version script to restrict visiblity of symbols in adapters. This is so that adapters don't use loader ur functions when populating proc tables... --- source/adapters/CMakeLists.txt | 24 ++++++++++++++++++++++- source/adapters/adapter.def.in | 20 +++++++++++++++++++ source/adapters/adapter.map.in | 23 ++++++++++++++++++++++ source/adapters/cuda/CMakeLists.txt | 2 +- source/adapters/hip/CMakeLists.txt | 4 ++-- source/adapters/level_zero/CMakeLists.txt | 8 +------- source/adapters/null/CMakeLists.txt | 7 +------ 7 files changed, 71 insertions(+), 17 deletions(-) create mode 100644 source/adapters/adapter.def.in create mode 100644 source/adapters/adapter.map.in diff --git a/source/adapters/CMakeLists.txt b/source/adapters/CMakeLists.txt index aa09004667..8a885923c0 100644 --- a/source/adapters/CMakeLists.txt +++ b/source/adapters/CMakeLists.txt @@ -3,8 +3,30 @@ # See LICENSE.TXT # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -add_subdirectory(null) +function(add_ur_adapter name) + add_library(${name} ${ARGN}) + if(MSVC) + set(TARGET_LIBNAME ${name}) + string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME) + + set(ADAPTER_VERSION_SCRIPT ${name}.def) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../adapter.def.in ${ADAPTER_VERSION_SCRIPT} @ONLY) + set_target_properties(${name} PROPERTIES + LINK_FLAGS "/DEF:${ADAPTER_VERSION_SCRIPT}" + ) + else() + set(TARGET_LIBNAME lib${name}_${PROJECT_VERSION_MAJOR}.0) + string(TOUPPER ${TARGET_LIBNAME} TARGET_LIBNAME) + set(ADAPTER_VERSION_SCRIPT ${name}.map) + + configure_file(${CMAKE_CURRENT_SOURCE_DIR}/../adapter.map.in ${ADAPTER_VERSION_SCRIPT} @ONLY) + target_link_options(${name} PRIVATE "-Wl,--version-script=${ADAPTER_VERSION_SCRIPT}") + endif() +endfunction() + +add_subdirectory(null) if(UR_BUILD_ADAPTER_L0 OR UR_BUILD_ADAPTER_CUDA OR UR_BUILD_ADAPTER_HIP) # fetch adapter sources from SYCL diff --git a/source/adapters/adapter.def.in b/source/adapters/adapter.def.in new file mode 100644 index 0000000000..bfe14a6a03 --- /dev/null +++ b/source/adapters/adapter.def.in @@ -0,0 +1,20 @@ +LIBRARY @TARGET_LIBNAME@ +EXPORTS + urGetBindlessImagesExpProcAddrTable + urGetCommandBufferExpProcAddrTable + urGetContextProcAddrTable + urGetDeviceProcAddrTable + urGetEnqueueProcAddrTable + urGetEventProcAddrTable + urGetGlobalProcAddrTable + urGetKernelProcAddrTable + urGetMemProcAddrTable + urGetPhysicalMemProcAddrTable + urGetPlatformProcAddrTable + urGetProgramProcAddrTable + urGetQueueProcAddrTable + urGetSamplerProcAddrTable + urGetUSMExpProcAddrTable + urGetUsmP2PExpProcAddrTable + urGetUSMProcAddrTable + urGetVirtualMemProcAddrTable diff --git a/source/adapters/adapter.map.in b/source/adapters/adapter.map.in new file mode 100644 index 0000000000..cbb5c6c4cb --- /dev/null +++ b/source/adapters/adapter.map.in @@ -0,0 +1,23 @@ +@TARGET_LIBNAME@ { + global: + urGetBindlessImagesExpProcAddrTable; + urGetCommandBufferExpProcAddrTable; + urGetContextProcAddrTable; + urGetDeviceProcAddrTable; + urGetEnqueueProcAddrTable; + urGetEventProcAddrTable; + urGetGlobalProcAddrTable; + urGetKernelProcAddrTable; + urGetMemProcAddrTable; + urGetPhysicalMemProcAddrTable; + urGetPlatformProcAddrTable; + urGetProgramProcAddrTable; + urGetQueueProcAddrTable; + urGetSamplerProcAddrTable; + urGetUSMExpProcAddrTable; + urGetUsmP2PExpProcAddrTable; + urGetUSMProcAddrTable; + urGetVirtualMemProcAddrTable; + local: + *; +}; diff --git a/source/adapters/cuda/CMakeLists.txt b/source/adapters/cuda/CMakeLists.txt index d0bc3fd6b2..29bdc87152 100644 --- a/source/adapters/cuda/CMakeLists.txt +++ b/source/adapters/cuda/CMakeLists.txt @@ -7,7 +7,7 @@ set(CUDA_DIR "${SYCL_ADAPTER_DIR}/sycl/plugins/unified_runtime/ur/adapters/cuda" set(TARGET_NAME ur_adapter_cuda) -add_library(${TARGET_NAME} +add_ur_adapter(${TARGET_NAME} SHARED ${CUDA_DIR}/ur_interface_loader.cpp ${CUDA_DIR}/common.hpp diff --git a/source/adapters/hip/CMakeLists.txt b/source/adapters/hip/CMakeLists.txt index 7db8bbf3fc..a014725268 100644 --- a/source/adapters/hip/CMakeLists.txt +++ b/source/adapters/hip/CMakeLists.txt @@ -42,7 +42,7 @@ endif() # Set includes used in added library (rocmdrv) set(HIP_HEADERS "${UR_HIP_INCLUDE_DIR};${UR_HIP_HSA_INCLUDE_DIR}") -add_library(${TARGET_NAME} +add_ur_adapter(${TARGET_NAME} SHARED ${HIP_DIR}/ur_interface_loader.cpp ${HIP_DIR}/common.hpp @@ -75,7 +75,7 @@ add_library(${TARGET_NAME} ${HIP_DIR}/../../usm_allocator_config.hpp ) -if (NOT MSVC) +if(NOT MSVC) target_compile_options(${TARGET_NAME} PRIVATE -Wno-deprecated-declarations ) diff --git a/source/adapters/level_zero/CMakeLists.txt b/source/adapters/level_zero/CMakeLists.txt index 52d22c3ea6..fa089c4b9a 100644 --- a/source/adapters/level_zero/CMakeLists.txt +++ b/source/adapters/level_zero/CMakeLists.txt @@ -71,7 +71,7 @@ target_include_directories(LevelZeroLoader-Headers INTERFACE "${LEVEL_ZERO_INCLUDE_DIR}" ) -add_library(${TARGET_NAME} +add_ur_adapter(${TARGET_NAME} SHARED ${L0_DIR}/ur_interface_loader.cpp ${L0_DIR}/common.hpp @@ -120,9 +120,3 @@ target_include_directories(${TARGET_NAME} PRIVATE ${L0_DIR}/../../../ LevelZeroLoader-Headers ) - -if(UNIX) - set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden -fno-strict-aliasing") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") -endif() - diff --git a/source/adapters/null/CMakeLists.txt b/source/adapters/null/CMakeLists.txt index 56b8815929..0d4aa13e01 100644 --- a/source/adapters/null/CMakeLists.txt +++ b/source/adapters/null/CMakeLists.txt @@ -5,7 +5,7 @@ set(TARGET_NAME ur_adapter_null) -add_library(${TARGET_NAME} +add_ur_adapter(${TARGET_NAME} SHARED ${CMAKE_CURRENT_SOURCE_DIR}/ur_null.hpp ${CMAKE_CURRENT_SOURCE_DIR}/ur_null.cpp @@ -21,8 +21,3 @@ target_link_libraries(${TARGET_NAME} PRIVATE ${PROJECT_NAME}::headers ${PROJECT_NAME}::common ) - -if(UNIX) - set(GCC_COVERAGE_COMPILE_FLAGS "-fvisibility=hidden -fvisibility-inlines-hidden -fno-strict-aliasing") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${GCC_COVERAGE_COMPILE_FLAGS}") -endif()