diff --git a/public/client/TracyCallstack.cpp b/public/client/TracyCallstack.cpp index 9095d847..59c4182f 100644 --- a/public/client/TracyCallstack.cpp +++ b/public/client/TracyCallstack.cpp @@ -237,9 +237,18 @@ private: if( cache->ContainsImage( startAddress ) ) return 0; const uint32_t headerCount = info->dlpi_phnum; - assert( headerCount > 0); - const auto endAddress = static_cast( info->dlpi_addr + - info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr + info->dlpi_phdr[info->dlpi_phnum - 1].p_memsz); + assert( headerCount > 0 ); + + // headers aren't guaranteed to be in address order; find the max + uint64_t endAddress = startAddress; + for( uint32_t i=0; idlpi_phdr[i]; + if( phdr.p_type != PT_LOAD ) continue; + + const auto phdrEnd = static_cast( info->dlpi_addr + phdr.p_vaddr + phdr.p_memsz ); + endAddress = std::max( phdrEnd, endAddress ); + } ImageEntry image{}; image.m_startAddress = startAddress; diff --git a/public/libbacktrace/elf.cpp b/public/libbacktrace/elf.cpp index 5f45b4e6..6d54ecff 100644 --- a/public/libbacktrace/elf.cpp +++ b/public/libbacktrace/elf.cpp @@ -7410,9 +7410,17 @@ phdr_callback_mock (struct dl_phdr_info *info, size_t size ATTRIBUTE_UNUSED, ptr->dlpi_addr = info->dlpi_addr; // calculate the end address as well, so we can quickly determine if a PC is within the range of this image - ptr->dlpi_end_addr = uintptr_t(info->dlpi_addr) + (info->dlpi_phnum ? uintptr_t( - info->dlpi_phdr[info->dlpi_phnum - 1].p_vaddr + - info->dlpi_phdr[info->dlpi_phnum - 1].p_memsz) : 0); + // headers aren't guaranteed to be in address order; find the max + ptr->dlpi_end_addr = uintptr_t(info->dlpi_addr); + for (uint32_t i = 0; i < info->dlpi_phnum; i++) + { + const auto &phdr = info->dlpi_phdr[i]; + if (phdr.p_type != PT_LOAD) + continue; + + const auto phdr_end = uintptr_t(info->dlpi_addr + phdr.p_vaddr + phdr.p_memsz); + ptr->dlpi_end_addr = std::max(phdr_end, ptr->dlpi_end_addr); + } return 0; }