From f87b900f9649c2950598717e9fbbedf2a7ba5fbb Mon Sep 17 00:00:00 2001 From: Aaron Enye Shi Date: Mon, 24 Jun 2019 21:02:29 -0400 Subject: [PATCH] Fix dlpi_name info empty when using GCC on ub18 (#1181) This fixes a bug where GCC++ on Ubuntu 18.04 creates failing executables compared to GCC++ on 16.04 and clang++. While creating function names on Ubuntu 18.04, dl_phdr_info seems to provide a non-zero value for dlpi_addr on initial iteration, and an empty string in dlpi_name. This is causing failure when linking with g++, since the empty string prevents the kernel function from being loaded. Clang++ and GCC on UB16 provide a zero value for dlpi_addr. To fix this, we need to verify both addr and name exists, so that /proc/self/exe can be properly loaded. --- hipamd/src/program_state.inl | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/hipamd/src/program_state.inl b/hipamd/src/program_state.inl index b01c22c6c6..f6cd290764 100644 --- a/hipamd/src/program_state.inl +++ b/hipamd/src/program_state.inl @@ -219,8 +219,8 @@ public: dl_iterate_phdr([](dl_phdr_info* info, std::size_t, void* p) { ELFIO::elfio tmp; - const auto elf = - info->dlpi_addr ? info->dlpi_name : "/proc/self/exe"; + const auto elf = (info->dlpi_addr && std::strlen(info->dlpi_name) != 0) ? + info->dlpi_name : "/proc/self/exe"; if (!tmp.load(elf)) return 0; @@ -277,8 +277,8 @@ public: program_state_impl* t = static_cast(psi_ptr); ELFIO::elfio tmp; - const auto elf = - info->dlpi_addr ? info->dlpi_name : "/proc/self/exe"; + const auto elf = (info->dlpi_addr && std::strlen(info->dlpi_name) != 0) ? + info->dlpi_name : "/proc/self/exe"; if (!tmp.load(elf)) return 0; @@ -503,8 +503,8 @@ public: std::call_once(function_names.first, [this]() { dl_iterate_phdr([](dl_phdr_info* info, std::size_t, void* p) { ELFIO::elfio tmp; - const auto elf = - info->dlpi_addr ? info->dlpi_name : "/proc/self/exe"; + const auto elf = (info->dlpi_addr && std::strlen(info->dlpi_name) != 0) ? + info->dlpi_name : "/proc/self/exe"; if (!tmp.load(elf)) return 0;