mdreloc.c revision 1.3 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.3 mycroft _rtld_relocate_nonplt_objects(obj, dodebug)
16 1.2 mycroft Obj_Entry *obj;
17 1.2 mycroft bool dodebug;
18 1.2 mycroft {
19 1.3 mycroft const Elf_Rela *rela;
20 1.2 mycroft
21 1.3 mycroft for (rela = obj->rela; rela < obj->relalim; rela++) {
22 1.3 mycroft Elf_Addr *where;
23 1.3 mycroft const Elf_Sym *def;
24 1.3 mycroft const Obj_Entry *defobj;
25 1.3 mycroft Elf_Addr tmp;
26 1.3 mycroft
27 1.3 mycroft where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
28 1.3 mycroft
29 1.3 mycroft switch (ELF_R_TYPE(rela->r_info)) {
30 1.3 mycroft case R_TYPE(NONE):
31 1.3 mycroft break;
32 1.3 mycroft
33 1.3 mycroft case R_TYPE(32): /* word32 S + A */
34 1.3 mycroft case R_TYPE(GLOB_DAT): /* word32 S + A */
35 1.3 mycroft def = _rtld_find_symdef(rela->r_info, obj, &defobj,
36 1.3 mycroft false);
37 1.3 mycroft if (def == NULL)
38 1.3 mycroft return -1;
39 1.3 mycroft
40 1.3 mycroft tmp = (Elf_Addr)(defobj->relocbase + def->st_value +
41 1.3 mycroft rela->r_addend);
42 1.3 mycroft
43 1.3 mycroft if (*where != tmp)
44 1.3 mycroft *where = tmp;
45 1.3 mycroft rdbg(dodebug, ("32/GLOB_DAT %s in %s --> %p in %s",
46 1.3 mycroft defobj->strtab + def->st_name, obj->path,
47 1.3 mycroft (void *)*where, defobj->path));
48 1.3 mycroft break;
49 1.3 mycroft
50 1.3 mycroft case R_TYPE(RELATIVE): /* word32 B + A */
51 1.3 mycroft tmp = (Elf_Addr)(obj->relocbase + rela->r_addend);
52 1.3 mycroft if (*where != tmp)
53 1.3 mycroft *where = tmp;
54 1.3 mycroft rdbg(dodebug, ("RELATIVE in %s --> %p", obj->path,
55 1.3 mycroft (void *)*where));
56 1.3 mycroft break;
57 1.3 mycroft
58 1.3 mycroft case R_TYPE(COPY):
59 1.3 mycroft /*
60 1.3 mycroft * These are deferred until all other relocations have
61 1.3 mycroft * been done. All we do here is make sure that the
62 1.3 mycroft * COPY relocation is not in a shared library. They
63 1.3 mycroft * are allowed only in executable files.
64 1.3 mycroft */
65 1.3 mycroft if (!obj->mainprog) {
66 1.3 mycroft _rtld_error(
67 1.2 mycroft "%s: Unexpected R_COPY relocation in shared library",
68 1.3 mycroft obj->path);
69 1.3 mycroft return -1;
70 1.3 mycroft }
71 1.3 mycroft rdbg(dodebug, ("COPY (avoid in main)"));
72 1.3 mycroft break;
73 1.3 mycroft
74 1.3 mycroft default:
75 1.3 mycroft def = _rtld_find_symdef(rela->r_info, obj, &defobj,
76 1.3 mycroft true);
77 1.3 mycroft rdbg(dodebug, ("sym = %lu, type = %lu, offset = %p, "
78 1.3 mycroft "addend = %p, contents = %p, symbol = %s",
79 1.3 mycroft (u_long)ELF_R_SYM(rela->r_info),
80 1.3 mycroft (u_long)ELF_R_TYPE(rela->r_info),
81 1.3 mycroft (void *)rela->r_offset, (void *)rela->r_addend,
82 1.3 mycroft (void *)*where,
83 1.3 mycroft def ? defobj->strtab + def->st_name : "??"));
84 1.3 mycroft _rtld_error("%s: Unsupported relocation type %ld "
85 1.3 mycroft "in non-PLT relocations\n",
86 1.3 mycroft obj->path, (u_long) ELF_R_TYPE(rela->r_info));
87 1.2 mycroft return -1;
88 1.2 mycroft }
89 1.2 mycroft }
90 1.2 mycroft return 0;
91 1.2 mycroft }
92