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

Last change on this file was b9f11607, checked in by Chris Johns <chrisj@…>, on 08/21/23 at 01:15:13

libdl: Realloc text memory if there are trampolines

  • Add resize to the allocator interface
  • Rework the trampoline variables in the obj struct to make better sense of what is happening

Closes #4944

  • Property mode set to 100644
File size: 6.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 <inttypes.h>
11#include <stdio.h>
12#include <sys/types.h>
13#include <sys/stat.h>
14
15#include <rtems/rtl/rtl.h>
16#include "rtl-elf.h"
17#include "rtl-error.h"
18#include <rtems/rtl/rtl-trace.h>
19#include "rtl-unwind.h"
20#include "rtl-unwind-dw2.h"
21
22uint32_t
23rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
24                             const Elf_Shdr*      shdr)
25{
26  return 0;
27}
28
29uint32_t
30rtems_rtl_elf_arch_parse_section (const rtems_rtl_obj* obj,
31                                  int                  section,
32                                  const char*          name,
33                                  const Elf_Shdr*      shdr,
34                                  const uint32_t       flags)
35{
36  (void) obj;
37  (void) section;
38  (void) name;
39  (void) shdr;
40  return flags;
41}
42
43bool
44rtems_rtl_elf_arch_section_alloc (const rtems_rtl_obj* obj,
45                                  rtems_rtl_obj_sect*  sect)
46{
47  (void) obj;
48  (void) sect;
49  return false;
50}
51
52bool
53rtems_rtl_elf_arch_section_free (const rtems_rtl_obj* obj,
54                                  rtems_rtl_obj_sect*  sect)
55{
56  (void) obj;
57  (void) sect;
58  return false;
59}
60
61bool
62rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
63{
64  return true;
65}
66
67uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj)
68{
69  (void) obj;
70  return sizeof(uint32_t);
71}
72
73size_t
74rtems_rtl_elf_relocate_tramp_max_size (void)
75{
76  /*
77   * Disable by returning 0.
78   */
79  return 0;
80}
81
82rtems_rtl_elf_rel_status
83rtems_rtl_elf_relocate_rela_tramp (rtems_rtl_obj*            obj,
84                                   const Elf_Rela*           rela,
85                                   const rtems_rtl_obj_sect* sect,
86                                   const char*               symname,
87                                   const Elf_Byte            syminfo,
88                                   const Elf_Word            symvalue)
89{
90  (void) obj;
91  (void) rela;
92  (void) sect;
93  (void) symname;
94  (void) syminfo;
95  (void) symvalue;
96  rtems_rtl_set_error (EINVAL, "rela type record not supported");
97  return rtems_rtl_elf_rel_failure;
98}
99
100rtems_rtl_elf_rel_status
101rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
102                             const Elf_Rela*           rel,
103                             const rtems_rtl_obj_sect* sect,
104                             const char*               symname,
105                             const Elf_Byte            syminfo,
106                             const Elf_Word            symvalue)
107{
108  (void) obj;
109  (void) rel;
110  (void) sect;
111  (void) symname;
112  (void) syminfo;
113  (void) symvalue;
114  rtems_rtl_set_error (EINVAL, "rela type record not supported");
115  return rtems_rtl_elf_rel_failure;
116}
117
118rtems_rtl_elf_rel_status
119rtems_rtl_elf_relocate_rel_tramp (rtems_rtl_obj*            obj,
120                                  const Elf_Rel*            rel,
121                                  const rtems_rtl_obj_sect* sect,
122                                  const char*               symname,
123                                  const Elf_Byte            syminfo,
124                                  const Elf_Word            symvalue)
125{
126  (void) obj;
127  (void) rel;
128  (void) sect;
129  (void) symname;
130  (void) syminfo;
131  (void) symvalue;
132  return rtems_rtl_elf_rel_no_error;
133}
134
135rtems_rtl_elf_rel_status
136rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
137                            const Elf_Rel*            rel,
138                            const rtems_rtl_obj_sect* sect,
139                            const char*               symname,
140                            const Elf_Byte            syminfo,
141                            const Elf_Word            symvalue)
142{
143  Elf_Addr  target = 0;
144  Elf_Addr* where;
145  Elf_Addr  tmp;
146
147  where = (Elf_Addr *)(sect->base + rel->r_offset);
148
149  switch (ELF_R_TYPE(rel->r_info)) {
150    case R_TYPE(NONE):
151      break;
152
153    case R_TYPE(PC32):
154      target = (Elf_Addr) symvalue;
155      *where += target - (Elf_Addr)where;
156
157      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
158        printf ("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n",
159                sect->name, (void*) symvalue,
160                (void *)*where, where, rtems_rtl_obj_oname (obj));
161      break;
162
163    case R_TYPE(GOT32):
164    case R_TYPE(32):
165    case R_TYPE(GLOB_DAT):
166      target = (Elf_Addr) symvalue;
167
168      tmp = target + *where;
169      if (*where != tmp)
170        *where = tmp;
171      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
172        printf ("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n",
173                sect->name, (void *)*where, where,
174                rtems_rtl_obj_oname (obj));
175      break;
176
177    case R_TYPE(RELATIVE):
178      *where += (Elf_Addr)sect->base;
179      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
180        printf ("rtl: reloc RELATIVE in %s --> %p @ %p\n",
181                rtems_rtl_obj_oname (obj), (void *)*where, where);
182      break;
183
184    case R_TYPE(COPY):
185      printf ("rtl: reloc COPY (please report)\n");
186      break;
187
188    default:
189      printf ("rtl: reloc unknown: sym = %i, type = %" PRIu32 ", offset = %p, "
190              "contents = %p\n",
191              (int) ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
192              (void *)rel->r_offset, (void *)*where);
193      rtems_rtl_set_error (EINVAL,
194                           "%s: Unsupported relocation type %" PRIu32 " "
195                           "in non-PLT relocations",
196                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
197      return rtems_rtl_elf_rel_failure;
198  }
199
200  return rtems_rtl_elf_rel_no_error;
201}
202
203bool
204rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
205                            const char*          name,
206                            uint32_t             flags)
207{
208  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
209}
210
211bool
212rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
213{
214  return rtems_rtl_elf_unwind_dw2_register (obj);
215}
216
217bool
218rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
219{
220  return rtems_rtl_elf_unwind_dw2_deregister (obj);
221}
Note: See TracBrowser for help on using the repository browser.