source: rtems/cpukit/libdl/rtl-mdreloc-m68k.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: 5.0 KB
Line 
1/*
2 * Taken from NetBSD and stripped of the relocations not needed on RTEMS.
3 */
4
5/*      $NetBSD: mdreloc.c,v 1.26 2010/01/14 11:58:32 skrll Exp $       */
6
7#include <sys/cdefs.h>
8
9#include <errno.h>
10#include <stdio.h>
11#include <sys/types.h>
12#include <sys/stat.h>
13
14#include <rtems/rtl/rtl.h>
15#include "rtl-elf.h"
16#include "rtl-error.h"
17#include <rtems/rtl/rtl-trace.h>
18#include "rtl-unwind.h"
19#include "rtl-unwind-dw2.h"
20
21static inline int overflow_8_check(int value)
22{
23  if ((value & 0xffffff00) && (~value & 0xffffff80))
24    return true;
25  return false;
26}
27
28static inline int overflow_16_check(int value)
29{
30  if ((value & 0xffff0000) && (~value & 0xffff8000))
31    return true;
32  return false;
33}
34
35uint32_t
36rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
37                             const Elf_Shdr*      shdr)
38{
39  return 0;
40}
41
42bool
43rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
44{
45  return true;
46}
47
48bool
49rtems_rtl_elf_relocate_rela (const rtems_rtl_obj*      obj,
50                             const Elf_Rela*           rela,
51                             const rtems_rtl_obj_sect* sect,
52                             const char*               symnane,
53                             const Elf_Byte            syminfo,
54                             const Elf_Word            symvalue)
55{
56  Elf_Addr  target = 0;
57  Elf_Addr* where;
58  Elf_Word  tmp;
59
60  where = (Elf_Addr *)(sect->base + rela->r_offset);
61
62  switch (ELF_R_TYPE(rela->r_info)) {
63                case R_TYPE(NONE):
64                        break;
65
66    case R_TYPE(PC8):
67      tmp = symvalue + rela->r_addend - (Elf_Addr)where;
68      if (overflow_8_check(tmp))
69        return false;
70
71      *(uint8_t *)where = tmp;
72
73      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
74        printf ("rtl: reloc R_TYPE_8/PC8 in %s --> %p (%p) in %s\n",
75                sect->name, (void*) (symvalue + rela->r_addend),
76                (void *)*where, rtems_rtl_obj_oname (obj));
77      break;
78
79    case R_TYPE(PC16):
80      tmp = symvalue + rela->r_addend - (Elf_Addr)where;
81      if (overflow_16_check(tmp))
82        return false;
83
84      *(uint16_t*)where = tmp;
85
86      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
87        printf ("rtl: reloc R_TYPE_16/PC16 in %s --> %p (%p) in %s\n",
88                sect->name, (void*) (symvalue + rela->r_addend),
89                (void *)*where, rtems_rtl_obj_oname (obj));
90      break;
91                case R_TYPE(PC32):
92      target = (Elf_Addr) symvalue + rela->r_addend;
93      *where += target - (Elf_Addr)where;
94
95      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
96        printf ("rtl: reloc PC32 in %s --> %p (%p) in %s\n",
97                sect->name, (void*) (symvalue + rela->r_addend),
98                (void *)*where, rtems_rtl_obj_oname (obj));
99      break;
100
101                case R_TYPE(GOT32):
102                case R_TYPE(32):
103                case R_TYPE(GLOB_DAT):
104      target = (Elf_Addr) symvalue + rela->r_addend;
105
106                        if (*where != target)
107                                *where = target;
108
109      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
110        printf ("rtl: reloc 32/GLOB_DAT in %s --> %p in %s\n",
111                sect->name, (void *)*where,
112                rtems_rtl_obj_oname (obj));
113                        break;
114
115                case R_TYPE(RELATIVE):
116                        *where += (Elf_Addr) sect->base + rela->r_addend;
117      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
118        printf ("rtl: reloc RELATIVE in %s --> %p\n",
119                rtems_rtl_obj_oname (obj), (void *)*where);
120                        break;
121
122                case R_TYPE(COPY):
123                        /*
124                         * These are deferred until all other relocations have
125                         * been done.  All we do here is make sure that the
126                         * COPY relocation is not in a shared library.  They
127                         * are allowed only in executable files.
128                         */
129      printf ("rtl: reloc COPY (please report)\n");
130                        break;
131
132                default:
133      printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
134              "contents = %p\n",
135              ELF_R_SYM(rela->r_info), (uint32_t) ELF_R_TYPE(rela->r_info),
136              (void *)rela->r_offset, (void *)*where);
137      rtems_rtl_set_error (EINVAL,
138                           "%s: Unsupported relocation type %ld "
139                           "in non-PLT relocations",
140                           sect->name, (uint32_t) ELF_R_TYPE(rela->r_info));
141      return false;
142  }
143
144  return true;
145}
146
147bool
148rtems_rtl_elf_relocate_rel (const rtems_rtl_obj*      obj,
149                            const Elf_Rel*            rel,
150                            const rtems_rtl_obj_sect* sect,
151                            const char*               symname,
152                            const Elf_Byte            syminfo,
153                            const Elf_Word            symvalue)
154{
155  rtems_rtl_set_error (EINVAL, "rel type record not supported");
156  return false;
157}
158
159bool
160rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
161                            const char*          name,
162                            uint32_t             flags)
163{
164  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
165}
166
167bool
168rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
169{
170  return rtems_rtl_elf_unwind_dw2_register (obj);
171}
172
173bool
174rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
175{
176  return rtems_rtl_elf_unwind_dw2_deregister (obj);
177}
Note: See TracBrowser for help on using the repository browser.