source: rtems/cpukit/libdl/rtl-mdreloc-bfin.c @ f59d435d

5
Last change on this file since f59d435d was f59d435d, checked in by Chris Johns <chrisj@…>, on 04/12/18 at 07:46:49

libdl: Remove _t from all structures as this is reserved for the standards

  • Property mode set to 100644
File size: 3.4 KB
Line 
1#include <sys/cdefs.h>
2
3#include <stdio.h>
4#include <rtems/rtl/rtl.h>
5#include <errno.h>
6#include "rtl-elf.h"
7#include "rtl-error.h"
8#include <rtems/rtl/rtl-trace.h>
9#include "rtl-unwind.h"
10#include "rtl-unwind-dw2.h"
11
12uint32_t
13rtems_rtl_elf_section_flags (const rtems_rtl_obj_t* obj,
14                             const Elf_Shdr*        shdr)
15{
16  return 0;
17}
18
19bool
20rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
21{
22  return true;
23}
24
25static inline Elf_Addr
26load_ptr(void *where)
27{
28        Elf_Addr res;
29
30        memcpy(&res, where, sizeof(res));
31
32        return (res);
33}
34
35bool
36rtems_rtl_elf_relocate_rela (const rtems_rtl_obj*      obj,
37                             const Elf_Rela*           rela,
38                             const rtems_rtl_obj_sect* sect,
39                             const char*               symname,
40                             const Elf_Byte            syminfo,
41                             const Elf_Word            symvalue)
42{
43  Elf_Addr target = 0;
44  Elf_Addr *where;
45  Elf_Word tmp;
46  Elf_Word size; //byte
47
48  where = (Elf_Addr *)(sect->base + rela->r_offset);
49
50  if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
51      printf("rela relocation type is %d relocated address 0x%08x",
52              ELF_R_TYPE(rela->r_info), where);
53  }
54
55  tmp = symvalue;
56  switch (ELF_R_TYPE(rela->r_info)) {
57    case R_TYPE(UNUSED0):
58      break;
59
60    case R_TYPE(HUIMM16):
61      tmp = symvalue >> 16;
62    case R_TYPE(LUIMM16):
63    case R_TYPE(RIMM16):
64      size = 2;
65      break;
66
67    case R_TYPE(BYTE4_DATA):
68      size = 4;
69      break;
70
71    case R_TYPE(PCREL24):
72    case R_TYPE(PCREL24_JU):
73      where = (Elf_Addr*)((Elf_Addr)where - 2); /* Back 2 bytes */
74      tmp = symvalue - (Elf_Addr)where;
75      tmp >>= 1;
76      if ((tmp & 0x20000000) == 0x20000000)
77        tmp |= 0xc0000000;
78
79      if ((tmp & 0xff000000) && (~tmp & 0xff800000)) {
80        printf("PCREL24/PCREL24_JU Overflow\n");
81        return false;
82      }
83
84      tmp = (load_ptr(where) & 0x0000ff00) | ((tmp & 0x0000ffff) << 16) |
85             ((tmp & 0x00ff0000) >> 16);
86      size = 4;
87      break;
88
89    case R_TYPE(PCREL12_JUMP_S):
90      tmp = symvalue - (Elf_Addr)where;
91      tmp >>= 1;
92      if ((tmp & 0x20000000) == 0x20000000)
93        tmp |= 0xc0000000;
94
95      if ((tmp & 0xfffff000) && (~tmp & 0xfffff800)) {
96        printf("PCREL12_JUMP_S Overflow\n");
97        return false;
98      }
99
100      tmp = ((*(uint16_t *)where) & 0xf000) | (tmp & 0xfff);
101      size = 2;
102      break;
103
104    default:
105      printf("Unspported rela type\n");
106      return false;
107  }
108
109  memcpy((void*)where, &tmp, size);
110
111  return true;
112}
113
114bool
115rtems_rtl_elf_relocate_rel (const rtems_rtl_obj*      obj,
116                            const Elf_Rel*            rel,
117                            const rtems_rtl_obj_sect* sect,
118                            const char*               symname,
119                            const Elf_Byte            syminfo,
120                            const Elf_Word            symvalue)
121{
122  rtems_rtl_set_error (EINVAL, "rel type record not supported");
123  return false;
124}
125
126bool
127rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
128                            const char*          name,
129                            uint32_t             flags)
130{
131  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
132}
133
134bool
135rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
136{
137  return rtems_rtl_elf_unwind_dw2_register (obj);
138}
139
140bool
141rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
142{
143  return rtems_rtl_elf_unwind_dw2_deregister (obj);
144}
Note: See TracBrowser for help on using the repository browser.