1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-28 06:37:35 +00:00

LibELF: Refactor how arch-specific dynamic relocation types are handled

We currently expect that the relocation type numbers are unique across
all architectures. But RISC-V and x86_64 use the same numbers for
different relocation types (R_X86_64_COPY = R_RISCV_JUMP_SLOT = 5).

So create a generic reloc type enum which maps to the arch-specific
reloc types instead of checking for all arch reloc types individually
everywhere.
This commit is contained in:
Sönke Holz 2024-02-10 20:43:07 +01:00 committed by Andrew Kaster
parent c216e7439f
commit f8628f94b8
6 changed files with 98 additions and 23 deletions

View file

@ -0,0 +1,17 @@
/*
* Copyright (c) 2024, Sönke Holz <sholz8530@gmail.com>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#pragma once
#include <AK/Platform.h>
#if ARCH(AARCH64)
# include <Userland/Libraries/LibELF/Arch/aarch64/GenericDynamicRelocationType.h>
#elif ARCH(X86_64)
# include <Userland/Libraries/LibELF/Arch/x86_64/GenericDynamicRelocationType.h>
#else
# error Unknown architecture
#endif

View file

@ -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_AARCH64()
namespace ELF {
enum class GenericDynamicRelocationType : unsigned {
NONE = R_AARCH64_NONE,
ABSOLUTE = R_AARCH64_ABS64,
COPY = R_AARCH64_COPY,
GLOB_DAT = R_AARCH64_GLOB_DAT,
JUMP_SLOT = R_AARCH64_JUMP_SLOT,
RELATIVE = R_AARCH64_RELATIVE,
TLS_DTPMOD = R_AARCH64_TLS_DTPMOD,
TLS_DTPREL = R_AARCH64_TLS_DTPREL,
TLS_TPREL = R_AARCH64_TLS_TPREL,
TLSDESC = R_AARCH64_TLSDESC,
IRELATIVE = R_AARCH64_IRELATIVE,
};
}

View file

@ -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_X86()
namespace ELF {
enum class GenericDynamicRelocationType : unsigned {
NONE = R_X86_64_NONE,
ABSOLUTE = R_X86_64_64,
COPY = R_X86_64_COPY,
GLOB_DAT = R_X86_64_GLOB_DAT,
JUMP_SLOT = R_X86_64_JUMP_SLOT,
RELATIVE = R_X86_64_RELATIVE,
TLS_DTPMOD = R_X86_64_DTPMOD64,
TLS_DTPREL = R_X86_64_DTPOFF64,
TLS_TPREL = R_X86_64_TPOFF64,
TLSDESC = R_X86_64_TLSDESC,
IRELATIVE = R_X86_64_IRELATIVE,
};
}