add general fdpic support in dynamic linker and arch support for sh
[musl] / src / internal / dynlink.h
1 #ifndef _INTERNAL_RELOC_H
2 #define _INTERNAL_RELOC_H
3
4 #include <features.h>
5 #include <elf.h>
6 #include <stdint.h>
7
8 #if UINTPTR_MAX == 0xffffffff
9 typedef Elf32_Ehdr Ehdr;
10 typedef Elf32_Phdr Phdr;
11 typedef Elf32_Sym Sym;
12 #define R_TYPE(x) ((x)&255)
13 #define R_SYM(x) ((x)>>8)
14 #else
15 typedef Elf64_Ehdr Ehdr;
16 typedef Elf64_Phdr Phdr;
17 typedef Elf64_Sym Sym;
18 #define R_TYPE(x) ((x)&0x7fffffff)
19 #define R_SYM(x) ((x)>>32)
20 #endif
21
22 /* These enum constants provide unmatchable default values for
23  * any relocation type the arch does not use. */
24 enum {
25         REL_NONE = 0,
26         REL_SYMBOLIC = -100,
27         REL_GOT,
28         REL_PLT,
29         REL_RELATIVE,
30         REL_OFFSET,
31         REL_OFFSET32,
32         REL_COPY,
33         REL_SYM_OR_REL,
34         REL_DTPMOD,
35         REL_DTPOFF,
36         REL_TPOFF,
37         REL_TPOFF_NEG,
38         REL_TLSDESC,
39         REL_FUNCDESC,
40         REL_FUNCDESC_VAL,
41 };
42
43 struct fdpic_loadseg {
44         uintptr_t addr, p_vaddr, p_memsz;
45 };
46
47 struct fdpic_loadmap {
48         unsigned short version, nsegs;
49         struct fdpic_loadseg segs[];
50 };
51
52 struct fdpic_dummy_loadmap {
53         unsigned short version, nsegs;
54         struct fdpic_loadseg segs[1];
55 };
56
57 #include "reloc.h"
58
59 #ifndef DL_FDPIC
60 #define DL_FDPIC 0
61 #endif
62
63 #if !DL_FDPIC
64 #define IS_RELATIVE(x,s) ( \
65         (R_TYPE(x) == REL_RELATIVE) || \
66         (R_TYPE(x) == REL_SYM_OR_REL && !R_SYM(x)) )
67 #else
68 #define IS_RELATIVE(x,s) ( ( \
69         (R_TYPE(x) == REL_FUNCDESC_VAL) || \
70         (R_TYPE(x) == REL_SYMBOLIC) ) \
71         && (((s)[R_SYM(x)].st_info & 0xf) == STT_SECTION) )
72 #endif
73
74 #ifndef NEED_MIPS_GOT_RELOCS
75 #define NEED_MIPS_GOT_RELOCS 0
76 #endif
77
78 #define AUX_CNT 32
79 #define DYN_CNT 32
80
81 typedef void (*stage2_func)(unsigned char *, size_t *);
82 typedef _Noreturn void (*stage3_func)(size_t *);
83
84 #endif