rework langinfo code for ABI compat and for use by time code
[musl] / arch / microblaze / reloc.h
1 #include <string.h>
2 #include <elf.h>
3 #include <endian.h>
4
5 #if __BYTE_ORDER == __LITTLE_ENDIAN
6 #define ENDIAN_SUFFIX "el"
7 #else
8 #define ENDIAN_SUFFIX ""
9 #endif
10
11 #define LDSO_ARCH "microblaze" ENDIAN_SUFFIX
12
13 #define IS_COPY(x) ((x)==R_MICROBLAZE_COPY)
14 #define IS_PLT(x) ((x)==R_MICROBLAZE_JUMP_SLOT)
15
16 static inline void do_single_reloc(
17         struct dso *self, unsigned char *base_addr,
18         size_t *reloc_addr, int type, size_t addend,
19         Sym *sym, size_t sym_size,
20         struct symdef def, size_t sym_val)
21 {
22         switch(type) {
23         case R_MICROBLAZE_32:
24         case R_MICROBLAZE_GLOB_DAT:
25         case R_MICROBLAZE_JUMP_SLOT:
26                 *reloc_addr = sym_val + addend;
27                 break;
28         case R_MICROBLAZE_REL:
29                 *reloc_addr = (size_t)base_addr + addend;
30                 break;
31         case R_MICROBLAZE_COPY:
32                 memcpy(reloc_addr, (void *)sym_val, sym_size);
33                 break;
34         case R_MICROBLAZE_TLSDTPMOD32:
35                 *reloc_addr = def.dso ? def.dso->tls_id : self->tls_id;
36                 break;
37         case R_MICROBLAZE_TLSDTPREL32:
38                 *reloc_addr = def.sym->st_value + addend;
39                 break;
40         }
41 }
42
43 #include "syscall.h"
44 void __reloc_self(int c, size_t *a, size_t *dynv)
45 {
46         char dot = '.', ex = 'x';
47         char *base;
48         size_t t[20], n;
49         for (a+=c+1; *a; a++);
50         for (a++; *a; a+=2) if (*a<20) t[*a] = a[1];
51         base = (char *)t[AT_BASE];
52         if (!base) base = (char *)(t[AT_PHDR] & -4096);
53         for (a=dynv; *a; a+=2) if (*a<20) t[*a] = a[1];
54         n = t[DT_RELASZ];
55         for (a=(void *)(base+t[DT_RELA]); n; a+=3, n-=12)
56                 if (a[1]%256 == R_MICROBLAZE_REL)
57                         *(size_t *)(base+a[0]) = (size_t)base + a[2];
58 }