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
RevLine 
[ae5fe7e6]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>
[194eb403]10#include <inttypes.h>
[ae5fe7e6]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"
[990adc5]18#include <rtems/rtl/rtl-trace.h>
[c6eead1]19#include "rtl-unwind.h"
20#include "rtl-unwind-dw2.h"
21
22uint32_t
[f59d435d]23rtems_rtl_elf_section_flags (const rtems_rtl_obj* obj,
24                             const Elf_Shdr*      shdr)
[c6eead1]25{
26  return 0;
27}
[ae5fe7e6]28
[6c9f017]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
[ae5fe7e6]61bool
62rtems_rtl_elf_rel_resolve_sym (Elf_Word type)
63{
64  return true;
65}
66
[b9f11607]67uint32_t rtems_rtl_obj_tramp_alignment (const rtems_rtl_obj* obj)
68{
69  (void) obj;
70  return sizeof(uint32_t);
71}
72
[d8c70ba6]73size_t
74rtems_rtl_elf_relocate_tramp_max_size (void)
75{
76  /*
77   * Disable by returning 0.
78   */
79  return 0;
80}
81
[b36c5209]82rtems_rtl_elf_rel_status
[d8c70ba6]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");
[b36c5209]97  return rtems_rtl_elf_rel_failure;
[d8c70ba6]98}
99
[b36c5209]100rtems_rtl_elf_rel_status
[d8c70ba6]101rtems_rtl_elf_relocate_rela (rtems_rtl_obj*            obj,
[f59d435d]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)
[ae5fe7e6]107{
[d8c70ba6]108  (void) obj;
[194eb403]109  (void) rel;
[d8c70ba6]110  (void) sect;
111  (void) symname;
112  (void) syminfo;
113  (void) symvalue;
[ae5fe7e6]114  rtems_rtl_set_error (EINVAL, "rela type record not supported");
[b36c5209]115  return rtems_rtl_elf_rel_failure;
[ae5fe7e6]116}
117
[b36c5209]118rtems_rtl_elf_rel_status
[d8c70ba6]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;
[b36c5209]132  return rtems_rtl_elf_rel_no_error;
[d8c70ba6]133}
134
[b36c5209]135rtems_rtl_elf_rel_status
[d8c70ba6]136rtems_rtl_elf_relocate_rel (rtems_rtl_obj*            obj,
[f59d435d]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)
[ae5fe7e6]142{
[f59d435d]143  Elf_Addr  target = 0;
[ae5fe7e6]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:
[194eb403]189      printf ("rtl: reloc unknown: sym = %i, type = %" PRIu32 ", offset = %p, "
[ae5fe7e6]190              "contents = %p\n",
[194eb403]191              (int) ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
[ae5fe7e6]192              (void *)rel->r_offset, (void *)*where);
193      rtems_rtl_set_error (EINVAL,
[194eb403]194                           "%s: Unsupported relocation type %" PRIu32 " "
[ae5fe7e6]195                           "in non-PLT relocations",
196                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
[b36c5209]197      return rtems_rtl_elf_rel_failure;
[ae5fe7e6]198  }
199
[b36c5209]200  return rtems_rtl_elf_rel_no_error;
[ae5fe7e6]201}
[c6eead1]202
203bool
[f59d435d]204rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
205                            const char*          name,
206                            uint32_t             flags)
[c6eead1]207{
208  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
209}
210
211bool
[f59d435d]212rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
[c6eead1]213{
214  return rtems_rtl_elf_unwind_dw2_register (obj);
215}
216
217bool
[f59d435d]218rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
[c6eead1]219{
220  return rtems_rtl_elf_unwind_dw2_deregister (obj);
221}
Note: See TracBrowser for help on using the repository browser.