Author: Shilei Tian Date: 2021-01-11T17:34:26-05:00 New Revision: a81c68ae6be58efa24e2573e155d5ef20260399b
URL: https://github.com/llvm/llvm-project/commit/a81c68ae6be58efa24e2573e155d5ef20260399b DIFF: https://github.com/llvm/llvm-project/commit/a81c68ae6be58efa24e2573e155d5ef20260399b.diff LOG: [OpenMP] Take elf_common.c as a interface library For now `elf_common.c` is taken as a common part included into different plugin implementations directly via `#include "../../common/elf_common.c"`, which is not a best practice. Since it is simple enough such that we don't need to create a real library for it, we just take it as a interface library so that other targets can link it directly. Another advantage of this method is, we don't need to add the folder into header search path which can potentially pollute the search path. VE and AMD platforms have not been tested because I don't have target machines. Reviewed By: JonChesterfield Differential Revision: https://reviews.llvm.org/D94443 Added: openmp/libomptarget/plugins/common/CMakeLists.txt openmp/libomptarget/plugins/common/elf_common/CMakeLists.txt openmp/libomptarget/plugins/common/elf_common/elf_common.h Modified: openmp/libomptarget/plugins/CMakeLists.txt openmp/libomptarget/plugins/amdgpu/CMakeLists.txt openmp/libomptarget/plugins/amdgpu/src/rtl.cpp openmp/libomptarget/plugins/cuda/CMakeLists.txt openmp/libomptarget/plugins/cuda/src/rtl.cpp openmp/libomptarget/plugins/generic-elf-64bit/src/rtl.cpp openmp/libomptarget/plugins/ve/CMakeLists.txt openmp/libomptarget/plugins/ve/src/rtl.cpp Removed: openmp/libomptarget/plugins/common/elf_common.c ################################################################################ diff --git a/openmp/libomptarget/plugins/CMakeLists.txt b/openmp/libomptarget/plugins/CMakeLists.txt index f8372b619407..85b5d62742bd 100644 --- 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 @@ macro(build_generic_elf64 tmachine tmachine_name tmachine_libname tmachine_tripl 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 index 38f0afabf3ad..2d58388c80bb 100644 --- a/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt +++ b/openmp/libomptarget/plugins/amdgpu/CMakeLists.txt @@ -73,6 +73,7 @@ set_property(TARGET omptarget.rtl.amdgpu PROPERTY INSTALL_RPATH "$ORIGIN") 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 index 5ec5f5e45e36..437846f8b15b 100644 --- a/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp +++ b/openmp/libomptarget/plugins/amdgpu/src/rtl.cpp @@ -91,7 +91,7 @@ uint32_t TgtStackItemSize = 0; {} #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 index 000000000000..947e0cc88bb6 --- /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 index 000000000000..7cad0a0a1d1a --- /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 similarity index 93% rename from openmp/libomptarget/plugins/common/elf_common.c rename to openmp/libomptarget/plugins/common/elf_common/elf_common.h index ba63a5fd9f2b..75994238b58d 100644 --- 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 index e0299b1f3270..15af8307bd72 100644 --- a/openmp/libomptarget/plugins/cuda/CMakeLists.txt +++ b/openmp/libomptarget/plugins/cuda/CMakeLists.txt @@ -37,6 +37,7 @@ add_library(omptarget.rtl.cuda SHARED src/rtl.cpp) 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 index a22195bae966..78f1f36bb3b5 100644 --- 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 index 3390aed08403..625518f46cca 100644 --- 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 index 3355d7347aee..16ce0891ca23 100644 --- a/openmp/libomptarget/plugins/ve/CMakeLists.txt +++ b/openmp/libomptarget/plugins/ve/CMakeLists.txt @@ -36,6 +36,7 @@ if(${LIBOMPTARGET_DEP_VEO_FOUND}) 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 index 1994389deb42..284ee04c850b 100644 --- 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; _______________________________________________ llvm-branch-commits mailing list llvm-branch-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits