LibELF+LibSymbolication: Remove i686 support

This commit is contained in:
Liav A 2022-10-04 02:53:58 +03:00 committed by Andreas Kling
parent 2f7443c900
commit a4c87fac56
Notes: sideshowbarker 2024-07-17 10:31:19 +09:00
7 changed files with 1 additions and 94 deletions

View file

@ -478,19 +478,12 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
};
switch (relocation.type()) {
#if ARCH(I386)
case R_386_NONE:
#else
case R_X86_64_NONE:
#endif
// Apparently most loaders will just skip these?
// Seems if the 'link editor' generates one something is funky with your code
break;
#if ARCH(I386)
case R_386_32: {
#else
case R_X86_64_64: {
#endif
auto symbol = relocation.symbol();
auto res = lookup_symbol(symbol);
if (!res.has_value()) {
@ -508,20 +501,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
*patch_ptr = call_ifunc_resolver(VirtualAddress { *patch_ptr }).get();
break;
}
#if ARCH(I386)
case R_386_PC32: {
auto symbol = relocation.symbol();
auto result = lookup_symbol(symbol);
if (!result.has_value())
return RelocationResult::Failed;
auto relative_offset = result.value().address - m_dynamic_object->base_address().offset(relocation.offset());
*patch_ptr += relative_offset.get();
break;
}
case R_386_GLOB_DAT: {
#else
case R_X86_64_GLOB_DAT: {
#endif
auto symbol = relocation.symbol();
auto res = lookup_symbol(symbol);
VirtualAddress symbol_location;
@ -549,11 +529,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
*patch_ptr = symbol_location.get();
break;
}
#if ARCH(I386)
case R_386_RELATIVE: {
#else
case R_X86_64_RELATIVE: {
#endif
if (!image().is_dynamic())
break;
// FIXME: According to the spec, R_386_relative ones must be done first.
@ -565,12 +541,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
*patch_ptr += m_dynamic_object->base_address().get();
break;
}
#if ARCH(I386)
case R_386_TLS_TPOFF32:
case R_386_TLS_TPOFF: {
#else
case R_X86_64_TPOFF64: {
#endif
auto symbol = relocation.symbol();
FlatPtr symbol_value;
DynamicObject const* dynamic_object_of_symbol;
@ -595,11 +566,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
break;
}
#if ARCH(I386)
case R_386_JMP_SLOT: {
#else
case R_X86_64_JUMP_SLOT: {
#endif
// FIXME: Or BIND_NOW flag passed in?
if (m_dynamic_object->must_bind_now()) {
// Eagerly BIND_NOW the PLT entries, doing all the symbol looking goodness
@ -613,11 +580,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_relocation(const ELF::DynamicO
}
break;
}
#if ARCH(I386)
case R_386_IRELATIVE: {
#else
case R_X86_64_IRELATIVE: {
#endif
VirtualAddress resolver;
if (relocation.addend_used())
resolver = m_dynamic_object->base_address().offset(relocation.addend());

View file

@ -484,11 +484,7 @@ NonnullRefPtr<DynamicObject> DynamicObject::create(DeprecatedString const& filep
VirtualAddress DynamicObject::patch_plt_entry(u32 relocation_offset)
{
auto relocation = plt_relocation_section().relocation_at_offset(relocation_offset);
#if ARCH(I386)
VERIFY(relocation.type() == R_386_JMP_SLOT);
#else
VERIFY(relocation.type() == R_X86_64_JUMP_SLOT);
#endif
auto symbol = relocation.symbol();
auto relocation_address = (FlatPtr*)relocation.address().as_ptr();

View file

@ -65,19 +65,11 @@ public:
FlatPtr value() const { return m_sym.st_value; }
size_t size() const { return m_sym.st_size; }
unsigned index() const { return m_index; }
#if ARCH(I386)
unsigned type() const
{
return ELF32_ST_TYPE(m_sym.st_info);
}
unsigned bind() const { return ELF32_ST_BIND(m_sym.st_info); }
#else
unsigned type() const
{
return ELF64_ST_TYPE(m_sym.st_info);
}
unsigned bind() const { return ELF64_ST_BIND(m_sym.st_info); }
#endif
bool is_undefined() const
{
@ -167,19 +159,11 @@ public:
unsigned offset_in_section() const { return m_offset_in_section; }
unsigned offset() const { return m_rel.r_offset; }
#if ARCH(I386)
unsigned type() const
{
return ELF32_R_TYPE(m_rel.r_info);
}
unsigned symbol_index() const { return ELF32_R_SYM(m_rel.r_info); }
#else
unsigned type() const
{
return ELF64_R_TYPE(m_rel.r_info);
}
unsigned symbol_index() const { return ELF64_R_SYM(m_rel.r_info); }
#endif
unsigned addend() const
{
VERIFY(m_addend_used);

View file

@ -58,19 +58,11 @@ public:
FlatPtr value() const { return m_sym.st_value; }
size_t size() const { return m_sym.st_size; }
unsigned index() const { return m_index; }
#if ARCH(I386)
unsigned type() const
{
return ELF32_ST_TYPE(m_sym.st_info);
}
unsigned bind() const { return ELF32_ST_BIND(m_sym.st_info); }
#else
unsigned type() const
{
return ELF64_ST_TYPE(m_sym.st_info);
}
unsigned bind() const { return ELF64_ST_BIND(m_sym.st_info); }
#endif
Section section() const
{
return m_image.section(section_index());
@ -169,19 +161,11 @@ public:
~Relocation() = default;
size_t offset() const { return m_rel.r_offset; }
#if ARCH(I386)
unsigned type() const
{
return ELF32_R_TYPE(m_rel.r_info);
}
unsigned symbol_index() const { return ELF32_R_SYM(m_rel.r_info); }
#else
unsigned type() const
{
return ELF64_R_TYPE(m_rel.r_info);
}
unsigned symbol_index() const { return ELF64_R_SYM(m_rel.r_info); }
#endif
Symbol symbol() const
{
return m_image.symbol(symbol_index());

View file

@ -59,11 +59,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);
#if ARCH(I386)
VERIFY(ELF32_R_TYPE(relocation->r_info) == R_386_RELATIVE);
#else
VERIFY(ELF64_R_TYPE(relocation->r_info) == R_X86_64_RELATIVE);
#endif
auto* patch_address = (FlatPtr*)(base_address + relocation->r_offset);
FlatPtr relocated_address;
if (use_addend) {

View file

@ -23,13 +23,8 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
return false;
}
#if ARCH(I386)
auto expected_class = ELFCLASS32;
auto expected_bitness = 32;
#else
auto expected_class = ELFCLASS64;
auto expected_bitness = 64;
#endif
if (expected_class != elf_header.e_ident[EI_CLASS]) {
if (verbose)
dbgln("File is not a {}-bit ELF file.", expected_bitness);
@ -61,13 +56,8 @@ bool validate_elf_header(ElfW(Ehdr) const& elf_header, size_t file_size, bool ve
return false;
}
#if ARCH(I386)
auto expected_machine = EM_386;
auto expected_machine_name = "i386";
#else
auto expected_machine = EM_X86_64;
auto expected_machine_name = "x86-64";
#endif
if (expected_machine != elf_header.e_machine) {
if (verbose)

View file

@ -43,13 +43,7 @@ Optional<FlatPtr> kernel_base()
return {};
}
auto kernel_base_str = DeprecatedString { file.value()->read_all(), NoChomp };
#if ARCH(I386)
using AddressType = u32;
#elif ARCH(X86_64) || ARCH(AARCH64)
using AddressType = u64;
#else
# error Unknown architecture
#endif
auto maybe_kernel_base = kernel_base_str.to_uint<AddressType>();
if (!maybe_kernel_base.has_value()) {
s_kernel_base_state = KernelBaseState::Invalid;