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

5
Last change on this file since 990adc5 was 990adc5, checked in by Sebastian Huber <sebastian.huber@…>, on 12/13/17 at 07:20:30

libdl: Include <rtems/rtl/rtl-*.h>

Prepare for header file move to common include directory.

Update #3254.

  • Property mode set to 100644
File size: 6.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_t* obj,
17                             const Elf_Shdr*        shdr)
18{
19  return 0;
20}
21
22bool
23rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
24{
25  return true;
26}
27
28bool
29rtems_rtl_elf_relocate_rela (const rtems_rtl_obj_t*      obj,
30                             const Elf_Rela*             rela,
31                             const rtems_rtl_obj_sect_t* sect,
32                             const char*                 symname,
33                             const Elf_Byte              syminfo,
34                             const Elf_Word              symvalue)
35{
36  rtems_rtl_set_error (EINVAL, "rela type record not supported");
37  return false;
38}
39
40/*
41 * 1. _gp_disp symbol are not considered in this file.
42 * 2. There is a local/external column;
43 * local corresponds to (STB_LOCAL & STT_SECTION) and
44 * all others are external. Because if the type of a
45 * symbol is STT_SECTION, it must be STB_LOCAL. Thus
46 * just consider symtype here.
47 */
48bool
49rtems_rtl_elf_relocate_rel (const rtems_rtl_obj_t*      obj,
50                            const Elf_Rel*              rel,
51                            const rtems_rtl_obj_sect_t* sect,
52                            const char*                 symname,
53                            const Elf_Byte              syminfo,
54                            const Elf_Word              symvalue)
55{
56  Elf_Addr *where;
57  Elf_Word  tmp;
58  Elf_Word addend = (Elf_Word)0;
59  Elf_Word local = 0;
60  uint32_t t;
61
62
63  static Elf_Addr *where_hi16;
64  static Elf_Addr ahl;
65
66  where = (Elf_Addr *)(sect->base + rel->r_offset);
67  addend = *where;
68
69  if (syminfo == STT_SECTION)
70    local = 1;
71
72  switch (ELF_R_TYPE(rel->r_info)) {
73    case R_TYPE(NONE):
74      break;
75
76    case R_TYPE(16):
77      tmp = addend & 0xffff;
78      if ((tmp & 0x8000) == 0x8000)
79        tmp |= 0xffff0000; /* Sign extend */
80      tmp = symvalue + (int)tmp;
81      if ((tmp & 0xffff0000) != 0) {
82        printf("R_MIPS_16 Overflow\n");
83        return false;
84      }
85
86      *where = (tmp & 0xffff) | (*where & 0xffff0000);
87
88      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
89        printf ("rtl: R_MIPS_16 %p @ %p in %s\n",
90                (void *)*(where), where, rtems_rtl_obj_oname (obj));
91      break;
92
93    case R_TYPE(32):
94      tmp = symvalue + addend;
95      if (addend != tmp)
96        *where = tmp;
97
98      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
99        printf ("rtl: R_MIPS_32 %p @ %p in %s\n",
100                (void *)*(where), where, rtems_rtl_obj_oname (obj));
101      break;
102
103    case R_TYPE(26):
104
105        addend &= 0x03ffffff;
106        addend <<= 2;
107
108      if (local == 1) { /* STB_LOCAL and STT_SECTION */
109        tmp = symvalue + (((Elf_Addr)where & 0xf0000000) | addend);
110        tmp >>= 2;
111
112      } else { /* external */
113
114        tmp = addend;
115
116        if ((tmp & 0x08000000) == 0x08000000)
117          tmp |= 0xf0000000; /* Sign extened */
118        tmp = ((int)tmp + symvalue) >> 2;
119
120      }
121
122      *where &= ~0x03ffffff;
123      *where |= tmp & 0x03ffffff;
124
125      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
126        printf ("rtl: R_MIPS_26 local=%lu @ %p in %s\n",
127                local, (void *)*(where), rtems_rtl_obj_oname (obj));
128      break;
129
130    case R_TYPE(HI16):
131      ahl = addend << 16;
132      where_hi16 = where;
133
134
135      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
136        printf ("rtl: R_MIPS_HI16 %p @ %p in %s\n",
137                (void *)*(where), where, rtems_rtl_obj_oname (obj));
138      break;
139
140    case R_TYPE(LO16):
141      //ahl += (int16_t)addend;
142      t = ahl + (int16_t)addend;
143      tmp = symvalue;
144      if (tmp == 0)
145        return false;
146
147      addend &= 0xffff0000;
148      addend |= (uint16_t)(t + tmp);
149      *where = addend;
150
151      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
152        printf("*where %lx where %p\n", *where, where);
153
154      addend = *where_hi16;
155      addend &= 0xffff0000;
156      addend |= ((t + tmp) - (int16_t)(t + tmp)) >> 16;
157      *where_hi16 = addend;
158
159      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
160        printf("*where_hi %lx where_hi %p\n", *where_hi16, where_hi16);
161
162      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
163        printf ("rtl: R_MIPS_LO16 %p @ %p in %s\n",
164                (void *)*(where), where, rtems_rtl_obj_oname (obj));
165      break;
166
167    case R_TYPE(PC16):
168      tmp = addend & 0xffff;
169      if ((tmp & 0x8000) == 0x8000)
170        tmp |= 0xffff0000; /* Sign extend */
171      tmp = symvalue + ((int)tmp*4) - (Elf_Addr)where;
172      tmp = (Elf_Sword)tmp >> 2;
173      if (((Elf_Sword)tmp > 0x7fff) || ((Elf_Sword)tmp < -0x8000)) {
174        printf("R_MIPS_PC16 Overflow\n");
175        return false;
176      }
177
178      *where = (tmp & 0xffff) | (*where & 0xffff0000);
179
180      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
181        printf ("rtl: R_MIPS_PC16 %p @ %p in %s\n",
182                (void *)*(where), where, rtems_rtl_obj_oname (obj));
183
184      break;
185
186                default:
187     printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
188             "contents = %p\n",
189              ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
190              (void *)rel->r_offset, (void *)*where);
191     rtems_rtl_set_error (EINVAL,
192                          "%s: Unsupported relocation type %ld "
193                          "in non-PLT relocations",
194                          sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
195     return false;
196  }
197
198  return true;
199}
200
201bool
202rtems_rtl_elf_unwind_parse (const rtems_rtl_obj_t* obj,
203                            const char*            name,
204                            uint32_t               flags)
205{
206  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
207}
208
209bool
210rtems_rtl_elf_unwind_register (rtems_rtl_obj_t* obj)
211{
212  return rtems_rtl_elf_unwind_dw2_register (obj);
213}
214
215bool
216rtems_rtl_elf_unwind_deregister (rtems_rtl_obj_t* obj)
217{
218  return rtems_rtl_elf_unwind_dw2_deregister (obj);
219}
Note: See TracBrowser for help on using the repository browser.