mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-04-23 13:05:12 +00:00
DynamicLoader: Add RELA support for self-relocations
GCC doesn't seem to rely on those to work, but Clang does.
This commit is contained in:
parent
42eb06f045
commit
2fc002f778
Notes:
sideshowbarker
2024-07-18 09:06:41 +09:00
Author: https://github.com/gunnarbeutner Commit: https://github.com/SerenityOS/serenity/commit/2fc002f7782 Pull-request: https://github.com/SerenityOS/serenity/pull/8721
1 changed files with 7 additions and 1 deletions
|
@ -49,11 +49,14 @@ static void perform_self_relocations(auxv_t* auxvp)
|
|||
FlatPtr relocation_section_addr = 0;
|
||||
size_t relocation_table_size = 0;
|
||||
size_t relocation_count = 0;
|
||||
bool use_addend = false;
|
||||
auto* dyns = reinterpret_cast<const ElfW(Dyn)*>(dynamic_section_addr);
|
||||
for (unsigned i = 0;; ++i) {
|
||||
auto& dyn = dyns[i];
|
||||
if (dyn.d_tag == DT_NULL)
|
||||
break;
|
||||
if (dyn.d_tag == DT_RELA)
|
||||
use_addend = true;
|
||||
if (dyn.d_tag == DT_REL || dyn.d_tag == DT_RELA)
|
||||
relocation_section_addr = base_address + dyn.d_un.d_ptr;
|
||||
else if (dyn.d_tag == DT_RELCOUNT || dyn.d_tag == DT_RELACOUNT)
|
||||
|
@ -73,7 +76,10 @@ static void perform_self_relocations(auxv_t* auxvp)
|
|||
#else
|
||||
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE);
|
||||
#endif
|
||||
*(FlatPtr*)(base_address + relocation->r_offset) += base_address;
|
||||
if (use_addend)
|
||||
*(FlatPtr*)(base_address + relocation->r_offset) = base_address + relocation->r_addend;
|
||||
else
|
||||
*(FlatPtr*)(base_address + relocation->r_offset) += base_address;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue