mirror of
https://github.com/RGBCube/serenity
synced 2025-05-14 07:54:58 +00:00
LibELF+readelf: Add support for RISC-V dynamic relocation types
This commit is contained in:
parent
f8628f94b8
commit
0b0ea19d12
5 changed files with 63 additions and 1 deletions
|
@ -10,6 +10,8 @@
|
||||||
|
|
||||||
#if ARCH(AARCH64)
|
#if ARCH(AARCH64)
|
||||||
# include <Userland/Libraries/LibELF/Arch/aarch64/GenericDynamicRelocationType.h>
|
# include <Userland/Libraries/LibELF/Arch/aarch64/GenericDynamicRelocationType.h>
|
||||||
|
#elif ARCH(RISCV64)
|
||||||
|
# include <Userland/Libraries/LibELF/Arch/riscv64/GenericDynamicRelocationType.h>
|
||||||
#elif ARCH(X86_64)
|
#elif ARCH(X86_64)
|
||||||
# include <Userland/Libraries/LibELF/Arch/x86_64/GenericDynamicRelocationType.h>
|
# include <Userland/Libraries/LibELF/Arch/x86_64/GenericDynamicRelocationType.h>
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -0,0 +1,30 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2024, Sönke Holz <sholz8530@gmail.com>
|
||||||
|
*
|
||||||
|
* SPDX-License-Identifier: BSD-2-Clause
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <Userland/Libraries/LibELF/ELFABI.h>
|
||||||
|
|
||||||
|
#include <AK/Platform.h>
|
||||||
|
VALIDATE_IS_RISCV64()
|
||||||
|
|
||||||
|
namespace ELF {
|
||||||
|
|
||||||
|
enum class GenericDynamicRelocationType : unsigned {
|
||||||
|
NONE = R_RISCV_NONE,
|
||||||
|
ABSOLUTE = R_RISCV_64,
|
||||||
|
COPY = R_RISCV_COPY,
|
||||||
|
// there is no R_RISCV_GLOB_DAT
|
||||||
|
JUMP_SLOT = R_RISCV_JUMP_SLOT,
|
||||||
|
RELATIVE = R_RISCV_RELATIVE,
|
||||||
|
TLS_DTPMOD = R_RISCV_TLS_DTPMOD64,
|
||||||
|
TLS_DTPREL = R_RISCV_TLS_DTPREL64,
|
||||||
|
TLS_TPREL = R_RISCV_TLS_TPREL64,
|
||||||
|
TLSDESC = R_RISCV_TLSDESC,
|
||||||
|
IRELATIVE = R_RISCV_IRELATIVE,
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
|
@ -536,7 +536,7 @@ void DynamicLoader::load_program_headers()
|
||||||
|
|
||||||
DynamicLoader::RelocationResult DynamicLoader::do_direct_relocation(DynamicObject::Relocation const& relocation,
|
DynamicLoader::RelocationResult DynamicLoader::do_direct_relocation(DynamicObject::Relocation const& relocation,
|
||||||
Optional<DynamicLoader::CachedLookupResult>& cached_result,
|
Optional<DynamicLoader::CachedLookupResult>& cached_result,
|
||||||
ShouldInitializeWeak should_initialize_weak,
|
[[maybe_unused]] ShouldInitializeWeak should_initialize_weak,
|
||||||
ShouldCallIfuncResolver should_call_ifunc_resolver)
|
ShouldCallIfuncResolver should_call_ifunc_resolver)
|
||||||
{
|
{
|
||||||
FlatPtr* patch_ptr = nullptr;
|
FlatPtr* patch_ptr = nullptr;
|
||||||
|
@ -603,6 +603,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_direct_relocation(DynamicObjec
|
||||||
*patch_ptr = call_ifunc_resolver(VirtualAddress { *patch_ptr }).get();
|
*patch_ptr = call_ifunc_resolver(VirtualAddress { *patch_ptr }).get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#if !ARCH(RISCV64)
|
||||||
case GLOB_DAT: {
|
case GLOB_DAT: {
|
||||||
auto symbol = relocation.symbol();
|
auto symbol = relocation.symbol();
|
||||||
auto res = lookup_symbol(symbol);
|
auto res = lookup_symbol(symbol);
|
||||||
|
@ -633,6 +634,7 @@ DynamicLoader::RelocationResult DynamicLoader::do_direct_relocation(DynamicObjec
|
||||||
*patch_ptr = symbol_location.get();
|
*patch_ptr = symbol_location.get();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
case RELATIVE: {
|
case RELATIVE: {
|
||||||
if (!image().is_dynamic())
|
if (!image().is_dynamic())
|
||||||
break;
|
break;
|
||||||
|
|
|
@ -882,3 +882,27 @@ struct elf_args {
|
||||||
R(R_AARCH64_TLS_TPREL) \
|
R(R_AARCH64_TLS_TPREL) \
|
||||||
R(R_AARCH64_TLSDESC) \
|
R(R_AARCH64_TLSDESC) \
|
||||||
R(R_AARCH64_IRELATIVE)
|
R(R_AARCH64_IRELATIVE)
|
||||||
|
|
||||||
|
/* https://github.com/riscv-non-isa/riscv-elf-psabi-doc/blob/v1.0/riscv-elf.adoc#relocations */
|
||||||
|
#define R_RISCV_NONE 0
|
||||||
|
#define R_RISCV_64 2
|
||||||
|
#define R_RISCV_RELATIVE 3
|
||||||
|
#define R_RISCV_COPY 4
|
||||||
|
#define R_RISCV_JUMP_SLOT 5
|
||||||
|
#define R_RISCV_TLS_DTPMOD64 7
|
||||||
|
#define R_RISCV_TLS_DTPREL64 9
|
||||||
|
#define R_RISCV_TLS_TPREL64 11
|
||||||
|
#define R_RISCV_TLSDESC 12
|
||||||
|
#define R_RISCV_IRELATIVE 58
|
||||||
|
|
||||||
|
#define __ENUMERATE_RISCV_DYNAMIC_RELOCS(R) \
|
||||||
|
R(R_RISCV_NONE) \
|
||||||
|
R(R_RISCV_64) \
|
||||||
|
R(R_RISCV_RELATIVE) \
|
||||||
|
R(R_RISCV_COPY) \
|
||||||
|
R(R_RISCV_JUMP_SLOT) \
|
||||||
|
R(R_RISCV_TLS_DTPMOD64) \
|
||||||
|
R(R_RISCV_TLS_DTPREL64) \
|
||||||
|
R(R_RISCV_TLS_TPREL64) \
|
||||||
|
R(R_RISCV_TLSDESC) \
|
||||||
|
R(R_RISCV_IRELATIVE)
|
||||||
|
|
|
@ -197,6 +197,10 @@ static char const* object_relocation_type_to_string(Elf_Half machine, Elf_Word t
|
||||||
switch (type) {
|
switch (type) {
|
||||||
__ENUMERATE_AARCH64_DYNAMIC_RELOCS(ENUMERATE_RELOCATION)
|
__ENUMERATE_AARCH64_DYNAMIC_RELOCS(ENUMERATE_RELOCATION)
|
||||||
}
|
}
|
||||||
|
} else if (machine == EM_RISCV) {
|
||||||
|
switch (type) {
|
||||||
|
__ENUMERATE_RISCV_DYNAMIC_RELOCS(ENUMERATE_RELOCATION)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
#undef ENUMERATE_RELOCATION
|
#undef ENUMERATE_RELOCATION
|
||||||
return "(?)";
|
return "(?)";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue