source: rtems/cpukit/libdl/rtl-mdreloc-v850.c @ b36c5209

5
Last change on this file since b36c5209 was b36c5209, checked in by Chris Johns <chrisj@…>, on 05/03/19 at 00:15:20

libdl: Do not access the ELF file while the allocator is locked.

  • Load symbols before allocation.
  • Parse reloc records and place any reloc recs in a cache to use while the allocator is locked.
  • Relocate symbols after section allocation.
  • Split section loading into allocation/locating and loading.
  • Update all arch back-ends with a new reloc interface to control tramp handling.
  • Add -a and -t to the object list shell command.

Closes #3741

  • Property mode set to 100644
File size: 5.5 KB
Line 
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
16uint32_t
17rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
18                             const Elf_Shdr*      shdr)
19{
20  return 0;
21}
22
23uint32_t
24rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj,
25                                  int                  section,
26                                  const char*          name,
27                                  const Elf_Shdr*      shdr,
28                                  const uint32_t       flags)
29{
30  (void) obj;
31  (void) section;
32  (void) name;
33  (void) shdr;
34  return flags;
35}
36
37bool
38rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj,
39                                  rtems_rtl_obj_sect*  sect)
40{
41  (void) obj;
42  (void) sect;
43  return false;
44}
45
46bool
47rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj,
48                                  rtems_rtl_obj_sect*  sect)
49{
50  (void) obj;
51  (void) sect;
52  return false;
53}
54
55bool
56rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
57{
58  return true;
59}
60
61size_t
62rtems_rtl_elf_relocate_tramp_max_size (void)
63{
64  /*
65   * Disable by returning 0.
66   */
67  return 0;
68}
69
70rtems_rtl_elf_rel_status
71rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
72                                   const Elf_Rela*           rela,
73                                   const rtems_rtl_obj_sect* sect,
74                                   const char*               symname,
75                                   const Elf_Byte            syminfo,
76                                   const Elf_Word            symvalue)
77{
78  (void) obj;
79  (void) rela;
80  (void) sect;
81  (void) symname;
82  (void) syminfo;
83  (void) symvalue;
84  return rtems_rtl_elf_rel_no_error;
85}
86
87rtems_rtl_elf_rel_status
88rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
89                             const Elf_Rela*           rela,
90                             const rtems_rtl_obj_sect* sect,
91                             const char*               symname,
92                             const Elf_Byte            syminfo,
93                             const Elf_Word            symvalue)
94{
95  Elf_Addr *where;
96  Elf_Word tmp;
97
98  where = (Elf_Addr *)(sect->base + rela->r_offset);
99
100  if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
101      printf("rela relocation type is %ld\n", ELF_R_TYPE(rela->r_info));
102      printf("relocated address 0x%08lx\n", (Elf_Addr)where);
103  }
104
105  switch (ELF_R_TYPE(rela->r_info)) {
106    case R_TYPE(NONE):
107      break;
108
109    case R_TYPE(HI16_S):
110      tmp = (Elf_Sword)(symvalue + rela->r_addend) >> 16;
111      ((uint16_t *)where)[0] = tmp & 0xffff;
112      break;
113
114    case R_TYPE(LO16):
115      tmp = symvalue + rela->r_addend;
116      ((uint16_t *)where)[0] = tmp & 0xffff;
117      break;
118
119    case R_TYPE(LO16_S1):
120      tmp = symvalue + rela->r_addend;
121      ((uint16_t *)where)[0] = tmp & 0xfffe | 0x1;
122      break;
123
124    case R_TYPE(22_PCREL):
125      tmp =  symvalue + rela->r_addend - (Elf_Addr)where;
126      if (((Elf_Sword)tmp > 0x1fffff) || ((Elf_Sword)tmp < -0x200000)) {
127        printf("Overflow\n");
128        return rtems_rtl_elf_rel_failure;
129      }
130
131      ((uint16_t *)where)[0] = (*(uint16_t *)where & 0xffc0) |
132        ((tmp >> 16) & 0x3f);
133      ((uint16_t *)where)[1] = (tmp & 0xfffe);
134
135      break;
136
137    case R_TYPE(ABS32):
138      tmp = symvalue + rela->r_addend;
139      tmp += ((uint16_t *)where)[0];
140      tmp += ((uint16_t *)where)[1] << 16;
141      ((uint16_t *)where)[0] = tmp & 0xffff;
142      ((uint16_t *)where)[1] = (tmp >> 16) & 0xffff;
143      break;
144
145    default:
146      rtems_rtl_set_error (EINVAL, "rela type record not supported");
147      printf("error reloc type\n");
148      return rtems_rtl_elf_rel_failure;
149  }
150
151  return rtems_rtl_elf_rel_no_error;
152}
153
154rtems_rtl_elf_rel_status
155rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
156                                  const Elf_Rel*            rel,
157                                  const rtems_rtl_obj_sect* sect,
158                                  const char*               symname,
159                                  const Elf_Byte            syminfo,
160                                  const Elf_Word            symvalue)
161{
162  (void) obj;
163  (void) rel;
164  (void) sect;
165  (void) symname;
166  (void) syminfo;
167  (void) symvalue;
168  rtems_rtl_set_error (EINVAL, "rel type record not supported");
169  return rtems_rtl_elf_rel_failure;
170}
171
172rtems_rtl_elf_rel_status
173rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
174                            const Elf_Rel*            rel,
175                            const rtems_rtl_obj_sect* sect,
176                            const char*               symname,
177                            const Elf_Byte            syminfo,
178                            const Elf_Word            symvalue)
179{
180  (void) obj;
181  (void) rel;
182  (void) sect;
183  (void) symname;
184  (void) syminfo;
185  (void) symvalue;
186  rtems_rtl_set_error (EINVAL, "rel type record not supported");
187  return rtems_rtl_elf_rel_failure;
188}
189
190bool
191rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
192                            const char*          name,
193                            uint32_t             flags)
194{
195  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
196}
197
198bool
199rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
200{
201  return rtems_rtl_elf_unwind_dw2_register (obj);
202}
203
204bool
205rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
206{
207  return rtems_rtl_elf_unwind_dw2_deregister (obj);
208}
Note: See TracBrowser for help on using the repository browser.