mirror of
https://github.com/RGBCube/serenity
synced 2025-07-27 20:47:45 +00:00
Everywhere: Replace ElfW(type)
macro usage with Elf_type
This works around a `clang-format-17` bug which caused certain usages to be misformatted and fail to compile. Fixes #8315
This commit is contained in:
parent
2151e6c8b4
commit
45d81dceed
20 changed files with 129 additions and 127 deletions
|
@ -13,10 +13,10 @@
|
|||
__BEGIN_DECLS
|
||||
|
||||
struct dl_phdr_info {
|
||||
ElfW(Addr) dlpi_addr;
|
||||
Elf_Addr dlpi_addr;
|
||||
char const* dlpi_name;
|
||||
const ElfW(Phdr) * dlpi_phdr;
|
||||
ElfW(Half) dlpi_phnum;
|
||||
Elf_Phdr const* dlpi_phdr;
|
||||
Elf_Half dlpi_phnum;
|
||||
};
|
||||
|
||||
int dl_iterate_phdr(int (*callback)(struct dl_phdr_info* info, size_t size, void* data), void* data);
|
||||
|
|
|
@ -244,7 +244,7 @@ static int __dl_iterate_phdr(DlIteratePhdrCallbackFunction callback, void* data)
|
|||
for (auto& it : s_global_objects) {
|
||||
auto& object = it.value;
|
||||
auto info = dl_phdr_info {
|
||||
.dlpi_addr = (ElfW(Addr))object->base_address().as_ptr(),
|
||||
.dlpi_addr = (Elf_Addr)object->base_address().as_ptr(),
|
||||
.dlpi_name = object->filepath().characters(),
|
||||
.dlpi_phdr = object->program_headers(),
|
||||
.dlpi_phnum = object->program_header_count()
|
||||
|
|
|
@ -55,7 +55,7 @@ Result<NonnullRefPtr<DynamicLoader>, DlErrorMessage> DynamicLoader::try_create(i
|
|||
|
||||
VERIFY(stat.st_size >= 0);
|
||||
auto size = static_cast<size_t>(stat.st_size);
|
||||
if (size < sizeof(ElfW(Ehdr)))
|
||||
if (size < sizeof(Elf_Ehdr))
|
||||
return DlErrorMessage { DeprecatedString::formatted("File {} has invalid ELF header", filepath) };
|
||||
|
||||
DeprecatedString file_mmap_name = DeprecatedString::formatted("ELF_DYN: {}", filepath);
|
||||
|
@ -132,7 +132,7 @@ bool DynamicLoader::validate()
|
|||
if (!image().is_valid())
|
||||
return false;
|
||||
|
||||
auto* elf_header = (ElfW(Ehdr)*)m_file_data;
|
||||
auto* elf_header = (Elf_Ehdr*)m_file_data;
|
||||
if (!validate_elf_header(*elf_header, m_file_size))
|
||||
return false;
|
||||
auto result_or_error = validate_program_headers(*elf_header, m_file_size, { m_file_data, m_file_size });
|
||||
|
|
|
@ -98,7 +98,7 @@ private:
|
|||
|
||||
class ProgramHeaderRegion {
|
||||
public:
|
||||
void set_program_header(const ElfW(Phdr) & header) { m_program_header = header; }
|
||||
void set_program_header(Elf_Phdr const& header) { m_program_header = header; }
|
||||
|
||||
// Information from ELF Program header
|
||||
u32 type() const { return m_program_header.p_type; }
|
||||
|
@ -117,7 +117,7 @@ private:
|
|||
bool is_relro() const { return type() == PT_GNU_RELRO; }
|
||||
|
||||
private:
|
||||
ElfW(Phdr) m_program_header; // Explicitly a copy of the PHDR in the image
|
||||
Elf_Phdr m_program_header; // Explicitly a copy of the PHDR in the image
|
||||
};
|
||||
|
||||
// Stage 1
|
||||
|
|
|
@ -21,7 +21,7 @@ DynamicObject::DynamicObject(DeprecatedString const& filepath, VirtualAddress ba
|
|||
, m_base_address(base_address)
|
||||
, m_dynamic_address(dynamic_section_address)
|
||||
{
|
||||
auto* header = (ElfW(Ehdr)*)base_address.as_ptr();
|
||||
auto* header = (Elf_Ehdr*)base_address.as_ptr();
|
||||
auto* const phdrs = program_headers();
|
||||
|
||||
// Calculate the base address using the PT_LOAD element with the lowest `p_vaddr` (which is the first element)
|
||||
|
@ -200,7 +200,7 @@ void DynamicObject::parse()
|
|||
// TODO: FIXME, this shouldn't be hardcoded
|
||||
// The reason we need this here is that for some reason, when there only PLT relocations, the compiler
|
||||
// doesn't insert a 'PLTRELSZ' entry to the dynamic section
|
||||
m_size_of_relocation_entry = sizeof(ElfW(Rel));
|
||||
m_size_of_relocation_entry = sizeof(Elf_Rel);
|
||||
}
|
||||
|
||||
// Whether or not RELASZ (stored in m_size_of_relocation_table) only refers to non-PLT entries is not clearly specified.
|
||||
|
@ -226,21 +226,21 @@ DynamicObject::Relocation DynamicObject::RelocationSection::relocation(unsigned
|
|||
{
|
||||
VERIFY(index < entry_count());
|
||||
unsigned offset_in_section = index * entry_size();
|
||||
auto relocation_address = (ElfW(Rela)*)address().offset(offset_in_section).as_ptr();
|
||||
auto relocation_address = (Elf_Rela*)address().offset(offset_in_section).as_ptr();
|
||||
return Relocation(m_dynamic, *relocation_address, offset_in_section, m_addend_used);
|
||||
}
|
||||
|
||||
DynamicObject::Relocation DynamicObject::RelocationSection::relocation_at_offset(unsigned offset) const
|
||||
{
|
||||
VERIFY(offset <= (m_section_size_bytes - m_entry_size));
|
||||
auto relocation_address = (ElfW(Rela)*)address().offset(offset).as_ptr();
|
||||
auto relocation_address = (Elf_Rela*)address().offset(offset).as_ptr();
|
||||
return Relocation(m_dynamic, *relocation_address, offset, m_addend_used);
|
||||
}
|
||||
|
||||
DynamicObject::Symbol DynamicObject::symbol(unsigned index) const
|
||||
{
|
||||
auto symbol_section = Section(*this, m_symbol_table_offset, (m_symbol_count * m_size_of_symbol_table_entry), m_size_of_symbol_table_entry, "DT_SYMTAB"sv);
|
||||
auto symbol_entry = (ElfW(Sym)*)symbol_section.address().offset(index * symbol_section.entry_size()).as_ptr();
|
||||
auto symbol_entry = (Elf_Sym*)symbol_section.address().offset(index * symbol_section.entry_size()).as_ptr();
|
||||
return Symbol(*this, index, *symbol_entry);
|
||||
}
|
||||
|
||||
|
@ -279,16 +279,16 @@ DynamicObject::Section DynamicObject::relr_relocation_section() const
|
|||
return Section(*this, m_relr_relocation_table_offset, m_size_of_relr_relocation_table, m_size_of_relr_relocations_entry, "DT_RELR"sv);
|
||||
}
|
||||
|
||||
ElfW(Half) DynamicObject::program_header_count() const
|
||||
Elf_Half DynamicObject::program_header_count() const
|
||||
{
|
||||
auto* header = (const ElfW(Ehdr)*)m_base_address.as_ptr();
|
||||
auto* header = (Elf_Ehdr const*)m_base_address.as_ptr();
|
||||
return header->e_phnum;
|
||||
}
|
||||
|
||||
const ElfW(Phdr) * DynamicObject::program_headers() const
|
||||
Elf_Phdr const* DynamicObject::program_headers() const
|
||||
{
|
||||
auto* header = (const ElfW(Ehdr)*)m_base_address.as_ptr();
|
||||
return (const ElfW(Phdr)*)(m_base_address.as_ptr() + header->e_phoff);
|
||||
auto* header = (Elf_Ehdr const*)m_base_address.as_ptr();
|
||||
return (Elf_Phdr const*)(m_base_address.as_ptr() + header->e_phoff);
|
||||
}
|
||||
|
||||
auto DynamicObject::HashSection::lookup_sysv_symbol(StringView name, u32 hash_value) const -> Optional<Symbol>
|
||||
|
@ -323,12 +323,12 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
|
||||
u32 const* hash_table_begin = (u32*)address().as_ptr();
|
||||
|
||||
const size_t num_buckets = hash_table_begin[0];
|
||||
const size_t num_omitted_symbols = hash_table_begin[1];
|
||||
const u32 num_maskwords = hash_table_begin[2];
|
||||
size_t const num_buckets = hash_table_begin[0];
|
||||
size_t const num_omitted_symbols = hash_table_begin[1];
|
||||
u32 const num_maskwords = hash_table_begin[2];
|
||||
// This works because num_maskwords is required to be a power of 2
|
||||
const u32 num_maskwords_bitmask = num_maskwords - 1;
|
||||
const u32 shift2 = hash_table_begin[3];
|
||||
u32 const num_maskwords_bitmask = num_maskwords - 1;
|
||||
u32 const shift2 = hash_table_begin[3];
|
||||
|
||||
BloomWord const* bloom_words = (BloomWord const*)&hash_table_begin[4];
|
||||
u32 const* const buckets = (u32 const*)&bloom_words[num_maskwords];
|
||||
|
@ -336,7 +336,7 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
|
||||
BloomWord hash1 = hash_value;
|
||||
BloomWord hash2 = hash1 >> shift2;
|
||||
const BloomWord bitmask = ((BloomWord)1 << (hash1 % bloom_word_size)) | ((BloomWord)1 << (hash2 % bloom_word_size));
|
||||
BloomWord const bitmask = ((BloomWord)1 << (hash1 % bloom_word_size)) | ((BloomWord)1 << (hash2 % bloom_word_size));
|
||||
|
||||
if ((bloom_words[(hash1 / bloom_word_size) & num_maskwords_bitmask] & bitmask) != bitmask)
|
||||
return {};
|
||||
|
@ -361,13 +361,13 @@ auto DynamicObject::HashSection::lookup_gnu_symbol(StringView name, u32 hash_val
|
|||
return {};
|
||||
}
|
||||
|
||||
StringView DynamicObject::symbol_string_table_string(ElfW(Word) index) const
|
||||
StringView DynamicObject::symbol_string_table_string(Elf_Word index) const
|
||||
{
|
||||
auto const* symbol_string_table_ptr = reinterpret_cast<char const*>(base_address().offset(m_string_table_offset + index).as_ptr());
|
||||
return StringView { symbol_string_table_ptr, strlen(symbol_string_table_ptr) };
|
||||
}
|
||||
|
||||
char const* DynamicObject::raw_symbol_string_table_string(ElfW(Word) index) const
|
||||
char const* DynamicObject::raw_symbol_string_table_string(Elf_Word index) const
|
||||
{
|
||||
return (char const*)base_address().offset(m_string_table_offset + index).as_ptr();
|
||||
}
|
||||
|
@ -384,7 +384,7 @@ DynamicObject::FinalizationFunction DynamicObject::fini_section_function() const
|
|||
return (FinalizationFunction)fini_section().address().as_ptr();
|
||||
}
|
||||
|
||||
char const* DynamicObject::name_for_dtag(ElfW(Sword) d_tag)
|
||||
char const* DynamicObject::name_for_dtag(Elf_Sword d_tag)
|
||||
{
|
||||
switch (d_tag) {
|
||||
case DT_NULL:
|
||||
|
|
|
@ -21,7 +21,7 @@ namespace ELF {
|
|||
class DynamicObject : public RefCounted<DynamicObject> {
|
||||
public:
|
||||
static NonnullRefPtr<DynamicObject> create(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
||||
static char const* name_for_dtag(ElfW(Sword) d_tag);
|
||||
static char const* name_for_dtag(Elf_Sword d_tag);
|
||||
|
||||
~DynamicObject();
|
||||
void dump() const;
|
||||
|
@ -35,24 +35,24 @@ public:
|
|||
|
||||
class DynamicEntry {
|
||||
public:
|
||||
explicit DynamicEntry(const ElfW(Dyn) & dyn)
|
||||
explicit DynamicEntry(Elf_Dyn const& dyn)
|
||||
: m_dyn(dyn)
|
||||
{
|
||||
}
|
||||
|
||||
~DynamicEntry() = default;
|
||||
|
||||
ElfW(Sword) tag() const { return m_dyn.d_tag; }
|
||||
ElfW(Addr) ptr() const { return m_dyn.d_un.d_ptr; }
|
||||
ElfW(Word) val() const { return m_dyn.d_un.d_val; }
|
||||
Elf_Sword tag() const { return m_dyn.d_tag; }
|
||||
Elf_Addr ptr() const { return m_dyn.d_un.d_ptr; }
|
||||
Elf_Word val() const { return m_dyn.d_un.d_val; }
|
||||
|
||||
private:
|
||||
const ElfW(Dyn) & m_dyn;
|
||||
Elf_Dyn const& m_dyn;
|
||||
};
|
||||
|
||||
class Symbol {
|
||||
public:
|
||||
Symbol(DynamicObject const& dynamic, unsigned index, const ElfW(Sym) & sym)
|
||||
Symbol(DynamicObject const& dynamic, unsigned index, Elf_Sym const& sym)
|
||||
: m_dynamic(dynamic)
|
||||
, m_sym(sym)
|
||||
, m_index(index)
|
||||
|
@ -92,7 +92,7 @@ public:
|
|||
|
||||
private:
|
||||
DynamicObject const& m_dynamic;
|
||||
const ElfW(Sym) & m_sym;
|
||||
Elf_Sym const& m_sym;
|
||||
unsigned const m_index;
|
||||
};
|
||||
|
||||
|
@ -153,7 +153,7 @@ public:
|
|||
|
||||
class Relocation {
|
||||
public:
|
||||
Relocation(DynamicObject const& dynamic, const ElfW(Rela) & rel, unsigned offset_in_section, bool addend_used)
|
||||
Relocation(DynamicObject const& dynamic, Elf_Rela const& rel, unsigned offset_in_section, bool addend_used)
|
||||
: m_dynamic(dynamic)
|
||||
, m_rel(rel)
|
||||
, m_offset_in_section(offset_in_section)
|
||||
|
@ -191,7 +191,7 @@ public:
|
|||
|
||||
private:
|
||||
DynamicObject const& m_dynamic;
|
||||
const ElfW(Rela) & m_rel;
|
||||
Elf_Rela const& m_rel;
|
||||
unsigned const m_offset_in_section;
|
||||
bool const m_addend_used;
|
||||
};
|
||||
|
@ -246,7 +246,7 @@ public:
|
|||
|
||||
typedef void (*InitializationFunction)();
|
||||
typedef void (*FinalizationFunction)();
|
||||
typedef ElfW(Addr) (*IfuncResolver)();
|
||||
typedef Elf_Addr (*IfuncResolver)();
|
||||
|
||||
bool has_init_section() const { return m_init_offset != 0; }
|
||||
bool has_init_array_section() const { return m_init_array_offset != 0; }
|
||||
|
@ -295,8 +295,8 @@ public:
|
|||
void set_tls_offset(FlatPtr offset) { m_tls_offset = offset; }
|
||||
void set_tls_size(FlatPtr size) { m_tls_size = size; }
|
||||
|
||||
ElfW(Half) program_header_count() const;
|
||||
const ElfW(Phdr) * program_headers() const;
|
||||
Elf_Half program_header_count() const;
|
||||
Elf_Phdr const* program_headers() const;
|
||||
|
||||
template<VoidFunction<StringView> F>
|
||||
void for_each_needed_library(F) const;
|
||||
|
@ -334,8 +334,8 @@ public:
|
|||
private:
|
||||
explicit DynamicObject(DeprecatedString const& filepath, VirtualAddress base_address, VirtualAddress dynamic_section_address);
|
||||
|
||||
StringView symbol_string_table_string(ElfW(Word)) const;
|
||||
char const* raw_symbol_string_table_string(ElfW(Word)) const;
|
||||
StringView symbol_string_table_string(Elf_Word) const;
|
||||
char const* raw_symbol_string_table_string(Elf_Word) const;
|
||||
void parse();
|
||||
|
||||
DeprecatedString m_filepath;
|
||||
|
@ -363,7 +363,7 @@ private:
|
|||
FlatPtr m_symbol_table_offset { 0 };
|
||||
size_t m_size_of_symbol_table_entry { 0 };
|
||||
|
||||
ElfW(Sword) m_procedure_linkage_table_relocation_type { -1 };
|
||||
Elf_Sword m_procedure_linkage_table_relocation_type { -1 };
|
||||
FlatPtr m_plt_relocation_offset_location { 0 }; // offset of PLT relocations, at end of relocations
|
||||
size_t m_size_of_plt_relocation_entry_list { 0 };
|
||||
Optional<FlatPtr> m_procedure_linkage_table_offset;
|
||||
|
@ -383,14 +383,14 @@ private:
|
|||
bool m_is_pie { false };
|
||||
|
||||
// DT_FLAGS
|
||||
ElfW(Word) m_dt_flags { 0 };
|
||||
Elf_Word m_dt_flags { 0 };
|
||||
|
||||
bool m_has_soname { false };
|
||||
ElfW(Word) m_soname_index { 0 }; // Index into dynstr table for SONAME
|
||||
Elf_Word m_soname_index { 0 }; // Index into dynstr table for SONAME
|
||||
bool m_has_rpath { false };
|
||||
ElfW(Word) m_rpath_index { 0 }; // Index into dynstr table for RPATH
|
||||
Elf_Word m_rpath_index { 0 }; // Index into dynstr table for RPATH
|
||||
bool m_has_runpath { false };
|
||||
ElfW(Word) m_runpath_index { 0 }; // Index into dynstr table for RUNPATH
|
||||
Elf_Word m_runpath_index { 0 }; // Index into dynstr table for RUNPATH
|
||||
|
||||
Optional<FlatPtr> m_tls_offset;
|
||||
Optional<FlatPtr> m_tls_size;
|
||||
|
@ -428,7 +428,7 @@ inline void DynamicObject::for_each_relr_relocation(F f) const
|
|||
VERIFY(section.entry_size() == sizeof(FlatPtr));
|
||||
VERIFY(section.size() >= section.entry_size() * section.entry_count());
|
||||
|
||||
auto* entries = reinterpret_cast<ElfW(Relr)*>(section.address().get());
|
||||
auto* entries = reinterpret_cast<Elf_Relr*>(section.address().get());
|
||||
auto base = base_address().get();
|
||||
FlatPtr patch_addr = 0;
|
||||
for (unsigned i = 0; i < section.entry_count(); ++i) {
|
||||
|
@ -458,7 +458,7 @@ inline void DynamicObject::for_each_symbol(F func) const
|
|||
template<IteratorFunction<DynamicObject::DynamicEntry&> F>
|
||||
inline void DynamicObject::for_each_dynamic_entry(F func) const
|
||||
{
|
||||
auto* dyns = reinterpret_cast<const ElfW(Dyn)*>(m_dynamic_address.as_ptr());
|
||||
auto* dyns = reinterpret_cast<Elf_Dyn const*>(m_dynamic_address.as_ptr());
|
||||
for (unsigned i = 0;; ++i) {
|
||||
auto&& dyn = DynamicEntry(dyns[i]);
|
||||
if (dyn.tag() == DT_NULL)
|
||||
|
@ -483,7 +483,7 @@ inline void DynamicObject::for_each_needed_library(F func) const
|
|||
for_each_dynamic_entry([func, this](auto entry) {
|
||||
if (entry.tag() != DT_NEEDED)
|
||||
return;
|
||||
ElfW(Word) offset = entry.val();
|
||||
Elf_Word offset = entry.val();
|
||||
func(symbol_string_table_string(offset));
|
||||
});
|
||||
}
|
||||
|
|
|
@ -761,6 +761,7 @@ struct elf_args {
|
|||
# define Elf_Sym Elf32_Sym
|
||||
# define Elf_Rel Elf32_Rel
|
||||
# define Elf_RelA Elf32_Rela
|
||||
# define Elf_Rela Elf32_Rela
|
||||
# define Elf_Relr Elf32_Relr
|
||||
# define Elf_Dyn Elf32_Dyn
|
||||
# define Elf_Half Elf32_Half
|
||||
|
@ -789,6 +790,7 @@ struct elf_args {
|
|||
# define Elf_Sym Elf64_Sym
|
||||
# define Elf_Rel Elf64_Rel
|
||||
# define Elf_RelA Elf64_Rela
|
||||
# define Elf_Rela Elf64_Rela
|
||||
# define Elf_Relr Elf64_Relr
|
||||
# define Elf_Dyn Elf64_Dyn
|
||||
# define Elf_Half Elf64_Half
|
||||
|
|
|
@ -121,7 +121,7 @@ unsigned Image::program_header_count() const
|
|||
|
||||
bool Image::parse()
|
||||
{
|
||||
if (m_size < sizeof(ElfW(Ehdr)) || !validate_elf_header(header(), m_size, m_verbose_logging)) {
|
||||
if (m_size < sizeof(Elf_Ehdr) || !validate_elf_header(header(), m_size, m_verbose_logging)) {
|
||||
if (m_verbose_logging)
|
||||
dbgln("ELF::Image::parse(): ELF Header not valid");
|
||||
m_valid = false;
|
||||
|
@ -198,31 +198,31 @@ char const* Image::raw_data(unsigned offset) const
|
|||
return reinterpret_cast<char const*>(m_buffer) + offset;
|
||||
}
|
||||
|
||||
const ElfW(Ehdr) & Image::header() const
|
||||
Elf_Ehdr const& Image::header() const
|
||||
{
|
||||
VERIFY(m_size >= sizeof(ElfW(Ehdr)));
|
||||
return *reinterpret_cast<const ElfW(Ehdr)*>(raw_data(0));
|
||||
VERIFY(m_size >= sizeof(Elf_Ehdr));
|
||||
return *reinterpret_cast<Elf_Ehdr const*>(raw_data(0));
|
||||
}
|
||||
|
||||
const ElfW(Phdr) & Image::program_header_internal(unsigned index) const
|
||||
Elf_Phdr const& Image::program_header_internal(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < header().e_phnum);
|
||||
return *reinterpret_cast<const ElfW(Phdr)*>(raw_data(header().e_phoff + (index * sizeof(ElfW(Phdr)))));
|
||||
return *reinterpret_cast<Elf_Phdr const*>(raw_data(header().e_phoff + (index * sizeof(Elf_Phdr))));
|
||||
}
|
||||
|
||||
const ElfW(Shdr) & Image::section_header(unsigned index) const
|
||||
Elf_Shdr const& Image::section_header(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < header().e_shnum);
|
||||
return *reinterpret_cast<const ElfW(Shdr)*>(raw_data(header().e_shoff + (index * header().e_shentsize)));
|
||||
return *reinterpret_cast<Elf_Shdr const*>(raw_data(header().e_shoff + (index * header().e_shentsize)));
|
||||
}
|
||||
|
||||
Image::Symbol Image::symbol(unsigned index) const
|
||||
{
|
||||
VERIFY(m_valid);
|
||||
VERIFY(index < symbol_count());
|
||||
auto* raw_syms = reinterpret_cast<const ElfW(Sym)*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
auto* raw_syms = reinterpret_cast<Elf_Sym const*>(raw_data(section(m_symbol_table_section_index).offset()));
|
||||
return Symbol(*this, index, raw_syms[index]);
|
||||
}
|
||||
|
||||
|
@ -243,7 +243,7 @@ Image::ProgramHeader Image::program_header(unsigned index) const
|
|||
Image::Relocation Image::RelocationSection::relocation(unsigned index) const
|
||||
{
|
||||
VERIFY(index < relocation_count());
|
||||
auto* rels = reinterpret_cast<const ElfW(Rel)*>(m_image.raw_data(offset()));
|
||||
auto* rels = reinterpret_cast<Elf_Rel const*>(m_image.raw_data(offset()));
|
||||
return Relocation(m_image, rels[index]);
|
||||
}
|
||||
|
||||
|
@ -272,7 +272,7 @@ Optional<Image::Section> Image::lookup_section(StringView name) const
|
|||
return {};
|
||||
}
|
||||
|
||||
Optional<StringView> Image::object_file_type_to_string(ElfW(Half) type)
|
||||
Optional<StringView> Image::object_file_type_to_string(Elf_Half type)
|
||||
{
|
||||
switch (type) {
|
||||
case ET_NONE:
|
||||
|
@ -290,7 +290,7 @@ Optional<StringView> Image::object_file_type_to_string(ElfW(Half) type)
|
|||
}
|
||||
}
|
||||
|
||||
Optional<StringView> Image::object_machine_type_to_string(ElfW(Half) type)
|
||||
Optional<StringView> Image::object_machine_type_to_string(Elf_Half type)
|
||||
{
|
||||
switch (type) {
|
||||
case ET_NONE:
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
|
||||
class Symbol {
|
||||
public:
|
||||
Symbol(Image const& image, unsigned index, const ElfW(Sym) & sym)
|
||||
Symbol(Image const& image, unsigned index, Elf_Sym const& sym)
|
||||
: m_image(image)
|
||||
, m_sym(sym)
|
||||
, m_index(index)
|
||||
|
@ -72,7 +72,7 @@ public:
|
|||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Sym) & m_sym;
|
||||
Elf_Sym const& m_sym;
|
||||
unsigned const m_index;
|
||||
};
|
||||
|
||||
|
@ -98,11 +98,11 @@ public:
|
|||
bool is_writable() const { return flags() & PF_W; }
|
||||
bool is_executable() const { return flags() & PF_X; }
|
||||
char const* raw_data() const { return m_image.raw_data(m_program_header.p_offset); }
|
||||
ElfW(Phdr) raw_header() const { return m_program_header; }
|
||||
Elf_Phdr raw_header() const { return m_program_header; }
|
||||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Phdr) & m_program_header;
|
||||
Elf_Phdr const& m_program_header;
|
||||
unsigned m_program_header_index { 0 };
|
||||
};
|
||||
|
||||
|
@ -133,7 +133,7 @@ public:
|
|||
protected:
|
||||
friend class RelocationSection;
|
||||
Image const& m_image;
|
||||
const ElfW(Shdr) & m_section_header;
|
||||
Elf_Shdr const& m_section_header;
|
||||
unsigned m_section_index;
|
||||
};
|
||||
|
||||
|
@ -152,7 +152,7 @@ public:
|
|||
|
||||
class Relocation {
|
||||
public:
|
||||
Relocation(Image const& image, const ElfW(Rel) & rel)
|
||||
Relocation(Image const& image, Elf_Rel const& rel)
|
||||
: m_image(image)
|
||||
, m_rel(rel)
|
||||
{
|
||||
|
@ -173,7 +173,7 @@ public:
|
|||
|
||||
private:
|
||||
Image const& m_image;
|
||||
const ElfW(Rel) & m_rel;
|
||||
Elf_Rel const& m_rel;
|
||||
};
|
||||
|
||||
unsigned symbol_count() const;
|
||||
|
@ -214,8 +214,8 @@ public:
|
|||
FlatPtr base_address() const { return (FlatPtr)m_buffer; }
|
||||
size_t size() const { return m_size; }
|
||||
|
||||
static Optional<StringView> object_file_type_to_string(ElfW(Half) type);
|
||||
static Optional<StringView> object_machine_type_to_string(ElfW(Half) type);
|
||||
static Optional<StringView> object_file_type_to_string(Elf_Half type);
|
||||
static Optional<StringView> object_machine_type_to_string(Elf_Half type);
|
||||
static Optional<StringView> object_abi_type_to_string(Elf_Byte type);
|
||||
|
||||
bool has_symbols() const { return symbol_count(); }
|
||||
|
@ -227,9 +227,9 @@ public:
|
|||
|
||||
private:
|
||||
char const* raw_data(unsigned offset) const;
|
||||
const ElfW(Ehdr) & header() const;
|
||||
const ElfW(Shdr) & section_header(unsigned) const;
|
||||
const ElfW(Phdr) & program_header_internal(unsigned) const;
|
||||
Elf_Ehdr const& header() const;
|
||||
Elf_Shdr const& section_header(unsigned) const;
|
||||
Elf_Phdr const& program_header_internal(unsigned) const;
|
||||
StringView table_string(unsigned offset) const;
|
||||
StringView section_header_table_string(unsigned offset) const;
|
||||
StringView section_index_to_string(unsigned index) const;
|
||||
|
|
|
@ -12,8 +12,8 @@ namespace ELF {
|
|||
bool perform_relative_relocations(FlatPtr base_address)
|
||||
{
|
||||
|
||||
ElfW(Ehdr)* header = (ElfW(Ehdr)*)(base_address);
|
||||
ElfW(Phdr)* pheader = (ElfW(Phdr)*)(base_address + header->e_phoff);
|
||||
Elf_Ehdr* header = (Elf_Ehdr*)(base_address);
|
||||
Elf_Phdr* pheader = (Elf_Phdr*)(base_address + header->e_phoff);
|
||||
FlatPtr dynamic_section_addr = 0;
|
||||
for (size_t i = 0; i < (size_t)header->e_phnum; ++i, ++pheader) {
|
||||
if (pheader->p_type != PT_DYNAMIC)
|
||||
|
@ -30,7 +30,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
FlatPtr relr_relocation_section_addr = 0;
|
||||
size_t relr_relocation_table_size = 0;
|
||||
bool use_addend = false;
|
||||
auto* dyns = reinterpret_cast<const ElfW(Dyn)*>(dynamic_section_addr);
|
||||
auto* dyns = reinterpret_cast<Elf_Dyn const*>(dynamic_section_addr);
|
||||
for (unsigned i = 0;; ++i) {
|
||||
auto& dyn = dyns[i];
|
||||
if (dyn.d_tag == DT_NULL)
|
||||
|
@ -58,7 +58,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
|
||||
for (unsigned i = 0; i < relocation_count; ++i) {
|
||||
size_t offset_in_section = i * relocation_entry_size;
|
||||
auto* relocation = (ElfW(Rela)*)(relocation_section_addr + offset_in_section);
|
||||
auto* relocation = (Elf_Rela*)(relocation_section_addr + offset_in_section);
|
||||
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE || ELF64_R_TYPE(relocation->r_info) == R_AARCH64_RELATIVE);
|
||||
auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset);
|
||||
FlatPtr relocated_address;
|
||||
|
@ -78,7 +78,7 @@ bool perform_relative_relocations(FlatPtr base_address)
|
|||
__builtin_memcpy(patch_ptr, &relocated_address, sizeof(FlatPtr));
|
||||
};
|
||||
|
||||
auto* entries = reinterpret_cast<ElfW(Relr)*>(relr_relocation_section_addr);
|
||||
auto* entries = reinterpret_cast<Elf_Relr*>(relr_relocation_section_addr);
|
||||
FlatPtr* patch_ptr = nullptr;
|
||||
|
||||
for (unsigned i = 0; i < relr_relocation_table_size / sizeof(FlatPtr); ++i) {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
namespace ELF {
|
||||
|
||||
bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool verbose)
|
||||
bool validate_elf_header(Elf_Ehdr const& elf_header, size_t file_size, bool verbose)
|
||||
{
|
||||
if (!IS_ELF(elf_header)) {
|
||||
if (verbose)
|
||||
|
@ -80,9 +80,9 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
return false;
|
||||
}
|
||||
|
||||
if (sizeof(ElfW(Ehdr)) != elf_header.e_ehsize) {
|
||||
if (sizeof(Elf_Ehdr) != elf_header.e_ehsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect ELF header size..? ({}), expected ({})!", elf_header.e_ehsize, sizeof(ElfW(Ehdr)));
|
||||
dbgln("File has incorrect ELF header size..? ({}), expected ({})!", elf_header.e_ehsize, sizeof(Elf_Ehdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -134,15 +134,15 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
}
|
||||
}
|
||||
|
||||
if (0 != elf_header.e_phnum && sizeof(ElfW(Phdr)) != elf_header.e_phentsize) {
|
||||
if (0 != elf_header.e_phnum && sizeof(Elf_Phdr) != elf_header.e_phentsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect program header size..? ({}), expected ({}).", elf_header.e_phentsize, sizeof(ElfW(Phdr)));
|
||||
dbgln("File has incorrect program header size..? ({}), expected ({}).", elf_header.e_phentsize, sizeof(Elf_Phdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
if (sizeof(ElfW(Shdr)) != elf_header.e_shentsize) {
|
||||
if (sizeof(Elf_Shdr) != elf_header.e_shentsize) {
|
||||
if (verbose)
|
||||
dbgln("File has incorrect section header size..? ({}), expected ({}).", elf_header.e_shentsize, sizeof(ElfW(Shdr)));
|
||||
dbgln("File has incorrect section header size..? ({}), expected ({}).", elf_header.e_shentsize, sizeof(Elf_Shdr));
|
||||
return false;
|
||||
}
|
||||
|
||||
|
@ -199,7 +199,7 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
|
|||
return true;
|
||||
}
|
||||
|
||||
ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder, Optional<size_t>* requested_stack_size, bool verbose)
|
||||
ErrorOr<bool> validate_program_headers(Elf_Ehdr const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder, Optional<size_t>* requested_stack_size, bool verbose)
|
||||
{
|
||||
Checked<size_t> total_size_of_program_headers = elf_header.e_phnum;
|
||||
total_size_of_program_headers *= elf_header.e_phentsize;
|
||||
|
@ -226,7 +226,7 @@ ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file
|
|||
}
|
||||
|
||||
size_t num_program_headers = elf_header.e_phnum;
|
||||
auto program_header_begin = (const ElfW(Phdr)*)buffer.offset(elf_header.e_phoff);
|
||||
auto program_header_begin = (Elf_Phdr const*)buffer.offset(elf_header.e_phoff);
|
||||
|
||||
for (size_t header_index = 0; header_index < num_program_headers; ++header_index) {
|
||||
auto& program_header = program_header_begin[header_index];
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
|
||||
namespace ELF {
|
||||
|
||||
bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool verbose = true);
|
||||
ErrorOr<bool> validate_program_headers(ElfW(Ehdr) const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder = nullptr, Optional<size_t>* requested_stack_size = nullptr, bool verbose = true);
|
||||
bool validate_elf_header(Elf_Ehdr const& elf_header, size_t file_size, bool verbose = true);
|
||||
ErrorOr<bool> validate_program_headers(Elf_Ehdr const& elf_header, size_t file_size, ReadonlyBytes buffer, StringBuilder* interpreter_path_builder = nullptr, Optional<size_t>* requested_stack_size = nullptr, bool verbose = true);
|
||||
|
||||
} // end namespace ELF
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue