1#pragma once 2 3#include <elf.h> 4#include <features.h> 5#include <link.h> 6#include <stddef.h> 7#include <stdint.h> 8 9#include "libc.h" 10 11typedef Elf64_Ehdr Ehdr; 12typedef Elf64_Phdr Phdr; 13typedef Elf64_Sym Sym; 14#define R_TYPE(x) ((x)&0x7fffffff) 15#define R_SYM(x) ((x) >> 32) 16#define R_INFO ELF64_R_INFO 17 18/* These enum constants provide unmatchable default values for 19 * any relocation type the arch does not use. */ 20enum { 21 REL_NONE = 0, 22 REL_SYMBOLIC = -100, 23 REL_GOT, 24 REL_PLT, 25 REL_RELATIVE, 26 REL_OFFSET, 27 REL_OFFSET32, 28 REL_COPY, 29 REL_DTPMOD, 30 REL_DTPOFF, 31 REL_TPOFF, 32 REL_TPOFF_NEG, 33 REL_TLSDESC, 34 REL_FUNCDESC, 35 REL_FUNCDESC_VAL, 36}; 37 38#include "reloc.h" 39 40#ifndef DT_DEBUG_INDIRECT 41#define DT_DEBUG_INDIRECT 0 42#endif 43 44// This is the return value of the dynamic linker startup functions. 45// They return all the way back to _start so as to pop their stack 46// frames. The DL_START_ASM code at _start then receives these two 47// values and jumps to the entry point with the argument in place for 48// the C ABI and return address/frame pointer cleared so it's the base 49// of the call stack. 50#ifndef DL_START_RETURN 51typedef struct { 52 void* arg; 53 void* entry; 54} dl_start_return_t; 55#define DL_START_RETURN(entry, arg) \ 56 (dl_start_return_t) { (arg), (entry) } 57#endif 58 59dl_start_return_t _dl_start(void* start_arg, void* vdso) ATTR_LIBC_VISIBILITY; 60dl_start_return_t __dls2(void* start_arg, void* vdso) ATTR_LIBC_VISIBILITY; 61 62// We can access these with simple PC-relative relocs. 63// Both of these symbols are defined automagically by the linker. 64// Since we use a standard 0-based DSO layout, __ehdr_start matches 65// the lowest address in the DSO image. 66extern const ElfW(Ehdr) __ehdr_start[] ATTR_LIBC_VISIBILITY; 67extern ElfW(Dyn) _DYNAMIC[] ATTR_LIBC_VISIBILITY; 68 69void _dl_log_unlogged(void) ATTR_LIBC_VISIBILITY; 70void _dl_log_write(const char *buffer, size_t len) ATTR_LIBC_VISIBILITY; 71