DynamicLoader: Honour STB_LOCAL binding

This commit is contained in:
Bananymous 2025-11-02 22:46:04 +02:00
parent 0be18c4a53
commit e05a735589
1 changed files with 6 additions and 0 deletions

View File

@ -354,6 +354,8 @@ static void handle_copy_relocation(const LoadedElf& elf, const RelocT& reloc)
auto* match = find_symbol(s_loaded_files[i], symbol_name); auto* match = find_symbol(s_loaded_files[i], symbol_name);
if (match == nullptr) if (match == nullptr)
continue; continue;
if (ELF_ST_BIND(match->st_info) == STB_LOCAL && &s_loaded_files[i] != &elf)
continue;
if (src_sym == nullptr || ELF_ST_BIND(match->st_info) != STB_WEAK) if (src_sym == nullptr || ELF_ST_BIND(match->st_info) != STB_WEAK)
{ {
src_sym = match; src_sym = match;
@ -399,6 +401,8 @@ static void handle_tls_relocation(const LoadedElf& elf, const RelocT& reloc)
const auto* match = find_symbol(s_loaded_files[i], symbol_name); const auto* match = find_symbol(s_loaded_files[i], symbol_name);
if (match == nullptr) if (match == nullptr)
continue; continue;
if (ELF_ST_BIND(match->st_info) == STB_LOCAL && &s_loaded_files[i] != &elf)
continue;
if (symbol_elf == nullptr || ELF_ST_BIND(match->st_info) != STB_WEAK) if (symbol_elf == nullptr || ELF_ST_BIND(match->st_info) != STB_WEAK)
{ {
symbol_elf = &s_loaded_files[i]; symbol_elf = &s_loaded_files[i];
@ -512,6 +516,8 @@ static uintptr_t handle_relocation(const LoadedElf& elf, const RelocT& reloc, bo
const auto* match = find_symbol(s_loaded_files[i], symbol_name); const auto* match = find_symbol(s_loaded_files[i], symbol_name);
if (match == nullptr) if (match == nullptr)
continue; continue;
if (ELF_ST_BIND(match->st_info) == STB_LOCAL && &s_loaded_files[i] != &elf)
continue;
if (symbol_address == SYM_NOT_FOUND || ELF_ST_BIND(match->st_info) != STB_WEAK) if (symbol_address == SYM_NOT_FOUND || ELF_ST_BIND(match->st_info) != STB_WEAK)
symbol_address = s_loaded_files[i].base + match->st_value; symbol_address = s_loaded_files[i].base + match->st_value;
if (ELF_ST_BIND(match->st_info) != STB_WEAK) if (ELF_ST_BIND(match->st_info) != STB_WEAK)