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