annotate head/libexec/rtld-elf/amd64/reloc.c @ 481:737774f27543

Update libexec/rtld-elf to @235221
author Aleksandr Rybalko <ray@ddteam.net>
date Thu, 10 May 2012 14:47:51 +0300
parents f2935497fa04
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
1 /*-
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
2 * Copyright 1996, 1997, 1998, 1999 John D. Polstra.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
3 * All rights reserved.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
4 *
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
5 * Redistribution and use in source and binary forms, with or without
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
6 * modification, are permitted provided that the following conditions
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
7 * are met:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
8 * 1. Redistributions of source code must retain the above copyright
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
9 * notice, this list of conditions and the following disclaimer.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
10 * 2. Redistributions in binary form must reproduce the above copyright
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
11 * notice, this list of conditions and the following disclaimer in the
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
12 * documentation and/or other materials provided with the distribution.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
13 *
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
15 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
16 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
17 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
18 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
19 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
20 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
21 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
24 *
481
737774f27543 Update libexec/rtld-elf to @235221
Aleksandr Rybalko <ray@ddteam.net>
parents: 453
diff changeset
25 * $FreeBSD: head/libexec/rtld-elf/amd64/reloc.c 234841 2012-04-30 13:31:10Z kib $
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
26 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
27
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
28 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
29 * Dynamic linker for ELF.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
30 *
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
31 * John Polstra <[email protected]>.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
32 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
33
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
34 #include <sys/param.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
35 #include <sys/mman.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
36 #include <machine/sysarch.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
37
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
38 #include <dlfcn.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
39 #include <err.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
40 #include <errno.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
41 #include <fcntl.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
42 #include <stdarg.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
43 #include <stdio.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
44 #include <stdlib.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
45 #include <string.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
46 #include <unistd.h>
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
47
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
48 #include "debug.h"
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
49 #include "rtld.h"
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
50
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
51 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
52 * Process the special R_X86_64_COPY relocations in the main program. These
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
53 * copy data from a shared object into a region in the main program's BSS
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
54 * segment.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
55 *
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
56 * Returns 0 on success, -1 on failure.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
57 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
58 int
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
59 do_copy_relocations(Obj_Entry *dstobj)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
60 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
61 const Elf_Rela *relalim;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
62 const Elf_Rela *rela;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
63
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
64 assert(dstobj->mainprog); /* COPY relocations are invalid elsewhere */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
65
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
66 relalim = (const Elf_Rela *) ((caddr_t) dstobj->rela + dstobj->relasize);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
67 for (rela = dstobj->rela; rela < relalim; rela++) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
68 if (ELF_R_TYPE(rela->r_info) == R_X86_64_COPY) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
69 void *dstaddr;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
70 const Elf_Sym *dstsym;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
71 const char *name;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
72 size_t size;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
73 const void *srcaddr;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
74 const Elf_Sym *srcsym;
86
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
75 const Obj_Entry *srcobj, *defobj;
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
76 SymLook req;
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
77 int res;
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
78
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
79 dstaddr = (void *) (dstobj->relocbase + rela->r_offset);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
80 dstsym = dstobj->symtab + ELF_R_SYM(rela->r_info);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
81 name = dstobj->strtab + dstsym->st_name;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
82 size = dstsym->st_size;
86
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
83 symlook_init(&req, name);
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
84 req.ventry = fetch_ventry(dstobj, ELF_R_SYM(rela->r_info));
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
85 req.flags = SYMLOOK_EARLY;
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
86
86
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
87 for (srcobj = dstobj->next; srcobj != NULL; srcobj = srcobj->next) {
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
88 res = symlook_obj(&req, srcobj);
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
89 if (res == 0) {
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
90 srcsym = req.sym_out;
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
91 defobj = req.defobj_out;
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
92 break;
86
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
93 }
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
94 }
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
95
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
96 if (srcobj == NULL) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
97 _rtld_error("Undefined symbol \"%s\" referenced from COPY"
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
98 " relocation in %s", name, dstobj->path);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
99 return -1;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
100 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
101
86
a350047c8ffe FreeBSD HEAD @svn r216736
ray@terran.dlink.ua
parents: 47
diff changeset
102 srcaddr = (const void *) (defobj->relocbase + srcsym->st_value);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
103 memcpy(dstaddr, srcaddr, size);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
104 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
105 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
106
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
107 return 0;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
108 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
109
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
110 /* Initialize the special GOT entries. */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
111 void
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
112 init_pltgot(Obj_Entry *obj)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
113 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
114 if (obj->pltgot != NULL) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
115 obj->pltgot[1] = (Elf_Addr) obj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
116 obj->pltgot[2] = (Elf_Addr) &_rtld_bind_start;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
117 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
118 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
119
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
120 /* Process the non-PLT relocations. */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
121 int
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
122 reloc_non_plt(Obj_Entry *obj, Obj_Entry *obj_rtld, int flags,
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
123 RtldLockState *lockstate)
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
124 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
125 const Elf_Rela *relalim;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
126 const Elf_Rela *rela;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
127 SymCache *cache;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
128 int r = -1;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
129
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
130 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
131 * The dynamic loader may be called from a thread, we have
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
132 * limited amounts of stack available so we cannot use alloca().
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
133 */
47
2a56ab25e52c FreeBSD HEAD @208589
ray@terran.dlink.ua
parents: 1
diff changeset
134 if (obj != obj_rtld) {
481
737774f27543 Update libexec/rtld-elf to @235221
Aleksandr Rybalko <ray@ddteam.net>
parents: 453
diff changeset
135 cache = calloc(obj->dynsymcount, sizeof(SymCache));
47
2a56ab25e52c FreeBSD HEAD @208589
ray@terran.dlink.ua
parents: 1
diff changeset
136 /* No need to check for NULL here */
2a56ab25e52c FreeBSD HEAD @208589
ray@terran.dlink.ua
parents: 1
diff changeset
137 } else
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
138 cache = NULL;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
139
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
140 relalim = (const Elf_Rela *) ((caddr_t) obj->rela + obj->relasize);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
141 for (rela = obj->rela; rela < relalim; rela++) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
142 Elf_Addr *where = (Elf_Addr *) (obj->relocbase + rela->r_offset);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
143 Elf32_Addr *where32 = (Elf32_Addr *)where;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
144
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
145 switch (ELF_R_TYPE(rela->r_info)) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
146
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
147 case R_X86_64_NONE:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
148 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
149
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
150 case R_X86_64_64:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
151 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
152 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
153 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
154
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
155 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
156 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
157 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
158 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
159
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
160 *where = (Elf_Addr) (defobj->relocbase + def->st_value + rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
161 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
162 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
163
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
164 case R_X86_64_PC32:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
165 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
166 * I don't think the dynamic linker should ever see this
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
167 * type of relocation. But the binutils-2.6 tools sometimes
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
168 * generate it.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
169 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
170 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
171 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
172 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
173
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
174 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
175 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
176 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
177 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
178
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
179 *where32 = (Elf32_Addr) (unsigned long) (defobj->relocbase +
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
180 def->st_value + rela->r_addend - (Elf_Addr) where);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
181 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
182 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
183 /* missing: R_X86_64_GOT32 R_X86_64_PLT32 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
184
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
185 case R_X86_64_COPY:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
186 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
187 * These are deferred until all other relocations have
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
188 * been done. All we do here is make sure that the COPY
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
189 * relocation is not in a shared library. They are allowed
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
190 * only in executable files.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
191 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
192 if (!obj->mainprog) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
193 _rtld_error("%s: Unexpected R_X86_64_COPY relocation"
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
194 " in shared library", obj->path);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
195 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
196 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
197 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
198
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
199 case R_X86_64_GLOB_DAT:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
200 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
201 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
202 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
203
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
204 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
205 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
206 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
207 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
208
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
209 *where = (Elf_Addr) (defobj->relocbase + def->st_value);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
210 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
211 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
212
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
213 case R_X86_64_TPOFF64:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
214 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
215 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
216 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
217
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
218 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
219 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
220 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
221 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
222
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
223 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
224 * We lazily allocate offsets for static TLS as we
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
225 * see the first relocation that references the
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
226 * TLS block. This allows us to support (small
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
227 * amounts of) static TLS in dynamically loaded
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
228 * modules. If we run out of space, we generate an
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
229 * error.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
230 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
231 if (!defobj->tls_done) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
232 if (!allocate_tls_offset((Obj_Entry*) defobj)) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
233 _rtld_error("%s: No space available for static "
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
234 "Thread Local Storage", obj->path);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
235 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
236 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
237 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
238
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
239 *where = (Elf_Addr) (def->st_value - defobj->tlsoffset +
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
240 rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
241 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
242 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
243
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
244 case R_X86_64_TPOFF32:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
245 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
246 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
247 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
248
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
249 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
250 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
251 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
252 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
253
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
254 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
255 * We lazily allocate offsets for static TLS as we
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
256 * see the first relocation that references the
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
257 * TLS block. This allows us to support (small
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
258 * amounts of) static TLS in dynamically loaded
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
259 * modules. If we run out of space, we generate an
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
260 * error.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
261 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
262 if (!defobj->tls_done) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
263 if (!allocate_tls_offset((Obj_Entry*) defobj)) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
264 _rtld_error("%s: No space available for static "
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
265 "Thread Local Storage", obj->path);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
266 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
267 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
268 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
269
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
270 *where32 = (Elf32_Addr) (def->st_value -
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
271 defobj->tlsoffset +
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
272 rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
273 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
274 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
275
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
276 case R_X86_64_DTPMOD64:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
277 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
278 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
279 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
280
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
281 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
282 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
283 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
284 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
285
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
286 *where += (Elf_Addr) defobj->tlsindex;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
287 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
288 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
289
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
290 case R_X86_64_DTPOFF64:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
291 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
292 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
293 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
294
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
295 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
296 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
297 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
298 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
299
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
300 *where += (Elf_Addr) (def->st_value + rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
301 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
302 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
303
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
304 case R_X86_64_DTPOFF32:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
305 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
306 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
307 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
308
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
309 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
310 flags, cache, lockstate);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
311 if (def == NULL)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
312 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
313
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
314 *where32 += (Elf32_Addr) (def->st_value + rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
315 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
316 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
317
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
318 case R_X86_64_RELATIVE:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
319 *where = (Elf_Addr)(obj->relocbase + rela->r_addend);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
320 break;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
321
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
322 /* missing: R_X86_64_GOTPCREL, R_X86_64_32, R_X86_64_32S, R_X86_64_16, R_X86_64_PC16, R_X86_64_8, R_X86_64_PC8 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
323
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
324 default:
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
325 _rtld_error("%s: Unsupported relocation type %u"
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
326 " in non-PLT relocations\n", obj->path,
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
327 (unsigned int)ELF_R_TYPE(rela->r_info));
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
328 goto done;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
329 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
330 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
331 r = 0;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
332 done:
47
2a56ab25e52c FreeBSD HEAD @208589
ray@terran.dlink.ua
parents: 1
diff changeset
333 if (cache != NULL)
2a56ab25e52c FreeBSD HEAD @208589
ray@terran.dlink.ua
parents: 1
diff changeset
334 free(cache);
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
335 return (r);
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
336 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
337
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
338 /* Process the PLT relocations. */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
339 int
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
340 reloc_plt(Obj_Entry *obj)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
341 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
342 const Elf_Rela *relalim;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
343 const Elf_Rela *rela;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
344
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
345 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
346 for (rela = obj->pltrela; rela < relalim; rela++) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
347 Elf_Addr *where;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
348
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
349 switch(ELF_R_TYPE(rela->r_info)) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
350 case R_X86_64_JMP_SLOT:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
351 /* Relocate the GOT slot pointing into the PLT. */
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
352 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
353 *where += (Elf_Addr)obj->relocbase;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
354 break;
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
355
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
356 case R_X86_64_IRELATIVE:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
357 obj->irelative = true;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
358 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
359
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
360 default:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
361 _rtld_error("Unknown relocation type %x in PLT",
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
362 (unsigned int)ELF_R_TYPE(rela->r_info));
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
363 return (-1);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
364 }
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
365 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
366 return 0;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
367 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
368
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
369 /* Relocate the jump slots in an object. */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
370 int
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
371 reloc_jmpslots(Obj_Entry *obj, int flags, RtldLockState *lockstate)
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
372 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
373 const Elf_Rela *relalim;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
374 const Elf_Rela *rela;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
375
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
376 if (obj->jmpslots_done)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
377 return 0;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
378 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
379 for (rela = obj->pltrela; rela < relalim; rela++) {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
380 Elf_Addr *where, target;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
381 const Elf_Sym *def;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
382 const Obj_Entry *defobj;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
383
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
384 switch (ELF_R_TYPE(rela->r_info)) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
385 case R_X86_64_JMP_SLOT:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
386 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
387 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
388 SYMLOOK_IN_PLT | flags, NULL, lockstate);
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
389 if (def == NULL)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
390 return (-1);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
391 if (ELF_ST_TYPE(def->st_info) == STT_GNU_IFUNC) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
392 obj->gnu_ifunc = true;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
393 continue;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
394 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
395 target = (Elf_Addr)(defobj->relocbase + def->st_value + rela->r_addend);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
396 reloc_jmpslot(where, target, defobj, obj, (const Elf_Rel *)rela);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
397 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
398
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
399 case R_X86_64_IRELATIVE:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
400 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
401
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
402 default:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
403 _rtld_error("Unknown relocation type %x in PLT",
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
404 (unsigned int)ELF_R_TYPE(rela->r_info));
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
405 return (-1);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
406 }
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
407 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
408 obj->jmpslots_done = true;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
409 return 0;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
410 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
411
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
412 int
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
413 reloc_iresolve(Obj_Entry *obj, RtldLockState *lockstate)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
414 {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
415 const Elf_Rela *relalim;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
416 const Elf_Rela *rela;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
417
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
418 if (!obj->irelative)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
419 return (0);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
420 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
421 for (rela = obj->pltrela; rela < relalim; rela++) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
422 Elf_Addr *where, target, *ptr;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
423
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
424 switch (ELF_R_TYPE(rela->r_info)) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
425 case R_X86_64_JMP_SLOT:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
426 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
427
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
428 case R_X86_64_IRELATIVE:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
429 ptr = (Elf_Addr *)(obj->relocbase + rela->r_addend);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
430 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
431 lock_release(rtld_bind_lock, lockstate);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
432 target = ((Elf_Addr (*)(void))ptr)();
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
433 wlock_acquire(rtld_bind_lock, lockstate);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
434 *where = target;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
435 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
436 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
437 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
438 obj->irelative = false;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
439 return (0);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
440 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
441
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
442 int
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
443 reloc_gnu_ifunc(Obj_Entry *obj, int flags, RtldLockState *lockstate)
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
444 {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
445 const Elf_Rela *relalim;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
446 const Elf_Rela *rela;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
447
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
448 if (!obj->gnu_ifunc)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
449 return (0);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
450 relalim = (const Elf_Rela *)((char *)obj->pltrela + obj->pltrelasize);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
451 for (rela = obj->pltrela; rela < relalim; rela++) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
452 Elf_Addr *where, target;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
453 const Elf_Sym *def;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
454 const Obj_Entry *defobj;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
455
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
456 switch (ELF_R_TYPE(rela->r_info)) {
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
457 case R_X86_64_JMP_SLOT:
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
458 where = (Elf_Addr *)(obj->relocbase + rela->r_offset);
453
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
459 def = find_symdef(ELF_R_SYM(rela->r_info), obj, &defobj,
f2935497fa04 FreeBSD HEAD @svn 234370r.
Aleksandr Rybalko <ray@ddteam.net>
parents: 325
diff changeset
460 SYMLOOK_IN_PLT | flags, NULL, lockstate);
247
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
461 if (def == NULL)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
462 return (-1);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
463 if (ELF_ST_TYPE(def->st_info) != STT_GNU_IFUNC)
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
464 continue;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
465 lock_release(rtld_bind_lock, lockstate);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
466 target = (Elf_Addr)rtld_resolve_ifunc(defobj, def);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
467 wlock_acquire(rtld_bind_lock, lockstate);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
468 reloc_jmpslot(where, target, defobj, obj, (const Elf_Rel *)rela);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
469 break;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
470 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
471 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
472 obj->gnu_ifunc = false;
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
473 return (0);
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
474 }
820af1e39cd6 FreeBSD HEAD @svn 228526r.
ray@terran.dlink.ua
parents: 86
diff changeset
475
1
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
476 void
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
477 allocate_initial_tls(Obj_Entry *objs)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
478 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
479 /*
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
480 * Fix the size of the static TLS block by using the maximum
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
481 * offset allocated so far and adding a bit for dynamic modules to
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
482 * use.
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
483 */
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
484 tls_static_space = tls_last_offset + RTLD_STATIC_TLS_EXTRA;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
485 amd64_set_fsbase(allocate_tls(objs, 0,
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
486 3*sizeof(Elf_Addr), sizeof(Elf_Addr)));
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
487 }
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
488
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
489 void *__tls_get_addr(tls_index *ti)
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
490 {
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
491 Elf_Addr** segbase;
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
492
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
493 __asm __volatile("movq %%fs:0, %0" : "=r" (segbase));
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
494
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
495 return tls_get_addr_common(&segbase[1], ti->ti_module, ti->ti_offset);
8101a7904232 FreeBSD HEAD @205277
ray@terran.dlink.ua
parents:
diff changeset
496 }