1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 #pragma ident "%Z%%M% %I% %E% SMI" 27 28 /* 29 * SPARC V9 machine dependent and ELF file class dependent functions. 30 * Contains routines for performing function binding and symbol relocations. 31 */ 32 #include "_synonyms.h" 33 34 #include <stdio.h> 35 #include <sys/elf.h> 36 #include <sys/elf_SPARC.h> 37 #include <sys/mman.h> 38 #include <dlfcn.h> 39 #include <synch.h> 40 #include <string.h> 41 #include <debug.h> 42 #include <reloc.h> 43 #include <conv.h> 44 #include "_rtld.h" 45 #include "_audit.h" 46 #include "_elf.h" 47 #include "msg.h" 48 49 extern void iflush_range(caddr_t, size_t); 50 extern void plt_upper_32(uintptr_t, uintptr_t); 51 extern void plt_upper_44(uintptr_t, uintptr_t); 52 extern void plt_full_range(uintptr_t, uintptr_t); 53 extern void elf_rtbndr(Rt_map *, ulong_t, caddr_t); 54 extern void elf_rtbndr_far(Rt_map *, ulong_t, caddr_t); 55 56 57 int 58 elf_mach_flags_check(Rej_desc *rej, Ehdr *ehdr) 59 { 60 /* 61 * Check machine type and flags. 62 */ 63 if (ehdr->e_flags & EF_SPARC_EXT_MASK) { 64 /* 65 * Check vendor-specific extensions. 66 */ 67 if (ehdr->e_flags & EF_SPARC_HAL_R1) { 68 rej->rej_type = SGS_REJ_HAL; 69 rej->rej_info = (uint_t)ehdr->e_flags; 70 return (0); 71 } 72 if ((ehdr->e_flags & EF_SPARC_SUN_US3) & ~at_flags) { 73 rej->rej_type = SGS_REJ_US3; 74 rej->rej_info = (uint_t)ehdr->e_flags; 75 return (0); 76 } 77 78 /* 79 * Generic check. 80 * All of our 64-bit SPARC's support the US1 (UltraSPARC 1) 81 * instructions so that bit isn't worth checking for explicitly. 82 */ 83 if ((ehdr->e_flags & EF_SPARC_EXT_MASK) & ~at_flags) { 84 rej->rej_type = SGS_REJ_BADFLAG; 85 rej->rej_info = (uint_t)ehdr->e_flags; 86 return (0); 87 } 88 } else if ((ehdr->e_flags & ~EF_SPARCV9_MM) != 0) { 89 rej->rej_type = SGS_REJ_BADFLAG; 90 rej->rej_info = (uint_t)ehdr->e_flags; 91 return (0); 92 } 93 return (1); 94 } 95 96 97 void 98 ldso_plt_init(Rt_map * lmp) 99 { 100 /* 101 * There is no need to analyze ld.so because we don't map in any of 102 * its dependencies. However we may map these dependencies in later 103 * (as if ld.so had dlopened them), so initialize the plt and the 104 * permission information. 105 */ 106 if (PLTGOT(lmp)) { 107 Xword pltoff; 108 109 /* 110 * Install the lm pointer in .PLT2 as per the ABI. 111 */ 112 pltoff = (2 * M_PLT_ENTSIZE) / M_PLT_INSSIZE; 113 elf_plt2_init(PLTGOT(lmp) + pltoff, lmp); 114 115 /* 116 * The V9 ABI states that the first 32k PLT entries 117 * use .PLT1, with .PLT0 used by the "latter" entries. 118 * We don't currently implement the extendend format, 119 * so install an error handler in .PLT0 to catch anyone 120 * trying to use it. 121 */ 122 elf_plt_init(PLTGOT(lmp), (caddr_t)elf_rtbndr_far); 123 124 /* 125 * Initialize .PLT1 126 */ 127 pltoff = M_PLT_ENTSIZE / M_PLT_INSSIZE; 128 elf_plt_init(PLTGOT(lmp) + pltoff, (caddr_t)elf_rtbndr); 129 } 130 } 131 132 /* 133 * elf_plt_write() will test to see how far away our destination 134 * address lies. If it is close enough that a branch can 135 * be used instead of a jmpl - we will fill the plt in with 136 * single branch. The branches are much quicker then 137 * a jmpl instruction - see bug#4356879 for further 138 * details. 139 * 140 * NOTE: we pass in both a 'pltaddr' and a 'vpltaddr' since 141 * librtld/dldump update PLT's who's physical 142 * address is not the same as the 'virtual' runtime 143 * address. 144 */ 145 Pltbindtype 146 elf_plt_write(uintptr_t addr, uintptr_t vaddr, void *rptr, uintptr_t symval, 147 Xword pltndx) 148 { 149 Rela *rel = (Rela *)rptr; 150 uintptr_t nsym = ~symval; 151 uintptr_t vpltaddr, pltaddr; 152 long disp; 153 154 155 pltaddr = addr + rel->r_offset; 156 vpltaddr = vaddr + rel->r_offset; 157 disp = symval - vpltaddr - 4; 158 159 if (pltndx >= (M64_PLT_NEARPLTS - M_PLT_XNumber)) { 160 *((Sxword *)pltaddr) = (uintptr_t)symval + 161 (uintptr_t)rel->r_addend - vaddr; 162 DBG_CALL(pltcntfar++); 163 return (PLT_T_FAR); 164 } 165 166 /* 167 * Test if the destination address is close enough to use 168 * a ba,a... instruction to reach it. 169 */ 170 if (S_INRANGE(disp, 23) && !(rtld_flags & RT_FL_NOBAPLT)) { 171 uint_t *pltent, bainstr; 172 Pltbindtype rc; 173 174 pltent = (uint_t *)pltaddr; 175 /* 176 * The 177 * 178 * ba,a,pt %icc, <dest> 179 * 180 * is the most efficient of the PLT's. If we 181 * are within +-20 bits - use that branch. 182 */ 183 if (S_INRANGE(disp, 20)) { 184 bainstr = M_BA_A_PT; /* ba,a,pt %icc,<dest> */ 185 /* LINTED */ 186 bainstr |= (uint_t)(S_MASK(19) & (disp >> 2)); 187 rc = PLT_T_21D; 188 DBG_CALL(pltcnt21d++); 189 } else { 190 /* 191 * Otherwise - we fall back to the good old 192 * 193 * ba,a <dest> 194 * 195 * Which still beats a jmpl instruction. 196 */ 197 bainstr = M_BA_A; /* ba,a <dest> */ 198 /* LINTED */ 199 bainstr |= (uint_t)(S_MASK(22) & (disp >> 2)); 200 rc = PLT_T_24D; 201 DBG_CALL(pltcnt24d++); 202 } 203 204 pltent[2] = M_NOP; /* nop instr */ 205 pltent[1] = bainstr; 206 207 iflush_range((char *)(&pltent[1]), 4); 208 pltent[0] = M_NOP; /* nop instr */ 209 iflush_range((char *)(&pltent[0]), 4); 210 return (rc); 211 } 212 213 if ((nsym >> 32) == 0) { 214 plt_upper_32(pltaddr, symval); 215 DBG_CALL(pltcntu32++); 216 return (PLT_T_U32); 217 } 218 219 if ((nsym >> 44) == 0) { 220 plt_upper_44(pltaddr, symval); 221 DBG_CALL(pltcntu44++); 222 return (PLT_T_U44); 223 } 224 225 /* 226 * The PLT destination is not in reach of 227 * a branch instruction - so we fall back 228 * to a 'jmpl' sequence. 229 */ 230 plt_full_range(pltaddr, symval); 231 DBG_CALL(pltcntfull++); 232 return (PLT_T_FULL); 233 } 234 235 236 237 /* 238 * Once relocated, the following 6 instruction sequence moves 239 * a 64-bit immediate value into register %g1 240 */ 241 #define VAL64_TO_G1 \ 242 /* 0x00 */ 0x0b, 0x00, 0x00, 0x00, /* sethi %hh(value), %g5 */ \ 243 /* 0x04 */ 0x8a, 0x11, 0x60, 0x00, /* or %g5, %hm(value), %g5 */ \ 244 /* 0x08 */ 0x8b, 0x29, 0x70, 0x20, /* sllx %g5, 32, %g5 */ \ 245 /* 0x0c */ 0x03, 0x00, 0x00, 0x00, /* sethi %lm(value), %g1 */ \ 246 /* 0x10 */ 0x82, 0x10, 0x60, 0x00, /* or %g1, %lo(value), %g1 */ \ 247 /* 0x14 */ 0x82, 0x10, 0x40, 0x05 /* or %g1, %g5, %g1 */ 248 249 /* 250 * Local storage space created on the stack created for this glue 251 * code includes space for: 252 * 0x8 pointer to dyn_data 253 * 0x8 size prev stack frame 254 */ 255 static const Byte dyn_plt_template[] = { 256 /* 0x0 */ 0x2a, 0xcf, 0x80, 0x03, /* brnz,a,pt %fp, 0xc */ 257 /* 0x4 */ 0x82, 0x27, 0x80, 0x0e, /* sub %fp, %sp, %g1 */ 258 /* 0x8 */ 0x82, 0x10, 0x20, 0xb0, /* mov 176, %g1 */ 259 /* 0xc */ 0x9d, 0xe3, 0xbf, 0x40, /* save %sp, -192, %sp */ 260 /* 0x10 */ 0xc2, 0x77, 0xa7, 0xef, /* stx %g1, [%fp + 2031] */ 261 262 /* store prev stack size */ 263 /* 0x14 */ VAL64_TO_G1, /* dyn_data to g1 */ 264 /* 0x2c */ 0xc2, 0x77, 0xa7, 0xf7, /* stx %g1, [%fp + 2039] */ 265 266 /* 0x30 */ VAL64_TO_G1, /* elf_plt_trace() addr to g1 */ 267 268 /* Call to elf_plt_trace() via g1 */ 269 /* 0x48 */ 0x9f, 0xc0, 0x60, 0x00, /* jmpl ! link r[15] to addr in g1 */ 270 /* 0x4c */ 0x01, 0x00, 0x00, 0x00 /* nop ! for jmpl delay slot *AND* */ 271 /* to get 8-byte alignment */ 272 }; 273 274 275 int dyn_plt_ent_size = sizeof (dyn_plt_template) + 276 sizeof (Addr) + /* reflmp */ 277 sizeof (Addr) + /* deflmp */ 278 sizeof (Word) + /* symndx */ 279 sizeof (Word) + /* sb_flags */ 280 sizeof (Sym); /* symdef */ 281 282 283 /* 284 * the dynamic plt entry is: 285 * 286 * brnz,a,pt %fp, 1f 287 * sub %sp, %fp, %g1 288 * mov SA(MINFRAME), %g1 289 * 1: 290 * save %sp, -(SA(MINFRAME) + (2 * CLONGSIZE)), %sp 291 * 292 * ! store prev stack size 293 * stx %g1, [%fp + STACK_BIAS - (2 * CLONGSIZE)] 294 * 295 * 2: 296 * ! move dyn_data to %g1 297 * sethi %hh(dyn_data), %g5 298 * or %g5, %hm(dyn_data), %g5 299 * sllx %g5, 32, %g5 300 * sethi %lm(dyn_data), %g1 301 * or %g1, %lo(dyn_data), %g1 302 * or %g1, %g5, %g1 303 * 304 * ! store dyn_data ptr on frame (from %g1) 305 * stx %g1, [%fp + STACK_BIAS - CLONGSIZE] 306 * 307 * ! Move address of elf_plt_trace() into %g1 308 * [Uses same 6 instructions as shown at label 2: above. Not shown.] 309 * 310 * ! Use JMPL to make call. CALL instruction is limited to 30-bits. 311 * ! of displacement. 312 * jmp1 %g1, %o7 313 * 314 * ! JMPL has a delay slot that must be filled. And, the sequence 315 * ! of instructions needs to have 8-byte alignment. This NOP does both. 316 * ! The alignment is needed for the data we put following the 317 * ! instruction. 318 * nop 319 * 320 * dyn data: 321 * Addr reflmp 322 * Addr deflmp 323 * Word symndx 324 * Word sb_flags 325 * Sym symdef (Elf64_Sym = 24-bytes) 326 */ 327 328 329 /* 330 * Relocate the instructions given by the VAL64_TO_G1 macro above. 331 * 332 * entry: 333 * lml - link map list 334 * dyndata - Value being relocated (addend) 335 * code_base - Address of 1st instruction in sequence. 336 * 337 * exit: 338 * Returns TRUE for success, FALSE for failure. 339 */ 340 static int 341 reloc_val64_to_g1(Lm_list *lml, Addr *dyndata, Byte *code_base) 342 { 343 Xword symvalue; 344 345 /* 346 * relocating: 347 * sethi %hh(dyndata), %g5 348 */ 349 symvalue = (Xword)dyndata; 350 if (do_reloc(R_SPARC_HH22, code_base, 351 &symvalue, MSG_ORIG(MSG_SYM_LADYNDATA), 352 MSG_ORIG(MSG_SPECFIL_DYNPLT), lml) == 0) { 353 return (0); 354 } 355 356 /* 357 * relocating: 358 * or %g5, %hm(dyndata), %g5 359 */ 360 symvalue = (Xword)dyndata; 361 if (do_reloc(R_SPARC_HM10, code_base + 4, 362 &symvalue, MSG_ORIG(MSG_SYM_LADYNDATA), 363 MSG_ORIG(MSG_SPECFIL_DYNPLT), lml) == 0) { 364 return (0); 365 } 366 367 /* 368 * relocating: 369 * sethi %lm(dyndata), %g1 370 */ 371 symvalue = (Xword)dyndata; 372 if (do_reloc(R_SPARC_LM22, code_base + 12, 373 &symvalue, MSG_ORIG(MSG_SYM_LADYNDATA), 374 MSG_ORIG(MSG_SPECFIL_DYNPLT), lml) == 0) { 375 return (0); 376 } 377 378 /* 379 * relocating: 380 * or %g1, %lo(dyndata), %g1 381 */ 382 symvalue = (Xword)dyndata; 383 if (do_reloc(R_SPARC_LO10, code_base + 16, 384 &symvalue, MSG_ORIG(MSG_SYM_LADYNDATA), 385 MSG_ORIG(MSG_SPECFIL_DYNPLT), lml) == 0) { 386 return (0); 387 } 388 389 return (1); 390 } 391 392 static caddr_t 393 elf_plt_trace_write(caddr_t addr, Rela * rptr, Rt_map * rlmp, Rt_map * dlmp, 394 Sym * sym, uint_t symndx, ulong_t pltndx, caddr_t to, uint_t sb_flags, 395 int *fail) 396 { 397 extern ulong_t elf_plt_trace(); 398 Addr dyn_plt, *dyndata; 399 400 /* 401 * If both pltenter & pltexit have been disabled there 402 * there is no reason to even create the glue code. 403 */ 404 if ((sb_flags & (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)) == 405 (LA_SYMB_NOPLTENTER | LA_SYMB_NOPLTEXIT)) { 406 (void) elf_plt_write((uintptr_t)addr, (uintptr_t)addr, 407 rptr, (uintptr_t)to, pltndx); 408 return (to); 409 } 410 411 /* 412 * We only need to add the glue code if there is an auditing 413 * library that is interested in this binding. 414 */ 415 dyn_plt = (Xword)AUDINFO(rlmp)->ai_dynplts + 416 (pltndx * dyn_plt_ent_size); 417 418 /* 419 * Have we initialized this dynamic plt entry yet? If we haven't do it 420 * now. Otherwise this function has been called before, but from a 421 * different plt (ie. from another shared object). In that case 422 * we just set the plt to point to the new dyn_plt. 423 */ 424 if (*(Word *)dyn_plt == 0) { 425 Sym *symp; 426 Lm_list *lml = LIST(rlmp); 427 428 (void) memcpy((void *)dyn_plt, dyn_plt_template, 429 sizeof (dyn_plt_template)); 430 dyndata = (Addr *)(dyn_plt + sizeof (dyn_plt_template)); 431 432 /* 433 * relocating: 434 * VAL64_TO_G1(dyndata) 435 * VAL64_TO_G1(&elf_plt_trace) 436 */ 437 if (!(reloc_val64_to_g1(lml, dyndata, 438 (Byte *) (dyn_plt + 0x14)) && 439 reloc_val64_to_g1(lml, (Addr *)&elf_plt_trace, 440 (Byte *) (dyn_plt + 0x30)))) { 441 *fail = 1; 442 return (0); 443 } 444 445 *dyndata++ = (Addr)rlmp; 446 *dyndata++ = (Addr)dlmp; 447 448 /* 449 * symndx in the high word, sb_flags in the low. 450 */ 451 *dyndata = (Addr)sb_flags; 452 *(Word *)dyndata = symndx; 453 dyndata++; 454 455 symp = (Sym *)dyndata; 456 *symp = *sym; 457 symp->st_value = (Addr)to; 458 iflush_range((void *)dyn_plt, sizeof (dyn_plt_template)); 459 } 460 461 (void) elf_plt_write((uintptr_t)addr, (uintptr_t)addr, rptr, 462 (uintptr_t)dyn_plt, pltndx); 463 return ((caddr_t)dyn_plt); 464 } 465 466 /* 467 * Function binding routine - invoked on the first call to a function through 468 * the procedure linkage table; 469 * passes first through an assembly language interface. 470 * 471 * Takes the address of the PLT entry where the call originated, 472 * the offset into the relocation table of the associated 473 * relocation entry and the address of the link map (rt_private_map struct) 474 * for the entry. 475 * 476 * Returns the address of the function referenced after re-writing the PLT 477 * entry to invoke the function directly. 478 * 479 * On error, causes process to terminate with a signal. 480 */ 481 482 ulong_t 483 elf_bndr(Rt_map *lmp, ulong_t pltoff, caddr_t from) 484 { 485 Rt_map *nlmp, *llmp; 486 Addr addr, vaddr, reloff, symval; 487 char *name; 488 Rela *rptr; 489 Sym *sym, *nsym; 490 Xword pltndx; 491 uint_t binfo, sb_flags = 0; 492 ulong_t rsymndx; 493 Slookup sl; 494 Pltbindtype pbtype; 495 int entry, lmflags, farplt = 0; 496 uint_t dbg_class; 497 Lm_list *lml = LIST(lmp); 498 499 /* 500 * For compatibility with libthread (TI_VERSION 1) we track the entry 501 * value. A zero value indicates we have recursed into ld.so.1 to 502 * further process a locking request. Under this recursion we disable 503 * tsort and cleanup activities. 504 */ 505 entry = enter(); 506 507 if ((lmflags = lml->lm_flags) & LML_FLG_RTLDLM) { 508 dbg_class = dbg_desc->d_class; 509 dbg_desc->d_class = 0; 510 } 511 512 /* 513 * Must calculate true plt relocation address from reloc. 514 * Take offset, subtract number of reserved PLT entries, and divide 515 * by PLT entry size, which should give the index of the plt 516 * entry (and relocation entry since they have been defined to be 517 * in the same order). Then we must multiply by the size of 518 * a relocation entry, which will give us the offset of the 519 * plt relocation entry from the start of them given by JMPREL(lm). 520 */ 521 addr = pltoff - M_PLT_RESERVSZ; 522 523 if (pltoff < (M64_PLT_NEARPLTS * M_PLT_ENTSIZE)) { 524 pltndx = addr / M_PLT_ENTSIZE; 525 } else { 526 ulong_t pltblockoff; 527 528 pltblockoff = pltoff - (M64_PLT_NEARPLTS * M_PLT_ENTSIZE); 529 pltndx = M64_PLT_NEARPLTS + 530 ((pltblockoff / M64_PLT_FBLOCKSZ) * M64_PLT_FBLKCNTS) + 531 ((pltblockoff % M64_PLT_FBLOCKSZ) / M64_PLT_FENTSIZE) - 532 M_PLT_XNumber; 533 farplt = 1; 534 } 535 536 /* 537 * Perform some basic sanity checks. If we didn't get a load map 538 * or the plt offset is invalid then its possible someone has walked 539 * over the plt entries or jumped to plt[01] out of the blue. 540 */ 541 if (!lmp || (!farplt && (addr % M_PLT_ENTSIZE) != 0) || 542 (farplt && (addr % M_PLT_INSSIZE))) { 543 eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_PLTREF), 544 conv_reloc_SPARC_type(R_SPARC_JMP_SLOT), 545 EC_NATPTR(lmp), EC_XWORD(pltoff), EC_NATPTR(from)); 546 rtldexit(lml, 1); 547 } 548 reloff = pltndx * sizeof (Rela); 549 550 /* 551 * Use relocation entry to get symbol table entry and symbol name. 552 */ 553 addr = (ulong_t)JMPREL(lmp); 554 rptr = (Rela *)(addr + reloff); 555 rsymndx = ELF_R_SYM(rptr->r_info); 556 sym = (Sym *)((ulong_t)SYMTAB(lmp) + (rsymndx * SYMENT(lmp))); 557 name = (char *)(STRTAB(lmp) + sym->st_name); 558 559 /* 560 * Determine the last link-map of this list, this'll be the starting 561 * point for any tsort() processing. 562 */ 563 llmp = lml->lm_tail; 564 565 /* 566 * Find definition for symbol. 567 */ 568 sl.sl_name = name; 569 sl.sl_cmap = lmp; 570 sl.sl_imap = lml->lm_head; 571 sl.sl_hash = 0; 572 sl.sl_rsymndx = rsymndx; 573 sl.sl_flags = LKUP_DEFT; 574 if ((nsym = lookup_sym(&sl, &nlmp, &binfo)) == 0) { 575 eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_NOSYM), NAME(lmp), 576 demangle(name)); 577 rtldexit(lml, 1); 578 } 579 580 symval = nsym->st_value; 581 if (!(FLAGS(nlmp) & FLG_RT_FIXED) && 582 (nsym->st_shndx != SHN_ABS)) 583 symval += ADDR(nlmp); 584 if ((lmp != nlmp) && ((FLAGS1(nlmp) & FL1_RT_NOINIFIN) == 0)) { 585 /* 586 * Record that this new link map is now bound to the caller. 587 */ 588 if (bind_one(lmp, nlmp, BND_REFER) == 0) 589 rtldexit(lml, 1); 590 } 591 592 if ((lml->lm_tflags | FLAGS1(lmp)) & LML_TFLG_AUD_SYMBIND) { 593 /* LINTED */ 594 uint_t symndx = (uint_t)(((uintptr_t)nsym - 595 (uintptr_t)SYMTAB(nlmp)) / SYMENT(nlmp)); 596 597 symval = audit_symbind(lmp, nlmp, nsym, symndx, symval, 598 &sb_flags); 599 } 600 601 if (FLAGS(lmp) & FLG_RT_FIXED) 602 vaddr = 0; 603 else 604 vaddr = ADDR(lmp); 605 606 pbtype = PLT_T_NONE; 607 if (!(rtld_flags & RT_FL_NOBIND)) { 608 if (((lml->lm_tflags | FLAGS1(lmp)) & 609 (LML_TFLG_AUD_PLTENTER | LML_TFLG_AUD_PLTEXIT)) && 610 AUDINFO(lmp)->ai_dynplts) { 611 int fail = 0; 612 /* LINTED */ 613 uint_t symndx = (uint_t)(((uintptr_t)nsym - 614 (uintptr_t)SYMTAB(nlmp)) / SYMENT(nlmp)); 615 616 symval = (ulong_t)elf_plt_trace_write((caddr_t)vaddr, 617 rptr, lmp, nlmp, nsym, symndx, pltndx, 618 (caddr_t)symval, sb_flags, &fail); 619 if (fail) 620 rtldexit(lml, 1); 621 } else { 622 /* 623 * Write standard PLT entry to jump directly 624 * to newly bound function. 625 */ 626 pbtype = elf_plt_write((uintptr_t)vaddr, 627 (uintptr_t)vaddr, rptr, symval, pltndx); 628 } 629 } 630 631 /* 632 * Print binding information and rebuild PLT entry. 633 */ 634 DBG_CALL(Dbg_bind_global(lmp, (Addr)from, (Off)(from - ADDR(lmp)), 635 (Xword)pltndx, pbtype, nlmp, (Addr)symval, nsym->st_value, 636 name, binfo)); 637 638 /* 639 * Complete any processing for newly loaded objects. Note we don't 640 * know exactly where any new objects are loaded (we know the object 641 * that supplied the symbol, but others may have been loaded lazily as 642 * we searched for the symbol), so sorting starts from the last 643 * link-map know on entry to this routine. 644 */ 645 if (entry) 646 load_completion(llmp, lmp); 647 648 /* 649 * Some operations like dldump() or dlopen()'ing a relocatable object 650 * result in objects being loaded on rtld's link-map, make sure these 651 * objects are initialized also. 652 */ 653 if ((LIST(nlmp)->lm_flags & LML_FLG_RTLDLM) && LIST(nlmp)->lm_init) 654 load_completion(nlmp, 0); 655 656 /* 657 * If the object we've bound to is in the process of being initialized 658 * by another thread, determine whether we should block. 659 */ 660 is_dep_ready(nlmp, lmp, DBG_WAIT_SYMBOL); 661 662 /* 663 * Make sure the object to which we've bound has had it's .init fired. 664 * Cleanup before return to user code. 665 */ 666 if (entry) { 667 is_dep_init(nlmp, lmp); 668 leave(LIST(lmp)); 669 } 670 671 if (lmflags & LML_FLG_RTLDLM) 672 dbg_desc->d_class = dbg_class; 673 674 return (symval); 675 } 676 677 678 static int 679 bindpltpad(Rt_map *lmp, List *padlist, Addr value, void **pltaddr, 680 const char *fname, const char *sname) 681 { 682 Listnode *lnp, *prevlnp; 683 Pltpadinfo *pip; 684 void *plt; 685 uintptr_t pltoff; 686 Rela rel; 687 int i; 688 689 prevlnp = 0; 690 for (LIST_TRAVERSE(padlist, lnp, pip)) { 691 if (pip->pp_addr == value) { 692 *pltaddr = pip->pp_plt; 693 DBG_CALL(Dbg_bind_pltpad_from(lmp, (Addr)*pltaddr, 694 sname)); 695 return (1); 696 } 697 if (pip->pp_addr > value) 698 break; 699 prevlnp = lnp; 700 } 701 702 plt = PLTPAD(lmp); 703 pltoff = (uintptr_t)plt - (uintptr_t)ADDR(lmp); 704 705 PLTPAD(lmp) = (void *)((uintptr_t)PLTPAD(lmp) + M_PLT_ENTSIZE); 706 707 if (PLTPAD(lmp) > PLTPADEND(lmp)) { 708 /* 709 * Just fail in usual relocation way 710 */ 711 *pltaddr = (void *)value; 712 return (1); 713 } 714 rel.r_offset = pltoff; 715 rel.r_info = 0; 716 rel.r_addend = 0; 717 718 719 /* 720 * elf_plt_write assumes the plt was previously filled 721 * with NOP's, so fill it in now. 722 */ 723 for (i = 0; i < (M_PLT_ENTSIZE / sizeof (uint_t)); i++) { 724 ((uint_t *)plt)[i] = M_NOP; 725 } 726 iflush_range((caddr_t)plt, M_PLT_ENTSIZE); 727 728 (void) elf_plt_write(ADDR(lmp), ADDR(lmp), &rel, value, 0); 729 730 if ((pip = calloc(sizeof (Pltpadinfo), 1)) == 0) 731 return (0); 732 pip->pp_addr = value; 733 pip->pp_plt = plt; 734 735 if (prevlnp) 736 lnp = list_insert(padlist, pip, prevlnp); 737 else 738 lnp = list_prepend(padlist, pip); 739 740 if (!lnp) { 741 free(pip); 742 return (0); 743 } 744 745 *pltaddr = plt; 746 DBG_CALL(Dbg_bind_pltpad_to(lmp, (Addr)*pltaddr, fname, sname)); 747 return (1); 748 } 749 750 /* 751 * Read and process the relocations for one link object, we assume all 752 * relocation sections for loadable segments are stored contiguously in 753 * the file. 754 */ 755 int 756 elf_reloc(Rt_map *lmp, uint_t plt) 757 { 758 ulong_t relbgn, relend, relsiz, basebgn, pltbgn, pltend; 759 ulong_t roffset, rsymndx, psymndx = 0, etext = ETEXT(lmp); 760 ulong_t emap, pltndx; 761 uint_t dsymndx, binfo, pbinfo; 762 Byte rtype; 763 long reladd; 764 Addr value, pvalue; 765 Sym *symref, *psymref, *symdef, *psymdef; 766 char *name, *pname; 767 Rt_map *_lmp, *plmp; 768 int textrel = 0, ret = 1, noplt = 0; 769 long relacount = RELACOUNT(lmp); 770 Rela *rel; 771 Pltbindtype pbtype; 772 List pltpadlist = {0, 0}; 773 Alist *bound = 0; 774 775 /* 776 * If an object has any DT_REGISTER entries associated with 777 * it, they are processed now. 778 */ 779 if ((plt == 0) && (FLAGS(lmp) & FLG_RT_REGSYMS)) { 780 if (elf_regsyms(lmp) == 0) 781 return (0); 782 } 783 784 /* 785 * Although only necessary for lazy binding, initialize the first 786 * procedure linkage table entry to go to elf_rtbndr(). dbx(1) seems 787 * to find this useful. 788 */ 789 if ((plt == 0) && PLTGOT(lmp)) { 790 Xword pltoff; 791 792 if ((ulong_t)PLTGOT(lmp) < etext) { 793 if (elf_set_prot(lmp, PROT_WRITE) == 0) 794 return (0); 795 textrel = 1; 796 } 797 798 /* 799 * Install the lm pointer in .PLT2 as per the ABI. 800 */ 801 pltoff = (2 * M_PLT_ENTSIZE) / M_PLT_INSSIZE; 802 elf_plt2_init(PLTGOT(lmp) + pltoff, lmp); 803 804 /* 805 * The V9 ABI states that the first 32k PLT entries 806 * use .PLT1, with .PLT0 used by the "latter" entries. 807 * We don't currently implement the extendend format, 808 * so install an error handler in .PLT0 to catch anyone 809 * trying to use it. 810 */ 811 elf_plt_init(PLTGOT(lmp), (caddr_t)elf_rtbndr_far); 812 813 /* 814 * Initialize .PLT1 815 */ 816 pltoff = M_PLT_ENTSIZE / M_PLT_INSSIZE; 817 elf_plt_init(PLTGOT(lmp) + pltoff, (caddr_t)elf_rtbndr); 818 } 819 820 /* 821 * Initialize the plt start and end addresses. 822 */ 823 if ((pltbgn = (ulong_t)JMPREL(lmp)) != 0) 824 pltend = pltbgn + (ulong_t)(PLTRELSZ(lmp)); 825 826 /* 827 * If we've been called upon to promote an RTLD_LAZY object to an 828 * RTLD_NOW then we're only interested in scaning the .plt table. 829 */ 830 if (plt) { 831 relbgn = pltbgn; 832 relend = pltend; 833 } else { 834 /* 835 * The relocation sections appear to the run-time linker as a 836 * single table. Determine the address of the beginning and end 837 * of this table. There are two different interpretations of 838 * the ABI at this point: 839 * 840 * o The REL table and its associated RELSZ indicate the 841 * concatenation of *all* relocation sections (this is the 842 * model our link-editor constructs). 843 * 844 * o The REL table and its associated RELSZ indicate the 845 * concatenation of all *but* the .plt relocations. These 846 * relocations are specified individually by the JMPREL and 847 * PLTRELSZ entries. 848 * 849 * Determine from our knowledege of the relocation range and 850 * .plt range, the range of the total relocation table. Note 851 * that one other ABI assumption seems to be that the .plt 852 * relocations always follow any other relocations, the 853 * following range checking drops that assumption. 854 */ 855 relbgn = (ulong_t)(REL(lmp)); 856 relend = relbgn + (ulong_t)(RELSZ(lmp)); 857 if (pltbgn) { 858 if (!relbgn || (relbgn > pltbgn)) 859 relbgn = pltbgn; 860 if (!relbgn || (relend < pltend)) 861 relend = pltend; 862 } 863 } 864 if (!relbgn || (relbgn == relend)) { 865 DBG_CALL(Dbg_reloc_run(lmp, 0, plt, DBG_REL_NONE)); 866 return (1); 867 } 868 869 relsiz = (ulong_t)(RELENT(lmp)); 870 basebgn = ADDR(lmp); 871 emap = ADDR(lmp) + MSIZE(lmp); 872 873 DBG_CALL(Dbg_reloc_run(lmp, M_REL_SHT_TYPE, plt, DBG_REL_START)); 874 875 /* 876 * If we're processing in lazy mode there is no need to scan the 877 * .rela.plt table. 878 */ 879 if (pltbgn && ((MODE(lmp) & RTLD_NOW) == 0)) 880 noplt = 1; 881 882 /* 883 * Loop through relocations. 884 */ 885 while (relbgn < relend) { 886 Addr vaddr; 887 uint_t sb_flags = 0; 888 889 rtype = (Byte)ELF_R_TYPE(((Rela *)relbgn)->r_info); 890 891 /* 892 * If this is a RELATIVE relocation in a shared object 893 * (the common case), and if we are not debugging, then 894 * jump into a tighter relocaiton loop (elf_reloc_relacount) 895 * Only make the jump if we've been given a hint on the 896 * number of relocations. 897 */ 898 if ((rtype == R_SPARC_RELATIVE) && 899 ((FLAGS(lmp) & FLG_RT_FIXED) == 0) && (DBG_ENABLED == 0)) { 900 /* 901 * It's possible that the relative relocation block 902 * has relocations against the text segment as well 903 * as the data segment. Since our optimized relocation 904 * engine does not check which segment the relocation 905 * is against - just mprotect it now if it's been 906 * marked as containing TEXTREL's. 907 */ 908 if ((textrel == 0) && (FLAGS1(lmp) & FL1_RT_TEXTREL)) { 909 if (elf_set_prot(lmp, PROT_WRITE) == 0) { 910 ret = 0; 911 break; 912 } 913 textrel = 1; 914 } 915 if (relacount) { 916 relbgn = elf_reloc_relacount(relbgn, relacount, 917 relsiz, basebgn); 918 relacount = 0; 919 } else { 920 relbgn = elf_reloc_relative(relbgn, relend, 921 relsiz, basebgn, etext, emap); 922 } 923 if (relbgn >= relend) 924 break; 925 rtype = (Byte)ELF_R_TYPE(((Rela *)relbgn)->r_info); 926 } 927 928 roffset = ((Rela *)relbgn)->r_offset; 929 930 reladd = (long)(((Rela *)relbgn)->r_addend); 931 rsymndx = ELF_R_SYM(((Rela *)relbgn)->r_info); 932 933 rel = (Rela *)relbgn; 934 relbgn += relsiz; 935 936 /* 937 * Optimizations. 938 */ 939 if (rtype == R_SPARC_NONE) 940 continue; 941 if (noplt && ((ulong_t)rel >= pltbgn) && 942 ((ulong_t)rel < pltend)) { 943 relbgn = pltend; 944 continue; 945 } 946 947 if (rtype != R_SPARC_REGISTER) { 948 /* 949 * If this is a shared object, add the base address 950 * to offset. 951 */ 952 if (!(FLAGS(lmp) & FLG_RT_FIXED)) 953 roffset += basebgn; 954 955 /* 956 * If this relocation is not against part of the image 957 * mapped into memory we skip it. 958 */ 959 if ((roffset < ADDR(lmp)) || (roffset > (ADDR(lmp) + 960 MSIZE(lmp)))) { 961 elf_reloc_bad(lmp, (void *)rel, rtype, roffset, 962 rsymndx); 963 continue; 964 } 965 } 966 967 /* 968 * If we're promoting plts determine if this one has already 969 * been written. An uninitialized plts' second instruction is a 970 * branch. 971 */ 972 if (plt) { 973 uchar_t *_roffset = (uchar_t *)roffset; 974 975 _roffset += M_PLT_INSSIZE; 976 /* LINTED */ 977 if ((*(uint_t *)_roffset & 978 (~(S_MASK(19)))) != M_BA_A_XCC) 979 continue; 980 } 981 982 binfo = 0; 983 pltndx = (ulong_t)-1; 984 pbtype = PLT_T_NONE; 985 /* 986 * If a symbol index is specified then get the symbol table 987 * entry, locate the symbol definition, and determine its 988 * address. 989 */ 990 if (rsymndx) { 991 /* 992 * Get the local symbol table entry. 993 */ 994 symref = (Sym *)((ulong_t)SYMTAB(lmp) + 995 (rsymndx * SYMENT(lmp))); 996 997 /* 998 * If this is a local symbol, just use the base address. 999 * (we should have no local relocations in the 1000 * executable). 1001 */ 1002 if (ELF_ST_BIND(symref->st_info) == STB_LOCAL) { 1003 value = basebgn; 1004 name = (char *)0; 1005 1006 /* 1007 * TLS relocation - value for DTPMOD relocation 1008 * is the TLS modid. 1009 */ 1010 if (rtype == M_R_DTPMOD) 1011 value = TLSMODID(lmp); 1012 } else { 1013 /* 1014 * If the symbol index is equal to the previous 1015 * symbol index relocation we processed then 1016 * reuse the previous values. (Note that there 1017 * have been cases where a relocation exists 1018 * against a copy relocation symbol, our ld(1) 1019 * should optimize this away, but make sure we 1020 * don't use the same symbol information should 1021 * this case exist). 1022 */ 1023 if ((rsymndx == psymndx) && 1024 (rtype != R_SPARC_COPY)) { 1025 /* LINTED */ 1026 if (psymdef == 0) { 1027 DBG_CALL(Dbg_bind_weak(lmp, 1028 (Addr)roffset, (Addr) 1029 (roffset - basebgn), name)); 1030 continue; 1031 } 1032 /* LINTED */ 1033 value = pvalue; 1034 /* LINTED */ 1035 name = pname; 1036 symdef = psymdef; 1037 /* LINTED */ 1038 symref = psymref; 1039 /* LINTED */ 1040 _lmp = plmp; 1041 /* LINTED */ 1042 binfo = pbinfo; 1043 1044 if ((LIST(_lmp)->lm_tflags | 1045 FLAGS1(_lmp)) & 1046 LML_TFLG_AUD_SYMBIND) { 1047 value = audit_symbind(lmp, _lmp, 1048 /* LINTED */ 1049 symdef, dsymndx, value, 1050 &sb_flags); 1051 } 1052 } else { 1053 Slookup sl; 1054 uchar_t bind; 1055 1056 /* 1057 * Lookup the symbol definition. 1058 */ 1059 name = (char *)(STRTAB(lmp) + 1060 symref->st_name); 1061 1062 sl.sl_name = name; 1063 sl.sl_cmap = lmp; 1064 sl.sl_imap = 0; 1065 sl.sl_hash = 0; 1066 sl.sl_rsymndx = rsymndx; 1067 1068 if (rtype == R_SPARC_COPY) 1069 sl.sl_flags = LKUP_COPY; 1070 else 1071 sl.sl_flags = LKUP_DEFT; 1072 1073 sl.sl_flags |= LKUP_ALLCNTLIST; 1074 1075 if (rtype != R_SPARC_JMP_SLOT) 1076 sl.sl_flags |= LKUP_SPEC; 1077 1078 bind = ELF_ST_BIND(symref->st_info); 1079 if (bind == STB_WEAK) 1080 sl.sl_flags |= LKUP_WEAK; 1081 1082 symdef = lookup_sym(&sl, &_lmp, &binfo); 1083 1084 /* 1085 * If the symbol is not found and the 1086 * reference was not to a weak symbol, 1087 * report an error. Weak references 1088 * may be unresolved. 1089 * chkmsg: MSG_INTL(MSG_LDD_SYM_NFOUND) 1090 */ 1091 if (symdef == 0) { 1092 Lm_list *lml = LIST(lmp); 1093 1094 if (bind != STB_WEAK) { 1095 if (lml->lm_flags & 1096 LML_FLG_IGNRELERR) { 1097 continue; 1098 } else if (lml->lm_flags & 1099 LML_FLG_TRC_WARN) { 1100 (void) printf(MSG_INTL( 1101 MSG_LDD_SYM_NFOUND), 1102 demangle(name), 1103 NAME(lmp)); 1104 continue; 1105 } else { 1106 eprintf(lml, ERR_FATAL, 1107 MSG_INTL(MSG_REL_NOSYM), 1108 NAME(lmp), 1109 demangle(name)); 1110 ret = 0; 1111 break; 1112 } 1113 } else { 1114 psymndx = rsymndx; 1115 psymdef = 0; 1116 1117 DBG_CALL(Dbg_bind_weak(lmp, 1118 (Addr)roffset, (Addr) 1119 (roffset - basebgn), name)); 1120 continue; 1121 } 1122 } 1123 1124 /* 1125 * If symbol was found in an object 1126 * other than the referencing object 1127 * then record the binding. 1128 */ 1129 if ((lmp != _lmp) && ((FLAGS1(_lmp) & 1130 FL1_RT_NOINIFIN) == 0)) { 1131 if (alist_test(&bound, _lmp, 1132 sizeof (Rt_map *), 1133 AL_CNT_RELBIND) == 0) { 1134 ret = 0; 1135 break; 1136 } 1137 } 1138 1139 /* 1140 * Calculate the location of definition; 1141 * symbol value plus base address of 1142 * containing shared object. 1143 */ 1144 value = symdef->st_value; 1145 if (!(FLAGS(_lmp) & FLG_RT_FIXED) && 1146 (symdef->st_shndx != SHN_ABS) && 1147 (ELF_ST_TYPE(symdef->st_info) != 1148 STT_TLS)) 1149 value += ADDR(_lmp); 1150 1151 /* 1152 * Retain this symbol index and the 1153 * value in case it can be used for the 1154 * subsequent relocations. 1155 */ 1156 if (rtype != R_SPARC_COPY) { 1157 psymndx = rsymndx; 1158 pvalue = value; 1159 pname = name; 1160 psymdef = symdef; 1161 psymref = symref; 1162 plmp = _lmp; 1163 pbinfo = binfo; 1164 } 1165 if ((LIST(_lmp)->lm_tflags | 1166 FLAGS1(_lmp)) & 1167 LML_TFLG_AUD_SYMBIND) { 1168 /* LINTED */ 1169 dsymndx = (((uintptr_t)symdef - 1170 (uintptr_t)SYMTAB(_lmp)) / 1171 SYMENT(_lmp)); 1172 value = audit_symbind(lmp, _lmp, 1173 symdef, dsymndx, value, 1174 &sb_flags); 1175 } 1176 } 1177 1178 /* 1179 * If relocation is PC-relative, subtract 1180 * offset address. 1181 */ 1182 if (IS_PC_RELATIVE(rtype)) 1183 value -= roffset; 1184 1185 /* 1186 * TLS relocation - value for DTPMOD relocation 1187 * is the TLS modid. 1188 */ 1189 if (rtype == M_R_DTPMOD) 1190 value = TLSMODID(_lmp); 1191 else if (rtype == M_R_TPOFF) 1192 value = -(TLSSTATOFF(_lmp) - value); 1193 } 1194 } else { 1195 /* 1196 * Special cases, a regsiter symbol associated with 1197 * symbol index 0 is initialized (i.e. relocated) to 1198 * a constant in the r_addend field rather than to a 1199 * symbol value. 1200 * 1201 * A DTPMOD relocation is a local binding to a TLS 1202 * symbol. Fill in the TLSMODID for the current object. 1203 */ 1204 if (rtype == R_SPARC_REGISTER) 1205 value = 0; 1206 else if (rtype == M_R_DTPMOD) 1207 value = TLSMODID(lmp); 1208 else 1209 value = basebgn; 1210 name = (char *)0; 1211 } 1212 1213 /* 1214 * If this object has relocations in the text segment, turn 1215 * off the write protect. 1216 */ 1217 if ((rtype != R_SPARC_REGISTER) && (roffset < etext) && 1218 (textrel == 0)) { 1219 if (elf_set_prot(lmp, PROT_WRITE) == 0) { 1220 ret = 0; 1221 break; 1222 } 1223 textrel = 1; 1224 } 1225 1226 /* 1227 * Call relocation routine to perform required relocation. 1228 */ 1229 DBG_CALL(Dbg_reloc_in(LIST(lmp), ELF_DBG_RTLD, M_MACH, 1230 M_REL_SHT_TYPE, rel, NULL, name)); 1231 1232 switch (rtype) { 1233 case R_SPARC_REGISTER: 1234 /* 1235 * The v9 ABI 4.2.4 says that system objects may, 1236 * but are not required to, use register symbols 1237 * to inidcate how they use global registers. Thus 1238 * at least %g6, %g7 must be allowed in addition 1239 * to %g2 and %g3. 1240 */ 1241 value += reladd; 1242 if (roffset == STO_SPARC_REGISTER_G1) { 1243 set_sparc_g1(value); 1244 } else if (roffset == STO_SPARC_REGISTER_G2) { 1245 set_sparc_g2(value); 1246 } else if (roffset == STO_SPARC_REGISTER_G3) { 1247 set_sparc_g3(value); 1248 } else if (roffset == STO_SPARC_REGISTER_G4) { 1249 set_sparc_g4(value); 1250 } else if (roffset == STO_SPARC_REGISTER_G5) { 1251 set_sparc_g5(value); 1252 } else if (roffset == STO_SPARC_REGISTER_G6) { 1253 set_sparc_g6(value); 1254 } else if (roffset == STO_SPARC_REGISTER_G7) { 1255 set_sparc_g7(value); 1256 } else { 1257 eprintf(LIST(lmp), ERR_FATAL, 1258 MSG_INTL(MSG_REL_BADREG), NAME(lmp), 1259 EC_ADDR(roffset)); 1260 ret = 0; 1261 break; 1262 } 1263 1264 DBG_CALL(Dbg_reloc_apply_reg(LIST(lmp), ELF_DBG_RTLD, 1265 M_MACH, (Xword)roffset, (Xword)value)); 1266 break; 1267 case R_SPARC_COPY: 1268 if (elf_copy_reloc(name, symref, lmp, (void *)roffset, 1269 symdef, _lmp, (const void *)value) == 0) 1270 ret = 0; 1271 break; 1272 case R_SPARC_JMP_SLOT: 1273 pltndx = ((uintptr_t)rel - 1274 (uintptr_t)JMPREL(lmp)) / relsiz; 1275 1276 if (FLAGS(lmp) & FLG_RT_FIXED) 1277 vaddr = 0; 1278 else 1279 vaddr = ADDR(lmp); 1280 1281 if (((LIST(lmp)->lm_tflags | FLAGS1(lmp)) & 1282 (LML_TFLG_AUD_PLTENTER | LML_TFLG_AUD_PLTEXIT)) && 1283 AUDINFO(lmp)->ai_dynplts) { 1284 int fail = 0; 1285 /* LINTED */ 1286 uint_t symndx = (uint_t)(((uintptr_t)symdef - 1287 (uintptr_t)SYMTAB(_lmp)) / 1288 SYMENT(_lmp)); 1289 1290 (void) elf_plt_trace_write((caddr_t)vaddr, 1291 (Rela *)rel, lmp, _lmp, symdef, symndx, 1292 pltndx, (caddr_t)value, sb_flags, &fail); 1293 if (fail) 1294 ret = 0; 1295 } else { 1296 /* 1297 * Write standard PLT entry to jump directly 1298 * to newly bound function. 1299 */ 1300 DBG_CALL(Dbg_reloc_apply_val(LIST(lmp), 1301 ELF_DBG_RTLD, (Xword)roffset, 1302 (Xword)value)); 1303 pbtype = elf_plt_write((uintptr_t)vaddr, 1304 (uintptr_t)vaddr, (void *)rel, value, 1305 pltndx); 1306 } 1307 break; 1308 case R_SPARC_WDISP30: 1309 if (PLTPAD(lmp) && 1310 (S_INRANGE((Sxword)value, 29) == 0)) { 1311 void * plt = 0; 1312 1313 if (bindpltpad(lmp, &pltpadlist, 1314 value + roffset, &plt, 1315 NAME(_lmp), name) == 0) { 1316 ret = 0; 1317 break; 1318 } 1319 value = (Addr)((Addr)plt - roffset); 1320 } 1321 /* FALLTHROUGH */ 1322 default: 1323 value += reladd; 1324 if (IS_EXTOFFSET(rtype)) 1325 value += (Word)ELF_R_TYPE_DATA(rel->r_info); 1326 1327 /* 1328 * Write the relocation out. If this relocation is a 1329 * common basic write, skip the doreloc() engine. 1330 */ 1331 if ((rtype == R_SPARC_GLOB_DAT) || 1332 (rtype == R_SPARC_64)) { 1333 if (roffset & 0x7) { 1334 eprintf(LIST(lmp), ERR_FATAL, 1335 MSG_INTL(MSG_REL_NONALIGN), 1336 conv_reloc_SPARC_type(rtype), 1337 NAME(lmp), demangle(name), 1338 EC_OFF(roffset)); 1339 ret = 0; 1340 } else 1341 *(ulong_t *)roffset += value; 1342 } else { 1343 if (do_reloc(rtype, (uchar_t *)roffset, 1344 (Xword *)&value, name, 1345 NAME(lmp), LIST(lmp)) == 0) 1346 ret = 0; 1347 } 1348 1349 /* 1350 * The value now contains the 'bit-shifted' value that 1351 * was or'ed into memory (this was set by do_reloc()). 1352 */ 1353 DBG_CALL(Dbg_reloc_apply_val(LIST(lmp), ELF_DBG_RTLD, 1354 (Xword)roffset, (Xword)value)); 1355 1356 /* 1357 * If this relocation is against a text segment, make 1358 * sure that the instruction cache is flushed. 1359 */ 1360 if (textrel) 1361 iflush_range((caddr_t)roffset, 0x4); 1362 } 1363 1364 if ((ret == 0) && 1365 ((LIST(lmp)->lm_flags & LML_FLG_TRC_WARN) == 0)) 1366 break; 1367 1368 if (binfo) { 1369 DBG_CALL(Dbg_bind_global(lmp, (Addr)roffset, 1370 (Off)(roffset - basebgn), pltndx, pbtype, 1371 _lmp, (Addr)value, symdef->st_value, name, binfo)); 1372 } 1373 } 1374 1375 /* 1376 * Free up any items on the pltpadlist if it was allocated 1377 */ 1378 if (pltpadlist.head) { 1379 Listnode * lnp; 1380 Listnode * plnp; 1381 Pltpadinfo * pip; 1382 1383 plnp = 0; 1384 for (LIST_TRAVERSE(&pltpadlist, lnp, pip)) { 1385 if (plnp != 0) 1386 free(plnp); 1387 free(pip); 1388 plnp = lnp; 1389 } 1390 if (plnp != 0) 1391 free(plnp); 1392 } 1393 1394 return (relocate_finish(lmp, bound, textrel, ret)); 1395 } 1396 1397 /* 1398 * Provide a machine specific interface to the conversion routine. By calling 1399 * the machine specific version, rather than the generic version, we insure that 1400 * the data tables/strings for all known machine versions aren't dragged into 1401 * ld.so.1. 1402 */ 1403 const char * 1404 _conv_reloc_type(uint_t rel) 1405 { 1406 return (conv_reloc_SPARC_type(rel)); 1407 } 1408