mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 18:28:12 +00:00
LibELF: Remove an ungodly amount of DYNAMIC_LOAD_DEBUG logging
This logging mode was unusable anyway since it spams way too much. The dynamic loader is in a pretty good place now anyway, so I think it's okay for us to drop some of the bring-up debug logging. :^) Also, we have to be careful with dbgln_if(FOO_DEBUG, "{}", foo()) where foo() is something expensive, since it might get evaluated even if !FOO_DEBUG.
This commit is contained in:
parent
37420f1baf
commit
af6a633468
1 changed files with 0 additions and 40 deletions
|
@ -178,10 +178,6 @@ bool DynamicLoader::load_stage_2(unsigned flags, size_t total_tls_size)
|
|||
{
|
||||
ASSERT(flags & RTLD_GLOBAL);
|
||||
|
||||
#if DYNAMIC_LOAD_DEBUG
|
||||
m_dynamic_object->dump();
|
||||
#endif
|
||||
|
||||
if (m_dynamic_object->has_text_relocations()) {
|
||||
ASSERT(m_text_segment_load_address.get() != 0);
|
||||
|
||||
|
@ -249,8 +245,6 @@ RefPtr<DynamicObject> DynamicLoader::load_stage_3(unsigned flags, size_t total_t
|
|||
}
|
||||
|
||||
call_object_init_functions();
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Loaded {}", m_filename);
|
||||
return m_dynamic_object;
|
||||
}
|
||||
|
||||
|
@ -396,25 +390,19 @@ void DynamicLoader::load_program_headers()
|
|||
|
||||
DynamicLoader::RelocationResult DynamicLoader::do_relocation(size_t total_tls_size, const ELF::DynamicObject::Relocation& relocation)
|
||||
{
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Relocation symbol: {}, type: {}", relocation.symbol().name(), relocation.type());
|
||||
FlatPtr* patch_ptr = nullptr;
|
||||
if (is_dynamic())
|
||||
patch_ptr = (FlatPtr*)(m_dynamic_object->base_address().as_ptr() + relocation.offset());
|
||||
else
|
||||
patch_ptr = (FlatPtr*)(FlatPtr)relocation.offset();
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "dynamic object base address: {:p}", m_dynamic_object->base_address().as_ptr());
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "relocation offset: {:#08x}", relocation.offset());
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "patch_ptr: {:p}", patch_ptr);
|
||||
switch (relocation.type()) {
|
||||
case R_386_NONE:
|
||||
// Apparently most loaders will just skip these?
|
||||
// Seems if the 'link editor' generates one something is funky with your code
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "None relocation. No symbol, no nothing.");
|
||||
break;
|
||||
case R_386_32: {
|
||||
auto symbol = relocation.symbol();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Absolute relocation: name: '{}', value: {}", symbol.name(), symbol.value());
|
||||
auto res = lookup_symbol(symbol);
|
||||
if (!res.has_value()) {
|
||||
if (symbol.bind() == STB_WEAK)
|
||||
|
@ -424,22 +412,18 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(size_t total_tls_si
|
|||
}
|
||||
auto symbol_address = res.value().address;
|
||||
*patch_ptr += symbol_address.get();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, " Symbol address: {:p}", *patch_ptr);
|
||||
break;
|
||||
}
|
||||
case R_386_PC32: {
|
||||
auto symbol = relocation.symbol();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "PC-relative relocation: '{}', value: {:p}", symbol.name(), symbol.value());
|
||||
auto result = lookup_symbol(symbol);
|
||||
ASSERT(result.has_value());
|
||||
auto relative_offset = result.value().address - m_dynamic_object->base_address().offset(relocation.offset());
|
||||
*patch_ptr += relative_offset.get();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, " Symbol address: {:p}", *patch_ptr);
|
||||
break;
|
||||
}
|
||||
case R_386_GLOB_DAT: {
|
||||
auto symbol = relocation.symbol();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Global data relocation: '{}', value: {:p}", symbol.name(), symbol.value());
|
||||
auto res = lookup_symbol(symbol);
|
||||
if (!res.has_value()) {
|
||||
// We do not support these
|
||||
|
@ -454,46 +438,32 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(size_t total_tls_si
|
|||
// Symbol not found
|
||||
return RelocationResult::Failed;
|
||||
}
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "symbol found, location: {:#08x}", res.value().address);
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "object: {}", m_filename);
|
||||
|
||||
auto symbol_location = res.value().address;
|
||||
ASSERT(symbol_location != m_dynamic_object->base_address());
|
||||
*patch_ptr = symbol_location.get();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, " Symbol address: {:p}", *patch_ptr);
|
||||
break;
|
||||
}
|
||||
case R_386_RELATIVE: {
|
||||
// FIXME: According to the spec, R_386_relative ones must be done first.
|
||||
// We could explicitly do them first using m_number_of_relocatoins from DT_RELCOUNT
|
||||
// However, our compiler is nice enough to put them at the front of the relocations for us :)
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Load address relocation at offset {:#08x}", relocation.offset());
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, " patch ptr == {:p}, adding load base address ({:p}) to it and storing {:p}", *patch_ptr, m_dynamic_object->base_address().as_ptr(), *patch_ptr + m_dynamic_object->base_address().as_ptr());
|
||||
*patch_ptr += (FlatPtr)m_dynamic_object->base_address().as_ptr(); // + addend for RelA (addend for Rel is stored at addr)
|
||||
break;
|
||||
}
|
||||
case R_386_TLS_TPOFF32:
|
||||
case R_386_TLS_TPOFF: {
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Relocation type: R_386_TLS_TPOFF at offset {:#08x}", relocation.offset());
|
||||
auto symbol = relocation.symbol();
|
||||
// For some reason, LibC has a R_386_TLS_TPOFF that refers to the undefined symbol.. huh
|
||||
if (relocation.symbol_index() == 0)
|
||||
break;
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Symbol index: {}", symbol.index());
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Symbol is_undefined?: {}", symbol.is_undefined());
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "TLS relocation: '{}', value: {:p}", symbol.name(), symbol.value());
|
||||
auto res = lookup_symbol(symbol);
|
||||
if (!res.has_value())
|
||||
break;
|
||||
u32 symbol_value = res.value().value;
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "symbol value: {}", symbol_value);
|
||||
auto* dynamic_object_of_symbol = res.value().dynamic_object;
|
||||
ASSERT(dynamic_object_of_symbol);
|
||||
size_t offset_of_tls_end = dynamic_object_of_symbol->tls_offset().value() + dynamic_object_of_symbol->tls_size().value();
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "patch ptr: {:p}", patch_ptr);
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "tls end offset: {}, total tls size: {}", offset_of_tls_end, total_tls_size);
|
||||
*patch_ptr = (offset_of_tls_end - total_tls_size - symbol_value - sizeof(Elf32_Addr));
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "*patch ptr: {}", (i32)*patch_ptr);
|
||||
break;
|
||||
}
|
||||
case R_386_JMP_SLOT: {
|
||||
|
@ -501,7 +471,6 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(size_t total_tls_si
|
|||
if (m_dynamic_object->must_bind_now()) {
|
||||
// Eagerly BIND_NOW the PLT entries, doing all the symbol looking goodness
|
||||
// The patch method returns the address for the LAZY fixup path, but we don't need it here
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "patching plt reloaction: {:p}", relocation.offset_in_section());
|
||||
m_dynamic_object->patch_plt_entry(relocation.offset_in_section());
|
||||
} else {
|
||||
u8* relocation_address = relocation.address().as_ptr();
|
||||
|
@ -514,7 +483,6 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(size_t total_tls_si
|
|||
default:
|
||||
// Raise the alarm! Someone needs to implement this relocation type
|
||||
dbgln("Found a new exciting relocation type {}", relocation.type());
|
||||
// printf("DynamicLoader: Found unknown relocation type %d\n", relocation.type());
|
||||
ASSERT_NOT_REACHED();
|
||||
}
|
||||
return RelocationResult::Success;
|
||||
|
@ -532,8 +500,6 @@ void DynamicLoader::setup_plt_trampoline()
|
|||
auto* got_ptr = (FlatPtr*)got_address.as_ptr();
|
||||
got_ptr[1] = (FlatPtr)m_dynamic_object.ptr();
|
||||
got_ptr[2] = (FlatPtr)&_plt_trampoline;
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Set GOT PLT entries at {:p}: [0] = {:p} [1] = {:p}, [2] = {:p}", got_ptr, (void*)got_ptr[0], (void*)got_ptr[1], (void*)got_ptr[2]);
|
||||
}
|
||||
|
||||
// Called from our ASM routine _plt_trampoline.
|
||||
|
@ -550,8 +516,6 @@ void DynamicLoader::call_object_init_functions()
|
|||
|
||||
if (m_dynamic_object->has_init_section()) {
|
||||
auto init_function = (InitFunc)(m_dynamic_object->init_section().address().as_ptr());
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Calling DT_INIT at {:p}", init_function);
|
||||
(init_function)();
|
||||
}
|
||||
|
||||
|
@ -565,7 +529,6 @@ void DynamicLoader::call_object_init_functions()
|
|||
// 0 definitely shows up. Apparently 0/-1 are valid? Confusing.
|
||||
if (!*init_begin || ((FlatPtr)*init_begin == (FlatPtr)-1))
|
||||
continue;
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "Calling DT_INITARRAY entry at {:p}", *init_begin);
|
||||
(*init_begin)();
|
||||
++init_begin;
|
||||
}
|
||||
|
@ -574,11 +537,8 @@ void DynamicLoader::call_object_init_functions()
|
|||
|
||||
Optional<DynamicObject::SymbolLookupResult> DynamicLoader::lookup_symbol(const ELF::DynamicObject::Symbol& symbol)
|
||||
{
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "looking up symbol: {}", symbol.name());
|
||||
if (symbol.is_undefined() || symbol.bind() == STB_WEAK)
|
||||
return DynamicLinker::lookup_global_symbol(symbol.name());
|
||||
|
||||
dbgln_if(DYNAMIC_LOAD_DEBUG, "symbol is defined in its object");
|
||||
return DynamicObject::SymbolLookupResult { symbol.value(), symbol.address(), symbol.bind(), &symbol.object() };
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue