mdreloc.c revision 1.2 1 1.1 mycroft #include <sys/types.h>
2 1.1 mycroft #include <sys/stat.h>
3 1.1 mycroft
4 1.1 mycroft #include "debug.h"
5 1.1 mycroft #include "rtld.h"
6 1.1 mycroft
7 1.1 mycroft void
8 1.1 mycroft _rtld_setup_pltgot(const Obj_Entry *obj)
9 1.1 mycroft {
10 1.1 mycroft obj->pltgot[1] = (Elf_Addr) obj;
11 1.1 mycroft obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
12 1.1 mycroft }
13 1.2 mycroft
14 1.2 mycroft int
15 1.2 mycroft _rtld_relocate_nonplt_object(obj, rela, dodebug)
16 1.2 mycroft Obj_Entry *obj;
17 1.2 mycroft const Elf_Rela *rela;
18 1.2 mycroft bool dodebug;
19 1.2 mycroft {
20 1.2 mycroft Elf_Addr *where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
21 1.2 mycroft const Elf_Sym *def;
22 1.2 mycroft const Obj_Entry *defobj;
23 1.2 mycroft Elf_Addr tmp;
24 1.2 mycroft
25 1.2 mycroft switch (ELF_R_TYPE(rela->r_info)) {
26 1.2 mycroft
27 1.2 mycroft case R_TYPE(NONE):
28 1.2 mycroft break;
29 1.2 mycroft
30 1.2 mycroft #if 1 /* XXX should not occur */
31 1.2 mycroft case R_TYPE(PC32):
32 1.2 mycroft def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
33 1.2 mycroft if (def == NULL)
34 1.2 mycroft return -1;
35 1.2 mycroft
36 1.2 mycroft tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
37 1.2 mycroft rela->r_addend) - (Elf_Addr)where;
38 1.2 mycroft if (*where != tmp)
39 1.2 mycroft *where = tmp;
40 1.2 mycroft rdbg(dodebug, ("PC32 %s in %s --> %p in %s",
41 1.2 mycroft defobj->strtab + def->st_name, obj->path,
42 1.2 mycroft (void *)*where, defobj->path));
43 1.2 mycroft break;
44 1.2 mycroft
45 1.2 mycroft case R_TYPE(GOT32):
46 1.2 mycroft #endif
47 1.2 mycroft case R_TYPE(32):
48 1.2 mycroft case R_TYPE(GLOB_DAT):
49 1.2 mycroft def = _rtld_find_symdef(rela->r_info, obj, &defobj, false);
50 1.2 mycroft if (def == NULL)
51 1.2 mycroft return -1;
52 1.2 mycroft
53 1.2 mycroft tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
54 1.2 mycroft rela->r_addend);
55 1.2 mycroft if (*where != tmp)
56 1.2 mycroft *where = tmp;
57 1.2 mycroft rdbg(dodebug, ("32/GLOB_DAT %s in %s --> %p in %s",
58 1.2 mycroft defobj->strtab + def->st_name, obj->path,
59 1.2 mycroft (void *)*where, defobj->path));
60 1.2 mycroft break;
61 1.2 mycroft
62 1.2 mycroft case R_TYPE(RELATIVE):
63 1.2 mycroft *where += (Elf_Addr)obj->relocbase;
64 1.2 mycroft rdbg(dodebug, ("RELATIVE in %s --> %p", obj->path,
65 1.2 mycroft (void *)*where));
66 1.2 mycroft break;
67 1.2 mycroft
68 1.2 mycroft case R_TYPE(COPY):
69 1.2 mycroft /*
70 1.2 mycroft * These are deferred until all other relocations have
71 1.2 mycroft * been done. All we do here is make sure that the COPY
72 1.2 mycroft * relocation is not in a shared library. They are allowed
73 1.2 mycroft * only in executable files.
74 1.2 mycroft */
75 1.2 mycroft if (!obj->mainprog) {
76 1.2 mycroft _rtld_error(
77 1.2 mycroft "%s: Unexpected R_COPY relocation in shared library",
78 1.2 mycroft obj->path);
79 1.2 mycroft return -1;
80 1.2 mycroft }
81 1.2 mycroft rdbg(dodebug, ("COPY (avoid in main)"));
82 1.2 mycroft break;
83 1.2 mycroft
84 1.2 mycroft default:
85 1.2 mycroft def = _rtld_find_symdef(rela->r_info, obj, &defobj, true);
86 1.2 mycroft rdbg(dodebug, ("sym = %lu, type = %lu, offset = %p, "
87 1.2 mycroft "addend = %p, contents = %p, symbol = %s",
88 1.2 mycroft (u_long)ELF_R_SYM(rela->r_info),
89 1.2 mycroft (u_long)ELF_R_TYPE(rela->r_info),
90 1.2 mycroft (void *)rela->r_offset, (void *)rela->r_addend,
91 1.2 mycroft (void *)*where,
92 1.2 mycroft def ? defobj->strtab + def->st_name : "??"));
93 1.2 mycroft _rtld_error("%s: Unsupported relocation type %ld "
94 1.2 mycroft "in non-PLT relocations\n",
95 1.2 mycroft obj->path, (u_long) ELF_R_TYPE(rela->r_info));
96 1.2 mycroft return -1;
97 1.2 mycroft }
98 1.2 mycroft return 0;
99 1.2 mycroft }
100