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

5
Last change on this file since f59d435d 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.6 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
34bool
35rtems_rtl_elf_relocate_rela (const rtems_rtl_obj*      obj,
36                             const Elf_Rela*           rel,
37                             const rtems_rtl_obj_sect* sect,
38                             const char*               symname,
39                             const Elf_Byte            syminfo,
40                             const Elf_Word            symvalue)
41{
42  rtems_rtl_set_error (EINVAL, "rela type record not supported");
43  return false;
44}
45
46bool
47rtems_rtl_elf_relocate_rel (const rtems_rtl_obj*      obj,
48                            const Elf_Rel*            rel,
49                            const rtems_rtl_obj_sect* sect,
50                            const char*               symname,
51                            const Elf_Byte            syminfo,
52                            const Elf_Word            symvalue)
53{
54  Elf_Addr  target = 0;
55  Elf_Addr* where;
56  Elf_Addr  tmp;
57
58  where = (Elf_Addr *)(sect->base + rel->r_offset);
59
60  switch (ELF_R_TYPE(rel->r_info)) {
61    case R_TYPE(NONE):
62      break;
63
64    case R_TYPE(PC32):
65      target = (Elf_Addr) symvalue;
66      *where += target - (Elf_Addr)where;
67
68      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
69        printf ("rtl: reloc PC32 in %s --> %p (%p @ %p) in %s\n",
70                sect->name, (void*) symvalue,
71                (void *)*where, where, rtems_rtl_obj_oname (obj));
72      break;
73
74    case R_TYPE(GOT32):
75    case R_TYPE(32):
76    case R_TYPE(GLOB_DAT):
77      target = (Elf_Addr) symvalue;
78
79      tmp = target + *where;
80      if (*where != tmp)
81        *where = tmp;
82      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
83        printf ("rtl: reloc 32/GLOB_DAT in %s --> %p @ %p in %s\n",
84                sect->name, (void *)*where, where,
85                rtems_rtl_obj_oname (obj));
86      break;
87
88    case R_TYPE(RELATIVE):
89      *where += (Elf_Addr)sect->base;
90      if (rtems_rtl_trace (RTEMS_RTL_TRACE_RELOC))
91        printf ("rtl: reloc RELATIVE in %s --> %p @ %p\n",
92                rtems_rtl_obj_oname (obj), (void *)*where, where);
93      break;
94
95    case R_TYPE(COPY):
96      printf ("rtl: reloc COPY (please report)\n");
97      break;
98
99    default:
100      printf ("rtl: reloc unknown: sym = %lu, type = %lu, offset = %p, "
101              "contents = %p\n",
102              ELF_R_SYM(rel->r_info), (uint32_t) ELF_R_TYPE(rel->r_info),
103              (void *)rel->r_offset, (void *)*where);
104      rtems_rtl_set_error (EINVAL,
105                           "%s: Unsupported relocation type %ld "
106                           "in non-PLT relocations",
107                           sect->name, (uint32_t) ELF_R_TYPE(rel->r_info));
108      return false;
109  }
110
111  return true;
112}
113
114bool
115rtems_rtl_elf_unwind_parse (const rtems_rtl_obj* obj,
116                            const char*          name,
117                            uint32_t             flags)
118{
119  return rtems_rtl_elf_unwind_dw2_parse (obj, name, flags);
120}
121
122bool
123rtems_rtl_elf_unwind_register (rtems_rtl_obj* obj)
124{
125  return rtems_rtl_elf_unwind_dw2_register (obj);
126}
127
128bool
129rtems_rtl_elf_unwind_deregister (rtems_rtl_obj* obj)
130{
131  return rtems_rtl_elf_unwind_dw2_deregister (obj);
132}
Note: See TracBrowser for help on using the repository browser.