source: rtems/cpukit/libdl/rtl-mdreloc-moxie.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
RevLine 
[ae5fe7e6]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"
[990adc5]12#include <rtems/rtl/rtl-trace.h>
[c6eead1]13#include "rtl-unwind.h"
14#include "rtl-unwind-dw2.h"
15
16uint32_t
[f59d435d]17rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
18                             const Elf_Shdr*      shdr)
[c6eead1]19{
20  return 0;
21}
[ae5fe7e6]22
[6c9f017]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
[ae5fe7e6]55bool
56rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
57{
58  return true;
59}
60
[d8c70ba6]61size_t
62rtems_rtl_elf_relocate_tramp_max_size (void)
63{
64  /*
65   * Disable by returning 0.
66   */
67  return 0;
68}
69
[b36c5209]70rtems_rtl_elf_rel_status
[d8c70ba6]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;
[b36c5209]84  return rtems_rtl_elf_rel_no_error;
[d8c70ba6]85}
86
[b36c5209]87rtems_rtl_elf_rel_status
[d8c70ba6]88rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
[f59d435d]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)
[ae5fe7e6]94{
95  Elf_Addr *where;
96  Elf_Sword tmp;
97
98  where = (Elf_Addr *)(sect->base + rela->r_offset);
99
100  /* Handle the not 4byte aligned address carefully */
101
102  switch (ELF_R_TYPE(rela->r_info)) {
103    case R_TYPE(NONE):
104      break;
105
106    case R_TYPE(32):
107      *(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
108      *((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff;
109
110      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
111          printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where);
112      }
113      break;
114
115    case R_TYPE(PCREL10):
116      /* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */
117      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
118        printf("*where %x\n", *(uint16_t *)where);
119        printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where));
120      }
121      tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */
122      tmp = (Elf_Sword)tmp >> 1;
123      if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){
[30ea9bf]124        printf("Overflow for PCREL10: %ld exceed -0x200:0x1ff\n", tmp);
[b36c5209]125        return rtems_rtl_elf_rel_failure;
[ae5fe7e6]126      }
127
128      *(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff);
129
130      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
131          printf("*where 0x%04x\n",  *(uint16_t *)where);
132      }
133
134      break;
135
136    default:
137      rtems_rtl_set_error (EINVAL, "rela type record not supported");
138      printf("Unsupported reloc types\n");
[b36c5209]139      return rtems_rtl_elf_rel_failure;
[ae5fe7e6]140  }
141
[b36c5209]142  return rtems_rtl_elf_rel_no_error;
[ae5fe7e6]143}
144
[b36c5209]145rtems_rtl_elf_rel_status
[d8c70ba6]146rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
147                                  const Elf_Rel*            rel,
148                                  const rtems_rtl_obj_sect* sect,
149                                  const char*               symname,
150                                  const Elf_Byte            syminfo,
151                                  const Elf_Word            symvalue)
152{
153  (void) obj;
154  (void) rel;
155  (void) sect;
156  (void) symname;
157  (void) syminfo;
158  (void) symvalue;
159  rtems_rtl_set_error (EINVAL, "rel type record not supported");
[b36c5209]160  return rtems_rtl_elf_rel_failure;
[d8c70ba6]161}
162
[b36c5209]163rtems_rtl_elf_rel_status
[d8c70ba6]164rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
[f59d435d]165                            const Elf_Rel*            rel,
166                            const rtems_rtl_obj_sect* sect,
167                            const char*               symname,
168                            const Elf_Byte            syminfo,
169                            const Elf_Word            symvalue)
[ae5fe7e6]170{
[d8c70ba6]171  (void) obj;
172  (void) rel;
173  (void) sect;
174  (void) symname;
175  (void) syminfo;
176  (void) symvalue;
[ae5fe7e6]177  rtems_rtl_set_error (EINVAL, "rel type record not supported");
[b36c5209]178  return rtems_rtl_elf_rel_failure;
[ae5fe7e6]179}
[c6eead1]180
181bool
[f59d435d]182rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
183                            const char*          name,
184                            uint32_t             flags)
[c6eead1]185{
186  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
187}
188
189bool
[f59d435d]190rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
[c6eead1]191{
192  return rtems_rtl_elf_unwind_dw2_register (obj);
193}
194
195bool
[f59d435d]196rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
[c6eead1]197{
198  return rtems_rtl_elf_unwind_dw2_deregister (obj);
199}
Note: See TracBrowser for help on using the repository browser.