source: rtems/cpukit/libdl/rtl-mdreloc-moxie.c @ 21275b58

5
Last change on this file since 21275b58 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.2 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
23bool
24rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
25{
26  return true;
27}
28
29bool
30rtems_rtl_elf_relocate_rela (const rtems_rtl_obj*      obj,
31                             const Elf_Rela*           rela,
32                             const rtems_rtl_obj_sect* sect,
33                             const char*               symname,
34                             const Elf_Byte            syminfo,
35                             const Elf_Word            symvalue)
36{
37  Elf_Addr *where;
38  Elf_Sword tmp;
39
40  where = (Elf_Addr *)(sect->base + rela->r_offset);
41
42  /* Handle the not 4byte aligned address carefully */
43
44  switch (ELF_R_TYPE(rela->r_info)) {
45    case R_TYPE(NONE):
46      break;
47
48    case R_TYPE(32):
49      *(uint16_t *)where = ((symvalue + rela->r_addend) >> 16) & 0xffff;
50      *((uint16_t *)where + 1) = (symvalue + rela->r_addend) & 0xffff;
51
52      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
53          printf("*where 0x%04x%04x\n", *((uint16_t *)where + 1), *(uint16_t *)where);
54      }
55      break;
56
57    case R_TYPE(PCREL10):
58      /* beq, bge, bgeu, bgt, bgtu, ble, bleu, blt, bltu, bne */
59      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
60        printf("*where %x\n", *(uint16_t *)where);
61        printf("symvalue - where %x\n", (int)(symvalue - (Elf_Word)where));
62      }
63      tmp = (symvalue + rela->r_addend - ((Elf_Word)where + 2)); /* pc is the next instruction */
64      tmp = (Elf_Sword)tmp >> 1;
65      if (((Elf32_Sword)tmp > 0x1ff) || ((Elf32_Sword)tmp < -(Elf32_Sword)0x200)){
66        printf("Overflow for PCREL10: %ld exceed -0x200:0x1ff\n", tmp);
67        return false;
68      }
69
70      *(uint16_t *)where = (*(uint16_t *)where & 0xfc00) | (tmp & 0x3ff);
71
72      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC)) {
73          printf("*where 0x%04x\n",  *(uint16_t *)where);
74      }
75
76      break;
77
78    default:
79      rtems_rtl_set_error (EINVAL, "rela type record not supported");
80      printf("Unsupported reloc types\n");
81      return false;
82  }
83
84  return true;
85}
86
87bool
88rtems_rtl_elf_relocate_rel (const rtems_rtl_obj*      obj,
89                            const Elf_Rel*            rel,
90                            const rtems_rtl_obj_sect* sect,
91                            const char*               symname,
92                            const Elf_Byte            syminfo,
93                            const Elf_Word            symvalue)
94{
95  rtems_rtl_set_error (EINVAL, "rel type record not supported");
96  return false;
97}
98
99bool
100rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
101                            const char*          name,
102                            uint32_t             flags)
103{
104  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
105}
106
107bool
108rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
109{
110  return rtems_rtl_elf_unwind_dw2_register (obj);
111}
112
113bool
114rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
115{
116  return rtems_rtl_elf_unwind_dw2_deregister (obj);
117}
Note: See TracBrowser for help on using the repository browser.