i386 vsyscall support (vdso-provided sysenter/syscall instruction based)
[musl] / arch / i386 / reloc.h
1 #include <string.h>
2 #include <elf.h>
3
4 #define ETC_LDSO_PATH "/etc/ld-musl-i386.path"
5
6 #define IS_COPY(x) ((x)==R_386_COPY)
7 #define IS_PLT(x) ((x)==R_386_JMP_SLOT)
8
9 static inline void do_single_reloc(
10         struct dso *self, unsigned char *base_addr,
11         size_t *reloc_addr, int type, size_t addend,
12         Sym *sym, size_t sym_size,
13         struct symdef def, size_t sym_val)
14 {
15         switch(type) {
16         case R_386_32:
17                 *reloc_addr += sym_val;
18                 break;
19         case R_386_PC32:
20                 *reloc_addr += sym_val - (size_t)reloc_addr;
21                 break;
22         case R_386_GLOB_DAT:
23         case R_386_JMP_SLOT:
24                 *reloc_addr = sym_val;
25                 break;
26         case R_386_RELATIVE:
27                 *reloc_addr += (size_t)base_addr;
28                 break;
29         case R_386_COPY:
30                 memcpy(reloc_addr, (void *)sym_val, sym_size);
31                 break;
32         case R_386_TLS_DTPMOD32:
33                 *reloc_addr = def.dso ? def.dso->tls_id : self->tls_id;
34                 break;
35         case R_386_TLS_DTPOFF32:
36                 *reloc_addr = def.sym->st_value;
37                 break;
38         case R_386_TLS_TPOFF:
39                 *reloc_addr += def.sym
40                         ? def.sym->st_value - def.dso->tls_offset
41                         : 0 - self->tls_offset;
42                 break;
43         case R_386_TLS_TPOFF32:
44                 *reloc_addr += def.sym
45                         ? def.dso->tls_offset - def.sym->st_value
46                         : self->tls_offset;
47                 break;
48         }
49 }