mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 19:27:45 +00:00
ELF: Run clang-format on everything.
This commit is contained in:
parent
e42c3b4fd7
commit
9145917bf0
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:
|
||||||
|
@ -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;
|
||||||
|
@ -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
|
||||||
|
|
||||||
|
@ -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;
|
||||||
|
@ -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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -52,4 +52,3 @@ private:
|
||||||
};
|
};
|
||||||
mutable Vector<SortedSymbol> m_sorted_symbols;
|
mutable Vector<SortedSymbol> m_sorted_symbols;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -117,10 +117,7 @@ typedef uint16_t Elf64_Quarter;
|
||||||
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
#define ELFOSABI_STANDALONE 255 /* Standalone (embedded) application */
|
||||||
|
|
||||||
/* e_ident */
|
/* e_ident */
|
||||||
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && \
|
#define IS_ELF(ehdr) ((ehdr).e_ident[EI_MAG0] == ELFMAG0 && (ehdr).e_ident[EI_MAG1] == ELFMAG1 && (ehdr).e_ident[EI_MAG2] == ELFMAG2 && (ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
||||||
(ehdr).e_ident[EI_MAG1] == ELFMAG1 && \
|
|
||||||
(ehdr).e_ident[EI_MAG2] == ELFMAG2 && \
|
|
||||||
(ehdr).e_ident[EI_MAG3] == ELFMAG3)
|
|
||||||
|
|
||||||
/* ELF Header */
|
/* ELF Header */
|
||||||
typedef struct elfhdr {
|
typedef struct elfhdr {
|
||||||
|
@ -311,7 +308,6 @@ typedef struct {
|
||||||
#define ELF_TEXT ".text" /* code */
|
#define ELF_TEXT ".text" /* code */
|
||||||
#define ELF_OPENBSDRANDOMDATA ".openbsd.randomdata" /* constant randomdata */
|
#define ELF_OPENBSDRANDOMDATA ".openbsd.randomdata" /* constant randomdata */
|
||||||
|
|
||||||
|
|
||||||
/* Section Attribute Flags - sh_flags */
|
/* Section Attribute Flags - sh_flags */
|
||||||
#define SHF_WRITE 0x1 /* Writable */
|
#define SHF_WRITE 0x1 /* Writable */
|
||||||
#define SHF_ALLOC 0x2 /* occupies memory */
|
#define SHF_ALLOC 0x2 /* occupies memory */
|
||||||
|
@ -518,7 +514,7 @@ typedef struct {
|
||||||
#define DT_INIT 12 /* address of initialization func. */
|
#define DT_INIT 12 /* address of initialization func. */
|
||||||
#define DT_FINI 13 /* address of termination function */
|
#define DT_FINI 13 /* address of termination function */
|
||||||
#define DT_SONAME 14 /* string table offset of shared obj */
|
#define DT_SONAME 14 /* string table offset of shared obj */
|
||||||
#define DT_RPATH 15 /* string table offset of library
|
#define DT_RPATH 15 /* string table offset of library \
|
||||||
search path */
|
search path */
|
||||||
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
#define DT_SYMBOLIC 16 /* start sym search in shared obj. */
|
||||||
#define DT_REL 17 /* address of rel. tbl. w addends */
|
#define DT_REL 17 /* address of rel. tbl. w addends */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue