diff --git a/openmp/libomptarget/plugins/CMakeLists.txt b/openmp/libomptarget/plugins/CMakeLists.txt --- a/openmp/libomptarget/plugins/CMakeLists.txt +++ b/openmp/libomptarget/plugins/CMakeLists.txt @@ -1,15 +1,17 @@ ##===----------------------------------------------------------------------===## -# +# # Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. # See https://llvm.org/LICENSE.txt for license information. # SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -# +# ##===----------------------------------------------------------------------===## # # Build plugins for the user system if available. # ##===----------------------------------------------------------------------===## +add_subdirectory(common) + # void build_generic_elf64(string tmachine, string tmachine_name, string tmachine_libname, string elf_machine_id); # - build a plugin for an ELF based generic 64-bit target based on libffi. # - tmachine: name of the machine processor as used in the cmake build system. @@ -19,41 +21,42 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "${tmachine}$") if(LIBOMPTARGET_DEP_LIBELF_FOUND) if(LIBOMPTARGET_DEP_LIBFFI_FOUND) - + libomptarget_say("Building ${tmachine_name} offloading plugin.") - + include_directories(${LIBOMPTARGET_DEP_LIBFFI_INCLUDE_DIR}) include_directories(${LIBOMPTARGET_DEP_LIBELF_INCLUDE_DIR}) - + # Define macro to be used as prefix of the runtime messages for this target. add_definitions("-DTARGET_NAME=${tmachine_name}") - + # Define macro with the ELF ID for this target. add_definitions("-DTARGET_ELF_ID=${elf_machine_id}") - - add_library("omptarget.rtl.${tmachine_libname}" SHARED + + add_library("omptarget.rtl.${tmachine_libname}" SHARED ${CMAKE_CURRENT_SOURCE_DIR}/../generic-elf-64bit/src/rtl.cpp) - + # Install plugin under the lib destination folder. - install(TARGETS "omptarget.rtl.${tmachine_libname}" + install(TARGETS "omptarget.rtl.${tmachine_libname}" LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") - + target_link_libraries( "omptarget.rtl.${tmachine_libname}" - ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES} + elf_common + ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES} ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES} dl "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports") - + list(APPEND LIBOMPTARGET_TESTED_PLUGINS "omptarget.rtl.${tmachine_libname}") # Report to the parent scope that we are building a plugin. - set(LIBOMPTARGET_SYSTEM_TARGETS + set(LIBOMPTARGET_SYSTEM_TARGETS "${LIBOMPTARGET_SYSTEM_TARGETS} ${tmachine_triple}" PARENT_SCOPE) set(LIBOMPTARGET_TESTED_PLUGINS "${LIBOMPTARGET_TESTED_PLUGINS}" PARENT_SCOPE) - + else(LIBOMPTARGET_DEP_LIBFFI_FOUND) libomptarget_say("Not building ${tmachine_name} offloading plugin: libffi dependency not found.") endif(LIBOMPTARGET_DEP_LIBFFI_FOUND) diff --git a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt --- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt +++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt @@ -73,6 +73,7 @@ target_link_libraries( omptarget.rtl.amdgpu PRIVATE + elf_common hsa-runtime64::hsa-runtime64 pthread dl elf "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports" diff --git a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp --- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp +++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp @@ -91,7 +91,7 @@ {} #endif -#include "../../common/elf_common.c" +#include "elf_common.h" /// Keep entries table per device struct FuncOrGblEntryTy { diff --git a/openmp/libomptarget/plugins/common/CMakeLists.txt b/openmp/libomptarget/plugins/common/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/plugins/common/CMakeLists.txt @@ -0,0 +1,13 @@ +##===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +##===----------------------------------------------------------------------===## +# +# Common parts which can be used by all plugins +# +##===----------------------------------------------------------------------===## + +add_subdirectory(elf_common) diff --git a/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt b/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt new file mode 100644 --- /dev/null +++ b/openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt @@ -0,0 +1,15 @@ +##===----------------------------------------------------------------------===## +# +# Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. +# See https://llvm.org/LICENSE.txt for license information. +# SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception +# +##===----------------------------------------------------------------------===## +# +# Common ELF functionality for target plugins +# +##===----------------------------------------------------------------------===## + +add_library(elf_common INTERFACE) + +target_include_directories(elf_common INTERFACE ${CMAKE_CURRENT_SOURCE_DIR}) diff --git a/openmp/libomptarget/plugins/common/elf_common.c b/openmp/libomptarget/plugins/common/elf_common/elf_common.h rename from openmp/libomptarget/plugins/common/elf_common.c rename to openmp/libomptarget/plugins/common/elf_common/elf_common.h --- a/openmp/libomptarget/plugins/common/elf_common.c +++ b/openmp/libomptarget/plugins/common/elf_common/elf_common.h @@ -1,4 +1,4 @@ -//===-- elf_common.c - Common ELF functionality -------------------*- C -*-===// +//===-- elf_common.h - Common ELF functionality -------------------*- C -*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -14,7 +14,7 @@ //===----------------------------------------------------------------------===// #if !(defined(_OMPTARGET_DEBUG_H)) -#error Include elf_common.c in the plugin source AFTER Debug.h has\ +#error Include elf_common.h in the plugin source AFTER Debug.h has\ been included. #endif @@ -23,7 +23,7 @@ // Check whether an image is valid for execution on target_id static inline int32_t elf_check_machine(__tgt_device_image *image, - uint16_t target_id) { + uint16_t target_id) { // Is the library version incompatible with the header file? if (elf_version(EV_CURRENT) == EV_NONE) { diff --git a/openmp/libomptarget/plugins/cuda/CMakeLists.txt b/openmp/libomptarget/plugins/cuda/CMakeLists.txt --- a/openmp/libomptarget/plugins/cuda/CMakeLists.txt +++ b/openmp/libomptarget/plugins/cuda/CMakeLists.txt @@ -37,6 +37,7 @@ install(TARGETS omptarget.rtl.cuda LIBRARY DESTINATION "${OPENMP_INSTALL_LIBDIR}") target_link_libraries(omptarget.rtl.cuda + elf_common ${LIBOMPTARGET_DEP_CUDA_DRIVER_LIBRARIES} ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES} "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/../exports" diff --git a/openmp/libomptarget/plugins/cuda/src/rtl.cpp b/openmp/libomptarget/plugins/cuda/src/rtl.cpp --- a/openmp/libomptarget/plugins/cuda/src/rtl.cpp +++ b/openmp/libomptarget/plugins/cuda/src/rtl.cpp @@ -58,7 +58,7 @@ } while (false) #endif // OMPTARGET_DEBUG -#include "../../common/elf_common.c" +#include "elf_common.h" /// Keep entries table per device. struct FuncOrGblEntryTy { diff --git a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp --- a/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp +++ b/openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp @@ -34,7 +34,7 @@ #define TARGET_ELF_ID 0 #endif -#include "../../common/elf_common.c" +#include "elf_common.h" #define NUMBER_OF_DEVICES 4 #define OFFLOADSECTIONNAME "omp_offloading_entries" diff --git a/openmp/libomptarget/plugins/ve/CMakeLists.txt b/openmp/libomptarget/plugins/ve/CMakeLists.txt --- a/openmp/libomptarget/plugins/ve/CMakeLists.txt +++ b/openmp/libomptarget/plugins/ve/CMakeLists.txt @@ -36,6 +36,7 @@ target_link_libraries( "omptarget.rtl.${tmachine_libname}" + elf_common ${LIBOMPTARGET_DEP_LIBFFI_LIBRARIES} ${LIBOMPTARGET_DEP_LIBELF_LIBRARIES} ${additional_libs} diff --git a/openmp/libomptarget/plugins/ve/src/rtl.cpp b/openmp/libomptarget/plugins/ve/src/rtl.cpp --- a/openmp/libomptarget/plugins/ve/src/rtl.cpp +++ b/openmp/libomptarget/plugins/ve/src/rtl.cpp @@ -36,7 +36,7 @@ #define TARGET_ELF_ID 0 #endif -#include "../../common/elf_common.c" +#include "elf_common.h" struct DynLibTy { char *FileName;