|
20 | 20 | #include <fcntl.h> |
21 | 21 | #include <link.h> |
22 | 22 | #include <linux/limits.h> |
| 23 | +#include <sys/auxv.h> |
23 | 24 | #include "symbols.h" |
24 | 25 | #include "dwarf.h" |
25 | 26 | #include "fdtransferClient.h" |
@@ -775,6 +776,11 @@ void Symbols::parseLibraries(CodeCacheArray* array, bool kernel_symbols) { |
775 | 776 | std::unordered_map<u64, SharedLibrary> libs; |
776 | 777 | collectSharedLibraries(libs, MAX_NATIVE_LIBS - array->count()); |
777 | 778 |
|
| 779 | + const char* ld_base = (const char*)getauxval(AT_BASE); |
| 780 | + if (!ld_base) { |
| 781 | + Log::warn("Cannot determine base address of the loader"); |
| 782 | + } |
| 783 | + |
778 | 784 | const void* main_phdr = NULL; |
779 | 785 | dl_iterate_phdr([](struct dl_phdr_info* info, size_t size, void* data) { |
780 | 786 | *(const void**)data = info->dlpi_phdr; |
@@ -813,9 +819,11 @@ void Symbols::parseLibraries(CodeCacheArray* array, bool kernel_symbols) { |
813 | 819 | // Main executable and ld-linux interpreter cannot be dlopen'ed, but dlerror() returns NULL for them on some systems. |
814 | 820 | void* handle = dlopen(lib.file, RTLD_LAZY | RTLD_NOLOAD); |
815 | 821 |
|
816 | | - // Parse main executable regardless of dlopen result, since it cannot be unloaded. |
| 822 | + // Parse main executable and the loader (ld.so) regardless of dlopen result, since they cannot be unloaded. |
817 | 823 | bool is_main_exe = main_phdr >= lib.image_base && main_phdr < lib.map_end; |
818 | | - if (handle != NULL || dlerror() == NULL || is_main_exe) { |
| 824 | + bool is_loader = ld_base == lib.image_base; |
| 825 | + |
| 826 | + if (handle != NULL || is_main_exe || is_loader) { |
819 | 827 | ElfParser::parseProgramHeaders(cc, lib.image_base, lib.map_end, OS::isMusl()); |
820 | 828 | } |
821 | 829 |
|
|
0 commit comments