dynamic linking support for powerpc
[musl] / arch / powerpc / reloc.h
1 #include <string.h>
2 #include <elf.h>
3
4 #define ETC_LDSO_PATH "/etc/ld-musl-powerpc.path"
5
6 #define IS_COPY(x) ((x)==R_PPC_COPY)
7 #define IS_PLT(x) ((x)==R_PPC_JMP_SLOT)
8
9 // see linux' arch/powerpc/include/asm/elf.h 
10 static inline void do_single_reloc(
11         struct dso *self, unsigned char *base_addr,
12         size_t *reloc_addr, int type, size_t addend,
13         Sym *sym, size_t sym_size,
14         struct symdef def, size_t sym_val)
15 {
16         switch(type) {
17         case R_PPC_GLOB_DAT:
18         case R_PPC_JMP_SLOT:
19         case R_PPC_ADDR32:
20                 *reloc_addr = sym_val + addend;
21                 break;
22         case R_PPC_COPY:
23                 memcpy(reloc_addr, (void *)sym_val, sym_size);
24                 break;
25         case R_PPC_RELATIVE:
26                 *reloc_addr = (size_t)base_addr + addend;
27                 break;
28         case R_PPC_DTPMOD32:
29                 *reloc_addr = def.dso ? def.dso->tls_id : self->tls_id;
30                 break;
31         case R_PPC_DTPREL32:
32                 *reloc_addr = def.sym->st_value + addend;
33                 break;
34         case R_PPC_TPREL32:
35                 *reloc_addr += def.sym
36                         ? def.sym->st_value + def.dso->tls_offset - 0x7000
37                         : self->tls_offset - 0x7000;
38                 break;
39         }
40 }
41
42 void __reloc_self(int c, size_t *a, size_t *dynv)
43 {
44         char *base;
45         size_t t[20], n;
46         for (a+=c+1; *a; a++);
47         for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
48         base = (char *)t[AT_BASE];
49         if (!base) base = (char *)(t[AT_PHDR] & -4096);
50         for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
51         n = t[DT_RELASZ];
52         for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
53                 if (a[1]%256 == R_PPC_RELATIVE)
54                         *(size_t *)(base+a[0]) = (size_t)base + a[2];
55 }