1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-26 03:27:45 +00:00

LibELF: Handle TLSDESC relocations in .rela.plt for GNU ld

GNU ld for some reason might put R_*_TLSDESC relocations in .rela.plt.
This commit is contained in:
Sönke Holz 2023-10-03 20:23:53 +02:00 committed by Daniel Bertalan
parent 0937d88869
commit 9d7e217566

View file

@ -233,14 +233,21 @@ void DynamicLoader::do_main_relocations()
*((FlatPtr*)relocation.address().as_ptr()) += m_dynamic_object->base_address().get(); *((FlatPtr*)relocation.address().as_ptr()) += m_dynamic_object->base_address().get();
}; };
// FIXME: Or LD_BIND_NOW is set? m_dynamic_object->plt_relocation_section().for_each_relocation([&](DynamicObject::Relocation const& relocation) {
if (m_dynamic_object->must_bind_now()) { if (relocation.type() == R_X86_64_IRELATIVE || relocation.type() == R_AARCH64_IRELATIVE) {
m_dynamic_object->plt_relocation_section().for_each_relocation([&](DynamicObject::Relocation const& relocation) { m_direct_ifunc_relocations.append(relocation);
if (relocation.type() == R_X86_64_IRELATIVE || relocation.type() == R_AARCH64_IRELATIVE) { return;
m_direct_ifunc_relocations.append(relocation); }
return; if (relocation.type() == R_X86_64_TLSDESC || relocation.type() == R_AARCH64_TLSDESC) {
} // GNU ld for some reason puts TLSDESC relocations into .rela.plt
// https://sourceware.org/bugzilla/show_bug.cgi?id=28387
VERIFY(do_direct_relocation(relocation, cached_result, ShouldInitializeWeak::No, ShouldCallIfuncResolver::No) == RelocationResult::Success);
return;
}
// FIXME: Or LD_BIND_NOW is set?
if (m_dynamic_object->must_bind_now()) {
switch (do_plt_relocation(relocation, ShouldCallIfuncResolver::No)) { switch (do_plt_relocation(relocation, ShouldCallIfuncResolver::No)) {
case RelocationResult::Failed: case RelocationResult::Failed:
dbgln("Loader.so: {} unresolved symbol '{}'", m_filepath, relocation.symbol().name()); dbgln("Loader.so: {} unresolved symbol '{}'", m_filepath, relocation.symbol().name());
@ -255,16 +262,10 @@ void DynamicLoader::do_main_relocations()
case RelocationResult::Success: case RelocationResult::Success:
break; break;
} }
}); } else {
} else {
m_dynamic_object->plt_relocation_section().for_each_relocation([&](DynamicObject::Relocation const& relocation) {
if (relocation.type() == R_X86_64_IRELATIVE || relocation.type() == R_AARCH64_IRELATIVE) {
m_direct_ifunc_relocations.append(relocation);
return;
}
fixup_trampoline_pointer(relocation); fixup_trampoline_pointer(relocation);
}); }
} });
} }
Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> DynamicLoader::load_stage_3(unsigned flags) Result<NonnullRefPtr<DynamicObject>, DlErrorMessage> DynamicLoader::load_stage_3(unsigned flags)