Print this page
10267 ld and GCC disagree about i386 local dynamic TLS
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/cmd/sgs/libld/common/machrel.intel.c
+++ new/usr/src/cmd/sgs/libld/common/machrel.intel.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc.
24 24 * Copyright (c) 1988 AT&T
25 25 * All Rights Reserved
26 26 *
27 27 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved.
28 28 */
29 29
30 30 /* Get the x86 version of the relocation engine */
31 31 #define DO_RELOC_LIBLD_X86
32 32
33 33 #include <string.h>
34 34 #include <stdio.h>
35 35 #include <sys/elf_386.h>
36 36 #include <debug.h>
37 37 #include <reloc.h>
38 38 #include <i386/machdep_x86.h>
39 39 #include "msg.h"
40 40 #include "_libld.h"
41 41
42 42 /*
43 43 * Search the GOT index list for a GOT entry with a matching reference.
44 44 */
45 45 /* ARGSUSED3 */
46 46 static Gotndx *
47 47 ld_find_got_ndx(Alist *alp, Gotref gref, Ofl_desc *ofl, Rel_desc *rdesc)
48 48 {
49 49 Aliste idx;
50 50 Gotndx *gnp;
51 51
52 52 if ((gref == GOT_REF_TLSLD) && ofl->ofl_tlsldgotndx)
53 53 return (ofl->ofl_tlsldgotndx);
54 54
55 55 for (ALIST_TRAVERSE(alp, idx, gnp)) {
56 56 if (gnp->gn_gotref == gref)
57 57 return (gnp);
58 58 }
59 59 return (NULL);
60 60 }
61 61
62 62 static Xword
63 63 ld_calc_got_offset(Rel_desc *rdesc, Ofl_desc *ofl)
64 64 {
65 65 Os_desc *osp = ofl->ofl_osgot;
66 66 Sym_desc *sdp = rdesc->rel_sym;
67 67 Xword gotndx;
68 68 Gotref gref;
69 69 Gotndx *gnp;
70 70
71 71 if (rdesc->rel_flags & FLG_REL_DTLS)
72 72 gref = GOT_REF_TLSGD;
73 73 else if (rdesc->rel_flags & FLG_REL_MTLS)
74 74 gref = GOT_REF_TLSLD;
75 75 else if (rdesc->rel_flags & FLG_REL_STLS)
76 76 gref = GOT_REF_TLSIE;
77 77 else
78 78 gref = GOT_REF_GENERIC;
79 79
80 80 gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL);
81 81 assert(gnp);
82 82
83 83 gotndx = (Xword)gnp->gn_gotndx;
84 84
85 85 if ((rdesc->rel_flags & FLG_REL_DTLS) &&
86 86 (rdesc->rel_rtype == R_386_TLS_DTPOFF32))
87 87 gotndx++;
88 88
89 89 return ((Xword)(osp->os_shdr->sh_addr + (gotndx * M_GOT_ENTSIZE)));
90 90 }
91 91
92 92 static Word
93 93 ld_init_rel(Rel_desc *reld, Word *typedata, void *reloc)
94 94 {
95 95 Rel *rel = (Rel *)reloc;
96 96
97 97 /* LINTED */
98 98 reld->rel_rtype = (Word)ELF_R_TYPE(rel->r_info, M_MACH);
99 99 reld->rel_roffset = rel->r_offset;
100 100 reld->rel_raddend = 0;
101 101 *typedata = 0;
102 102
103 103 return ((Word)ELF_R_SYM(rel->r_info));
104 104 }
105 105
106 106 static void
107 107 ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl)
108 108 {
109 109 ofl->ofl_dehdr->e_flags |= ehdr->e_flags;
110 110 }
111 111
112 112 static void
113 113 ld_mach_make_dynamic(Ofl_desc *ofl, size_t *cnt)
114 114 {
115 115 if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) {
116 116 /*
117 117 * Create this entry if we are going to create a PLT table.
118 118 */
119 119 if (ofl->ofl_pltcnt)
120 120 (*cnt)++; /* DT_PLTGOT */
121 121 }
122 122 }
123 123
124 124 static void
125 125 ld_mach_update_odynamic(Ofl_desc *ofl, Dyn **dyn)
126 126 {
127 127 if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) && ofl->ofl_pltcnt) {
128 128 (*dyn)->d_tag = DT_PLTGOT;
129 129 if (ofl->ofl_osgot)
130 130 (*dyn)->d_un.d_ptr = ofl->ofl_osgot->os_shdr->sh_addr;
131 131 else
132 132 (*dyn)->d_un.d_ptr = 0;
133 133 (*dyn)++;
134 134 }
135 135 }
136 136
137 137 static Xword
138 138 ld_calc_plt_addr(Sym_desc *sdp, Ofl_desc *ofl)
139 139 {
140 140 Xword value;
141 141
142 142 value = (Xword)(ofl->ofl_osplt->os_shdr->sh_addr) +
143 143 M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * M_PLT_ENTSIZE);
144 144 return (value);
145 145 }
146 146
147 147 /*
148 148 * Build a single plt entry - code is:
149 149 * if (building a.out)
150 150 * JMP *got_off
151 151 * else
152 152 * JMP *got_off@GOT(%ebx)
153 153 * PUSHL &rel_off
154 154 * JMP -n(%pc) # -n is pcrel offset to first plt entry
155 155 *
156 156 * The got_off@GOT entry gets filled with the address of the PUSHL,
157 157 * so the first pass through the plt jumps back here, jumping
158 158 * in turn to the first plt entry, which jumps to the dynamic
159 159 * linker. The dynamic linker then patches the GOT, rerouting
160 160 * future plt calls to the proper destination.
161 161 */
162 162 static void
163 163 plt_entry(Ofl_desc * ofl, Word rel_off, Sym_desc * sdp)
164 164 {
165 165 uchar_t *pltent, *gotent;
166 166 Sword plt_off;
167 167 Word got_off;
168 168 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0;
169 169
170 170 got_off = sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE;
171 171 plt_off = M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) *
172 172 M_PLT_ENTSIZE);
173 173 pltent = (uchar_t *)(ofl->ofl_osplt->os_outdata->d_buf) + plt_off;
174 174 gotent = (uchar_t *)(ofl->ofl_osgot->os_outdata->d_buf) + got_off;
175 175
176 176 /*
177 177 * Fill in the got entry with the address of the next instruction.
178 178 */
179 179 /* LINTED */
180 180 *(Word *)gotent = ofl->ofl_osplt->os_shdr->sh_addr + plt_off +
181 181 M_PLT_INSSIZE;
182 182 if (bswap)
183 183 /* LINTED */
184 184 *(Word *)gotent = ld_bswap_Word(*(Word *)gotent);
185 185
186 186 if (!(ofl->ofl_flags & FLG_OF_SHAROBJ)) {
187 187 pltent[0] = M_SPECIAL_INST;
188 188 pltent[1] = M_JMP_DISP_IND;
189 189 pltent += 2;
190 190 /* LINTED */
191 191 *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr->sh_addr +
192 192 got_off);
193 193 } else {
194 194 pltent[0] = M_SPECIAL_INST;
195 195 pltent[1] = M_JMP_REG_DISP_IND;
196 196 pltent += 2;
197 197 /* LINTED */
198 198 *(Word *)pltent = (Word)got_off;
199 199 }
200 200 if (bswap)
201 201 /* LINTED */
202 202 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent);
203 203 pltent += 4;
204 204
205 205 pltent[0] = M_INST_PUSHL;
206 206 pltent++;
207 207 /* LINTED */
208 208 *(Word *)pltent = (Word)rel_off;
209 209 if (bswap)
210 210 /* LINTED */
211 211 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent);
212 212 pltent += 4;
213 213
214 214 plt_off = -(plt_off + 16); /* JMP, PUSHL, JMP take 16 bytes */
215 215 pltent[0] = M_INST_JMP;
216 216 pltent++;
217 217 /* LINTED */
218 218 *(Word *)pltent = (Word)plt_off;
219 219 if (bswap)
220 220 /* LINTED */
221 221 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent);
222 222 }
223 223
224 224 static uintptr_t
225 225 ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen)
226 226 {
227 227 Os_desc * relosp, * osp = 0;
228 228 Word ndx, roffset, value;
229 229 Rel rea;
230 230 char *relbits;
231 231 Sym_desc * sdp, * psym = (Sym_desc *)0;
232 232 int sectmoved = 0;
233 233
234 234 sdp = orsp->rel_sym;
235 235
236 236 /*
237 237 * If the section this relocation is against has been discarded
238 238 * (-zignore), then also discard (skip) the relocation itself.
239 239 */
240 240 if (orsp->rel_isdesc && ((orsp->rel_flags &
241 241 (FLG_REL_GOT | FLG_REL_BSS | FLG_REL_PLT | FLG_REL_NOINFO)) == 0) &&
242 242 (orsp->rel_isdesc->is_flags & FLG_IS_DISCARD)) {
243 243 DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, orsp));
244 244 return (1);
245 245 }
246 246
247 247 /*
248 248 * If this is a relocation against a move table, or expanded move
249 249 * table, adjust the relocation entries.
250 250 */
251 251 if (RELAUX_GET_MOVE(orsp))
252 252 ld_adj_movereloc(ofl, orsp);
253 253
254 254 /*
255 255 * If this is a relocation against a section using a partial initialized
256 256 * symbol, adjust the embedded symbol info.
257 257 *
258 258 * The second argument of the am_I_partial() is the value stored at the
259 259 * target address relocation is going to be applied.
260 260 */
261 261 if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) {
262 262 if (ofl->ofl_parsyms &&
263 263 (sdp->sd_isc->is_flags & FLG_IS_RELUPD) &&
264 264 /* LINTED */
265 265 (psym = ld_am_I_partial(orsp, *(Xword *)
266 266 ((uchar_t *)(orsp->rel_isdesc->is_indata->d_buf) +
267 267 orsp->rel_roffset)))) {
268 268 DBG_CALL(Dbg_move_outsctadj(ofl->ofl_lml, psym));
269 269 sectmoved = 1;
270 270 }
271 271 }
272 272
273 273 value = sdp->sd_sym->st_value;
274 274
275 275 if (orsp->rel_flags & FLG_REL_GOT) {
276 276 osp = ofl->ofl_osgot;
277 277 roffset = (Word)ld_calc_got_offset(orsp, ofl);
278 278
279 279 } else if (orsp->rel_flags & FLG_REL_PLT) {
280 280 /*
281 281 * Note that relocations for PLT's actually
282 282 * cause a relocation againt the GOT.
283 283 */
284 284 osp = ofl->ofl_osplt;
285 285 roffset = (Word) (ofl->ofl_osgot->os_shdr->sh_addr) +
286 286 sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE;
287 287
288 288 plt_entry(ofl, osp->os_relosdesc->os_szoutrels, sdp);
289 289
290 290 } else if (orsp->rel_flags & FLG_REL_BSS) {
291 291 /*
292 292 * This must be a R_386_COPY. For these set the roffset to
293 293 * point to the new symbols location.
294 294 */
295 295 osp = ofl->ofl_isbss->is_osdesc;
296 296 roffset = (Word)value;
297 297 } else {
298 298 osp = RELAUX_GET_OSDESC(orsp);
299 299
300 300 /*
301 301 * Calculate virtual offset of reference point; equals offset
302 302 * into section + vaddr of section for loadable sections, or
303 303 * offset plus section displacement for nonloadable sections.
304 304 */
305 305 roffset = orsp->rel_roffset +
306 306 (Off)_elf_getxoff(orsp->rel_isdesc->is_indata);
307 307 if (!(ofl->ofl_flags & FLG_OF_RELOBJ))
308 308 roffset += orsp->rel_isdesc->is_osdesc->
309 309 os_shdr->sh_addr;
310 310 }
311 311
312 312 if ((osp == 0) || ((relosp = osp->os_relosdesc) == 0))
313 313 relosp = ofl->ofl_osrel;
314 314
315 315 /*
316 316 * Assign the symbols index for the output relocation. If the
317 317 * relocation refers to a SECTION symbol then it's index is based upon
318 318 * the output sections symbols index. Otherwise the index can be
319 319 * derived from the symbols index itself.
320 320 */
321 321 if (orsp->rel_rtype == R_386_RELATIVE)
322 322 ndx = STN_UNDEF;
323 323 else if ((orsp->rel_flags & FLG_REL_SCNNDX) ||
324 324 (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION)) {
325 325 if (sectmoved == 0) {
326 326 /*
327 327 * Check for a null input section. This can
328 328 * occur if this relocation references a symbol
329 329 * generated by sym_add_sym().
330 330 */
331 331 if (sdp->sd_isc && sdp->sd_isc->is_osdesc)
332 332 ndx = sdp->sd_isc->is_osdesc->os_identndx;
333 333 else
334 334 ndx = sdp->sd_shndx;
335 335 } else
336 336 ndx = ofl->ofl_parexpnndx;
337 337 } else
338 338 ndx = sdp->sd_symndx;
339 339
340 340 /*
341 341 * If we have a replacement value for the relocation
342 342 * target, put it in place now.
343 343 */
344 344 if (orsp->rel_flags & FLG_REL_NADDEND) {
345 345 Xword addend = orsp->rel_raddend;
346 346 uchar_t *addr;
347 347
348 348 /*
349 349 * Get the address of the data item we need to modify.
350 350 */
351 351 addr = (uchar_t *)((uintptr_t)orsp->rel_roffset +
352 352 (uintptr_t)_elf_getxoff(orsp->rel_isdesc->is_indata));
353 353 addr += (uintptr_t)RELAUX_GET_OSDESC(orsp)->os_outdata->d_buf;
354 354 if (ld_reloc_targval_set(ofl, orsp, addr, addend) == 0)
355 355 return (S_ERROR);
356 356 }
357 357
358 358 relbits = (char *)relosp->os_outdata->d_buf;
359 359
360 360 rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype);
361 361 rea.r_offset = roffset;
362 362 DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_REL, &rea, relosp->os_name,
363 363 ld_reloc_sym_name(orsp)));
364 364
365 365 /*
366 366 * Assert we haven't walked off the end of our relocation table.
367 367 */
368 368 assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size);
369 369
370 370 (void) memcpy((relbits + relosp->os_szoutrels),
371 371 (char *)&rea, sizeof (Rel));
372 372 relosp->os_szoutrels += sizeof (Rel);
373 373
374 374 /*
375 375 * Determine if this relocation is against a non-writable, allocatable
376 376 * section. If so we may need to provide a text relocation diagnostic.
377 377 * Note that relocations against the .plt (R_386_JMP_SLOT) actually
378 378 * result in modifications to the .got.
379 379 */
380 380 if (orsp->rel_rtype == R_386_JMP_SLOT)
381 381 osp = ofl->ofl_osgot;
382 382
383 383 ld_reloc_remain_entry(orsp, osp, ofl, remain_seen);
384 384 return (1);
385 385 }
386 386
387 387 /*
388 388 * i386 Instructions for TLS processing
389 389 */
390 390 static uchar_t tlsinstr_gd_ie[] = {
391 391 /*
392 392 * 0x00 movl %gs:0x0, %eax
393 393 */
394 394 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
395 395 /*
396 396 * 0x06 addl x(%eax), %eax
397 397 * 0x0c ...
398 398 */
399 399 0x03, 0x80, 0x00, 0x00, 0x00, 0x00
400 400 };
401 401
402 402 static uchar_t tlsinstr_gd_le[] = {
403 403 /*
404 404 * 0x00 movl %gs:0x0, %eax
405 405 */
406 406 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
407 407 /*
↓ open down ↓ |
407 lines elided |
↑ open up ↑ |
408 408 * 0x06 addl $0x0, %eax
409 409 */
410 410 0x05, 0x00, 0x00, 0x00, 0x00,
411 411 /*
412 412 * 0x0b nop
413 413 * 0x0c
414 414 */
415 415 0x90
416 416 };
417 417
418 -static uchar_t tlsinstr_gd_ie_movgs[] = {
418 +static uchar_t tlsinstr_ld_le_movgs[] = {
419 419 /*
420 - * movl %gs:0x0,%eax
420 + * 0x00 movl %gs:0x0,%eax
421 421 */
422 - 0x65, 0xa1, 0x00, 0x00, 0x00, 00
422 + 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00,
423 +};
424 +
425 +/*
426 + * 0x00 nopl 0(%eax,%eax) -- the intel recommended 5-byte nop
427 + * See Intel® 64 and IA-32 Architectures Software Developer’s Manual
428 + * Volume 2B: Instruction Set Reference, M-U
429 + * Table 4-12, Recommended Multi-Byte Sequence of NOP Instruction
430 + */
431 +static uchar_t tlsinstr_nop5[] = {
432 +
433 + 0x0f, 0x1f, 0x44, 0x00, 0x00
423 434 };
424 435
425 436 #define TLS_GD_IE_MOV 0x8b /* movl opcode */
426 437 #define TLS_GD_IE_POP 0x58 /* popl + reg */
427 438
428 439 #define TLS_GD_LE_MOVL 0xb8 /* movl + reg */
429 440
430 441 #define TLS_NOP 0x90 /* NOP instruction */
431 442
432 443 #define MODRM_MSK_MOD 0xc0
433 444 #define MODRM_MSK_RO 0x38
434 445 #define MODRM_MSK_RM 0x07
435 446
436 447 #define SIB_MSK_SS 0xc0
437 448 #define SIB_MSK_IND 0x38
438 449 #define SIB_MSK_BS 0x07
439 450
440 451 static Fixupret
441 452 tls_fixups(Ofl_desc *ofl, Rel_desc *arsp)
442 453 {
443 454 Sym_desc *sdp = arsp->rel_sym;
444 455 Word rtype = arsp->rel_rtype;
445 456 uchar_t *offset, r1, r2;
446 457
447 458 offset = (uchar_t *)((uintptr_t)arsp->rel_roffset +
448 459 (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata) +
449 460 (uintptr_t)RELAUX_GET_OSDESC(arsp)->os_outdata->d_buf);
450 461
451 462 if (sdp->sd_ref == REF_DYN_NEED) {
452 463 /*
453 464 * IE reference model
454 465 */
455 466 switch (rtype) {
456 467 case R_386_TLS_GD:
457 468 /*
458 469 * Transition:
459 470 * 0x0 leal x@tlsgd(,r1,1), %eax
460 471 * 0x7 call ___tls_get_addr
461 472 * 0xc
462 473 * To:
463 474 * 0x0 movl %gs:0, %eax
464 475 * 0x6 addl x@gotntpoff(r1), %eax
465 476 */
466 477 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
467 478 R_386_TLS_GOTIE, arsp, ld_reloc_sym_name));
468 479 arsp->rel_rtype = R_386_TLS_GOTIE;
469 480 arsp->rel_roffset += 5;
470 481
471 482 /*
472 483 * Adjust 'offset' to beginning of instruction
473 484 * sequence.
474 485 */
475 486 offset -= 3;
476 487 r1 = (offset[2] & SIB_MSK_IND) >> 3;
477 488 (void) memcpy(offset, tlsinstr_gd_ie,
478 489 sizeof (tlsinstr_gd_ie));
479 490
480 491 /*
481 492 * set register %r1 into the addl
482 493 * instruction.
483 494 */
484 495 offset[0x7] |= r1;
485 496 return (FIX_RELOC);
486 497
487 498 case R_386_TLS_GD_PLT:
488 499 /*
489 500 * Fixup done via the TLS_GD relocation
490 501 */
491 502 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
492 503 R_386_NONE, arsp, ld_reloc_sym_name));
493 504 return (FIX_DONE);
494 505 }
495 506 }
496 507
497 508 /*
498 509 * LE reference model
499 510 */
500 511 switch (rtype) {
501 512 case R_386_TLS_GD:
502 513 /*
503 514 * Transition:
504 515 * 0x0 leal x@tlsgd(,r1,1), %eax
505 516 * 0x7 call ___tls_get_addr
506 517 * 0xc
507 518 * To:
508 519 * 0x0 movl %gs:0, %eax
509 520 * 0x6 addl $x@ntpoff, %eax
510 521 * 0xb nop
511 522 * 0xc
512 523 */
513 524 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
514 525 R_386_TLS_LE, arsp, ld_reloc_sym_name));
515 526
516 527 arsp->rel_rtype = R_386_TLS_LE;
517 528 arsp->rel_roffset += 4;
518 529
519 530 /*
520 531 * Adjust 'offset' to beginning of instruction
↓ open down ↓ |
88 lines elided |
↑ open up ↑ |
521 532 * sequence.
522 533 */
523 534 offset -= 3;
524 535 (void) memcpy(offset, tlsinstr_gd_le,
525 536 sizeof (tlsinstr_gd_le));
526 537 return (FIX_RELOC);
527 538
528 539 case R_386_TLS_GD_PLT:
529 540 case R_386_PLT32:
530 541 /*
531 - * Fixup done via the TLS_GD relocation
542 + * Fixup done via the TLS_GD/TLS_LDM relocation processing
543 + * and ld_reloc_plt() handling __tls_get_addr().
532 544 */
533 545 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
534 546 R_386_NONE, arsp, ld_reloc_sym_name));
535 547 return (FIX_DONE);
536 548
537 549 case R_386_TLS_LDM_PLT:
538 550 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
539 551 R_386_NONE, arsp, ld_reloc_sym_name));
540 552
541 553 /*
542 554 * Transition:
543 555 * call __tls_get_addr()
544 556 * to:
545 - * nop
546 - * nop
547 - * nop
548 - * nop
549 - * nop
550 - */
551 - *(offset - 1) = TLS_NOP;
552 - *(offset) = TLS_NOP;
553 - *(offset + 1) = TLS_NOP;
554 - *(offset + 2) = TLS_NOP;
555 - *(offset + 3) = TLS_NOP;
557 + * nopl 0x0(%eax,%eax)
558 + */
559 + (void) memcpy(offset - 1, tlsinstr_nop5,
560 + sizeof (tlsinstr_nop5));
556 561 return (FIX_DONE);
557 562
558 563 case R_386_TLS_LDM:
559 564 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
560 565 R_386_NONE, arsp, ld_reloc_sym_name));
561 566
562 567 /*
563 568 * Transition:
564 569 *
565 570 * 0x00 leal x1@tlsldm(%ebx), %eax
566 571 * 0x06 call ___tls_get_addr
567 572 *
568 573 * to:
569 574 *
570 575 * 0x00 movl %gs:0, %eax
571 576 */
572 - (void) memcpy(offset - 2, tlsinstr_gd_ie_movgs,
573 - sizeof (tlsinstr_gd_ie_movgs));
577 + (void) memcpy(offset - 2, tlsinstr_ld_le_movgs,
578 + sizeof (tlsinstr_ld_le_movgs));
579 +
580 + /*
581 + * We implicitly treat this as if a R_386_TLS_LDM_PLT for the
582 + * __tls_get_addr call followed it as the GNU compiler
583 + * doesn't generate one. This is safe, because if one _does_
584 + * exist we'll just write the nop again.
585 + */
586 + (void) memcpy(offset + 4, tlsinstr_nop5,
587 + sizeof (tlsinstr_nop5));
574 588 return (FIX_DONE);
575 589
576 590 case R_386_TLS_LDO_32:
577 591 /*
578 592 * Instructions:
579 593 *
580 594 * 0x10 leal x1@dtpoff(%eax), %edx R_386_TLS_LDO_32
581 595 * to
582 596 * 0x10 leal x1@ntpoff(%eax), %edx R_386_TLS_LE
583 597 *
584 598 */
585 599 offset -= 2;
586 600
587 601 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
588 602 R_386_TLS_LE, arsp, ld_reloc_sym_name));
589 603 arsp->rel_rtype = R_386_TLS_LE;
590 604 return (FIX_RELOC);
591 605
592 606 case R_386_TLS_GOTIE:
593 607 /*
594 608 * These transitions are a little different than the
595 609 * others, in that we could have multiple instructions
596 610 * pointed to by a single relocation. Depending upon the
597 611 * instruction, we perform a different code transition.
598 612 *
599 613 * Here's the known transitions:
600 614 *
601 615 * 1) movl foo@gotntpoff(%reg1), %reg2
602 616 * 0x8b, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff
603 617 *
604 618 * 2) addl foo@gotntpoff(%reg1), %reg2
605 619 * 0x03, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff
606 620 *
607 621 * Transitions IE -> LE
608 622 *
609 623 * 1) movl $foo@ntpoff, %reg2
610 624 * 0xc7, 0xc0 | reg2, foo@ntpoff
611 625 *
612 626 * 2) addl $foo@ntpoff, %reg2
613 627 * 0x81, 0xc0 | reg2, foo@ntpoff
614 628 *
615 629 * Note: reg1 != 4 (%esp)
616 630 */
617 631 DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH,
618 632 R_386_TLS_LE, arsp, ld_reloc_sym_name));
619 633 arsp->rel_rtype = R_386_TLS_LE;
620 634
621 635 offset -= 2;
622 636 r2 = (offset[1] & MODRM_MSK_RO) >> 3;
623 637 if (offset[0] == 0x8b) {
624 638 /* case 1 above */
625 639 offset[0] = 0xc7; /* movl */
626 640 offset[1] = 0xc0 | r2;
627 641 return (FIX_RELOC);
628 642 }
629 643
630 644 if (offset[0] == 0x03) {
631 645 /* case 2 above */
632 646 assert(offset[0] == 0x03);
633 647 offset[0] = 0x81; /* addl */
634 648 offset[1] = 0xc0 | r2;
635 649 return (FIX_RELOC);
636 650 }
637 651
638 652 /*
639 653 * Unexpected instruction sequence - fatal error.
640 654 */
641 655 {
642 656 Conv_inv_buf_t inv_buf;
643 657
644 658 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_BADTLSINS),
645 659 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf),
646 660 arsp->rel_isdesc->is_file->ifl_name,
647 661 ld_reloc_sym_name(arsp),
648 662 arsp->rel_isdesc->is_name,
649 663 EC_OFF(arsp->rel_roffset));
650 664 }
651 665 return (FIX_ERROR);
652 666
653 667 case R_386_TLS_IE:
654 668 /*
655 669 * These transitions are a little different than the
656 670 * others, in that we could have multiple instructions
657 671 * pointed to by a single relocation. Depending upon the
658 672 * instruction, we perform a different code transition.
659 673 *
660 674 * Here's the known transitions:
661 675 * 1) movl foo@indntpoff, %eax
662 676 * 0xa1, foo@indntpoff
663 677 *
664 678 * 2) movl foo@indntpoff, %eax
665 679 * 0x8b, 0x05 | (reg << 3), foo@gotntpoff
666 680 *
667 681 * 3) addl foo@indntpoff, %eax
668 682 * 0x03, 0x05 | (reg << 3), foo@gotntpoff
669 683 *
670 684 * Transitions IE -> LE
671 685 *
672 686 * 1) movl $foo@ntpoff, %eax
673 687 * 0xb8, foo@ntpoff
674 688 *
675 689 * 2) movl $foo@ntpoff, %reg
676 690 * 0xc7, 0xc0 | reg, foo@ntpoff
677 691 *
678 692 * 3) addl $foo@ntpoff, %reg
679 693 * 0x81, 0xc0 | reg, foo@ntpoff
680 694 */
681 695 arsp->rel_rtype = R_386_TLS_LE;
682 696 offset--;
683 697 if (offset[0] == 0xa1) {
684 698 /* case 1 above */
685 699 offset[0] = 0xb8; /* movl */
686 700 return (FIX_RELOC);
687 701 }
688 702
689 703 offset--;
690 704 if (offset[0] == 0x8b) {
691 705 /* case 2 above */
692 706 r2 = (offset[1] & MODRM_MSK_RO) >> 3;
693 707 offset[0] = 0xc7; /* movl */
694 708 offset[1] = 0xc0 | r2;
695 709 return (FIX_RELOC);
696 710 }
697 711 if (offset[0] == 0x03) {
698 712 /* case 3 above */
699 713 r2 = (offset[1] & MODRM_MSK_RO) >> 3;
700 714 offset[0] = 0x81; /* addl */
701 715 offset[1] = 0xc0 | r2;
702 716 return (FIX_RELOC);
703 717 }
704 718 /*
705 719 * Unexpected instruction sequence - fatal error.
706 720 */
707 721 {
708 722 Conv_inv_buf_t inv_buf;
709 723
710 724 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_BADTLSINS),
711 725 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf),
712 726 arsp->rel_isdesc->is_file->ifl_name,
713 727 ld_reloc_sym_name(arsp),
714 728 arsp->rel_isdesc->is_name,
715 729 EC_OFF(arsp->rel_roffset));
716 730 }
717 731 return (FIX_ERROR);
718 732 }
719 733 return (FIX_RELOC);
720 734 }
721 735
722 736 static uintptr_t
723 737 ld_do_activerelocs(Ofl_desc *ofl)
724 738 {
725 739 Rel_desc *arsp;
726 740 Rel_cachebuf *rcbp;
727 741 Aliste idx;
728 742 uintptr_t return_code = 1;
↓ open down ↓ |
145 lines elided |
↑ open up ↑ |
729 743 ofl_flag_t flags = ofl->ofl_flags;
730 744
731 745 if (aplist_nitems(ofl->ofl_actrels.rc_list) != 0)
732 746 DBG_CALL(Dbg_reloc_doact_title(ofl->ofl_lml));
733 747
734 748 /*
735 749 * Process active relocations.
736 750 */
737 751 REL_CACHE_TRAVERSE(&ofl->ofl_actrels, idx, rcbp, arsp) {
738 752 uchar_t *addr;
739 - Xword value;
753 + Xword value;
740 754 Sym_desc *sdp;
741 755 const char *ifl_name;
742 756 Xword refaddr;
743 757 int moved = 0;
744 758 Gotref gref;
745 759 Os_desc *osp;
746 760
747 761 /*
748 762 * If the section this relocation is against has been discarded
749 763 * (-zignore), then discard (skip) the relocation itself.
750 764 */
751 765 if ((arsp->rel_isdesc->is_flags & FLG_IS_DISCARD) &&
752 766 ((arsp->rel_flags & (FLG_REL_GOT | FLG_REL_BSS |
753 767 FLG_REL_PLT | FLG_REL_NOINFO)) == 0)) {
754 768 DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, arsp));
755 769 continue;
756 770 }
757 771
758 772 /*
759 773 * We determine what the 'got reference' model (if required)
760 774 * is at this point. This needs to be done before tls_fixup()
761 775 * since it may 'transition' our instructions.
762 776 *
763 777 * The got table entries have already been assigned,
764 778 * and we bind to those initial entries.
765 779 */
766 780 if (arsp->rel_flags & FLG_REL_DTLS)
767 781 gref = GOT_REF_TLSGD;
768 782 else if (arsp->rel_flags & FLG_REL_MTLS)
769 783 gref = GOT_REF_TLSLD;
770 784 else if (arsp->rel_flags & FLG_REL_STLS)
771 785 gref = GOT_REF_TLSIE;
772 786 else
773 787 gref = GOT_REF_GENERIC;
774 788
775 789 /*
776 790 * Perform any required TLS fixups.
777 791 */
778 792 if (arsp->rel_flags & FLG_REL_TLSFIX) {
779 793 Fixupret ret;
780 794
781 795 if ((ret = tls_fixups(ofl, arsp)) == FIX_ERROR)
782 796 return (S_ERROR);
783 797 if (ret == FIX_DONE)
784 798 continue;
785 799 }
786 800
787 801 /*
788 802 * If this is a relocation against a move table, or
789 803 * expanded move table, adjust the relocation entries.
790 804 */
791 805 if (RELAUX_GET_MOVE(arsp))
792 806 ld_adj_movereloc(ofl, arsp);
793 807
794 808 sdp = arsp->rel_sym;
795 809 refaddr = arsp->rel_roffset +
796 810 (Off)_elf_getxoff(arsp->rel_isdesc->is_indata);
797 811
798 812 if (arsp->rel_flags & FLG_REL_CLVAL)
799 813 value = 0;
800 814 else if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) {
801 815 /*
802 816 * The value for a symbol pointing to a SECTION
803 817 * is based off of that sections position.
804 818 */
805 819 if (sdp->sd_isc->is_flags & FLG_IS_RELUPD) {
806 820 Sym_desc *sym;
807 821 Xword radd;
808 822 uchar_t *raddr = (uchar_t *)
809 823 arsp->rel_isdesc->is_indata->d_buf +
810 824 arsp->rel_roffset;
811 825
812 826 /*
813 827 * This is a REL platform. Hence, the second
814 828 * argument of ld_am_I_partial() is the value
815 829 * stored at the target address where the
816 830 * relocation is going to be applied.
817 831 */
818 832 if (ld_reloc_targval_get(ofl, arsp, raddr,
819 833 &radd) == 0)
820 834 return (S_ERROR);
821 835 sym = ld_am_I_partial(arsp, radd);
822 836 if (sym) {
823 837 Sym *osym = sym->sd_osym;
824 838
825 839 /*
826 840 * The symbol was moved, so adjust the
827 841 * value relative to the new section.
828 842 */
829 843 value = sym->sd_sym->st_value;
830 844 moved = 1;
831 845
832 846 /*
833 847 * The original raddend covers the
834 848 * displacement from the section start
835 849 * to the desired address. The value
836 850 * computed above gets us from the
837 851 * section start to the start of the
838 852 * symbol range. Adjust the old raddend
839 853 * to remove the offset from section
840 854 * start to symbol start, leaving the
841 855 * displacement within the range of
842 856 * the symbol.
843 857 */
844 858 if (osym->st_value != 0) {
845 859 radd -= osym->st_value;
846 860 if (ld_reloc_targval_set(ofl,
847 861 arsp, raddr, radd) == 0)
848 862 return (S_ERROR);
849 863 }
850 864 }
851 865 }
852 866 if (!moved) {
853 867 value = _elf_getxoff(sdp->sd_isc->is_indata);
854 868 if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC)
855 869 value += sdp->sd_isc->
856 870 is_osdesc->os_shdr->sh_addr;
857 871 }
858 872 if (sdp->sd_isc->is_shdr->sh_flags & SHF_TLS)
859 873 value -= ofl->ofl_tlsphdr->p_vaddr;
860 874
861 875 } else if (IS_SIZE(arsp->rel_rtype)) {
862 876 /*
863 877 * Size relocations require the symbols size.
864 878 */
865 879 value = sdp->sd_sym->st_size;
866 880
867 881 } else if ((sdp->sd_flags & FLG_SY_CAP) &&
868 882 sdp->sd_aux && sdp->sd_aux->sa_PLTndx) {
869 883 /*
870 884 * If relocation is against a capabilities symbol, we
871 885 * need to jump to an associated PLT, so that at runtime
872 886 * ld.so.1 is involved to determine the best binding
873 887 * choice. Otherwise, the value is the symbols value.
874 888 */
875 889 value = ld_calc_plt_addr(sdp, ofl);
876 890
877 891 } else
878 892 value = sdp->sd_sym->st_value;
879 893
880 894 /*
881 895 * Relocation against the GLOBAL_OFFSET_TABLE.
882 896 */
883 897 if ((arsp->rel_flags & FLG_REL_GOT) &&
884 898 !ld_reloc_set_aux_osdesc(ofl, arsp, ofl->ofl_osgot))
885 899 return (S_ERROR);
886 900 osp = RELAUX_GET_OSDESC(arsp);
887 901
888 902 /*
889 903 * If loadable and not producing a relocatable object add the
890 904 * sections virtual address to the reference address.
891 905 */
892 906 if ((arsp->rel_flags & FLG_REL_LOAD) &&
893 907 ((flags & FLG_OF_RELOBJ) == 0))
894 908 refaddr +=
895 909 arsp->rel_isdesc->is_osdesc->os_shdr->sh_addr;
896 910
897 911 /*
898 912 * If this entry has a PLT assigned to it, its value is actually
899 913 * the address of the PLT (and not the address of the function).
900 914 */
901 915 if (IS_PLT(arsp->rel_rtype)) {
902 916 if (sdp->sd_aux && sdp->sd_aux->sa_PLTndx)
903 917 value = ld_calc_plt_addr(sdp, ofl);
904 918 }
905 919
906 920 /*
907 921 * Determine whether the value needs further adjustment. Filter
908 922 * through the attributes of the relocation to determine what
909 923 * adjustment is required. Note, many of the following cases
910 924 * are only applicable when a .got is present. As a .got is
911 925 * not generated when a relocatable object is being built,
912 926 * any adjustments that require a .got need to be skipped.
913 927 */
914 928 if ((arsp->rel_flags & FLG_REL_GOT) &&
915 929 ((flags & FLG_OF_RELOBJ) == 0)) {
916 930 Xword R1addr;
917 931 uintptr_t R2addr;
918 932 Word gotndx;
919 933 Gotndx *gnp;
920 934
921 935 /*
922 936 * Perform relocation against GOT table. Since this
923 937 * doesn't fit exactly into a relocation we place the
924 938 * appropriate byte in the GOT directly
925 939 *
926 940 * Calculate offset into GOT at which to apply
927 941 * the relocation.
928 942 */
929 943 gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL);
930 944 assert(gnp);
931 945
932 946 if (arsp->rel_rtype == R_386_TLS_DTPOFF32)
933 947 gotndx = gnp->gn_gotndx + 1;
934 948 else
935 949 gotndx = gnp->gn_gotndx;
936 950
937 951 R1addr = (Xword)(gotndx * M_GOT_ENTSIZE);
938 952
939 953 /*
940 954 * Add the GOTs data's offset.
941 955 */
942 956 R2addr = R1addr + (uintptr_t)osp->os_outdata->d_buf;
943 957
944 958 DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT,
945 959 M_MACH, SHT_REL, arsp, R1addr, value,
946 960 ld_reloc_sym_name));
947 961
948 962 /*
949 963 * And do it.
950 964 */
951 965 if (ofl->ofl_flags1 & FLG_OF1_ENCDIFF)
952 966 *(Xword *)R2addr = ld_bswap_Xword(value);
953 967 else
954 968 *(Xword *)R2addr = value;
955 969 continue;
956 970
957 971 } else if (IS_GOT_BASED(arsp->rel_rtype) &&
958 972 ((flags & FLG_OF_RELOBJ) == 0)) {
959 973 value -= ofl->ofl_osgot->os_shdr->sh_addr;
960 974
961 975 } else if (IS_GOT_PC(arsp->rel_rtype) &&
962 976 ((flags & FLG_OF_RELOBJ) == 0)) {
963 977 value = (Xword)(ofl->ofl_osgot->os_shdr->sh_addr) -
964 978 refaddr;
965 979
966 980 } else if ((IS_PC_RELATIVE(arsp->rel_rtype)) &&
967 981 (((flags & FLG_OF_RELOBJ) == 0) ||
968 982 (osp == sdp->sd_isc->is_osdesc))) {
969 983 value -= refaddr;
970 984
971 985 } else if (IS_TLS_INS(arsp->rel_rtype) &&
972 986 IS_GOT_RELATIVE(arsp->rel_rtype) &&
973 987 ((flags & FLG_OF_RELOBJ) == 0)) {
974 988 Gotndx *gnp;
975 989
976 990 gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL);
977 991 assert(gnp);
978 992 value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE;
979 993 if (arsp->rel_rtype == R_386_TLS_IE) {
980 994 value += ofl->ofl_osgot->os_shdr->sh_addr;
981 995 }
982 996
983 997 } else if (IS_GOT_RELATIVE(arsp->rel_rtype) &&
984 998 ((flags & FLG_OF_RELOBJ) == 0)) {
985 999 Gotndx *gnp;
986 1000
987 1001 gnp = ld_find_got_ndx(sdp->sd_GOTndxs,
988 1002 GOT_REF_GENERIC, ofl, NULL);
989 1003 assert(gnp);
990 1004 value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE;
991 1005
992 1006 } else if ((arsp->rel_flags & FLG_REL_STLS) &&
993 1007 ((flags & FLG_OF_RELOBJ) == 0)) {
994 1008 Xword tlsstatsize;
995 1009
996 1010 /*
997 1011 * This is the LE TLS reference model. Static
998 1012 * offset is hard-coded.
999 1013 */
1000 1014 tlsstatsize = S_ROUND(ofl->ofl_tlsphdr->p_memsz,
1001 1015 M_TLSSTATALIGN);
1002 1016 value = tlsstatsize - value;
1003 1017
1004 1018 /*
1005 1019 * Since this code is fixed up, it assumes a
1006 1020 * negative offset that can be added to the
1007 1021 * thread pointer.
1008 1022 */
1009 1023 if ((arsp->rel_rtype == R_386_TLS_LDO_32) ||
1010 1024 (arsp->rel_rtype == R_386_TLS_LE))
1011 1025 value = -value;
1012 1026 }
1013 1027
1014 1028 if (arsp->rel_isdesc->is_file)
1015 1029 ifl_name = arsp->rel_isdesc->is_file->ifl_name;
1016 1030 else
1017 1031 ifl_name = MSG_INTL(MSG_STR_NULL);
1018 1032
1019 1033 /*
1020 1034 * Make sure we have data to relocate. Compiler and assembler
1021 1035 * developers have been known to generate relocations against
1022 1036 * invalid sections (normally .bss), so for their benefit give
1023 1037 * them sufficient information to help analyze the problem.
1024 1038 * End users should never see this.
1025 1039 */
1026 1040 if (arsp->rel_isdesc->is_indata->d_buf == 0) {
1027 1041 Conv_inv_buf_t inv_buf;
1028 1042
1029 1043 ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_EMPTYSEC),
1030 1044 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf),
1031 1045 ifl_name, ld_reloc_sym_name(arsp),
1032 1046 EC_WORD(arsp->rel_isdesc->is_scnndx),
1033 1047 arsp->rel_isdesc->is_name);
1034 1048 return (S_ERROR);
1035 1049 }
1036 1050
1037 1051 /*
1038 1052 * Get the address of the data item we need to modify.
1039 1053 */
1040 1054 addr = (uchar_t *)((uintptr_t)arsp->rel_roffset +
1041 1055 (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata));
1042 1056
1043 1057 DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT,
1044 1058 M_MACH, SHT_REL, arsp, EC_NATPTR(addr), value,
1045 1059 ld_reloc_sym_name));
1046 1060 addr += (uintptr_t)osp->os_outdata->d_buf;
1047 1061
1048 1062 if ((((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) >
1049 1063 ofl->ofl_size) || (arsp->rel_roffset >
1050 1064 osp->os_shdr->sh_size)) {
1051 1065 Conv_inv_buf_t inv_buf;
1052 1066 int class;
1053 1067
1054 1068 if (((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) >
1055 1069 ofl->ofl_size)
1056 1070 class = ERR_FATAL;
1057 1071 else
1058 1072 class = ERR_WARNING;
1059 1073
1060 1074 ld_eprintf(ofl, class, MSG_INTL(MSG_REL_INVALOFFSET),
1061 1075 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf),
1062 1076 ifl_name, EC_WORD(arsp->rel_isdesc->is_scnndx),
1063 1077 arsp->rel_isdesc->is_name, ld_reloc_sym_name(arsp),
1064 1078 EC_ADDR((uintptr_t)addr -
1065 1079 (uintptr_t)ofl->ofl_nehdr));
1066 1080
1067 1081 if (class == ERR_FATAL) {
1068 1082 return_code = S_ERROR;
1069 1083 continue;
1070 1084 }
1071 1085 }
1072 1086
1073 1087 /*
1074 1088 * The relocation is additive. Ignore the previous symbol
1075 1089 * value if this local partial symbol is expanded.
1076 1090 */
1077 1091 if (moved)
1078 1092 value -= *addr;
1079 1093
1080 1094 /*
1081 1095 * If we have a replacement value for the relocation
1082 1096 * target, put it in place now.
1083 1097 */
1084 1098 if (arsp->rel_flags & FLG_REL_NADDEND) {
1085 1099 Xword addend = arsp->rel_raddend;
1086 1100
1087 1101 if (ld_reloc_targval_set(ofl, arsp, addr, addend) == 0)
1088 1102 return (S_ERROR);
1089 1103 }
1090 1104
1091 1105 /*
1092 1106 * If '-z noreloc' is specified - skip the do_reloc_ld stage.
1093 1107 */
1094 1108 if (OFL_DO_RELOC(ofl)) {
1095 1109 if (do_reloc_ld(arsp, addr, &value, ld_reloc_sym_name,
1096 1110 ifl_name, OFL_SWAP_RELOC_DATA(ofl, arsp),
1097 1111 ofl->ofl_lml) == 0) {
1098 1112 ofl->ofl_flags |= FLG_OF_FATAL;
1099 1113 return_code = S_ERROR;
1100 1114 }
1101 1115 }
1102 1116 }
1103 1117 return (return_code);
1104 1118 }
1105 1119
1106 1120 /*
1107 1121 * Add an output relocation record.
1108 1122 */
1109 1123 static uintptr_t
1110 1124 ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl)
1111 1125 {
1112 1126 Rel_desc *orsp;
1113 1127 Sym_desc *sdp = rsp->rel_sym;
1114 1128
1115 1129 /*
1116 1130 * Static executables *do not* want any relocations against them.
1117 1131 * Since our engine still creates relocations against a WEAK UNDEFINED
1118 1132 * symbol in a static executable, it's best to disable them here
1119 1133 * instead of through out the relocation code.
1120 1134 */
1121 1135 if (OFL_IS_STATIC_EXEC(ofl))
1122 1136 return (1);
1123 1137
1124 1138 /*
1125 1139 * If we are adding a output relocation against a section
1126 1140 * symbol (non-RELATIVE) then mark that section. These sections
1127 1141 * will be added to the .dynsym symbol table.
1128 1142 */
1129 1143 if (sdp && (rsp->rel_rtype != M_R_RELATIVE) &&
1130 1144 ((flags & FLG_REL_SCNNDX) ||
1131 1145 (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) {
1132 1146
1133 1147 /*
1134 1148 * If this is a COMMON symbol - no output section
1135 1149 * exists yet - (it's created as part of sym_validate()).
1136 1150 * So - we mark here that when it's created it should
1137 1151 * be tagged with the FLG_OS_OUTREL flag.
1138 1152 */
1139 1153 if ((sdp->sd_flags & FLG_SY_SPECSEC) &&
1140 1154 (sdp->sd_sym->st_shndx == SHN_COMMON)) {
1141 1155 if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS)
1142 1156 ofl->ofl_flags1 |= FLG_OF1_BSSOREL;
1143 1157 else
1144 1158 ofl->ofl_flags1 |= FLG_OF1_TLSOREL;
1145 1159 } else {
1146 1160 Os_desc *osp;
1147 1161 Is_desc *isp = sdp->sd_isc;
1148 1162
1149 1163 if (isp && ((osp = isp->is_osdesc) != NULL) &&
1150 1164 ((osp->os_flags & FLG_OS_OUTREL) == 0)) {
1151 1165 ofl->ofl_dynshdrcnt++;
1152 1166 osp->os_flags |= FLG_OS_OUTREL;
1153 1167 }
1154 1168 }
1155 1169 }
1156 1170
1157 1171 /* Enter it into the output relocation cache */
1158 1172 if ((orsp = ld_reloc_enter(ofl, &ofl->ofl_outrels, rsp, flags)) == NULL)
1159 1173 return (S_ERROR);
1160 1174
1161 1175 if (flags & FLG_REL_GOT)
1162 1176 ofl->ofl_relocgotsz += (Xword)sizeof (Rel);
1163 1177 else if (flags & FLG_REL_PLT)
1164 1178 ofl->ofl_relocpltsz += (Xword)sizeof (Rel);
1165 1179 else if (flags & FLG_REL_BSS)
1166 1180 ofl->ofl_relocbsssz += (Xword)sizeof (Rel);
1167 1181 else if (flags & FLG_REL_NOINFO)
1168 1182 ofl->ofl_relocrelsz += (Xword)sizeof (Rel);
1169 1183 else
1170 1184 RELAUX_GET_OSDESC(orsp)->os_szoutrels += (Xword)sizeof (Rel);
1171 1185
1172 1186 if (orsp->rel_rtype == M_R_RELATIVE)
1173 1187 ofl->ofl_relocrelcnt++;
1174 1188
1175 1189 /*
1176 1190 * We don't perform sorting on PLT relocations because
1177 1191 * they have already been assigned a PLT index and if we
1178 1192 * were to sort them we would have to re-assign the plt indexes.
1179 1193 */
1180 1194 if (!(flags & FLG_REL_PLT))
1181 1195 ofl->ofl_reloccnt++;
1182 1196
1183 1197 /*
1184 1198 * Insure a GLOBAL_OFFSET_TABLE is generated if required.
1185 1199 */
1186 1200 if (IS_GOT_REQUIRED(orsp->rel_rtype))
1187 1201 ofl->ofl_flags |= FLG_OF_BLDGOT;
1188 1202
1189 1203 /*
1190 1204 * Identify and possibly warn of a displacement relocation.
1191 1205 */
1192 1206 if (orsp->rel_flags & FLG_REL_DISP) {
1193 1207 ofl->ofl_dtflags_1 |= DF_1_DISPRELPND;
1194 1208
1195 1209 if (ofl->ofl_flags & FLG_OF_VERBOSE)
1196 1210 ld_disp_errmsg(MSG_INTL(MSG_REL_DISPREL4), orsp, ofl);
1197 1211 }
1198 1212 DBG_CALL(Dbg_reloc_ors_entry(ofl->ofl_lml, ELF_DBG_LD, SHT_REL,
1199 1213 M_MACH, orsp));
1200 1214 return (1);
1201 1215 }
1202 1216
1203 1217 /*
1204 1218 * process relocation for a LOCAL symbol
1205 1219 */
1206 1220 static uintptr_t
1207 1221 ld_reloc_local(Rel_desc * rsp, Ofl_desc * ofl)
1208 1222 {
1209 1223 ofl_flag_t flags = ofl->ofl_flags;
1210 1224 Sym_desc *sdp = rsp->rel_sym;
1211 1225 Word shndx = sdp->sd_sym->st_shndx;
1212 1226
1213 1227 /*
1214 1228 * if ((shared object) and (not pc relative relocation) and
1215 1229 * (not against ABS symbol))
1216 1230 * then
1217 1231 * build R_386_RELATIVE
1218 1232 * fi
1219 1233 */
1220 1234 if ((flags & FLG_OF_SHAROBJ) && (rsp->rel_flags & FLG_REL_LOAD) &&
1221 1235 !(IS_PC_RELATIVE(rsp->rel_rtype)) && !(IS_SIZE(rsp->rel_rtype)) &&
1222 1236 !(IS_GOT_BASED(rsp->rel_rtype)) &&
1223 1237 !(rsp->rel_isdesc != NULL &&
1224 1238 (rsp->rel_isdesc->is_shdr->sh_type == SHT_SUNW_dof)) &&
1225 1239 (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) ||
1226 1240 (shndx != SHN_ABS) || (sdp->sd_aux && sdp->sd_aux->sa_symspec))) {
1227 1241 Word ortype = rsp->rel_rtype;
1228 1242
1229 1243 rsp->rel_rtype = R_386_RELATIVE;
1230 1244 if (ld_add_outrel(NULL, rsp, ofl) == S_ERROR)
1231 1245 return (S_ERROR);
1232 1246 rsp->rel_rtype = ortype;
1233 1247 }
1234 1248
1235 1249 /*
1236 1250 * If the relocation is against a 'non-allocatable' section
1237 1251 * and we can not resolve it now - then give a warning
1238 1252 * message.
1239 1253 *
1240 1254 * We can not resolve the symbol if either:
1241 1255 * a) it's undefined
1242 1256 * b) it's defined in a shared library and a
1243 1257 * COPY relocation hasn't moved it to the executable
1244 1258 *
1245 1259 * Note: because we process all of the relocations against the
1246 1260 * text segment before any others - we know whether
1247 1261 * or not a copy relocation will be generated before
1248 1262 * we get here (see reloc_init()->reloc_segments()).
1249 1263 */
1250 1264 if (!(rsp->rel_flags & FLG_REL_LOAD) &&
1251 1265 ((shndx == SHN_UNDEF) ||
1252 1266 ((sdp->sd_ref == REF_DYN_NEED) &&
1253 1267 ((sdp->sd_flags & FLG_SY_MVTOCOMM) == 0)))) {
1254 1268 Conv_inv_buf_t inv_buf;
1255 1269 Os_desc *osp = RELAUX_GET_OSDESC(rsp);
1256 1270
1257 1271 /*
1258 1272 * If the relocation is against a SHT_SUNW_ANNOTATE
1259 1273 * section - then silently ignore that the relocation
1260 1274 * can not be resolved.
1261 1275 */
1262 1276 if (osp && (osp->os_shdr->sh_type == SHT_SUNW_ANNOTATE))
1263 1277 return (0);
1264 1278 ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_REL_EXTERNSYM),
1265 1279 conv_reloc_386_type(rsp->rel_rtype, 0, &inv_buf),
1266 1280 rsp->rel_isdesc->is_file->ifl_name,
1267 1281 ld_reloc_sym_name(rsp), osp->os_name);
1268 1282 return (1);
1269 1283 }
1270 1284
1271 1285 /*
1272 1286 * Perform relocation.
1273 1287 */
1274 1288 return (ld_add_actrel(NULL, rsp, ofl));
1275 1289 }
1276 1290
1277 1291 static uintptr_t
1278 1292 ld_reloc_TLS(Boolean local, Rel_desc * rsp, Ofl_desc * ofl)
1279 1293 {
1280 1294 Word rtype = rsp->rel_rtype;
1281 1295 Sym_desc *sdp = rsp->rel_sym;
1282 1296 ofl_flag_t flags = ofl->ofl_flags;
1283 1297 Gotndx *gnp;
1284 1298
1285 1299 /*
1286 1300 * If we're building an executable - use either the IE or LE access
1287 1301 * model. If we're building a shared object process any IE model.
1288 1302 */
1289 1303 if ((flags & FLG_OF_EXEC) || (IS_TLS_IE(rtype))) {
1290 1304 /*
1291 1305 * Set the DF_STATIC_TLS flag.
1292 1306 */
1293 1307 ofl->ofl_dtflags |= DF_STATIC_TLS;
1294 1308
1295 1309 if (!local || ((flags & FLG_OF_EXEC) == 0)) {
1296 1310 /*
1297 1311 * Assign a GOT entry for static TLS references.
1298 1312 */
1299 1313 if ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs,
1300 1314 GOT_REF_TLSIE, ofl, NULL)) == NULL) {
1301 1315
1302 1316 if (ld_assign_got_TLS(local, rsp, ofl, sdp,
1303 1317 gnp, GOT_REF_TLSIE, FLG_REL_STLS,
1304 1318 rtype, R_386_TLS_TPOFF, NULL) == S_ERROR)
1305 1319 return (S_ERROR);
1306 1320 }
1307 1321
1308 1322 /*
1309 1323 * IE access model.
1310 1324 */
1311 1325 if (IS_TLS_IE(rtype)) {
1312 1326 if (ld_add_actrel(FLG_REL_STLS,
1313 1327 rsp, ofl) == S_ERROR)
1314 1328 return (S_ERROR);
1315 1329
1316 1330 /*
1317 1331 * A non-pic shared object needs to adjust the
1318 1332 * active relocation (indntpoff).
1319 1333 */
1320 1334 if (((flags & FLG_OF_EXEC) == 0) &&
1321 1335 (rtype == R_386_TLS_IE)) {
1322 1336 rsp->rel_rtype = R_386_RELATIVE;
1323 1337 return (ld_add_outrel(NULL, rsp, ofl));
1324 1338 }
1325 1339 return (1);
1326 1340 }
1327 1341
1328 1342 /*
1329 1343 * Fixups are required for other executable models.
1330 1344 */
1331 1345 return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS),
1332 1346 rsp, ofl));
1333 1347 }
1334 1348
1335 1349 /*
1336 1350 * LE access model.
1337 1351 */
1338 1352 if (IS_TLS_LE(rtype) || (rtype == R_386_TLS_LDO_32))
1339 1353 return (ld_add_actrel(FLG_REL_STLS, rsp, ofl));
1340 1354
1341 1355 return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS),
1342 1356 rsp, ofl));
1343 1357 }
1344 1358
1345 1359 /*
1346 1360 * Building a shared object.
1347 1361 *
1348 1362 * Assign a GOT entry for a dynamic TLS reference.
1349 1363 */
1350 1364 if (IS_TLS_LD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs,
1351 1365 GOT_REF_TLSLD, ofl, NULL)) == NULL)) {
1352 1366
1353 1367 if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSLD,
1354 1368 FLG_REL_MTLS, rtype, R_386_TLS_DTPMOD32, NULL) == S_ERROR)
1355 1369 return (S_ERROR);
1356 1370
1357 1371 } else if (IS_TLS_GD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs,
1358 1372 GOT_REF_TLSGD, ofl, NULL)) == NULL)) {
1359 1373
1360 1374 if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSGD,
1361 1375 FLG_REL_DTLS, rtype, R_386_TLS_DTPMOD32,
1362 1376 R_386_TLS_DTPOFF32) == S_ERROR)
1363 1377 return (S_ERROR);
1364 1378 }
1365 1379
1366 1380 /*
1367 1381 * For GD/LD TLS reference - TLS_{GD,LD}_CALL, this will eventually
1368 1382 * cause a call to __tls_get_addr(). Convert this relocation to that
1369 1383 * symbol now, and prepare for the PLT magic.
1370 1384 */
1371 1385 if ((rtype == R_386_TLS_GD_PLT) || (rtype == R_386_TLS_LDM_PLT)) {
1372 1386 Sym_desc *tlsgetsym;
1373 1387
1374 1388 if ((tlsgetsym = ld_sym_add_u(MSG_ORIG(MSG_SYM_TLSGETADDR_UU),
1375 1389 ofl, MSG_STR_TLSREL)) == (Sym_desc *)S_ERROR)
1376 1390 return (S_ERROR);
1377 1391
1378 1392 rsp->rel_sym = tlsgetsym;
1379 1393 rsp->rel_rtype = R_386_PLT32;
1380 1394
1381 1395 if (ld_reloc_plt(rsp, ofl) == S_ERROR)
1382 1396 return (S_ERROR);
1383 1397
1384 1398 rsp->rel_sym = sdp;
1385 1399 rsp->rel_rtype = rtype;
1386 1400 return (1);
1387 1401 }
1388 1402
1389 1403 if (IS_TLS_LD(rtype))
1390 1404 return (ld_add_actrel(FLG_REL_MTLS, rsp, ofl));
1391 1405
1392 1406 return (ld_add_actrel(FLG_REL_DTLS, rsp, ofl));
1393 1407 }
1394 1408
1395 1409 /* ARGSUSED4 */
1396 1410 static uintptr_t
1397 1411 ld_assign_got_ndx(Alist **alpp, Gotndx *pgnp, Gotref gref, Ofl_desc *ofl,
1398 1412 Rel_desc *rsp, Sym_desc *sdp)
1399 1413 {
1400 1414 Gotndx gn, *gnp;
1401 1415 uint_t gotents;
1402 1416
1403 1417 if (pgnp)
1404 1418 return (1);
1405 1419
1406 1420 if ((gref == GOT_REF_TLSGD) || (gref == GOT_REF_TLSLD))
1407 1421 gotents = 2;
1408 1422 else
1409 1423 gotents = 1;
1410 1424
1411 1425 gn.gn_addend = 0;
1412 1426 gn.gn_gotndx = ofl->ofl_gotcnt;
1413 1427 gn.gn_gotref = gref;
1414 1428
1415 1429 ofl->ofl_gotcnt += gotents;
1416 1430
1417 1431 if (gref == GOT_REF_TLSLD) {
1418 1432 if (ofl->ofl_tlsldgotndx == NULL) {
1419 1433 if ((gnp = libld_malloc(sizeof (Gotndx))) == NULL)
1420 1434 return (S_ERROR);
1421 1435 (void) memcpy(gnp, &gn, sizeof (Gotndx));
1422 1436 ofl->ofl_tlsldgotndx = gnp;
1423 1437 }
1424 1438 return (1);
1425 1439 }
1426 1440
1427 1441 /*
1428 1442 * GOT indexes are maintained on an Alist, where there is typically
1429 1443 * only one index. The usage of this list is to scan the list to find
1430 1444 * an index, and then apply that index immediately to a relocation.
1431 1445 * Thus there are no external references to these GOT index structures
1432 1446 * that can be compromised by the Alist being reallocated.
1433 1447 */
1434 1448 if (alist_append(alpp, &gn, sizeof (Gotndx), AL_CNT_SDP_GOT) == NULL)
1435 1449 return (S_ERROR);
1436 1450
1437 1451 return (1);
1438 1452 }
1439 1453
1440 1454 static void
1441 1455 ld_assign_plt_ndx(Sym_desc * sdp, Ofl_desc *ofl)
1442 1456 {
1443 1457 sdp->sd_aux->sa_PLTndx = 1 + ofl->ofl_pltcnt++;
1444 1458 sdp->sd_aux->sa_PLTGOTndx = ofl->ofl_gotcnt++;
1445 1459 ofl->ofl_flags |= FLG_OF_BLDGOT;
1446 1460 }
1447 1461
1448 1462 /*
1449 1463 * Initializes .got[0] with the _DYNAMIC symbol value.
1450 1464 */
1451 1465 static uintptr_t
1452 1466 ld_fillin_gotplt(Ofl_desc *ofl)
1453 1467 {
1454 1468 ofl_flag_t flags = ofl->ofl_flags;
1455 1469 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0;
1456 1470
1457 1471 if (ofl->ofl_osgot) {
1458 1472 Sym_desc *sdp;
1459 1473
1460 1474 if ((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_DYNAMIC_U),
1461 1475 SYM_NOHASH, NULL, ofl)) != NULL) {
1462 1476 uchar_t *genptr;
1463 1477
1464 1478 genptr = ((uchar_t *)ofl->ofl_osgot->os_outdata->d_buf +
1465 1479 (M_GOT_XDYNAMIC * M_GOT_ENTSIZE));
1466 1480 /* LINTED */
1467 1481 *(Word *)genptr = (Word)sdp->sd_sym->st_value;
1468 1482 if (bswap)
1469 1483 /* LINTED */
1470 1484 *(Word *)genptr =
1471 1485 /* LINTED */
1472 1486 ld_bswap_Word(*(Word *)genptr);
1473 1487 }
1474 1488 }
1475 1489
1476 1490 /*
1477 1491 * Fill in the reserved slot in the procedure linkage table the first
1478 1492 * entry is:
1479 1493 * if (building a.out) {
1480 1494 * PUSHL got[1] # the address of the link map entry
1481 1495 * JMP * got[2] # the address of rtbinder
1482 1496 * } else {
1483 1497 * PUSHL got[1]@GOT(%ebx) # the address of the link map entry
1484 1498 * JMP * got[2]@GOT(%ebx) # the address of rtbinder
1485 1499 * }
1486 1500 */
1487 1501 if ((flags & FLG_OF_DYNAMIC) && ofl->ofl_osplt) {
1488 1502 uchar_t *pltent;
1489 1503
1490 1504 pltent = (uchar_t *)ofl->ofl_osplt->os_outdata->d_buf;
1491 1505 if (!(flags & FLG_OF_SHAROBJ)) {
1492 1506 pltent[0] = M_SPECIAL_INST;
1493 1507 pltent[1] = M_PUSHL_DISP;
1494 1508 pltent += 2;
1495 1509 /* LINTED */
1496 1510 *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr->
1497 1511 sh_addr + M_GOT_XLINKMAP * M_GOT_ENTSIZE);
1498 1512 if (bswap)
1499 1513 /* LINTED */
1500 1514 *(Word *)pltent =
1501 1515 /* LINTED */
1502 1516 ld_bswap_Word(*(Word *)pltent);
1503 1517 pltent += 4;
1504 1518 pltent[0] = M_SPECIAL_INST;
1505 1519 pltent[1] = M_JMP_DISP_IND;
1506 1520 pltent += 2;
1507 1521 /* LINTED */
1508 1522 *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr->
1509 1523 sh_addr + M_GOT_XRTLD * M_GOT_ENTSIZE);
1510 1524 if (bswap)
1511 1525 /* LINTED */
1512 1526 *(Word *)pltent =
1513 1527 /* LINTED */
1514 1528 ld_bswap_Word(*(Word *)pltent);
1515 1529 } else {
1516 1530 pltent[0] = M_SPECIAL_INST;
1517 1531 pltent[1] = M_PUSHL_REG_DISP;
1518 1532 pltent += 2;
1519 1533 /* LINTED */
1520 1534 *(Word *)pltent = (Word)(M_GOT_XLINKMAP *
1521 1535 M_GOT_ENTSIZE);
1522 1536 if (bswap)
1523 1537 /* LINTED */
1524 1538 *(Word *)pltent =
1525 1539 /* LINTED */
1526 1540 ld_bswap_Word(*(Word *)pltent);
1527 1541 pltent += 4;
1528 1542 pltent[0] = M_SPECIAL_INST;
1529 1543 pltent[1] = M_JMP_REG_DISP_IND;
1530 1544 pltent += 2;
1531 1545 /* LINTED */
1532 1546 *(Word *)pltent = (Word)(M_GOT_XRTLD *
1533 1547 M_GOT_ENTSIZE);
1534 1548 if (bswap)
1535 1549 /* LINTED */
1536 1550 *(Word *)pltent =
1537 1551 /* LINTED */
1538 1552 ld_bswap_Word(*(Word *)pltent);
1539 1553 }
1540 1554 }
1541 1555 return (1);
1542 1556 }
1543 1557
1544 1558
1545 1559
1546 1560 /*
1547 1561 * Template for generating "void (*)(void)" function
1548 1562 */
1549 1563 static const uchar_t nullfunc_tmpl[] = { /* IA32 */
1550 1564 /* 0x00 */ 0xc3 /* ret */
1551 1565 };
1552 1566
1553 1567
1554 1568
1555 1569 /*
1556 1570 * Function used to provide fill padding in SHF_EXECINSTR sections
1557 1571 *
1558 1572 * entry:
1559 1573 *
1560 1574 * base - base address of section being filled
1561 1575 * offset - starting offset for fill within memory referenced by base
1562 1576 * cnt - # bytes to be filled
1563 1577 *
1564 1578 * exit:
1565 1579 * The fill has been completed.
1566 1580 */
1567 1581 static void
1568 1582 execfill(void *base, off_t off, size_t cnt)
1569 1583 {
1570 1584 /*
1571 1585 * 0x90 is an X86 NOP instruction in both 32 and 64-bit worlds.
1572 1586 * There are no alignment constraints.
1573 1587 */
1574 1588 (void) memset(off + (char *)base, 0x90, cnt);
1575 1589 }
1576 1590
1577 1591
1578 1592 /*
1579 1593 * Return the ld_targ definition for this target.
1580 1594 */
1581 1595 const Target *
1582 1596 ld_targ_init_x86(void)
1583 1597 {
1584 1598 static const Target _ld_targ = {
1585 1599 { /* Target_mach */
1586 1600 M_MACH, /* m_mach */
1587 1601 M_MACHPLUS, /* m_machplus */
1588 1602 M_FLAGSPLUS, /* m_flagsplus */
1589 1603 M_CLASS, /* m_class */
1590 1604 M_DATA, /* m_data */
1591 1605
1592 1606 M_SEGM_ALIGN, /* m_segm_align */
1593 1607 M_SEGM_ORIGIN, /* m_segm_origin */
1594 1608 M_SEGM_AORIGIN, /* m_segm_aorigin */
1595 1609 M_DATASEG_PERM, /* m_dataseg_perm */
1596 1610 M_STACK_PERM, /* m_stack_perm */
1597 1611 M_WORD_ALIGN, /* m_word_align */
1598 1612 MSG_ORIG(MSG_PTH_RTLD), /* m_def_interp */
1599 1613
1600 1614 /* Relocation type codes */
1601 1615 M_R_ARRAYADDR, /* m_r_arrayaddr */
1602 1616 M_R_COPY, /* m_r_copy */
1603 1617 M_R_GLOB_DAT, /* m_r_glob_dat */
1604 1618 M_R_JMP_SLOT, /* m_r_jmp_slot */
1605 1619 M_R_NUM, /* m_r_num */
1606 1620 M_R_NONE, /* m_r_none */
1607 1621 M_R_RELATIVE, /* m_r_relative */
1608 1622 M_R_REGISTER, /* m_r_register */
1609 1623
1610 1624 /* Relocation related constants */
1611 1625 M_REL_DT_COUNT, /* m_rel_dt_count */
1612 1626 M_REL_DT_ENT, /* m_rel_dt_ent */
1613 1627 M_REL_DT_SIZE, /* m_rel_dt_size */
1614 1628 M_REL_DT_TYPE, /* m_rel_dt_type */
1615 1629 M_REL_SHT_TYPE, /* m_rel_sht_type */
1616 1630
1617 1631 /* GOT related constants */
1618 1632 M_GOT_ENTSIZE, /* m_got_entsize */
1619 1633 M_GOT_XNumber, /* m_got_xnumber */
1620 1634
1621 1635 /* PLT related constants */
1622 1636 M_PLT_ALIGN, /* m_plt_align */
1623 1637 M_PLT_ENTSIZE, /* m_plt_entsize */
1624 1638 M_PLT_RESERVSZ, /* m_plt_reservsz */
1625 1639 M_PLT_SHF_FLAGS, /* m_plt_shf_flags */
1626 1640
1627 1641 /* Section type of .eh_frame/.eh_frame_hdr sections */
1628 1642 SHT_PROGBITS, /* m_sht_unwind */
1629 1643
1630 1644 M_DT_REGISTER, /* m_dt_register */
1631 1645 },
1632 1646 { /* Target_machid */
1633 1647 M_ID_ARRAY, /* id_array */
1634 1648 M_ID_BSS, /* id_bss */
1635 1649 M_ID_CAP, /* id_cap */
1636 1650 M_ID_CAPINFO, /* id_capinfo */
1637 1651 M_ID_CAPCHAIN, /* id_capchain */
1638 1652 M_ID_DATA, /* id_data */
1639 1653 M_ID_DYNAMIC, /* id_dynamic */
1640 1654 M_ID_DYNSORT, /* id_dynsort */
1641 1655 M_ID_DYNSTR, /* id_dynstr */
1642 1656 M_ID_DYNSYM, /* id_dynsym */
1643 1657 M_ID_DYNSYM_NDX, /* id_dynsym_ndx */
1644 1658 M_ID_GOT, /* id_got */
1645 1659 M_ID_UNKNOWN, /* id_gotdata (unused) */
1646 1660 M_ID_HASH, /* id_hash */
1647 1661 M_ID_INTERP, /* id_interp */
1648 1662 M_ID_LBSS, /* id_lbss */
1649 1663 M_ID_LDYNSYM, /* id_ldynsym */
1650 1664 M_ID_NOTE, /* id_note */
1651 1665 M_ID_NULL, /* id_null */
1652 1666 M_ID_PLT, /* id_plt */
1653 1667 M_ID_REL, /* id_rel */
1654 1668 M_ID_STRTAB, /* id_strtab */
1655 1669 M_ID_SYMINFO, /* id_syminfo */
1656 1670 M_ID_SYMTAB, /* id_symtab */
1657 1671 M_ID_SYMTAB_NDX, /* id_symtab_ndx */
1658 1672 M_ID_TEXT, /* id_text */
1659 1673 M_ID_TLS, /* id_tls */
1660 1674 M_ID_TLSBSS, /* id_tlsbss */
1661 1675 M_ID_UNKNOWN, /* id_unknown */
1662 1676 M_ID_UNWIND, /* id_unwind */
1663 1677 M_ID_UNWINDHDR, /* id_unwindhdr */
1664 1678 M_ID_USER, /* id_user */
1665 1679 M_ID_VERSION, /* id_version */
1666 1680 },
1667 1681 { /* Target_nullfunc */
1668 1682 nullfunc_tmpl, /* nf_template */
1669 1683 sizeof (nullfunc_tmpl), /* nf_size */
1670 1684 },
1671 1685 { /* Target_fillfunc */
1672 1686 execfill /* ff_execfill */
1673 1687 },
1674 1688 { /* Target_machrel */
1675 1689 reloc_table,
1676 1690
1677 1691 ld_init_rel, /* mr_init_rel */
1678 1692 ld_mach_eflags, /* mr_mach_eflags */
1679 1693 ld_mach_make_dynamic, /* mr_mach_make_dynamic */
1680 1694 ld_mach_update_odynamic, /* mr_mach_update_odynamic */
1681 1695 ld_calc_plt_addr, /* mr_calc_plt_addr */
1682 1696 ld_perform_outreloc, /* mr_perform_outreloc */
1683 1697 ld_do_activerelocs, /* mr_do_activerelocs */
1684 1698 ld_add_outrel, /* mr_add_outrel */
1685 1699 NULL, /* mr_reloc_register */
1686 1700 ld_reloc_local, /* mr_reloc_local */
1687 1701 NULL, /* mr_reloc_GOTOP */
1688 1702 ld_reloc_TLS, /* mr_reloc_TLS */
1689 1703 NULL, /* mr_assign_got */
1690 1704 ld_find_got_ndx, /* mr_find_got_ndx */
1691 1705 ld_calc_got_offset, /* mr_calc_got_offset */
1692 1706 ld_assign_got_ndx, /* mr_assign_got_ndx */
1693 1707 ld_assign_plt_ndx, /* mr_assign_plt_ndx */
1694 1708 NULL, /* mr_allocate_got */
1695 1709 ld_fillin_gotplt, /* mr_fillin_gotplt */
1696 1710 },
1697 1711 { /* Target_machsym */
1698 1712 NULL, /* ms_reg_check */
1699 1713 NULL, /* ms_mach_sym_typecheck */
1700 1714 NULL, /* ms_is_regsym */
1701 1715 NULL, /* ms_reg_find */
1702 1716 NULL /* ms_reg_enter */
1703 1717 }
1704 1718 };
1705 1719
1706 1720 return (&_ld_targ);
1707 1721 }
↓ open down ↓ |
958 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX