5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27 /*
28 * x86 relocation code.
29 */
30
31 #include <sys/types.h>
32 #include <sys/param.h>
33 #include <sys/sysmacros.h>
34 #include <sys/systm.h>
35 #include <sys/user.h>
36 #include <sys/bootconf.h>
37 #include <sys/modctl.h>
38 #include <sys/elf.h>
39 #include <sys/kobj.h>
40 #include <sys/kobj_impl.h>
41 #include <sys/tnf.h>
42 #include <sys/tnf_probe.h>
43
44 #include "reloc.h"
141 " symbol\n");
142 _kobj_printf(ops, "krtld:\t\t\t\t\t value\n");
143 }
144 #endif
145
146 symnum = -1;
147 /* loop through relocations */
148 while (reladdr < rend) {
149 symnum++;
150 rtype = ELF_R_TYPE(((Rela *)reladdr)->r_info);
151 off = ((Rela *)reladdr)->r_offset;
152 stndx = ELF_R_SYM(((Rela *)reladdr)->r_info);
153 if (stndx >= mp->nsyms) {
154 _kobj_printf(ops, "do_relocate: bad strndx %d\n",
155 symnum);
156 return (-1);
157 }
158 if ((rtype > R_AMD64_NUM) || IS_TLS_INS(rtype)) {
159 _kobj_printf(ops, "krtld: invalid relocation type %d",
160 rtype);
161 _kobj_printf(ops, " at 0x%llx:", off);
162 _kobj_printf(ops, " file=%s\n", mp->filename);
163 err = 1;
164 continue;
165 }
166
167
168 addend = (long)(((Rela *)reladdr)->r_addend);
169 reladdr += relocsize;
170
171
172 if (rtype == R_AMD64_NONE)
173 continue;
174
175 #ifdef KOBJ_DEBUG
176 if (kobj_debug & D_RELOCATIONS) {
177 Sym * symp;
178 symp = (Sym *)
179 (mp->symtbl+(stndx * mp->symhdr->sh_entsize));
180 _kobj_printf(ops, "krtld:\t%s",
181 conv_reloc_amd64_type(rtype));
182 _kobj_printf(ops, "\t0x%8llx", off);
183 _kobj_printf(ops, " 0x%8llx", addend);
184 _kobj_printf(ops, " %s\n",
185 (const char *)mp->strings + symp->st_name);
186 }
187 #endif
188
189 if (!(mp->flags & KOBJ_EXEC))
190 off += baseaddr;
191
192 /*
193 * if R_AMD64_RELATIVE, simply add base addr
194 * to reloc location
195 */
196
197 if (rtype == R_AMD64_RELATIVE) {
198 value = baseaddr;
199 } else {
200 /*
201 * get symbol table entry - if symbol is local
202 * value is base address of this object
203 */
237 * calculate location of definition
238 * - symbol value plus base address of
239 * containing shared object
240 */
241 value = symref->st_value;
242
243 } /* end else symbol found */
244 } /* end global or weak */
245 } /* end not R_AMD64_RELATIVE */
246
247 value += addend;
248 /*
249 * calculate final value -
250 * if PC-relative, subtract ref addr
251 */
252 if (IS_PC_RELATIVE(rtype))
253 value -= off;
254
255 #ifdef KOBJ_DEBUG
256 if (kobj_debug & D_RELOCATIONS) {
257 _kobj_printf(ops, "krtld:\t\t\t\t0x%8llx", off);
258 _kobj_printf(ops, " 0x%8llx\n", value);
259 }
260 #endif
261
262 if (do_reloc_krtld(rtype, (unsigned char *)off, &value,
263 (const char *)mp->strings + symref->st_name,
264 mp->filename) == 0)
265 err = 1;
266
267 } /* end of while loop */
268 if (err)
269 return (-1);
270
271 if (tnf_splice_probes(mp->flags & KOBJ_PRIM, probelist, taglist))
272 mp->flags |= KOBJ_TNF_PROBE;
273
274 return (0);
275 }
276
277 int
278 do_relocations(struct module *mp)
|
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 *
26 * Copyright 2020 Joyent, Inc.
27 */
28
29 /*
30 * x86 relocation code.
31 */
32
33 #include <sys/types.h>
34 #include <sys/param.h>
35 #include <sys/sysmacros.h>
36 #include <sys/systm.h>
37 #include <sys/user.h>
38 #include <sys/bootconf.h>
39 #include <sys/modctl.h>
40 #include <sys/elf.h>
41 #include <sys/kobj.h>
42 #include <sys/kobj_impl.h>
43 #include <sys/tnf.h>
44 #include <sys/tnf_probe.h>
45
46 #include "reloc.h"
143 " symbol\n");
144 _kobj_printf(ops, "krtld:\t\t\t\t\t value\n");
145 }
146 #endif
147
148 symnum = -1;
149 /* loop through relocations */
150 while (reladdr < rend) {
151 symnum++;
152 rtype = ELF_R_TYPE(((Rela *)reladdr)->r_info);
153 off = ((Rela *)reladdr)->r_offset;
154 stndx = ELF_R_SYM(((Rela *)reladdr)->r_info);
155 if (stndx >= mp->nsyms) {
156 _kobj_printf(ops, "do_relocate: bad strndx %d\n",
157 symnum);
158 return (-1);
159 }
160 if ((rtype > R_AMD64_NUM) || IS_TLS_INS(rtype)) {
161 _kobj_printf(ops, "krtld: invalid relocation type %d",
162 rtype);
163 _kobj_printf(ops, " at 0x%lx:", off);
164 _kobj_printf(ops, " file=%s\n", mp->filename);
165 err = 1;
166 continue;
167 }
168
169
170 addend = (long)(((Rela *)reladdr)->r_addend);
171 reladdr += relocsize;
172
173
174 if (rtype == R_AMD64_NONE)
175 continue;
176
177 #ifdef KOBJ_DEBUG
178 if (kobj_debug & D_RELOCATIONS) {
179 Sym * symp;
180 symp = (Sym *)
181 (mp->symtbl+(stndx * mp->symhdr->sh_entsize));
182 _kobj_printf(ops, "krtld:\t%s",
183 conv_reloc_amd64_type(rtype));
184 _kobj_printf(ops, "\t0x%8lx", off);
185 _kobj_printf(ops, " %8lld", (longlong_t)addend);
186 _kobj_printf(ops, " %s\n",
187 (const char *)mp->strings + symp->st_name);
188 }
189 #endif
190
191 if (!(mp->flags & KOBJ_EXEC))
192 off += baseaddr;
193
194 /*
195 * if R_AMD64_RELATIVE, simply add base addr
196 * to reloc location
197 */
198
199 if (rtype == R_AMD64_RELATIVE) {
200 value = baseaddr;
201 } else {
202 /*
203 * get symbol table entry - if symbol is local
204 * value is base address of this object
205 */
239 * calculate location of definition
240 * - symbol value plus base address of
241 * containing shared object
242 */
243 value = symref->st_value;
244
245 } /* end else symbol found */
246 } /* end global or weak */
247 } /* end not R_AMD64_RELATIVE */
248
249 value += addend;
250 /*
251 * calculate final value -
252 * if PC-relative, subtract ref addr
253 */
254 if (IS_PC_RELATIVE(rtype))
255 value -= off;
256
257 #ifdef KOBJ_DEBUG
258 if (kobj_debug & D_RELOCATIONS) {
259 _kobj_printf(ops, "krtld:\t\t\t\t0x%8lx", off);
260 _kobj_printf(ops, " 0x%8lx\n", value);
261 }
262 #endif
263
264 if (do_reloc_krtld(rtype, (unsigned char *)off, &value,
265 (const char *)mp->strings + symref->st_name,
266 mp->filename) == 0)
267 err = 1;
268
269 } /* end of while loop */
270 if (err)
271 return (-1);
272
273 if (tnf_splice_probes(mp->flags & KOBJ_PRIM, probelist, taglist))
274 mp->flags |= KOBJ_TNF_PROBE;
275
276 return (0);
277 }
278
279 int
280 do_relocations(struct module *mp)
|