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 <rtems/rtl/rtl-trace.h> |
---|
13 | #include "rtl-unwind.h" |
---|
14 | #include "rtl-unwind-dw2.h" |
---|
15 | |
---|
16 | uint32_t |
---|
17 | rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj, |
---|
18 | const Elf_Shdr* shdr) |
---|
19 | { |
---|
20 | return 0; |
---|
21 | } |
---|
22 | |
---|
23 | bool |
---|
24 | rtems_rtl_elf_rel_resolve_sym (Elf_Word type) |
---|
25 | { |
---|
26 | return true; |
---|
27 | } |
---|
28 | |
---|
29 | bool |
---|
30 | rtems_rtl_elf_relocate_rela (const rtems_rtl_obj* obj, |
---|
31 | const Elf_Rela* rela, |
---|
32 | const rtems_rtl_obj_sect* sect, |
---|
33 | const char* symname, |
---|
34 | const Elf_Byte syminfo, |
---|
35 | const Elf_Word symvalue) |
---|
36 | { |
---|
37 | Elf_Addr *where; |
---|
38 | Elf_Word tmp; |
---|
39 | |
---|
40 | where = (Elf_Addr *)(sect->base + rela->r_offset); |
---|
41 | |
---|
42 | if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) { |
---|
43 | printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info)); |
---|
44 | printf("relocated address 0x%08lx\n", (Elf_Addr)where); |
---|
45 | } |
---|
46 | |
---|
47 | switch (ELF_R_TYPE(rela->r_info)) { |
---|
48 | case R_TYPE(NONE): |
---|
49 | break; |
---|
50 | |
---|
51 | case R_TYPE(HI16_S): |
---|
52 | tmp = (Elf_Sword)(symvalue + rela->r_addend) >> 16; |
---|
53 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
54 | break; |
---|
55 | |
---|
56 | case R_TYPE(LO16): |
---|
57 | tmp = symvalue + rela->r_addend; |
---|
58 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
59 | break; |
---|
60 | |
---|
61 | case R_TYPE(LO16_S1): |
---|
62 | tmp = symvalue + rela->r_addend; |
---|
63 | ((uint16_t *)where)[0] = tmp & 0xfffe | 0x1; |
---|
64 | break; |
---|
65 | |
---|
66 | case R_TYPE(22_PCREL): |
---|
67 | tmp = symvalue + rela->r_addend - (Elf_Addr)where; |
---|
68 | if (((Elf_Sword)tmp > 0x1fffff) || ((Elf_Sword)tmp < -0x200000)) { |
---|
69 | printf("Overflow\n"); |
---|
70 | return false; |
---|
71 | } |
---|
72 | |
---|
73 | ((uint16_t *)where)[0] = (*(uint16_t *)where & 0xffc0) | |
---|
74 | ((tmp >> 16) & 0x3f); |
---|
75 | ((uint16_t *)where)[1] = (tmp & 0xfffe); |
---|
76 | |
---|
77 | break; |
---|
78 | |
---|
79 | case R_TYPE(ABS32): |
---|
80 | tmp = symvalue + rela->r_addend; |
---|
81 | tmp += ((uint16_t *)where)[0]; |
---|
82 | tmp += ((uint16_t *)where)[1] << 16; |
---|
83 | ((uint16_t *)where)[0] = tmp & 0xffff; |
---|
84 | ((uint16_t *)where)[1] = (tmp >> 16) & 0xffff; |
---|
85 | break; |
---|
86 | |
---|
87 | default: |
---|
88 | rtems_rtl_set_error (EINVAL, "rela type record not supported"); |
---|
89 | printf("error reloc type\n"); |
---|
90 | return false; |
---|
91 | } |
---|
92 | |
---|
93 | return true; |
---|
94 | } |
---|
95 | |
---|
96 | bool |
---|
97 | rtems_rtl_elf_relocate_rel (const rtems_rtl_obj* obj, |
---|
98 | const Elf_Rel* rel, |
---|
99 | const rtems_rtl_obj_sect* sect, |
---|
100 | const char* symname, |
---|
101 | const Elf_Byte syminfo, |
---|
102 | const Elf_Word symvalue) |
---|
103 | { |
---|
104 | rtems_rtl_set_error (EINVAL, "rel type record not supported"); |
---|
105 | return false; |
---|
106 | } |
---|
107 | |
---|
108 | bool |
---|
109 | rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj, |
---|
110 | const char* name, |
---|
111 | uint32_t flags) |
---|
112 | { |
---|
113 | return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags); |
---|
114 | } |
---|
115 | |
---|
116 | bool |
---|
117 | rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj) |
---|
118 | { |
---|
119 | return rtems_rtl_elf_unwind_dw2_register (obj); |
---|
120 | } |
---|
121 | |
---|
122 | bool |
---|
123 | rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj) |
---|
124 | { |
---|
125 | return rtems_rtl_elf_unwind_dw2_deregister (obj); |
---|
126 | } |
---|