source: rtems/cpukit/libdl/rtl-mdreloc-i386.c @ d8c70ba6

5
Last change on this file since d8c70ba6 was d8c70ba6, checked in by Chris Johns <chrisj@…>, on 01/15/19 at 06:47:41

libdl: Add support for trampolines

  • Trampolines or fixups for veneers provide long jump support for instruciton sets that implement short relative address branches. The linker provides trampolines when creating a static image. This patch adds trampoline support to libdl and the ARM architecture.
  • The dl09 test requires enough memory so modules are outside the relative branch instruction ranges for the architecture.

Updates #3685

  • 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.31 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
21uint32_t
22rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
23                             const Elf_Shdr*      shdr)
24{
25  return 0;
26}
27
28bool
29rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
30{
31  return true;
32}
33
34size_t
35rtems_rtl_elf_relocate_tramp_max_size (void)
36{
37  /*
38   * Disable by returning 0.
39   */
40  return 0;
41}
42
43bool
44rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
45                                   const Elf_Rela*           rela,
46                                   const rtems_rtl_obj_sect* sect,
47                                   const char*               symname,
48                                   const Elf_Byte            syminfo,
49                                   const Elf_Word            symvalue)
50{
51  (void) obj;
52  (void) rela;
53  (void) sect;
54  (void) symname;
55  (void) syminfo;
56  (void) symvalue;
57  rtems_rtl_set_error (EINVAL, "rela type record not supported");
58  return false;
59}
60
61bool
62rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
63                             const Elf_Rela*           rel,
64                             const rtems_rtl_obj_sect* sect,
65                             const char*               symname,
66                             const Elf_Byte            syminfo,
67                             const Elf_Word            symvalue)
68{
69  (void) obj;
70  (void) rela;
71  (void) sect;
72  (void) symname;
73  (void) syminfo;
74  (void) symvalue;
75  rtems_rtl_set_error (EINVAL, "rela type record not supported");
76  return false;
77}
78
79bool
80rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
81                                  const Elf_Rel*            rel,
82                                  const rtems_rtl_obj_sect* sect,
83                                  const char*               symname,
84                                  const Elf_Byte            syminfo,
85                                  const Elf_Word            symvalue)
86{
87  (void) obj;
88  (void) rel;
89  (void) sect;
90  (void) symname;
91  (void) syminfo;
92  (void) symvalue;
93  return true;
94}
95
96bool
97rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
98                            const Elf_Rel*            rel,
99                            const rtems_rtl_obj_sect* sect,
100                            const char*               symname,
101                            const Elf_Byte            syminfo,
102                            const Elf_Word            symvalue)
103{
104  Elf_Addr  target = 0;
105  Elf_Addr* where;
106  Elf_Addr  tmp;
107
108  where = (Elf_Addr *)(sect->base + rel->r_offset);
109
110  switch (ELF_R_TYPE(rel->r_info)) {
111    case R_TYPE(NONE):
112      break;
113
114    case R_TYPE(PC32):
115      target = (Elf_Addr) symvalue;
116      *where += target - (Elf_Addr)where;
117
118      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
119        printf ("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n",
120                sect->name, (void*) symvalue,
121                (void *)*where, where, rtems_rtl_obj_oname (obj));
122      break;
123
124    case R_TYPE(GOT32):
125    case R_TYPE(32):
126    case R_TYPE(GLOB_DAT):
127      target = (Elf_Addr) symvalue;
128
129      tmp = target + *where;
130      if (*where != tmp)
131        *where = tmp;
132      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
133        printf ("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n",
134                sect->name, (void *)*where, where,
135                rtems_rtl_obj_oname (obj));
136      break;
137
138    case R_TYPE(RELATIVE):
139      *where += (Elf_Addr)sect->base;
140      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
141        printf ("rtl: reloc RELATIVE in %s --> %p @ %p\n",
142                rtems_rtl_obj_oname (obj), (void *)*where, where);
143      break;
144
145    case R_TYPE(COPY):
146      printf ("rtl: reloc COPY (please report)\n");
147      break;
148
149    default:
150      printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
151              "contents = %p\n",
152              ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
153              (void *)rel->r_offset, (void *)*where);
154      rtems_rtl_set_error (EINVAL,
155                           "%s: Unsupported relocation type %ld "
156                           "in non-PLT relocations",
157                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
158      return false;
159  }
160
161  return true;
162}
163
164bool
165rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
166                            const char*          name,
167                            uint32_t             flags)
168{
169  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
170}
171
172bool
173rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
174{
175  return rtems_rtl_elf_unwind_dw2_register (obj);
176}
177
178bool
179rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
180{
181  return rtems_rtl_elf_unwind_dw2_deregister (obj);
182}
Note: See TracBrowser for help on using the repository browser.