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

LibELF: Remove ELF::Loader and move everyone to ELF::Image

This commit gets rid of ELF::Loader entirely since its very ambiguous
purpose was actually to load executables for the kernel, and that is
now handled by the kernel itself.

This patch includes some drive-by cleanup in LibDebug and CrashDaemon
enabled by the fact that we no longer need to keep the ref-counted
ELF::Loader around.
This commit is contained in:
Andreas Kling 2020-12-25 02:14:56 +01:00
parent 7551a66f73
commit 1e4c010643
24 changed files with 178 additions and 318 deletions

View file

@ -29,7 +29,7 @@
#include <AK/QuickSort.h>
#include <AK/Vector.h>
#include <LibCore/ArgsParser.h>
#include <LibELF/Loader.h>
#include <LibELF/Image.h>
#include <LibX86/Disassembler.h>
#include <LibX86/ELFSymbolProvider.h>
#include <stdio.h>
@ -70,14 +70,13 @@ int main(int argc, char** argv)
size_t asm_size = file.size();
size_t file_offset = 0;
Vector<Symbol>::Iterator current_symbol = symbols.begin();
RefPtr<ELF::Loader> elf;
OwnPtr<X86::ELFSymbolProvider> symbol_provider; // nullptr for non-ELF disassembly.
OwnPtr<ELF::Image> elf;
if (asm_size >= 4 && strncmp((const char*)asm_data, "\u007fELF", 4) == 0) {
NonnullRefPtr<ELF::Loader> elf_loader = ELF::Loader::create(asm_data, asm_size);
if (elf_loader->image().is_valid()) {
elf = elf_loader;
elf = make<ELF::Image>(asm_data, asm_size);
if (elf->is_valid()) {
symbol_provider = make<X86::ELFSymbolProvider>(*elf);
elf->image().for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) {
elf->for_each_section_of_type(SHT_PROGBITS, [&](const ELF::Image::Section& section) {
// FIXME: Disassemble all SHT_PROGBITS sections, not just .text.
if (section.name() != ".text")
return IterationDecision::Continue;
@ -86,9 +85,9 @@ int main(int argc, char** argv)
file_offset = section.address();
return IterationDecision::Break;
});
symbols.ensure_capacity(elf->image().symbol_count() + 1);
symbols.ensure_capacity(elf->symbol_count() + 1);
symbols.append({ 0, 0, StringView() }); // Sentinel.
elf->image().for_each_symbol([&](const ELF::Image::Symbol& symbol) {
elf->for_each_symbol([&](const ELF::Image::Symbol& symbol) {
symbols.append({ symbol.value(), symbol.size(), symbol.name() });
return IterationDecision::Continue;
});