mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-25 09:00:22 +00:00
ELF: Run clang-format on everything.
This commit is contained in:
parent
e42c3b4fd7
commit
9145917bf0
Notes:
sideshowbarker
2024-07-19 13:41:06 +09:00
Author: https://github.com/awesomekling Commit: https://github.com/SerenityOS/serenity/commit/9145917bf01
5 changed files with 551 additions and 547 deletions
|
@ -14,12 +14,18 @@ ELFImage::~ELFImage()
|
||||||
static const char* object_file_type_to_string(Elf32_Half type)
|
static const char* object_file_type_to_string(Elf32_Half type)
|
||||||
{
|
{
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ET_NONE: return "None";
|
case ET_NONE:
|
||||||
case ET_REL: return "Relocatable";
|
return "None";
|
||||||
case ET_EXEC: return "Executable";
|
case ET_REL:
|
||||||
case ET_DYN: return "Shared object";
|
return "Relocatable";
|
||||||
case ET_CORE: return "Core";
|
case ET_EXEC:
|
||||||
default: return "(?)";
|
return "Executable";
|
||||||
|
case ET_DYN:
|
||||||
|
return "Shared object";
|
||||||
|
case ET_CORE:
|
||||||
|
return "Core";
|
||||||
|
default:
|
||||||
|
return "(?)";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <AK/OwnPtr.h>
|
|
||||||
#include <AK/HashMap.h>
|
|
||||||
#include <AK/AKString.h>
|
#include <AK/AKString.h>
|
||||||
#include <AK/ELF/exec_elf.h>
|
#include <AK/ELF/exec_elf.h>
|
||||||
|
#include <AK/HashMap.h>
|
||||||
|
#include <AK/OwnPtr.h>
|
||||||
|
|
||||||
class ELFImage {
|
class ELFImage {
|
||||||
public:
|
public:
|
||||||
|
@ -27,7 +27,7 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
~Symbol() { }
|
~Symbol() {}
|
||||||
|
|
||||||
const char* name() const { return m_image.table_string(m_sym.st_name); }
|
const char* name() const { return m_image.table_string(m_sym.st_name); }
|
||||||
unsigned section_index() const { return m_sym.st_shndx; }
|
unsigned section_index() const { return m_sym.st_shndx; }
|
||||||
|
@ -51,7 +51,7 @@ public:
|
||||||
, m_program_header_index(program_header_index)
|
, m_program_header_index(program_header_index)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~ProgramHeader() { }
|
~ProgramHeader() {}
|
||||||
|
|
||||||
unsigned index() const { return m_program_header_index; }
|
unsigned index() const { return m_program_header_index; }
|
||||||
dword type() const { return m_program_header.p_type; }
|
dword type() const { return m_program_header.p_type; }
|
||||||
|
@ -65,6 +65,7 @@ public:
|
||||||
bool is_writable() const { return flags() & PF_W; }
|
bool is_writable() const { return flags() & PF_W; }
|
||||||
bool is_executable() const { return flags() & PF_X; }
|
bool is_executable() const { return flags() & PF_X; }
|
||||||
const char* raw_data() const { return m_image.raw_data(m_program_header.p_offset); }
|
const char* raw_data() const { return m_image.raw_data(m_program_header.p_offset); }
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const ELFImage& m_image;
|
const ELFImage& m_image;
|
||||||
const Elf32_Phdr& m_program_header;
|
const Elf32_Phdr& m_program_header;
|
||||||
|
@ -79,7 +80,7 @@ public:
|
||||||
, m_section_index(sectionIndex)
|
, m_section_index(sectionIndex)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
~Section() { }
|
~Section() {}
|
||||||
|
|
||||||
const char* name() const { return m_image.section_header_table_string(m_section_header.sh_name); }
|
const char* name() const { return m_image.section_header_table_string(m_section_header.sh_name); }
|
||||||
unsigned type() const { return m_section_header.sh_type; }
|
unsigned type() const { return m_section_header.sh_type; }
|
||||||
|
@ -109,10 +110,14 @@ public:
|
||||||
const Section section(unsigned) const;
|
const Section section(unsigned) const;
|
||||||
const ProgramHeader program_header(unsigned const) const;
|
const ProgramHeader program_header(unsigned const) const;
|
||||||
|
|
||||||
template<typename F> void for_each_section(F) const;
|
template<typename F>
|
||||||
template<typename F> void for_each_section_of_type(unsigned, F) const;
|
void for_each_section(F) const;
|
||||||
template<typename F> void for_each_symbol(F) const;
|
template<typename F>
|
||||||
template<typename F> void for_each_program_header(F) const;
|
void for_each_section_of_type(unsigned, F) const;
|
||||||
|
template<typename F>
|
||||||
|
void for_each_symbol(F) const;
|
||||||
|
template<typename F>
|
||||||
|
void for_each_program_header(F) const;
|
||||||
|
|
||||||
bool is_executable() const { return header().e_type == ET_EXEC; }
|
bool is_executable() const { return header().e_type == ET_EXEC; }
|
||||||
bool is_relocatable() const { return header().e_type == ET_REL; }
|
bool is_relocatable() const { return header().e_type == ET_REL; }
|
||||||
|
@ -158,7 +163,7 @@ template<typename F>
|
||||||
inline void ELFImage::for_each_symbol(F func) const
|
inline void ELFImage::for_each_symbol(F func) const
|
||||||
{
|
{
|
||||||
for (unsigned i = 0; i < symbol_count(); ++i) {
|
for (unsigned i = 0; i < symbol_count(); ++i) {
|
||||||
if (func(symbol(i)) == IterationDecision::Abort)
|
if (func(symbol(i)) == IterationDecision::Break)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
#include "ELFLoader.h"
|
#include "ELFLoader.h"
|
||||||
#include <AK/kstdio.h>
|
|
||||||
#include <AK/QuickSort.h>
|
#include <AK/QuickSort.h>
|
||||||
|
#include <AK/kstdio.h>
|
||||||
|
|
||||||
//#define ELFLOADER_DEBUG
|
//#define ELFLOADER_DEBUG
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ bool ELFLoader::load()
|
||||||
bool ELFLoader::layout()
|
bool ELFLoader::layout()
|
||||||
{
|
{
|
||||||
bool failed = false;
|
bool failed = false;
|
||||||
m_image.for_each_program_header([&] (const ELFImage::ProgramHeader& program_header) {
|
m_image.for_each_program_header([&](const ELFImage::ProgramHeader& program_header) {
|
||||||
if (program_header.type() != PT_LOAD)
|
if (program_header.type() != PT_LOAD)
|
||||||
return;
|
return;
|
||||||
#ifdef ELFLOADER_DEBUG
|
#ifdef ELFLOADER_DEBUG
|
||||||
|
@ -43,8 +43,7 @@ bool ELFLoader::layout()
|
||||||
program_header.alignment(),
|
program_header.alignment(),
|
||||||
program_header.is_readable(),
|
program_header.is_readable(),
|
||||||
program_header.is_writable(),
|
program_header.is_writable(),
|
||||||
String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "")
|
String::format("elf-alloc-%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : ""));
|
||||||
);
|
|
||||||
memcpy(program_header.vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
|
memcpy(program_header.vaddr().as_ptr(), program_header.raw_data(), program_header.size_in_image());
|
||||||
} else {
|
} else {
|
||||||
map_section_hook(
|
map_section_hook(
|
||||||
|
@ -55,8 +54,7 @@ bool ELFLoader::layout()
|
||||||
program_header.is_readable(),
|
program_header.is_readable(),
|
||||||
program_header.is_writable(),
|
program_header.is_writable(),
|
||||||
program_header.is_executable(),
|
program_header.is_executable(),
|
||||||
String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : "")
|
String::format("elf-map-%s%s%s", program_header.is_readable() ? "r" : "", program_header.is_writable() ? "w" : "", program_header.is_executable() ? "x" : ""));
|
||||||
);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return !failed;
|
return !failed;
|
||||||
|
@ -65,7 +63,7 @@ bool ELFLoader::layout()
|
||||||
char* ELFLoader::symbol_ptr(const char* name)
|
char* ELFLoader::symbol_ptr(const char* name)
|
||||||
{
|
{
|
||||||
char* found_ptr = nullptr;
|
char* found_ptr = nullptr;
|
||||||
m_image.for_each_symbol([&] (const ELFImage::Symbol symbol) {
|
m_image.for_each_symbol([&](const ELFImage::Symbol symbol) {
|
||||||
if (symbol.type() != STT_FUNC)
|
if (symbol.type() != STT_FUNC)
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
if (strcmp(symbol.name(), name))
|
if (strcmp(symbol.name(), name))
|
||||||
|
@ -74,7 +72,7 @@ char* ELFLoader::symbol_ptr(const char* name)
|
||||||
found_ptr = (char*)symbol.value();
|
found_ptr = (char*)symbol.value();
|
||||||
else
|
else
|
||||||
ASSERT_NOT_REACHED();
|
ASSERT_NOT_REACHED();
|
||||||
return IterationDecision::Abort;
|
return IterationDecision::Break;
|
||||||
});
|
});
|
||||||
return found_ptr;
|
return found_ptr;
|
||||||
}
|
}
|
||||||
|
@ -83,11 +81,11 @@ String ELFLoader::symbolicate(dword address) const
|
||||||
{
|
{
|
||||||
if (m_sorted_symbols.is_empty()) {
|
if (m_sorted_symbols.is_empty()) {
|
||||||
m_sorted_symbols.ensure_capacity(m_image.symbol_count());
|
m_sorted_symbols.ensure_capacity(m_image.symbol_count());
|
||||||
m_image.for_each_symbol([this] (auto& symbol) {
|
m_image.for_each_symbol([this](auto& symbol) {
|
||||||
m_sorted_symbols.append({ symbol.value(), symbol.name() });
|
m_sorted_symbols.append({ symbol.value(), symbol.name() });
|
||||||
return IterationDecision::Continue;
|
return IterationDecision::Continue;
|
||||||
});
|
});
|
||||||
quick_sort(m_sorted_symbols.begin(), m_sorted_symbols.end(), [] (auto& a, auto& b) {
|
quick_sort(m_sorted_symbols.begin(), m_sorted_symbols.end(), [](auto& a, auto& b) {
|
||||||
return a.address < b.address;
|
return a.address < b.address;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
#include <AK/OwnPtr.h>
|
#include <AK/OwnPtr.h>
|
||||||
#include <AK/Vector.h>
|
#include <AK/Vector.h>
|
||||||
#if defined(KERNEL)
|
#if defined(KERNEL)
|
||||||
#include <Kernel/VirtualAddress.h>
|
# include <Kernel/VirtualAddress.h>
|
||||||
#endif
|
#endif
|
||||||
#include <AK/ELF/ELFImage.h>
|
#include <AK/ELF/ELFImage.h>
|
||||||
|
|
||||||
|
@ -34,7 +34,7 @@ private:
|
||||||
char* area_for_section_name(const char*);
|
char* area_for_section_name(const char*);
|
||||||
|
|
||||||
struct PtrAndSize {
|
struct PtrAndSize {
|
||||||
PtrAndSize() { }
|
PtrAndSize() {}
|
||||||
PtrAndSize(char* p, unsigned s)
|
PtrAndSize(char* p, unsigned s)
|
||||||
: ptr(p)
|
: ptr(p)
|
||||||
, size(s)
|
, size(s)
|
||||||
|
@ -52,4 +52,3 @@ private:
|
||||||
};
|
};
|
||||||
mutable Vector<SortedSymbol> m_sorted_symbols;
|
mutable Vector<SortedSymbol> m_sorted_symbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
1032
AK/ELF/exec_elf.h
1032
AK/ELF/exec_elf.h
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue