From 4e1344de0f9703044d9d34e756b88e40082a5131 Mon Sep 17 00:00:00 2001 From: Tao Sang Date: Tue, 11 Aug 2020 12:49:50 -0400 Subject: [PATCH] Replace private libelf with elfio Change-Id: I59ae33f7cc55e73f6519af14be91dd9863b03af3 --- lpl_ca/CMakeLists.txt | 13 ++++++++++++- lpl_ca/lpl.hpp | 6 +++--- rocclr/CMakeLists.txt | 4 ---- rocclr/hip_code_object.cpp | 19 ++----------------- rocclr/hip_module.cpp | 20 ++------------------ rocclr/hip_platform.cpp | 1 - 6 files changed, 19 insertions(+), 44 deletions(-) diff --git a/lpl_ca/CMakeLists.txt b/lpl_ca/CMakeLists.txt index 90e7143f66..c272273c09 100644 --- a/lpl_ca/CMakeLists.txt +++ b/lpl_ca/CMakeLists.txt @@ -1,4 +1,10 @@ #-------------------------------------LPL--------------------------------------# +# Look for ROCclr which contains elfio +find_package(ROCclr REQUIRED CONFIG + PATHS + /opt/rocm + /opt/rocm/rocclr) + add_executable(lpl lpl.cpp) set_target_properties( lpl PROPERTIES @@ -6,7 +12,12 @@ set_target_properties( CXX_STANDARD_REQUIRED ON CXX_EXTENSIONS OFF RUNTIME_OUTPUT_DIRECTORY ${PROJECT_BINARY_DIR}) -target_include_directories(lpl PUBLIC ${PROJECT_SOURCE_DIR}/src) +target_include_directories(lpl + PUBLIC + ${PROJECT_SOURCE_DIR}/src + PRIVATE + $) + target_compile_options(lpl PUBLIC -Wall) target_link_libraries(lpl PUBLIC pthread) diff --git a/lpl_ca/lpl.hpp b/lpl_ca/lpl.hpp index 84a6930753..00635d3f26 100644 --- a/lpl_ca/lpl.hpp +++ b/lpl_ca/lpl.hpp @@ -4,7 +4,7 @@ #include "clara/clara.hpp" #include "pstreams/pstream.h" -#include "hip/hcc_detail/elfio/elfio.hpp" +#include #include @@ -71,14 +71,14 @@ inline std::string make_hipcc_call(const std::vector& sources, } inline void copy_kernel_section_to_fat_binary(const std::string& tmp, const std::string& output) { - ELFIO::elfio reader; + amd::ELFIO::elfio reader; if (!reader.load(tmp)) { throw std::runtime_error{"The result of the compilation is inaccessible."}; } const auto it = std::find_if(reader.sections.begin(), reader.sections.end(), - [](const ELFIO::section* x) { return x->get_name() == kernel_section(); }); + [](const amd::ELFIO::section* x) { return x->get_name() == kernel_section(); }); std::ofstream out{output}; diff --git a/rocclr/CMakeLists.txt b/rocclr/CMakeLists.txt index e6c4225984..378307aaef 100755 --- a/rocclr/CMakeLists.txt +++ b/rocclr/CMakeLists.txt @@ -96,8 +96,6 @@ find_package(amd_comgr REQUIRED CONFIG message(STATUS "Code Object Manager found at ${amd_comgr_DIR}.") -add_definitions(-DBSD_LIBELF) - add_library(hip64 OBJECT hip_context.cpp hip_code_object.cpp @@ -129,10 +127,8 @@ target_include_directories(hip64 ${PROJECT_SOURCE_DIR}/include ${PROJECT_BINARY_DIR}/include PRIVATE - ${CMAKE_SOURCE_DIR}/elfio ${PROJECT_SOURCE_DIR} ${PROJECT_SOURCE_DIR}/amdocl - ${PROJECT_SOURCE_DIR}/include/hip/hcc_detail/elfio ${ROCR_INCLUDES} $ $) diff --git a/rocclr/hip_code_object.cpp b/rocclr/hip_code_object.cpp index 8b89647e89..26852bee6d 100755 --- a/rocclr/hip_code_object.cpp +++ b/rocclr/hip_code_object.cpp @@ -6,27 +6,12 @@ #include "hip/hip_runtime.h" #include "hip_internal.hpp" #include "platform/program.hpp" +#include namespace hip { uint64_t CodeObject::ElfSize(const void *emi) { - const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)emi; - const Elf64_Shdr *shdr = (const Elf64_Shdr*)((char*)emi + ehdr->e_shoff); - - uint64_t max_offset = ehdr->e_shoff; - uint64_t total_size = max_offset + ehdr->e_shentsize * ehdr->e_shnum; - - for (uint16_t i=0; i < ehdr->e_shnum; ++i){ - uint64_t cur_offset = static_cast(shdr[i].sh_offset); - if (max_offset < cur_offset) { - max_offset = cur_offset; - total_size = max_offset; - if(SHT_NOBITS != shdr[i].sh_type) { - total_size += static_cast(shdr[i].sh_size); - } - } - } - return total_size; + return amd::Elf::getElfSize(emi); } bool CodeObject::isCompatibleCodeObject(const std::string& codeobj_target_id, diff --git a/rocclr/hip_module.cpp b/rocclr/hip_module.cpp index 146c6f3829..3af767d8a9 100755 --- a/rocclr/hip_module.cpp +++ b/rocclr/hip_module.cpp @@ -19,7 +19,7 @@ THE SOFTWARE. */ #include -#include +#include #include #include "hip_internal.hpp" @@ -45,23 +45,7 @@ const std::string& FunctionName(const hipFunction_t f) { static uint64_t ElfSize(const void *emi) { - const Elf64_Ehdr *ehdr = (const Elf64_Ehdr*)emi; - const Elf64_Shdr *shdr = (const Elf64_Shdr*)((char*)emi + ehdr->e_shoff); - - uint64_t max_offset = ehdr->e_shoff; - uint64_t total_size = max_offset + ehdr->e_shentsize * ehdr->e_shnum; - - for (uint16_t i=0; i < ehdr->e_shnum; ++i){ - uint64_t cur_offset = static_cast(shdr[i].sh_offset); - if (max_offset < cur_offset) { - max_offset = cur_offset; - total_size = max_offset; - if(SHT_NOBITS != shdr[i].sh_type) { - total_size += static_cast(shdr[i].sh_size); - } - } - } - return total_size; + return amd::Elf::getElfSize(emi); } hipError_t hipModuleUnload(hipModule_t hmod) { diff --git a/rocclr/hip_platform.cpp b/rocclr/hip_platform.cpp index 2d74d8f440..dc610affdc 100755 --- a/rocclr/hip_platform.cpp +++ b/rocclr/hip_platform.cpp @@ -26,7 +26,6 @@ #include "platform/runtime.hpp" #include -#include "elfio.hpp" constexpr unsigned __hipFatMAGIC2 = 0x48495046; // "HIPF"