From f3ddd173806fd5c60b3f034528ca24542aecc5b9 Mon Sep 17 00:00:00 2001 From: Rich Felker Date: Mon, 13 Apr 2015 02:56:26 -0400 Subject: dynamic linker bootstrap overhaul this overhaul further reduces the amount of arch-specific code needed by the dynamic linker and removes a number of assumptions, including: - that symbolic function references inside libc are bound at link time via the linker option -Bsymbolic-functions. - that libc functions used by the dynamic linker do not require access to data symbols. - that static/internal function calls and data accesses can be made without performing any relocations, or that arch-specific startup code handled any such relocations needed. removing these assumptions paves the way for allowing libc.so itself to be built with stack protector (among other things), and is achieved by a three-stage bootstrap process: 1. relative relocations are processed with a flat function. 2. symbolic relocations are processed with no external calls/data. 3. main program and dependency libs are processed with a fully-functional libc/ldso. reduction in arch-specific code is achived through the following: - crt_arch.h, used for generating crt1.o, now provides the entry point for the dynamic linker too. - asm is no longer responsible for skipping the beginning of argv[] when ldso is invoked as a command. - the functionality previously provided by __reloc_self for heavily GOT-dependent RISC archs is now the arch-agnostic stage-1. - arch-specific relocation type codes are mapped directly as macros rather than via an inline translation function/switch statement. --- src/internal/dynlink.h | 57 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 src/internal/dynlink.h (limited to 'src/internal/dynlink.h') diff --git a/src/internal/dynlink.h b/src/internal/dynlink.h new file mode 100644 index 00000000..53661d62 --- /dev/null +++ b/src/internal/dynlink.h @@ -0,0 +1,57 @@ +#ifndef _INTERNAL_RELOC_H +#define _INTERNAL_RELOC_H + +#include +#include +#include + +#if UINTPTR_MAX == 0xffffffff +typedef Elf32_Ehdr Ehdr; +typedef Elf32_Phdr Phdr; +typedef Elf32_Sym Sym; +#define R_TYPE(x) ((x)&255) +#define R_SYM(x) ((x)>>8) +#else +typedef Elf64_Ehdr Ehdr; +typedef Elf64_Phdr Phdr; +typedef Elf64_Sym Sym; +#define R_TYPE(x) ((x)&0x7fffffff) +#define R_SYM(x) ((x)>>32) +#endif + +/* These enum constants provide unmatchable default values for + * any relocation type the arch does not use. */ +enum { + REL_NONE = 0, + REL_SYMBOLIC = -100, + REL_GOT, + REL_PLT, + REL_RELATIVE, + REL_OFFSET, + REL_OFFSET32, + REL_COPY, + REL_SYM_OR_REL, + REL_DTPMOD, + REL_DTPOFF, + REL_TPOFF, + REL_TPOFF_NEG, + REL_TLSDESC, +}; + +#include "reloc.h" + +#define IS_RELATIVE(x) ( \ + (R_TYPE(x) == REL_RELATIVE) || \ + (R_TYPE(x) == REL_SYM_OR_REL && !R_SYM(x)) ) + +#ifndef NEED_MIPS_GOT_RELOCS +#define NEED_MIPS_GOT_RELOCS 0 +#endif + +#define AUX_CNT 32 +#define DYN_CNT 32 + +typedef void (*stage2_func)(unsigned char *); +typedef _Noreturn void (*stage3_func)(size_t *); + +#endif -- cgit v1.2.1