Skip to content

Commit

Permalink
Merge pull request #915 from no92/arch-generic-rtdl
Browse files Browse the repository at this point in the history
  • Loading branch information
Dennisbonke authored Sep 10, 2023
2 parents 74efefb + 71dd37b commit 187df8d
Show file tree
Hide file tree
Showing 10 changed files with 511 additions and 277 deletions.
2 changes: 2 additions & 0 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@ fs = import('fs')
rtdl_include_dirs = [
include_directories('options/internal/include'),
include_directories('options/internal' / host_machine.cpu_family() + '-include'),
include_directories('options/rtdl' / host_machine.cpu_family()),
include_directories('options/rtdl/include'),
]
libc_include_dirs = [
include_directories('options/internal/include'),
include_directories('options/elf/include'),
include_directories('options/lsb/include'),
include_directories('options/rtdl/include'),
include_directories('options/rtdl' / host_machine.cpu_family()),
include_directories('options/internal' / host_machine.cpu_family() + '-include')
]

Expand Down
44 changes: 42 additions & 2 deletions options/elf/include/elf.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,19 +236,43 @@ enum {
R_X86_64_TPOFF64 = 18,
R_X86_64_PC64 = 24,
R_X86_64_GOTPC32 = 26,
R_X86_64_TLSDESC = 36,
R_X86_64_IRELATIVE = 37,
};

enum {
R_386_NONE = 0,
R_386_32 = 1,
R_386_PC32 = 2,
R_386_COPY = 5,
R_386_GLOB_DAT = 6,
R_386_JMP_SLOT = 7,
R_386_RELATIVE = 8,
R_386_TLS_TPOFF = 14,
R_386_TLS_DTPMOD32 = 35,
R_386_TLS_DTPOFF32 = 36,
R_386_TLS_DESC = 41,
R_386_IRELATIVE = 42,
};

enum {
R_AARCH64_NONE = 0,
R_AARCH64_ABS64 = 257,
R_AARCH64_COPY = 1024,
R_AARCH64_GLOB_DAT = 1025,
R_AARCH64_JUMP_SLOT = 1026,
R_AARCH64_RELATIVE = 1027,
R_AARCH64_TLS_TPREL = 1030,
R_AARCH64_TLSDESC = 1031
R_AARCH64_TLS_DTPREL64 = 1028,
R_AARCH64_TLS_DTPMOD64 = 1029,
R_AARCH64_TLS_TPREL64 = 1030,
R_AARCH64_TLSDESC = 1031,
R_AARCH64_IRELATIVE = 1032,
};

#define R_AARCH64_TLS_DTPREL R_AARCH64_TLS_DTPREL64
#define R_AARCH64_TLS_DTPMOD R_AARCH64_TLS_DTPMOD64
#define R_AARCH64_TLS_TPREL R_AARCH64_TLS_TPREL64

enum {
R_RISCV_NONE = 0,
R_RISCV_32 = 1,
Expand All @@ -262,9 +286,15 @@ enum {
R_RISCV_TLS_DTPREL64 = 9,
R_RISCV_TLS_TPREL32 = 10,
R_RISCV_TLS_TPREL64 = 11,
R_RISCV_TLSDESC = 12, // currently a draft but looking good
R_RISCV_IRELATIVE = 58
};

typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel;

typedef struct {
Elf64_Addr r_offset;
uint64_t r_info;
Expand Down Expand Up @@ -292,6 +322,13 @@ __MLIBC_INLINE_DEFINITION Elf64_Xword ELF64_R_INFO(Elf64_Xword sym, Elf64_Xword
return ((((Elf64_Xword)(sym)) << 32) + (type));
}

__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_SYM(Elf32_Word info) {
return info >> 8;
}
__MLIBC_INLINE_DEFINITION Elf32_Word ELF32_R_TYPE(Elf32_Word info) {
return info & 0xFF;
}

enum {
PT_NULL = 0,
PT_LOAD = 1,
Expand Down Expand Up @@ -363,6 +400,8 @@ enum {
DT_RPATH = 15,
DT_SYMBOLIC = 16,
DT_REL = 17,
DT_RELSZ = 18,
DT_RELENT = 19,
DT_TEXTREL = 22,
DT_BIND_NOW = 24,
DT_INIT_ARRAY = 25,
Expand All @@ -383,6 +422,7 @@ enum {
DT_TLSDESC_GOT = 0x6ffffef7,
DT_VERSYM = 0x6ffffff0,
DT_RELACOUNT = 0x6ffffff9,
DT_RELCOUNT = 0x6ffffffa,
DT_FLAGS_1 = 0x6ffffffb,
DT_VERDEF = 0x6ffffffc,
DT_VERDEFNUM = 0x6ffffffd,
Expand Down
6 changes: 4 additions & 2 deletions options/internal/include/mlibc/tcb.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#include <bits/size_t.h>
#include <frg/array.hpp>

#include "elf.hpp"

/*
* Explanation of cancellation bits:
*
Expand Down Expand Up @@ -151,9 +153,9 @@ static_assert(offsetof(Tcb, cancelBits) == 0x30);
#elif defined(__aarch64__)
// The thread pointer on AArch64 points to 16 bytes before the end of the TCB.
// options/linker/aarch64/runtime.S uses the offset of dtvPointers.
static_assert(sizeof(Tcb) - offsetof(Tcb, dtvPointers) - 0x10 == 96);
static_assert(sizeof(Tcb) - offsetof(Tcb, dtvPointers) - TP_TCB_OFFSET == 96);
// sysdeps/linux/aarch64/cp_syscall.S uses the offset of cancelBits.
static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) - 0x10 == 64);
static_assert(sizeof(Tcb) - offsetof(Tcb, cancelBits) - TP_TCB_OFFSET == 64);
#elif defined(__riscv) && __riscv_xlen == 64
// The thread pointer on RISC-V points to *after* the TCB, and since
// we need to access specific fields that means that the value in
Expand Down
35 changes: 35 additions & 0 deletions options/rtdl/aarch64/elf.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#pragma once

#include <elf.h>

#define ELF_CLASS 64

using elf_ehdr = Elf64_Ehdr;
using elf_phdr = Elf64_Phdr;
using elf_dyn = Elf64_Dyn;
using elf_rel = Elf64_Rel;
using elf_rela = Elf64_Rela;
using elf_sym = Elf64_Sym;
using elf_addr = Elf64_Addr;

using elf_info = Elf64_Xword;
using elf_addend = Elf64_Sxword;

#define ELF_R_SYM ELF64_R_SYM
#define ELF_R_TYPE ELF64_R_TYPE
#define ELF_ST_BIND ELF64_ST_BIND

#define R_NONE R_AARCH64_NONE
#define R_JUMP_SLOT R_AARCH64_JUMP_SLOT
#define R_ABSOLUTE R_AARCH64_ABS64
#define R_GLOB_DAT R_AARCH64_GLOB_DAT
#define R_RELATIVE R_AARCH64_RELATIVE
#define R_IRELATIVE R_AARCH64_IRELATIVE
// #define R_OFFSET
#define R_COPY R_AARCH64_COPY
#define R_TLS_DTPMOD R_AARCH64_TLS_DTPMOD
#define R_TLS_DTPREL R_AARCH64_TLS_DTPREL
#define R_TLS_TPREL R_AARCH64_TLS_TPREL
#define R_TLSDESC R_AARCH64_TLSDESC

#define TP_TCB_OFFSET (16)
Loading

0 comments on commit 187df8d

Please sign in to comment.