1 | |
---|
2 | #include <sys/cdefs.h> |
---|
3 | |
---|
4 | #include <errno.h> |
---|
5 | #include <stdio.h> |
---|
6 | #include <sys/types.h> |
---|
7 | #include <sys/stat.h> |
---|
8 | |
---|
9 | #include <rtems/rtl/rtl.h> |
---|
10 | #include "rtl-elf.h" |
---|
11 | #include "rtl-error.h" |
---|
12 | #include "rtl-trace.h" |
---|
13 | |
---|
14 | bool |
---|
15 | rtems_rtl_elf_rel_resolve_sym (Elf_Word type) |
---|
16 | { |
---|
17 | return true; |
---|
18 | } |
---|
19 | |
---|
20 | bool |
---|
21 | rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t* obj, |
---|
22 | const Elf_Rela* rela, |
---|
23 | const rtems_rtl_obj_sect_t* sect, |
---|
24 | const char* symname, |
---|
25 | const Elf_Byte syminfo, |
---|
26 | const Elf_Word symvalue) |
---|
27 | { |
---|
28 | Elf_Addr *where; |
---|
29 | Elf_Word tmp; |
---|
30 | |
---|
31 | where = (Elf_Addr *)(sect->base + rela->r_offset); |
---|
32 | |
---|
33 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { |
---|
34 | printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info)); |
---|
35 | printf("relocated address 0x%08lx\n", (Elf_Addr)where); |
---|
36 | } |
---|
37 | |
---|
38 | switch (ELF_R_TYPE(rela->r_info)) { |
---|
39 | case R_TYPE(NONE): |
---|
40 | break; |
---|
41 | |
---|
42 | case R_TYPE(HI16_S): |
---|
43 | tmp = (Elf_Sword)(symvalue + rela->r_addend) >> 16; |
---|
44 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
45 | break; |
---|
46 | |
---|
47 | case R_TYPE(LO16): |
---|
48 | tmp = symvalue + rela->r_addend; |
---|
49 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
50 | break; |
---|
51 | |
---|
52 | case R_TYPE(LO16_S1): |
---|
53 | tmp = symvalue + rela->r_addend; |
---|
54 | ((uint16_t *)where)[0] = tmp & 0xfffe | 0x1; |
---|
55 | break; |
---|
56 | |
---|
57 | case R_TYPE(22_PCREL): |
---|
58 | tmp = symvalue + rela->r_addend - (Elf_Addr)where; |
---|
59 | if (((Elf_Sword)tmp > 0x1fffff) || ((Elf_Sword)tmp < -0x200000)) { |
---|
60 | printf("Overflow\n"); |
---|
61 | return false; |
---|
62 | } |
---|
63 | |
---|
64 | ((uint16_t *)where)[0] = (*(uint16_t *)where & 0xffc0) | |
---|
65 | ((tmp >> 16) & 0x3f); |
---|
66 | ((uint16_t *)where)[1] = (tmp & 0xfffe); |
---|
67 | |
---|
68 | break; |
---|
69 | |
---|
70 | case R_TYPE(ABS32): |
---|
71 | tmp = symvalue + rela->r_addend; |
---|
72 | tmp += ((uint16_t *)where)[0]; |
---|
73 | tmp += ((uint16_t *)where)[1] << 16; |
---|
74 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
75 | ((uint16_t *)where)[1] = (tmp >> 16) & 0xffff; |
---|
76 | break; |
---|
77 | |
---|
78 | default: |
---|
79 | rtems_rtl_set_error (EINVAL, "rela type record not supported"); |
---|
80 | printf("error reloc type\n"); |
---|
81 | return false; |
---|
82 | } |
---|
83 | |
---|
84 | return true; |
---|
85 | } |
---|
86 | |
---|
87 | bool |
---|
88 | rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t* obj, |
---|
89 | const Elf_Rel* rel, |
---|
90 | const rtems_rtl_obj_sect_t* sect, |
---|
91 | const char* symname, |
---|
92 | const Elf_Byte syminfo, |
---|
93 | const Elf_Word symvalue) |
---|
94 | { |
---|
95 | rtems_rtl_set_error (EINVAL, "rel type record not supported"); |
---|
96 | return false; |
---|
97 | } |
---|