source: rtems/cpukit/libdl/rtl-mdreloc-mips.c @ be50969

5
Last change on this file since be50969 was 6c9f017, checked in by Chris Johns <chrisj@…>, on 02/02/19 at 04:09:53

libdl: Add powerpc large memory and small data support.

  • Add support for architecure sections that can be handled by the architecture back end.
  • Add trampoline/fixup support for PowerPC. This means the PowerPC now supports large memory loading of applications.
  • Add a bit allocator to manage small block based regions of memory.
  • Add small data (sdata/sbss) support for the PowerPC. The support makes the linker allocated small data region of memory a global resource available to libdl loaded object files.

Updates #3687
Updates #3685

  • Property mode set to 100644
File size: 8.0 KB
Line 
1#include <sys/cdefs.h>
2
3#include <errno.h>
4#include <stdio.h>
5#include <sys/types.h>
6#include <sys/stat.h>
7
8#include <rtems/rtl/rtl.h>
9#include "rtl-elf.h"
10#include "rtl-error.h"
11#include <rtems/rtl/rtl-trace.h>
12#include "rtl-unwind.h"
13#include "rtl-unwind-dw2.h"
14
15uint32_t
16rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
17                             const Elf_Shdr*      shdr)
18{
19  return 0;
20}
21
22uint32_t
23rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj,
24                                  int                  section,
25                                  const char*          name,
26                                  const Elf_Shdr*      shdr,
27                                  const uint32_t       flags)
28{
29  (void) obj;
30  (void) section;
31  (void) name;
32  (void) shdr;
33  return flags;
34}
35
36bool
37rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj,
38                                  rtems_rtl_obj_sect*  sect)
39{
40  (void) obj;
41  (void) sect;
42  return false;
43}
44
45bool
46rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj,
47                                  rtems_rtl_obj_sect*  sect)
48{
49  (void) obj;
50  (void) sect;
51  return false;
52}
53
54bool
55rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
56{
57  return true;
58}
59
60size_t
61rtems_rtl_elf_relocate_tramp_max_size (void)
62{
63  /*
64   * Disable by returning 0.
65   */
66  return 0;
67}
68
69bool
70rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
71                                   const Elf_Rela*           rela,
72                                   const rtems_rtl_obj_sect* sect,
73                                   const char*               symname,
74                                   const Elf_Byte            syminfo,
75                                   const Elf_Word            symvalue)
76{
77  (void) obj;
78  (void) rela;
79  (void) sect;
80  (void) symname;
81  (void) syminfo;
82  (void) symvalue;
83  rtems_rtl_set_error (EINVAL, "rela type record not supported");
84  return false;
85}
86
87bool
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  (void) obj;
96  (void) rela;
97  (void) sect;
98  (void) symname;
99  (void) syminfo;
100  (void) symvalue;
101  rtems_rtl_set_error (EINVAL, "rela type record not supported");
102  return false;
103}
104
105bool
106rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
107                                  const Elf_Rel*            rel,
108                                  const rtems_rtl_obj_sect* sect,
109                                  const char*               symname,
110                                  const Elf_Byte            syminfo,
111                                  const Elf_Word            symvalue)
112{
113  (void) obj;
114  (void) rel;
115  (void) sect;
116  (void) symname;
117  (void) syminfo;
118  (void) symvalue;
119  return true;
120}
121
122/*
123 * 1. _gp_disp symbol are not considered in this file.
124 * 2. There is a local/external column;
125 * local corresponds to (STB_LOCAL & STT_SECTION) and
126 * all others are external. Because if the type of a
127 * symbol is STT_SECTION, it must be STB_LOCAL. Thus
128 * just consider symtype here.
129 */
130bool
131rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
132                            const Elf_Rel*            rel,
133                            const rtems_rtl_obj_sect* sect,
134                            const char*               symname,
135                            const Elf_Byte            syminfo,
136                            const Elf_Word            symvalue)
137{
138  Elf_Addr *where;
139  Elf_Word  tmp;
140  Elf_Word addend = (Elf_Word)0;
141  Elf_Word local = 0;
142  uint32_t t;
143
144
145  static Elf_Addr *where_hi16;
146  static Elf_Addr ahl;
147
148  where = (Elf_Addr *)(sect->base + rel->r_offset);
149  addend = *where;
150
151  if (syminfo == STT_SECTION)
152    local = 1;
153
154  switch (ELF_R_TYPE(rel->r_info)) {
155    case R_TYPE(NONE):
156      break;
157
158    case R_TYPE(16):
159      tmp = addend & 0xffff;
160      if ((tmp & 0x8000) == 0x8000)
161        tmp |= 0xffff0000; /* Sign extend */
162      tmp = symvalue + (int)tmp;
163      if ((tmp & 0xffff0000) != 0) {
164        printf("R_MIPS_16 Overflow\n");
165        return false;
166      }
167
168      *where = (tmp & 0xffff) | (*where & 0xffff0000);
169
170      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
171        printf ("rtl: R_MIPS_16 %p @ %p in %s\n",
172                (void *)*(where), where, rtems_rtl_obj_oname (obj));
173      break;
174
175    case R_TYPE(32):
176      tmp = symvalue + addend;
177      if (addend != tmp)
178        *where = tmp;
179
180      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
181        printf ("rtl: R_MIPS_32 %p @ %p in %s\n",
182                (void *)*(where), where, rtems_rtl_obj_oname (obj));
183      break;
184
185    case R_TYPE(26):
186
187        addend &= 0x03ffffff;
188        addend <<= 2;
189
190      if (local == 1) { /* STB_LOCAL and STT_SECTION */
191        tmp = symvalue + (((Elf_Addr)where & 0xf0000000) | addend);
192        tmp >>= 2;
193
194      } else { /* external */
195
196        tmp = addend;
197
198        if ((tmp & 0x08000000) == 0x08000000)
199          tmp |= 0xf0000000; /* Sign extened */
200        tmp = ((int)tmp + symvalue) >> 2;
201
202      }
203
204      *where &= ~0x03ffffff;
205      *where |= tmp & 0x03ffffff;
206
207      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
208        printf ("rtl: R_MIPS_26 local=%lu @ %p in %s\n",
209                local, (void *)*(where), rtems_rtl_obj_oname (obj));
210      break;
211
212    case R_TYPE(HI16):
213      ahl = addend << 16;
214      where_hi16 = where;
215
216
217      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
218        printf ("rtl: R_MIPS_HI16 %p @ %p in %s\n",
219                (void *)*(where), where, rtems_rtl_obj_oname (obj));
220      break;
221
222    case R_TYPE(LO16):
223      //ahl += (int16_t)addend;
224      t = ahl + (int16_t)addend;
225      tmp = symvalue;
226      if (tmp == 0)
227        return false;
228
229      addend &= 0xffff0000;
230      addend |= (uint16_t)(t + tmp);
231      *where = addend;
232
233      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
234        printf("*where %lx where %p\n", *where, where);
235
236      addend = *where_hi16;
237      addend &= 0xffff0000;
238      addend |= ((t + tmp) - (int16_t)(t + tmp)) >> 16;
239      *where_hi16 = addend;
240
241      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
242        printf("*where_hi %lx where_hi %p\n", *where_hi16, where_hi16);
243
244      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
245        printf ("rtl: R_MIPS_LO16 %p @ %p in %s\n",
246                (void *)*(where), where, rtems_rtl_obj_oname (obj));
247      break;
248
249    case R_TYPE(PC16):
250      tmp = addend & 0xffff;
251      if ((tmp & 0x8000) == 0x8000)
252        tmp |= 0xffff0000; /* Sign extend */
253      tmp = symvalue + ((int)tmp*4) - (Elf_Addr)where;
254      tmp = (Elf_Sword)tmp >> 2;
255      if (((Elf_Sword)tmp > 0x7fff) || ((Elf_Sword)tmp < -0x8000)) {
256        printf("R_MIPS_PC16 Overflow\n");
257        return false;
258      }
259
260      *where = (tmp & 0xffff) | (*where & 0xffff0000);
261
262      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
263        printf ("rtl: R_MIPS_PC16 %p @ %p in %s\n",
264                (void *)*(where), where, rtems_rtl_obj_oname (obj));
265
266      break;
267
268    default:
269      printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
270              "contents = %p\n",
271              ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
272              (void *)rel->r_offset, (void *)*where);
273      rtems_rtl_set_error (EINVAL,
274                           "%s: Unsupported relocation type %ld "
275                           "in non-PLT relocations",
276                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
277      return false;
278  }
279
280  return true;
281}
282
283bool
284rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
285                            const char*          name,
286                            uint32_t             flags)
287{
288  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
289}
290
291bool
292rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
293{
294  return rtems_rtl_elf_unwind_dw2_register (obj);
295}
296
297bool
298rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
299{
300  return rtems_rtl_elf_unwind_dw2_deregister (obj);
301}
Note: See TracBrowser for help on using the repository browser.