17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21141040e8Srie 227c478bd9Sstevel@tonic-gate /* 23bf994817SAli Bahrami * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 247c478bd9Sstevel@tonic-gate */ 257c478bd9Sstevel@tonic-gate 26ba2be530Sab /* Get the x86 version of the relocation engine */ 27ba2be530Sab #define DO_RELOC_LIBLD_X86 28ba2be530Sab 297c478bd9Sstevel@tonic-gate #include <string.h> 307c478bd9Sstevel@tonic-gate #include <stdio.h> 317c478bd9Sstevel@tonic-gate #include <strings.h> 327c478bd9Sstevel@tonic-gate #include <sys/elf_amd64.h> 337c478bd9Sstevel@tonic-gate #include <debug.h> 347c478bd9Sstevel@tonic-gate #include <reloc.h> 35ba2be530Sab #include <i386/machdep_x86.h> 365aefb655Srie #include "msg.h" 375aefb655Srie #include "_libld.h" 38ba2be530Sab 39bf994817SAli Bahrami /* 40bf994817SAli Bahrami * This module uses do_reloc_ld() to execute several synthesized relocations. 41bf994817SAli Bahrami * That function expects to be passed two things that we need to construct 42bf994817SAli Bahrami * here: 43bf994817SAli Bahrami * 44bf994817SAli Bahrami * 1) A Rel_desc descriptor for each relocation type, from which the 45bf994817SAli Bahrami * rel_rtype field, and nothing else, is obtained. This is easily 46bf994817SAli Bahrami * handled by constructing the necessary descriptors. 47bf994817SAli Bahrami * 48bf994817SAli Bahrami * 2) A function, which called with the Rel_desc descriptor, returns 49bf994817SAli Bahrami * a string representing the name of the symbol associated with 50bf994817SAli Bahrami * the descriptor. The usual function for this is ld_reloc_sym_name(). 51bf994817SAli Bahrami * However, that function will not work in this case, as these synthetic 52bf994817SAli Bahrami * relocations do not have an associated symbol. We supply the 53bf994817SAli Bahrami * syn_rdesc_sym_name() function to simply return the fixed name. 54bf994817SAli Bahrami */ 55bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_gotpcrel = { 56bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_GOTPCREL }; 57bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_32 = { 58bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_32 }; 59bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_pc32 = { 60bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_PC32 }; 61bf994817SAli Bahrami 62bf994817SAli Bahrami /*ARGSUSED*/ 63bf994817SAli Bahrami static const char * 64bf994817SAli Bahrami syn_rdesc_sym_name(Rel_desc *rdesc) 65bf994817SAli Bahrami { 66bf994817SAli Bahrami return (MSG_ORIG(MSG_SYM_PLTENT)); 67bf994817SAli Bahrami } 68bf994817SAli Bahrami 6957ef7aa9SRod Evans /* 7057ef7aa9SRod Evans * Search the GOT index list for a GOT entry with a matching reference and the 7157ef7aa9SRod Evans * proper addend. 7257ef7aa9SRod Evans */ 7357ef7aa9SRod Evans static Gotndx * 7457ef7aa9SRod Evans ld_find_got_ndx(Alist *alp, Gotref gref, Ofl_desc *ofl, Rel_desc *rdesc) 7557ef7aa9SRod Evans { 7657ef7aa9SRod Evans Aliste idx; 7757ef7aa9SRod Evans Gotndx *gnp; 7857ef7aa9SRod Evans 7957ef7aa9SRod Evans assert(rdesc != 0); 8057ef7aa9SRod Evans 8157ef7aa9SRod Evans if ((gref == GOT_REF_TLSLD) && ofl->ofl_tlsldgotndx) 8257ef7aa9SRod Evans return (ofl->ofl_tlsldgotndx); 83ba2be530Sab 8457ef7aa9SRod Evans for (ALIST_TRAVERSE(alp, idx, gnp)) { 8557ef7aa9SRod Evans if ((rdesc->rel_raddend == gnp->gn_addend) && 8657ef7aa9SRod Evans (gnp->gn_gotref == gref)) { 8757ef7aa9SRod Evans return (gnp); 8857ef7aa9SRod Evans } 8957ef7aa9SRod Evans } 9057ef7aa9SRod Evans return (NULL); 9157ef7aa9SRod Evans } 927c478bd9Sstevel@tonic-gate 9357ef7aa9SRod Evans static Xword 9457ef7aa9SRod Evans ld_calc_got_offset(Rel_desc *rdesc, Ofl_desc *ofl) 9557ef7aa9SRod Evans { 9657ef7aa9SRod Evans Os_desc *osp = ofl->ofl_osgot; 9757ef7aa9SRod Evans Sym_desc *sdp = rdesc->rel_sym; 9857ef7aa9SRod Evans Xword gotndx; 9957ef7aa9SRod Evans Gotref gref; 10057ef7aa9SRod Evans Gotndx *gnp; 10157ef7aa9SRod Evans 10257ef7aa9SRod Evans if (rdesc->rel_flags & FLG_REL_DTLS) 10357ef7aa9SRod Evans gref = GOT_REF_TLSGD; 10457ef7aa9SRod Evans else if (rdesc->rel_flags & FLG_REL_MTLS) 10557ef7aa9SRod Evans gref = GOT_REF_TLSLD; 10657ef7aa9SRod Evans else if (rdesc->rel_flags & FLG_REL_STLS) 10757ef7aa9SRod Evans gref = GOT_REF_TLSIE; 10857ef7aa9SRod Evans else 10957ef7aa9SRod Evans gref = GOT_REF_GENERIC; 11057ef7aa9SRod Evans 11157ef7aa9SRod Evans gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, rdesc); 11257ef7aa9SRod Evans assert(gnp); 11357ef7aa9SRod Evans 11457ef7aa9SRod Evans gotndx = (Xword)gnp->gn_gotndx; 11557ef7aa9SRod Evans 11657ef7aa9SRod Evans if ((rdesc->rel_flags & FLG_REL_DTLS) && 11757ef7aa9SRod Evans (rdesc->rel_rtype == R_AMD64_DTPOFF64)) 11857ef7aa9SRod Evans gotndx++; 11957ef7aa9SRod Evans 12057ef7aa9SRod Evans return ((Xword)(osp->os_shdr->sh_addr + (gotndx * M_GOT_ENTSIZE))); 12157ef7aa9SRod Evans } 122ba2be530Sab 123ba2be530Sab static Word 124bf994817SAli Bahrami ld_init_rel(Rel_desc *reld, Word *typedata, void *reloc) 1257c478bd9Sstevel@tonic-gate { 12657ef7aa9SRod Evans Rela *rel = (Rela *)reloc; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate /* LINTED */ 129ba2be530Sab reld->rel_rtype = (Word)ELF_R_TYPE(rel->r_info, M_MACH); 1307c478bd9Sstevel@tonic-gate reld->rel_roffset = rel->r_offset; 1317c478bd9Sstevel@tonic-gate reld->rel_raddend = rel->r_addend; 132bf994817SAli Bahrami *typedata = 0; 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate reld->rel_flags |= FLG_REL_RELA; 1357c478bd9Sstevel@tonic-gate 1367c478bd9Sstevel@tonic-gate return ((Word)ELF_R_SYM(rel->r_info)); 1377c478bd9Sstevel@tonic-gate } 1387c478bd9Sstevel@tonic-gate 139ba2be530Sab static void 1405aefb655Srie ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl) 1417c478bd9Sstevel@tonic-gate { 1425aefb655Srie ofl->ofl_dehdr->e_flags |= ehdr->e_flags; 1437c478bd9Sstevel@tonic-gate } 1447c478bd9Sstevel@tonic-gate 145ba2be530Sab static void 1465aefb655Srie ld_mach_make_dynamic(Ofl_desc *ofl, size_t *cnt) 1477c478bd9Sstevel@tonic-gate { 1487c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) { 1497c478bd9Sstevel@tonic-gate /* 1507c478bd9Sstevel@tonic-gate * Create this entry if we are going to create a PLT table. 1517c478bd9Sstevel@tonic-gate */ 1527c478bd9Sstevel@tonic-gate if (ofl->ofl_pltcnt) 1537c478bd9Sstevel@tonic-gate (*cnt)++; /* DT_PLTGOT */ 1547c478bd9Sstevel@tonic-gate } 1557c478bd9Sstevel@tonic-gate } 1567c478bd9Sstevel@tonic-gate 157ba2be530Sab static void 1585aefb655Srie ld_mach_update_odynamic(Ofl_desc *ofl, Dyn **dyn) 1597c478bd9Sstevel@tonic-gate { 1605aefb655Srie if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) && ofl->ofl_pltcnt) { 1615aefb655Srie (*dyn)->d_tag = DT_PLTGOT; 1625aefb655Srie if (ofl->ofl_osgot) 1635aefb655Srie (*dyn)->d_un.d_ptr = ofl->ofl_osgot->os_shdr->sh_addr; 1645aefb655Srie else 1655aefb655Srie (*dyn)->d_un.d_ptr = 0; 1665aefb655Srie (*dyn)++; 1677c478bd9Sstevel@tonic-gate } 1687c478bd9Sstevel@tonic-gate } 1697c478bd9Sstevel@tonic-gate 170ba2be530Sab static Xword 1715aefb655Srie ld_calc_plt_addr(Sym_desc *sdp, Ofl_desc *ofl) 1727c478bd9Sstevel@tonic-gate { 1737c478bd9Sstevel@tonic-gate Xword value; 1747c478bd9Sstevel@tonic-gate 1757c478bd9Sstevel@tonic-gate value = (Xword)(ofl->ofl_osplt->os_shdr->sh_addr) + 1767c478bd9Sstevel@tonic-gate M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * M_PLT_ENTSIZE); 1777c478bd9Sstevel@tonic-gate return (value); 1787c478bd9Sstevel@tonic-gate } 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate /* 1817c478bd9Sstevel@tonic-gate * Build a single plt entry - code is: 1827c478bd9Sstevel@tonic-gate * JMP *name1@GOTPCREL(%rip) 1837c478bd9Sstevel@tonic-gate * PUSHL $index 1847c478bd9Sstevel@tonic-gate * JMP .PLT0 1857c478bd9Sstevel@tonic-gate */ 186b3fbe5e6Sseizo static uchar_t pltn_entry[M_PLT_ENTSIZE] = { 1877c478bd9Sstevel@tonic-gate /* 0x00 jmpq *name1@GOTPCREL(%rip) */ 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 1887c478bd9Sstevel@tonic-gate /* 0x06 pushq $index */ 0x68, 0x00, 0x00, 0x00, 0x00, 1897c478bd9Sstevel@tonic-gate /* 0x0b jmpq .plt0(%rip) */ 0xe9, 0x00, 0x00, 0x00, 0x00 1907c478bd9Sstevel@tonic-gate /* 0x10 */ 1917c478bd9Sstevel@tonic-gate }; 1927c478bd9Sstevel@tonic-gate 1937c478bd9Sstevel@tonic-gate static uintptr_t 1947c478bd9Sstevel@tonic-gate plt_entry(Ofl_desc * ofl, Sym_desc * sdp) 1957c478bd9Sstevel@tonic-gate { 196b3fbe5e6Sseizo uchar_t *plt0, *pltent, *gotent; 1977c478bd9Sstevel@tonic-gate Sword plt_off; 1987c478bd9Sstevel@tonic-gate Word got_off; 1997c478bd9Sstevel@tonic-gate Xword val1; 200ba2be530Sab int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 2017c478bd9Sstevel@tonic-gate 2027c478bd9Sstevel@tonic-gate got_off = sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 2037c478bd9Sstevel@tonic-gate plt_off = M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * 2047c478bd9Sstevel@tonic-gate M_PLT_ENTSIZE); 205b3fbe5e6Sseizo plt0 = (uchar_t *)(ofl->ofl_osplt->os_outdata->d_buf); 2067c478bd9Sstevel@tonic-gate pltent = plt0 + plt_off; 207b3fbe5e6Sseizo gotent = (uchar_t *)(ofl->ofl_osgot->os_outdata->d_buf) + got_off; 2087c478bd9Sstevel@tonic-gate 2097c478bd9Sstevel@tonic-gate bcopy(pltn_entry, pltent, sizeof (pltn_entry)); 2107c478bd9Sstevel@tonic-gate /* 2117c478bd9Sstevel@tonic-gate * Fill in the got entry with the address of the next instruction. 2127c478bd9Sstevel@tonic-gate */ 2137c478bd9Sstevel@tonic-gate /* LINTED */ 214b3fbe5e6Sseizo *(Word *)gotent = ofl->ofl_osplt->os_shdr->sh_addr + plt_off + 215b3fbe5e6Sseizo M_PLT_INSSIZE; 216ba2be530Sab if (bswap) 217ba2be530Sab /* LINTED */ 218ba2be530Sab *(Word *)gotent = ld_bswap_Word(*(Word *)gotent); 2197c478bd9Sstevel@tonic-gate 220f3324781Sab /* 221f3324781Sab * If '-z noreloc' is specified - skip the do_reloc_ld 222f3324781Sab * stage. 223f3324781Sab */ 224f3324781Sab if (!OFL_DO_RELOC(ofl)) 225f3324781Sab return (1); 226f3324781Sab 2277c478bd9Sstevel@tonic-gate /* 2287c478bd9Sstevel@tonic-gate * patchup: 2297c478bd9Sstevel@tonic-gate * jmpq *name1@gotpcrel(%rip) 2307c478bd9Sstevel@tonic-gate * 2317c478bd9Sstevel@tonic-gate * NOTE: 0x06 represents next instruction. 2327c478bd9Sstevel@tonic-gate */ 2337c478bd9Sstevel@tonic-gate val1 = (ofl->ofl_osgot->os_shdr->sh_addr + got_off) - 234de777a60Sab (ofl->ofl_osplt->os_shdr->sh_addr + plt_off) - 0x06; 2357c478bd9Sstevel@tonic-gate 236bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x02], &val1, 237bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 238bf994817SAli Bahrami ofl->ofl_lml) == 0) { 2391007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 240f3324781Sab sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 241f3324781Sab return (S_ERROR); 2427c478bd9Sstevel@tonic-gate } 2437c478bd9Sstevel@tonic-gate 2447c478bd9Sstevel@tonic-gate /* 2457c478bd9Sstevel@tonic-gate * patchup: 2467c478bd9Sstevel@tonic-gate * pushq $pltndx 2477c478bd9Sstevel@tonic-gate */ 2487c478bd9Sstevel@tonic-gate val1 = (Xword)(sdp->sd_aux->sa_PLTndx - 1); 249f3324781Sab 250bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_32, &pltent[0x07], &val1, 251bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 252bf994817SAli Bahrami ofl->ofl_lml) == 0) { 2531007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 254f3324781Sab sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 255f3324781Sab return (S_ERROR); 2567c478bd9Sstevel@tonic-gate } 2577c478bd9Sstevel@tonic-gate 2587c478bd9Sstevel@tonic-gate /* 2597c478bd9Sstevel@tonic-gate * patchup: 2607c478bd9Sstevel@tonic-gate * jmpq .plt0(%rip) 261f3324781Sab * NOTE: 0x10 represents next instruction. The rather complex 262f3324781Sab * series of casts is necessary to sign extend an offset into 263f3324781Sab * a 64-bit value while satisfying various compiler error 264f3324781Sab * checks. Handle with care. 2657c478bd9Sstevel@tonic-gate */ 266b3fbe5e6Sseizo val1 = (Xword)((intptr_t)((uintptr_t)plt0 - 267b3fbe5e6Sseizo (uintptr_t)(&pltent[0x10]))); 268b3fbe5e6Sseizo 269bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_pc32, &pltent[0x0c], &val1, 270bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 271bf994817SAli Bahrami ofl->ofl_lml) == 0) { 2721007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 273f3324781Sab sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 274f3324781Sab return (S_ERROR); 2757c478bd9Sstevel@tonic-gate } 276f3324781Sab 2777c478bd9Sstevel@tonic-gate return (1); 2787c478bd9Sstevel@tonic-gate } 2797c478bd9Sstevel@tonic-gate 280ba2be530Sab static uintptr_t 2811007fd6fSAli Bahrami ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl, Boolean *remain_seen) 2827c478bd9Sstevel@tonic-gate { 2837c478bd9Sstevel@tonic-gate Os_desc * relosp, * osp = 0; 2847c478bd9Sstevel@tonic-gate Word ndx; 2857c478bd9Sstevel@tonic-gate Xword roffset, value; 2867c478bd9Sstevel@tonic-gate Sxword raddend; 2877c478bd9Sstevel@tonic-gate Rela rea; 2887c478bd9Sstevel@tonic-gate char *relbits; 2897c478bd9Sstevel@tonic-gate Sym_desc * sdp, * psym = (Sym_desc *)0; 2907c478bd9Sstevel@tonic-gate int sectmoved = 0; 2917c478bd9Sstevel@tonic-gate 2927c478bd9Sstevel@tonic-gate raddend = orsp->rel_raddend; 2937c478bd9Sstevel@tonic-gate sdp = orsp->rel_sym; 2947c478bd9Sstevel@tonic-gate 2957c478bd9Sstevel@tonic-gate /* 2967c478bd9Sstevel@tonic-gate * If the section this relocation is against has been discarded 2977c478bd9Sstevel@tonic-gate * (-zignore), then also discard (skip) the relocation itself. 2987c478bd9Sstevel@tonic-gate */ 2997c478bd9Sstevel@tonic-gate if (orsp->rel_isdesc && ((orsp->rel_flags & 3007c478bd9Sstevel@tonic-gate (FLG_REL_GOT | FLG_REL_BSS | FLG_REL_PLT | FLG_REL_NOINFO)) == 0) && 3017c478bd9Sstevel@tonic-gate (orsp->rel_isdesc->is_flags & FLG_IS_DISCARD)) { 3025aefb655Srie DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, orsp)); 3037c478bd9Sstevel@tonic-gate return (1); 3047c478bd9Sstevel@tonic-gate } 3057c478bd9Sstevel@tonic-gate 3067c478bd9Sstevel@tonic-gate /* 3077c478bd9Sstevel@tonic-gate * If this is a relocation against a move table, or expanded move 3087c478bd9Sstevel@tonic-gate * table, adjust the relocation entries. 3097c478bd9Sstevel@tonic-gate */ 310bf994817SAli Bahrami if (RELAUX_GET_MOVE(orsp)) 3115aefb655Srie ld_adj_movereloc(ofl, orsp); 3127c478bd9Sstevel@tonic-gate 3137c478bd9Sstevel@tonic-gate /* 3147c478bd9Sstevel@tonic-gate * If this is a relocation against a section then we need to adjust the 3157c478bd9Sstevel@tonic-gate * raddend field to compensate for the new position of the input section 3167c478bd9Sstevel@tonic-gate * within the new output section. 3177c478bd9Sstevel@tonic-gate */ 3187c478bd9Sstevel@tonic-gate if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 31957ef7aa9SRod Evans if (ofl->ofl_parsyms && 3207c478bd9Sstevel@tonic-gate (sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 3217c478bd9Sstevel@tonic-gate /* LINTED */ 3225aefb655Srie (psym = ld_am_I_partial(orsp, orsp->rel_raddend))) { 3235aefb655Srie DBG_CALL(Dbg_move_outsctadj(ofl->ofl_lml, psym)); 3247c478bd9Sstevel@tonic-gate sectmoved = 1; 3257c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_RELOBJ) 3267c478bd9Sstevel@tonic-gate raddend = psym->sd_sym->st_value; 3277c478bd9Sstevel@tonic-gate else 3287c478bd9Sstevel@tonic-gate raddend = psym->sd_sym->st_value - 3297c478bd9Sstevel@tonic-gate psym->sd_isc->is_osdesc->os_shdr->sh_addr; 3307c478bd9Sstevel@tonic-gate /* LINTED */ 3317c478bd9Sstevel@tonic-gate raddend += (Off)_elf_getxoff(psym->sd_isc->is_indata); 3327c478bd9Sstevel@tonic-gate if (psym->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 3337c478bd9Sstevel@tonic-gate raddend += 334de777a60Sab psym->sd_isc->is_osdesc->os_shdr->sh_addr; 3357c478bd9Sstevel@tonic-gate } else { 3367c478bd9Sstevel@tonic-gate /* LINTED */ 3377c478bd9Sstevel@tonic-gate raddend += (Off)_elf_getxoff(sdp->sd_isc->is_indata); 3387c478bd9Sstevel@tonic-gate if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 3397c478bd9Sstevel@tonic-gate raddend += 340de777a60Sab sdp->sd_isc->is_osdesc->os_shdr->sh_addr; 3417c478bd9Sstevel@tonic-gate } 3427c478bd9Sstevel@tonic-gate } 3437c478bd9Sstevel@tonic-gate 3447c478bd9Sstevel@tonic-gate value = sdp->sd_sym->st_value; 3457c478bd9Sstevel@tonic-gate 3467c478bd9Sstevel@tonic-gate if (orsp->rel_flags & FLG_REL_GOT) { 3477c478bd9Sstevel@tonic-gate /* 3487c478bd9Sstevel@tonic-gate * Note: for GOT relative relocations on amd64 3497c478bd9Sstevel@tonic-gate * we discard the addend. It was relevant 3507c478bd9Sstevel@tonic-gate * to the reference - not to the data item 3517c478bd9Sstevel@tonic-gate * being referenced (ie: that -4 thing). 3527c478bd9Sstevel@tonic-gate */ 3537c478bd9Sstevel@tonic-gate raddend = 0; 3547c478bd9Sstevel@tonic-gate osp = ofl->ofl_osgot; 3555aefb655Srie roffset = ld_calc_got_offset(orsp, ofl); 3565aefb655Srie 3577c478bd9Sstevel@tonic-gate } else if (orsp->rel_flags & FLG_REL_PLT) { 3587c478bd9Sstevel@tonic-gate /* 3597c478bd9Sstevel@tonic-gate * Note that relocations for PLT's actually 3607c478bd9Sstevel@tonic-gate * cause a relocation againt the GOT. 3617c478bd9Sstevel@tonic-gate */ 3627c478bd9Sstevel@tonic-gate osp = ofl->ofl_osplt; 3637c478bd9Sstevel@tonic-gate roffset = (ofl->ofl_osgot->os_shdr->sh_addr) + 3647c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 3657c478bd9Sstevel@tonic-gate raddend = 0; 3667c478bd9Sstevel@tonic-gate if (plt_entry(ofl, sdp) == S_ERROR) 3677c478bd9Sstevel@tonic-gate return (S_ERROR); 3687c478bd9Sstevel@tonic-gate 3697c478bd9Sstevel@tonic-gate } else if (orsp->rel_flags & FLG_REL_BSS) { 3707c478bd9Sstevel@tonic-gate /* 3717c478bd9Sstevel@tonic-gate * This must be a R_AMD64_COPY. For these set the roffset to 3727c478bd9Sstevel@tonic-gate * point to the new symbols location. 3737c478bd9Sstevel@tonic-gate */ 3747c478bd9Sstevel@tonic-gate osp = ofl->ofl_isbss->is_osdesc; 3757c478bd9Sstevel@tonic-gate roffset = value; 3767c478bd9Sstevel@tonic-gate 3777c478bd9Sstevel@tonic-gate /* 3787c478bd9Sstevel@tonic-gate * The raddend doesn't mean anything in a R_SPARC_COPY 3797c478bd9Sstevel@tonic-gate * relocation. Null it out because it can confuse people. 3807c478bd9Sstevel@tonic-gate */ 3817c478bd9Sstevel@tonic-gate raddend = 0; 3827c478bd9Sstevel@tonic-gate } else { 383bf994817SAli Bahrami osp = RELAUX_GET_OSDESC(orsp); 3847c478bd9Sstevel@tonic-gate 3857c478bd9Sstevel@tonic-gate /* 3867c478bd9Sstevel@tonic-gate * Calculate virtual offset of reference point; equals offset 3877c478bd9Sstevel@tonic-gate * into section + vaddr of section for loadable sections, or 3887c478bd9Sstevel@tonic-gate * offset plus section displacement for nonloadable sections. 3897c478bd9Sstevel@tonic-gate */ 3907c478bd9Sstevel@tonic-gate roffset = orsp->rel_roffset + 3917c478bd9Sstevel@tonic-gate (Off)_elf_getxoff(orsp->rel_isdesc->is_indata); 3927c478bd9Sstevel@tonic-gate if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) 3937c478bd9Sstevel@tonic-gate roffset += orsp->rel_isdesc->is_osdesc-> 3947c478bd9Sstevel@tonic-gate os_shdr->sh_addr; 3957c478bd9Sstevel@tonic-gate } 3967c478bd9Sstevel@tonic-gate 3977c478bd9Sstevel@tonic-gate if ((osp == 0) || ((relosp = osp->os_relosdesc) == 0)) 3987c478bd9Sstevel@tonic-gate relosp = ofl->ofl_osrel; 3997c478bd9Sstevel@tonic-gate 4007c478bd9Sstevel@tonic-gate /* 4017c478bd9Sstevel@tonic-gate * Assign the symbols index for the output relocation. If the 4027c478bd9Sstevel@tonic-gate * relocation refers to a SECTION symbol then it's index is based upon 4037c478bd9Sstevel@tonic-gate * the output sections symbols index. Otherwise the index can be 4047c478bd9Sstevel@tonic-gate * derived from the symbols index itself. 4057c478bd9Sstevel@tonic-gate */ 4067c478bd9Sstevel@tonic-gate if (orsp->rel_rtype == R_AMD64_RELATIVE) 4077c478bd9Sstevel@tonic-gate ndx = STN_UNDEF; 4087c478bd9Sstevel@tonic-gate else if ((orsp->rel_flags & FLG_REL_SCNNDX) || 4097c478bd9Sstevel@tonic-gate (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION)) { 4107c478bd9Sstevel@tonic-gate if (sectmoved == 0) { 4117c478bd9Sstevel@tonic-gate /* 4127c478bd9Sstevel@tonic-gate * Check for a null input section. This can 4137c478bd9Sstevel@tonic-gate * occur if this relocation references a symbol 4147c478bd9Sstevel@tonic-gate * generated by sym_add_sym(). 4157c478bd9Sstevel@tonic-gate */ 41657ef7aa9SRod Evans if (sdp->sd_isc && sdp->sd_isc->is_osdesc) 41757ef7aa9SRod Evans ndx = sdp->sd_isc->is_osdesc->os_identndx; 4187c478bd9Sstevel@tonic-gate else 4197c478bd9Sstevel@tonic-gate ndx = sdp->sd_shndx; 4207c478bd9Sstevel@tonic-gate } else 42135450702SAli Bahrami ndx = ofl->ofl_parexpnndx; 4227c478bd9Sstevel@tonic-gate } else 4237c478bd9Sstevel@tonic-gate ndx = sdp->sd_symndx; 4247c478bd9Sstevel@tonic-gate 4257c478bd9Sstevel@tonic-gate /* 4267c478bd9Sstevel@tonic-gate * Add the symbols 'value' to the addend field. 4277c478bd9Sstevel@tonic-gate */ 4287c478bd9Sstevel@tonic-gate if (orsp->rel_flags & FLG_REL_ADVAL) 4297c478bd9Sstevel@tonic-gate raddend += value; 4307c478bd9Sstevel@tonic-gate 4317c478bd9Sstevel@tonic-gate /* 4327010c12aSrie * The addend field for R_AMD64_DTPMOD64 means nothing. The addend 4337010c12aSrie * is propagated in the corresponding R_AMD64_DTPOFF64 relocation. 4347c478bd9Sstevel@tonic-gate */ 4357c478bd9Sstevel@tonic-gate if (orsp->rel_rtype == R_AMD64_DTPMOD64) 4367c478bd9Sstevel@tonic-gate raddend = 0; 4377c478bd9Sstevel@tonic-gate 4387c478bd9Sstevel@tonic-gate relbits = (char *)relosp->os_outdata->d_buf; 4397c478bd9Sstevel@tonic-gate 4407c478bd9Sstevel@tonic-gate rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); 4417c478bd9Sstevel@tonic-gate rea.r_offset = roffset; 4427c478bd9Sstevel@tonic-gate rea.r_addend = raddend; 4435aefb655Srie DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_RELA, &rea, relosp->os_name, 444bf994817SAli Bahrami ld_reloc_sym_name(orsp))); 4457c478bd9Sstevel@tonic-gate 4467c478bd9Sstevel@tonic-gate /* 4477c478bd9Sstevel@tonic-gate * Assert we haven't walked off the end of our relocation table. 4487c478bd9Sstevel@tonic-gate */ 4497c478bd9Sstevel@tonic-gate assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); 4507c478bd9Sstevel@tonic-gate 4517c478bd9Sstevel@tonic-gate (void) memcpy((relbits + relosp->os_szoutrels), 4527c478bd9Sstevel@tonic-gate (char *)&rea, sizeof (Rela)); 4537c478bd9Sstevel@tonic-gate relosp->os_szoutrels += (Xword)sizeof (Rela); 4547c478bd9Sstevel@tonic-gate 4557c478bd9Sstevel@tonic-gate /* 4567c478bd9Sstevel@tonic-gate * Determine if this relocation is against a non-writable, allocatable 4577c478bd9Sstevel@tonic-gate * section. If so we may need to provide a text relocation diagnostic. 4587c478bd9Sstevel@tonic-gate * Note that relocations against the .plt (R_AMD64_JUMP_SLOT) actually 4597c478bd9Sstevel@tonic-gate * result in modifications to the .got. 4607c478bd9Sstevel@tonic-gate */ 4617c478bd9Sstevel@tonic-gate if (orsp->rel_rtype == R_AMD64_JUMP_SLOT) 4627c478bd9Sstevel@tonic-gate osp = ofl->ofl_osgot; 4637c478bd9Sstevel@tonic-gate 4641007fd6fSAli Bahrami ld_reloc_remain_entry(orsp, osp, ofl, remain_seen); 4657c478bd9Sstevel@tonic-gate return (1); 4667c478bd9Sstevel@tonic-gate } 4677c478bd9Sstevel@tonic-gate 4687c478bd9Sstevel@tonic-gate /* 4697c478bd9Sstevel@tonic-gate * amd64 Instructions for TLS processing 4707c478bd9Sstevel@tonic-gate */ 471b3fbe5e6Sseizo static uchar_t tlsinstr_gd_ie[] = { 4727c478bd9Sstevel@tonic-gate /* 4737c478bd9Sstevel@tonic-gate * 0x00 movq %fs:0, %rax 4747c478bd9Sstevel@tonic-gate */ 4757c478bd9Sstevel@tonic-gate 0x64, 0x48, 0x8b, 0x04, 0x25, 4767c478bd9Sstevel@tonic-gate 0x00, 0x00, 0x00, 0x00, 4777c478bd9Sstevel@tonic-gate /* 4787c478bd9Sstevel@tonic-gate * 0x09 addq x@gottpoff(%rip), %rax 4797c478bd9Sstevel@tonic-gate */ 4807c478bd9Sstevel@tonic-gate 0x48, 0x03, 0x05, 0x00, 0x00, 4817c478bd9Sstevel@tonic-gate 0x00, 0x00 4827c478bd9Sstevel@tonic-gate }; 4837c478bd9Sstevel@tonic-gate 484b3fbe5e6Sseizo static uchar_t tlsinstr_gd_le[] = { 4857c478bd9Sstevel@tonic-gate /* 4867c478bd9Sstevel@tonic-gate * 0x00 movq %fs:0, %rax 4877c478bd9Sstevel@tonic-gate */ 4887c478bd9Sstevel@tonic-gate 0x64, 0x48, 0x8b, 0x04, 0x25, 4897c478bd9Sstevel@tonic-gate 0x00, 0x00, 0x00, 0x00, 4907c478bd9Sstevel@tonic-gate /* 4917c478bd9Sstevel@tonic-gate * 0x09 leaq x@gottpoff(%rip), %rax 4927c478bd9Sstevel@tonic-gate */ 4937c478bd9Sstevel@tonic-gate 0x48, 0x8d, 0x80, 0x00, 0x00, 4947c478bd9Sstevel@tonic-gate 0x00, 0x00 4957c478bd9Sstevel@tonic-gate }; 4967c478bd9Sstevel@tonic-gate 497b3fbe5e6Sseizo static uchar_t tlsinstr_ld_le[] = { 4987c478bd9Sstevel@tonic-gate /* 4997c478bd9Sstevel@tonic-gate * .byte 0x66 5007c478bd9Sstevel@tonic-gate */ 5017c478bd9Sstevel@tonic-gate 0x66, 5027c478bd9Sstevel@tonic-gate /* 5037c478bd9Sstevel@tonic-gate * .byte 0x66 5047c478bd9Sstevel@tonic-gate */ 5057c478bd9Sstevel@tonic-gate 0x66, 5067c478bd9Sstevel@tonic-gate /* 5077c478bd9Sstevel@tonic-gate * .byte 0x66 5087c478bd9Sstevel@tonic-gate */ 5097c478bd9Sstevel@tonic-gate 0x66, 5107c478bd9Sstevel@tonic-gate /* 5117c478bd9Sstevel@tonic-gate * movq %fs:0, %rax 5127c478bd9Sstevel@tonic-gate */ 5137c478bd9Sstevel@tonic-gate 0x64, 0x48, 0x8b, 0x04, 0x25, 5147c478bd9Sstevel@tonic-gate 0x00, 0x00, 0x00, 0x00 5157c478bd9Sstevel@tonic-gate }; 5167c478bd9Sstevel@tonic-gate 517*49f9b365SRichard Lowe #define REX_B 0x1 518*49f9b365SRichard Lowe #define REX_X 0x2 519*49f9b365SRichard Lowe #define REX_R 0x4 520*49f9b365SRichard Lowe #define REX_W 0x8 521*49f9b365SRichard Lowe #define REX_PREFIX 0x40 522*49f9b365SRichard Lowe 523*49f9b365SRichard Lowe #define REX_RW (REX_PREFIX | REX_R | REX_W) 524*49f9b365SRichard Lowe #define REX_BW (REX_PREFIX | REX_B | REX_W) 525*49f9b365SRichard Lowe #define REX_BRW (REX_PREFIX | REX_B | REX_R | REX_W) 526*49f9b365SRichard Lowe 527*49f9b365SRichard Lowe #define REG_ESP 0x4 528*49f9b365SRichard Lowe 529*49f9b365SRichard Lowe #define INSN_ADDMR 0x03 /* addq mem,reg */ 530*49f9b365SRichard Lowe #define INSN_ADDIR 0x81 /* addq imm,reg */ 531*49f9b365SRichard Lowe #define INSN_MOVMR 0x8b /* movq mem,reg */ 532*49f9b365SRichard Lowe #define INSN_MOVIR 0xc7 /* movq imm,reg */ 533*49f9b365SRichard Lowe #define INSN_LEA 0x8d /* leaq mem,reg */ 5347c478bd9Sstevel@tonic-gate 5355aefb655Srie static Fixupret 5365aefb655Srie tls_fixups(Ofl_desc *ofl, Rel_desc *arsp) 5377c478bd9Sstevel@tonic-gate { 5387c478bd9Sstevel@tonic-gate Sym_desc *sdp = arsp->rel_sym; 5397c478bd9Sstevel@tonic-gate Word rtype = arsp->rel_rtype; 540b3fbe5e6Sseizo uchar_t *offset; 5417c478bd9Sstevel@tonic-gate 542b3fbe5e6Sseizo offset = (uchar_t *)((uintptr_t)arsp->rel_roffset + 543b3fbe5e6Sseizo (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata) + 544bf994817SAli Bahrami (uintptr_t)RELAUX_GET_OSDESC(arsp)->os_outdata->d_buf); 5457c478bd9Sstevel@tonic-gate 546*49f9b365SRichard Lowe /* 547*49f9b365SRichard Lowe * Note that in certain of the original insn sequences below, the 548*49f9b365SRichard Lowe * instructions are not necessarily adjacent 549*49f9b365SRichard Lowe */ 5507c478bd9Sstevel@tonic-gate if (sdp->sd_ref == REF_DYN_NEED) { 5517c478bd9Sstevel@tonic-gate /* 5527c478bd9Sstevel@tonic-gate * IE reference model 5537c478bd9Sstevel@tonic-gate */ 5547c478bd9Sstevel@tonic-gate switch (rtype) { 5557c478bd9Sstevel@tonic-gate case R_AMD64_TLSGD: 5567c478bd9Sstevel@tonic-gate /* 5577c478bd9Sstevel@tonic-gate * GD -> IE 5587c478bd9Sstevel@tonic-gate * 5597c478bd9Sstevel@tonic-gate * Transition: 5607c478bd9Sstevel@tonic-gate * 0x00 .byte 0x66 5617c478bd9Sstevel@tonic-gate * 0x01 leaq x@tlsgd(%rip), %rdi 5627c478bd9Sstevel@tonic-gate * 0x08 .word 0x6666 5637c478bd9Sstevel@tonic-gate * 0x0a rex64 5647c478bd9Sstevel@tonic-gate * 0x0b call __tls_get_addr@plt 5657c478bd9Sstevel@tonic-gate * 0x10 5667c478bd9Sstevel@tonic-gate * To: 5677c478bd9Sstevel@tonic-gate * 0x00 movq %fs:0, %rax 5687c478bd9Sstevel@tonic-gate * 0x09 addq x@gottpoff(%rip), %rax 5697c478bd9Sstevel@tonic-gate * 0x10 5707c478bd9Sstevel@tonic-gate */ 5715aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 572bf994817SAli Bahrami R_AMD64_GOTTPOFF, arsp, ld_reloc_sym_name)); 5737c478bd9Sstevel@tonic-gate arsp->rel_rtype = R_AMD64_GOTTPOFF; 5747c478bd9Sstevel@tonic-gate arsp->rel_roffset += 8; 5757c478bd9Sstevel@tonic-gate arsp->rel_raddend = (Sxword)-4; 5765aefb655Srie 5777c478bd9Sstevel@tonic-gate /* 578051d39bbSrie * Adjust 'offset' to beginning of instruction 5797c478bd9Sstevel@tonic-gate * sequence. 5807c478bd9Sstevel@tonic-gate */ 5817c478bd9Sstevel@tonic-gate offset -= 4; 5827c478bd9Sstevel@tonic-gate (void) memcpy(offset, tlsinstr_gd_ie, 5835aefb655Srie sizeof (tlsinstr_gd_ie)); 5847c478bd9Sstevel@tonic-gate return (FIX_RELOC); 5855aefb655Srie 5867c478bd9Sstevel@tonic-gate case R_AMD64_PLT32: 5877c478bd9Sstevel@tonic-gate /* 588051d39bbSrie * Fixup done via the TLS_GD relocation. 5897c478bd9Sstevel@tonic-gate */ 5905aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 591bf994817SAli Bahrami R_AMD64_NONE, arsp, ld_reloc_sym_name)); 5927c478bd9Sstevel@tonic-gate return (FIX_DONE); 5937c478bd9Sstevel@tonic-gate } 5947c478bd9Sstevel@tonic-gate } 5957c478bd9Sstevel@tonic-gate 5967c478bd9Sstevel@tonic-gate /* 5977c478bd9Sstevel@tonic-gate * LE reference model 5987c478bd9Sstevel@tonic-gate */ 5997c478bd9Sstevel@tonic-gate switch (rtype) { 6007c478bd9Sstevel@tonic-gate case R_AMD64_TLSGD: 6017c478bd9Sstevel@tonic-gate /* 6027c478bd9Sstevel@tonic-gate * GD -> LE 6037c478bd9Sstevel@tonic-gate * 6047c478bd9Sstevel@tonic-gate * Transition: 6057c478bd9Sstevel@tonic-gate * 0x00 .byte 0x66 6067c478bd9Sstevel@tonic-gate * 0x01 leaq x@tlsgd(%rip), %rdi 6077c478bd9Sstevel@tonic-gate * 0x08 .word 0x6666 6087c478bd9Sstevel@tonic-gate * 0x0a rex64 6097c478bd9Sstevel@tonic-gate * 0x0b call __tls_get_addr@plt 6107c478bd9Sstevel@tonic-gate * 0x10 6117c478bd9Sstevel@tonic-gate * To: 6127c478bd9Sstevel@tonic-gate * 0x00 movq %fs:0, %rax 6137c478bd9Sstevel@tonic-gate * 0x09 leaq x@tpoff(%rax), %rax 6147c478bd9Sstevel@tonic-gate * 0x10 6157c478bd9Sstevel@tonic-gate */ 6165aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 617bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 6187c478bd9Sstevel@tonic-gate arsp->rel_rtype = R_AMD64_TPOFF32; 6197c478bd9Sstevel@tonic-gate arsp->rel_roffset += 8; 6207c478bd9Sstevel@tonic-gate arsp->rel_raddend = 0; 6215aefb655Srie 6227c478bd9Sstevel@tonic-gate /* 623051d39bbSrie * Adjust 'offset' to beginning of instruction sequence. 6247c478bd9Sstevel@tonic-gate */ 6257c478bd9Sstevel@tonic-gate offset -= 4; 6265aefb655Srie (void) memcpy(offset, tlsinstr_gd_le, sizeof (tlsinstr_gd_le)); 6277c478bd9Sstevel@tonic-gate return (FIX_RELOC); 6285aefb655Srie 629*49f9b365SRichard Lowe case R_AMD64_GOTTPOFF: { 6307c478bd9Sstevel@tonic-gate /* 6317c478bd9Sstevel@tonic-gate * IE -> LE 6327c478bd9Sstevel@tonic-gate * 633*49f9b365SRichard Lowe * Transition 1: 634*49f9b365SRichard Lowe * movq %fs:0, %reg 635*49f9b365SRichard Lowe * addq x@gottpoff(%rip), %reg 6367c478bd9Sstevel@tonic-gate * To: 637*49f9b365SRichard Lowe * movq %fs:0, %reg 638*49f9b365SRichard Lowe * leaq x@tpoff(%reg), %reg 639*49f9b365SRichard Lowe * 640*49f9b365SRichard Lowe * Transition (as a special case): 641*49f9b365SRichard Lowe * movq %fs:0, %r12/%rsp 642*49f9b365SRichard Lowe * addq x@gottpoff(%rip), %r12/%rsp 643*49f9b365SRichard Lowe * To: 644*49f9b365SRichard Lowe * movq %fs:0, %r12/%rsp 645*49f9b365SRichard Lowe * addq x@tpoff(%rax), %r12/%rsp 646*49f9b365SRichard Lowe * 647*49f9b365SRichard Lowe * Transition 2: 648*49f9b365SRichard Lowe * movq x@gottpoff(%rip), %reg 649*49f9b365SRichard Lowe * movq %fs:(%reg), %reg 650*49f9b365SRichard Lowe * To: 651*49f9b365SRichard Lowe * movq x@tpoff(%reg), %reg 652*49f9b365SRichard Lowe * movq %fs:(%reg), %reg 6537c478bd9Sstevel@tonic-gate */ 654*49f9b365SRichard Lowe Conv_inv_buf_t inv_buf; 655*49f9b365SRichard Lowe uint8_t reg; /* Register */ 656*49f9b365SRichard Lowe 657*49f9b365SRichard Lowe offset -= 3; 658*49f9b365SRichard Lowe 659*49f9b365SRichard Lowe reg = offset[2] >> 3; /* Encoded dest. reg. operand */ 660*49f9b365SRichard Lowe 661051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 662bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 6637c478bd9Sstevel@tonic-gate arsp->rel_rtype = R_AMD64_TPOFF32; 6647c478bd9Sstevel@tonic-gate arsp->rel_raddend = 0; 6655aefb655Srie 6667c478bd9Sstevel@tonic-gate /* 667*49f9b365SRichard Lowe * This is transition 2, and the special case of form 1 where 668*49f9b365SRichard Lowe * a normal transition would index %rsp or %r12 and need a SIB 669*49f9b365SRichard Lowe * byte in the leaq for which we lack space 6707c478bd9Sstevel@tonic-gate */ 671*49f9b365SRichard Lowe if ((offset[1] == INSN_MOVMR) || 672*49f9b365SRichard Lowe ((offset[1] == INSN_ADDMR) && (reg == REG_ESP))) { 673*49f9b365SRichard Lowe /* 674*49f9b365SRichard Lowe * If we needed an extra bit of MOD.reg to refer to 675*49f9b365SRichard Lowe * this register as the dest of the original movq we 676*49f9b365SRichard Lowe * need an extra bit of MOD.rm to refer to it in the 677*49f9b365SRichard Lowe * dest of the replacement movq or addq. 678*49f9b365SRichard Lowe */ 679*49f9b365SRichard Lowe if (offset[0] == REX_RW) 680*49f9b365SRichard Lowe offset[0] = REX_BW; 6815aefb655Srie 682*49f9b365SRichard Lowe offset[1] = (offset[1] == INSN_MOVMR) ? 683*49f9b365SRichard Lowe INSN_MOVIR : INSN_ADDIR; 684*49f9b365SRichard Lowe offset[2] = 0xc0 | reg; 6855aefb655Srie 686*49f9b365SRichard Lowe return (FIX_RELOC); 687*49f9b365SRichard Lowe } else if (offset[1] == INSN_ADDMR) { 688*49f9b365SRichard Lowe /* 689*49f9b365SRichard Lowe * If we needed an extra bit of MOD.reg to refer to 690*49f9b365SRichard Lowe * this register in the dest of the addq we need an 691*49f9b365SRichard Lowe * extra bit of both MOD.reg and MOD.rm to refer to it 692*49f9b365SRichard Lowe * in the source and dest of the leaq 693*49f9b365SRichard Lowe */ 694*49f9b365SRichard Lowe if (offset[0] == REX_RW) 695*49f9b365SRichard Lowe offset[0] = REX_BRW; 696*49f9b365SRichard Lowe 697*49f9b365SRichard Lowe offset[1] = INSN_LEA; 698*49f9b365SRichard Lowe offset[2] = 0x80 | (reg << 3) | reg; 699*49f9b365SRichard Lowe 700*49f9b365SRichard Lowe return (FIX_RELOC); 701*49f9b365SRichard Lowe } 702*49f9b365SRichard Lowe 703*49f9b365SRichard Lowe ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_BADTLSINS), 704*49f9b365SRichard Lowe conv_reloc_amd64_type(arsp->rel_rtype, 0, &inv_buf), 705*49f9b365SRichard Lowe arsp->rel_isdesc->is_file->ifl_name, 706*49f9b365SRichard Lowe ld_reloc_sym_name(arsp), 707*49f9b365SRichard Lowe arsp->rel_isdesc->is_name, 708*49f9b365SRichard Lowe EC_OFF(arsp->rel_roffset)); 709*49f9b365SRichard Lowe return (FIX_ERROR); 710*49f9b365SRichard Lowe } 7117c478bd9Sstevel@tonic-gate case R_AMD64_TLSLD: 7127c478bd9Sstevel@tonic-gate /* 7137c478bd9Sstevel@tonic-gate * LD -> LE 7147c478bd9Sstevel@tonic-gate * 7157c478bd9Sstevel@tonic-gate * Transition 7167c478bd9Sstevel@tonic-gate * 0x00 leaq x1@tlsgd(%rip), %rdi 7177c478bd9Sstevel@tonic-gate * 0x07 call __tls_get_addr@plt 7187c478bd9Sstevel@tonic-gate * 0x0c 7197c478bd9Sstevel@tonic-gate * To: 7207c478bd9Sstevel@tonic-gate * 0x00 .byte 0x66 7217c478bd9Sstevel@tonic-gate * 0x01 .byte 0x66 7227c478bd9Sstevel@tonic-gate * 0x02 .byte 0x66 7237c478bd9Sstevel@tonic-gate * 0x03 movq %fs:0, %rax 7247c478bd9Sstevel@tonic-gate */ 725051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 726bf994817SAli Bahrami R_AMD64_NONE, arsp, ld_reloc_sym_name)); 7277c478bd9Sstevel@tonic-gate offset -= 3; 7285aefb655Srie (void) memcpy(offset, tlsinstr_ld_le, sizeof (tlsinstr_ld_le)); 7297c478bd9Sstevel@tonic-gate return (FIX_DONE); 7305aefb655Srie 7317c478bd9Sstevel@tonic-gate case R_AMD64_DTPOFF32: 7327c478bd9Sstevel@tonic-gate /* 7337c478bd9Sstevel@tonic-gate * LD->LE 7347c478bd9Sstevel@tonic-gate * 7357c478bd9Sstevel@tonic-gate * Transition: 7367c478bd9Sstevel@tonic-gate * 0x00 leaq x1@dtpoff(%rax), %rcx 7377c478bd9Sstevel@tonic-gate * To: 7387c478bd9Sstevel@tonic-gate * 0x00 leaq x1@tpoff(%rax), %rcx 7397c478bd9Sstevel@tonic-gate */ 740051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 741bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 7427c478bd9Sstevel@tonic-gate arsp->rel_rtype = R_AMD64_TPOFF32; 7437c478bd9Sstevel@tonic-gate arsp->rel_raddend = 0; 7447c478bd9Sstevel@tonic-gate return (FIX_RELOC); 7457c478bd9Sstevel@tonic-gate } 7467c478bd9Sstevel@tonic-gate 7477c478bd9Sstevel@tonic-gate return (FIX_RELOC); 7487c478bd9Sstevel@tonic-gate } 7497c478bd9Sstevel@tonic-gate 750ba2be530Sab static uintptr_t 7515aefb655Srie ld_do_activerelocs(Ofl_desc *ofl) 7527c478bd9Sstevel@tonic-gate { 753141040e8Srie Rel_desc *arsp; 754bf994817SAli Bahrami Rel_cachebuf *rcbp; 75557ef7aa9SRod Evans Aliste idx; 7567c478bd9Sstevel@tonic-gate uintptr_t return_code = 1; 7571d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 7587c478bd9Sstevel@tonic-gate 759bf994817SAli Bahrami if (aplist_nitems(ofl->ofl_actrels.rc_list) != 0) 7607010c12aSrie DBG_CALL(Dbg_reloc_doact_title(ofl->ofl_lml)); 7617010c12aSrie 7627c478bd9Sstevel@tonic-gate /* 763141040e8Srie * Process active relocations. 7647c478bd9Sstevel@tonic-gate */ 765bf994817SAli Bahrami REL_CACHE_TRAVERSE(&ofl->ofl_actrels, idx, rcbp, arsp) { 766bf994817SAli Bahrami uchar_t *addr; 767bf994817SAli Bahrami Xword value; 768bf994817SAli Bahrami Sym_desc *sdp; 769bf994817SAli Bahrami const char *ifl_name; 770bf994817SAli Bahrami Xword refaddr; 771bf994817SAli Bahrami int moved = 0; 772bf994817SAli Bahrami Gotref gref; 773bf994817SAli Bahrami Os_desc *osp; 7747c478bd9Sstevel@tonic-gate 775bf994817SAli Bahrami /* 776bf994817SAli Bahrami * If the section this relocation is against has been discarded 777bf994817SAli Bahrami * (-zignore), then discard (skip) the relocation itself. 778bf994817SAli Bahrami */ 779bf994817SAli Bahrami if ((arsp->rel_isdesc->is_flags & FLG_IS_DISCARD) && 780bf994817SAli Bahrami ((arsp->rel_flags & (FLG_REL_GOT | FLG_REL_BSS | 781bf994817SAli Bahrami FLG_REL_PLT | FLG_REL_NOINFO)) == 0)) { 782bf994817SAli Bahrami DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, arsp)); 783bf994817SAli Bahrami continue; 784bf994817SAli Bahrami } 7857c478bd9Sstevel@tonic-gate 786bf994817SAli Bahrami /* 787bf994817SAli Bahrami * We determine what the 'got reference' model (if required) 788bf994817SAli Bahrami * is at this point. This needs to be done before tls_fixup() 789bf994817SAli Bahrami * since it may 'transition' our instructions. 790bf994817SAli Bahrami * 791bf994817SAli Bahrami * The got table entries have already been assigned, 792bf994817SAli Bahrami * and we bind to those initial entries. 793bf994817SAli Bahrami */ 794bf994817SAli Bahrami if (arsp->rel_flags & FLG_REL_DTLS) 795bf994817SAli Bahrami gref = GOT_REF_TLSGD; 796bf994817SAli Bahrami else if (arsp->rel_flags & FLG_REL_MTLS) 797bf994817SAli Bahrami gref = GOT_REF_TLSLD; 798bf994817SAli Bahrami else if (arsp->rel_flags & FLG_REL_STLS) 799bf994817SAli Bahrami gref = GOT_REF_TLSIE; 800bf994817SAli Bahrami else 801bf994817SAli Bahrami gref = GOT_REF_GENERIC; 8027c478bd9Sstevel@tonic-gate 803bf994817SAli Bahrami /* 804bf994817SAli Bahrami * Perform any required TLS fixups. 805bf994817SAli Bahrami */ 806bf994817SAli Bahrami if (arsp->rel_flags & FLG_REL_TLSFIX) { 807bf994817SAli Bahrami Fixupret ret; 808141040e8Srie 809bf994817SAli Bahrami if ((ret = tls_fixups(ofl, arsp)) == FIX_ERROR) 810bf994817SAli Bahrami return (S_ERROR); 811bf994817SAli Bahrami if (ret == FIX_DONE) 812bf994817SAli Bahrami continue; 813bf994817SAli Bahrami } 8147c478bd9Sstevel@tonic-gate 815bf994817SAli Bahrami /* 816bf994817SAli Bahrami * If this is a relocation against a move table, or 817bf994817SAli Bahrami * expanded move table, adjust the relocation entries. 818bf994817SAli Bahrami */ 819bf994817SAli Bahrami if (RELAUX_GET_MOVE(arsp)) 820bf994817SAli Bahrami ld_adj_movereloc(ofl, arsp); 8217c478bd9Sstevel@tonic-gate 822bf994817SAli Bahrami sdp = arsp->rel_sym; 823bf994817SAli Bahrami refaddr = arsp->rel_roffset + 824bf994817SAli Bahrami (Off)_elf_getxoff(arsp->rel_isdesc->is_indata); 8257c478bd9Sstevel@tonic-gate 826bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_CLVAL) || 827bf994817SAli Bahrami (arsp->rel_flags & FLG_REL_GOTCL)) 828bf994817SAli Bahrami value = 0; 829bf994817SAli Bahrami else if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 830bf994817SAli Bahrami Sym_desc *sym; 8317c478bd9Sstevel@tonic-gate 832bf994817SAli Bahrami /* 833bf994817SAli Bahrami * The value for a symbol pointing to a SECTION 834bf994817SAli Bahrami * is based off of that sections position. 835bf994817SAli Bahrami */ 836bf994817SAli Bahrami if ((sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 837bf994817SAli Bahrami /* LINTED */ 838bf994817SAli Bahrami (sym = ld_am_I_partial(arsp, arsp->rel_raddend))) { 8397c478bd9Sstevel@tonic-gate /* 840bf994817SAli Bahrami * The symbol was moved, so adjust the value 841bf994817SAli Bahrami * relative to the new section. 8422926dd2eSrie */ 843bf994817SAli Bahrami value = sym->sd_sym->st_value; 844bf994817SAli Bahrami moved = 1; 84508278a5eSRod Evans 8467c478bd9Sstevel@tonic-gate /* 847bf994817SAli Bahrami * The original raddend covers the displacement 848bf994817SAli Bahrami * from the section start to the desired 849bf994817SAli Bahrami * address. The value computed above gets us 850bf994817SAli Bahrami * from the section start to the start of the 851bf994817SAli Bahrami * symbol range. Adjust the old raddend to 852bf994817SAli Bahrami * remove the offset from section start to 853bf994817SAli Bahrami * symbol start, leaving the displacement 854bf994817SAli Bahrami * within the range of the symbol. 8557c478bd9Sstevel@tonic-gate */ 856bf994817SAli Bahrami arsp->rel_raddend -= sym->sd_osym->st_value; 857bf994817SAli Bahrami } else { 858bf994817SAli Bahrami value = _elf_getxoff(sdp->sd_isc->is_indata); 859bf994817SAli Bahrami if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 860bf994817SAli Bahrami value += sdp->sd_isc->is_osdesc-> 861bf994817SAli Bahrami os_shdr->sh_addr; 862bf994817SAli Bahrami } 863bf994817SAli Bahrami if (sdp->sd_isc->is_shdr->sh_flags & SHF_TLS) 864bf994817SAli Bahrami value -= ofl->ofl_tlsphdr->p_vaddr; 8657c478bd9Sstevel@tonic-gate 866bf994817SAli Bahrami } else if (IS_SIZE(arsp->rel_rtype)) { 8677c478bd9Sstevel@tonic-gate /* 868bf994817SAli Bahrami * Size relocations require the symbols size. 8697c478bd9Sstevel@tonic-gate */ 870bf994817SAli Bahrami value = sdp->sd_sym->st_size; 8717c478bd9Sstevel@tonic-gate 872bf994817SAli Bahrami } else if ((sdp->sd_flags & FLG_SY_CAP) && 873bf994817SAli Bahrami sdp->sd_aux && sdp->sd_aux->sa_PLTndx) { 8747c478bd9Sstevel@tonic-gate /* 875bf994817SAli Bahrami * If relocation is against a capabilities symbol, we 876bf994817SAli Bahrami * need to jump to an associated PLT, so that at runtime 877bf994817SAli Bahrami * ld.so.1 is involved to determine the best binding 878bf994817SAli Bahrami * choice. Otherwise, the value is the symbols value. 8797c478bd9Sstevel@tonic-gate */ 880bf994817SAli Bahrami value = ld_calc_plt_addr(sdp, ofl); 881bf994817SAli Bahrami } else 882bf994817SAli Bahrami value = sdp->sd_sym->st_value; 8837c478bd9Sstevel@tonic-gate 884bf994817SAli Bahrami /* 885bf994817SAli Bahrami * Relocation against the GLOBAL_OFFSET_TABLE. 886bf994817SAli Bahrami */ 887bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_GOT) && 888bf994817SAli Bahrami !ld_reloc_set_aux_osdesc(ofl, arsp, ofl->ofl_osgot)) 889bf994817SAli Bahrami return (S_ERROR); 890bf994817SAli Bahrami osp = RELAUX_GET_OSDESC(arsp); 8917c478bd9Sstevel@tonic-gate 892bf994817SAli Bahrami /* 893bf994817SAli Bahrami * If loadable and not producing a relocatable object add the 894bf994817SAli Bahrami * sections virtual address to the reference address. 895bf994817SAli Bahrami */ 896bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_LOAD) && 897bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) 898bf994817SAli Bahrami refaddr += arsp->rel_isdesc->is_osdesc-> 899bf994817SAli Bahrami os_shdr->sh_addr; 9007c478bd9Sstevel@tonic-gate 901bf994817SAli Bahrami /* 902bf994817SAli Bahrami * If this entry has a PLT assigned to it, its value is actually 903bf994817SAli Bahrami * the address of the PLT (and not the address of the function). 904bf994817SAli Bahrami */ 905bf994817SAli Bahrami if (IS_PLT(arsp->rel_rtype)) { 906bf994817SAli Bahrami if (sdp->sd_aux && sdp->sd_aux->sa_PLTndx) 907bf994817SAli Bahrami value = ld_calc_plt_addr(sdp, ofl); 908bf994817SAli Bahrami } 9097c478bd9Sstevel@tonic-gate 910bf994817SAli Bahrami /* 911bf994817SAli Bahrami * Add relocations addend to value. Add extra 912bf994817SAli Bahrami * relocation addend if needed. 913bf994817SAli Bahrami * 914bf994817SAli Bahrami * Note: For GOT relative relocations on amd64 we discard the 915bf994817SAli Bahrami * addend. It was relevant to the reference - not to the 916bf994817SAli Bahrami * data item being referenced (ie: that -4 thing). 917bf994817SAli Bahrami */ 918bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_GOT) == 0) 919bf994817SAli Bahrami value += arsp->rel_raddend; 9207c478bd9Sstevel@tonic-gate 921bf994817SAli Bahrami /* 922bf994817SAli Bahrami * Determine whether the value needs further adjustment. Filter 923bf994817SAli Bahrami * through the attributes of the relocation to determine what 924bf994817SAli Bahrami * adjustment is required. Note, many of the following cases 925bf994817SAli Bahrami * are only applicable when a .got is present. As a .got is 926bf994817SAli Bahrami * not generated when a relocatable object is being built, 927bf994817SAli Bahrami * any adjustments that require a .got need to be skipped. 928bf994817SAli Bahrami */ 929bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_GOT) && 930bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 931bf994817SAli Bahrami Xword R1addr; 932bf994817SAli Bahrami uintptr_t R2addr; 933bf994817SAli Bahrami Word gotndx; 934bf994817SAli Bahrami Gotndx *gnp; 9357c478bd9Sstevel@tonic-gate 936bf994817SAli Bahrami /* 937bf994817SAli Bahrami * Perform relocation against GOT table. Since this 938bf994817SAli Bahrami * doesn't fit exactly into a relocation we place the 939bf994817SAli Bahrami * appropriate byte in the GOT directly 940bf994817SAli Bahrami * 941bf994817SAli Bahrami * Calculate offset into GOT at which to apply 942bf994817SAli Bahrami * the relocation. 943bf994817SAli Bahrami */ 944bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 945bf994817SAli Bahrami assert(gnp); 9467c478bd9Sstevel@tonic-gate 947bf994817SAli Bahrami if (arsp->rel_rtype == R_AMD64_DTPOFF64) 948bf994817SAli Bahrami gotndx = gnp->gn_gotndx + 1; 949bf994817SAli Bahrami else 950bf994817SAli Bahrami gotndx = gnp->gn_gotndx; 9517c478bd9Sstevel@tonic-gate 952bf994817SAli Bahrami R1addr = (Xword)(gotndx * M_GOT_ENTSIZE); 9537c478bd9Sstevel@tonic-gate 954bf994817SAli Bahrami /* 955bf994817SAli Bahrami * Add the GOTs data's offset. 956bf994817SAli Bahrami */ 957bf994817SAli Bahrami R2addr = R1addr + (uintptr_t)osp->os_outdata->d_buf; 958141040e8Srie 959bf994817SAli Bahrami DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 960bf994817SAli Bahrami M_MACH, SHT_RELA, arsp, R1addr, value, 961bf994817SAli Bahrami ld_reloc_sym_name)); 962141040e8Srie 963bf994817SAli Bahrami /* 964bf994817SAli Bahrami * And do it. 965bf994817SAli Bahrami */ 966bf994817SAli Bahrami if (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) 967bf994817SAli Bahrami *(Xword *)R2addr = ld_bswap_Xword(value); 968bf994817SAli Bahrami else 969bf994817SAli Bahrami *(Xword *)R2addr = value; 970bf994817SAli Bahrami continue; 971141040e8Srie 972bf994817SAli Bahrami } else if (IS_GOT_BASED(arsp->rel_rtype) && 973bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 974bf994817SAli Bahrami value -= ofl->ofl_osgot->os_shdr->sh_addr; 975141040e8Srie 976bf994817SAli Bahrami } else if (IS_GOTPCREL(arsp->rel_rtype) && 977bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 978bf994817SAli Bahrami Gotndx *gnp; 9797c478bd9Sstevel@tonic-gate 980bf994817SAli Bahrami /* 981bf994817SAli Bahrami * Calculation: 982bf994817SAli Bahrami * G + GOT + A - P 983bf994817SAli Bahrami */ 984bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 985bf994817SAli Bahrami assert(gnp); 986bf994817SAli Bahrami value = (Xword)(ofl->ofl_osgot->os_shdr-> sh_addr) + 987bf994817SAli Bahrami ((Xword)gnp->gn_gotndx * M_GOT_ENTSIZE) + 988bf994817SAli Bahrami arsp->rel_raddend - refaddr; 989bf994817SAli Bahrami 990bf994817SAli Bahrami } else if (IS_GOT_PC(arsp->rel_rtype) && 991bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 992bf994817SAli Bahrami value = (Xword)(ofl->ofl_osgot->os_shdr-> 993bf994817SAli Bahrami sh_addr) - refaddr + arsp->rel_raddend; 994bf994817SAli Bahrami 995bf994817SAli Bahrami } else if ((IS_PC_RELATIVE(arsp->rel_rtype)) && 996bf994817SAli Bahrami (((flags & FLG_OF_RELOBJ) == 0) || 997bf994817SAli Bahrami (osp == sdp->sd_isc->is_osdesc))) { 998bf994817SAli Bahrami value -= refaddr; 999bf994817SAli Bahrami 1000bf994817SAli Bahrami } else if (IS_TLS_INS(arsp->rel_rtype) && 1001bf994817SAli Bahrami IS_GOT_RELATIVE(arsp->rel_rtype) && 1002bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 1003bf994817SAli Bahrami Gotndx *gnp; 1004bf994817SAli Bahrami 1005bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 1006bf994817SAli Bahrami assert(gnp); 1007bf994817SAli Bahrami value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 1008bf994817SAli Bahrami 1009bf994817SAli Bahrami } else if (IS_GOT_RELATIVE(arsp->rel_rtype) && 1010bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 1011bf994817SAli Bahrami Gotndx *gnp; 1012bf994817SAli Bahrami 1013bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 1014bf994817SAli Bahrami assert(gnp); 1015bf994817SAli Bahrami value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 1016bf994817SAli Bahrami 1017bf994817SAli Bahrami } else if ((arsp->rel_flags & FLG_REL_STLS) && 1018bf994817SAli Bahrami ((flags & FLG_OF_RELOBJ) == 0)) { 1019bf994817SAli Bahrami Xword tlsstatsize; 10207c478bd9Sstevel@tonic-gate 10217c478bd9Sstevel@tonic-gate /* 1022bf994817SAli Bahrami * This is the LE TLS reference model. Static 1023bf994817SAli Bahrami * offset is hard-coded. 10247c478bd9Sstevel@tonic-gate */ 1025bf994817SAli Bahrami tlsstatsize = S_ROUND(ofl->ofl_tlsphdr->p_memsz, 1026bf994817SAli Bahrami M_TLSSTATALIGN); 1027bf994817SAli Bahrami value = tlsstatsize - value; 10287c478bd9Sstevel@tonic-gate 10297c478bd9Sstevel@tonic-gate /* 1030bf994817SAli Bahrami * Since this code is fixed up, it assumes a negative 1031bf994817SAli Bahrami * offset that can be added to the thread pointer. 10327c478bd9Sstevel@tonic-gate */ 1033bf994817SAli Bahrami if (arsp->rel_rtype == R_AMD64_TPOFF32) 1034bf994817SAli Bahrami value = -value; 1035bf994817SAli Bahrami } 10367c478bd9Sstevel@tonic-gate 1037bf994817SAli Bahrami if (arsp->rel_isdesc->is_file) 1038bf994817SAli Bahrami ifl_name = arsp->rel_isdesc->is_file->ifl_name; 1039bf994817SAli Bahrami else 1040bf994817SAli Bahrami ifl_name = MSG_INTL(MSG_STR_NULL); 1041bf994817SAli Bahrami 1042bf994817SAli Bahrami /* 1043bf994817SAli Bahrami * Make sure we have data to relocate. Compiler and assembler 1044bf994817SAli Bahrami * developers have been known to generate relocations against 1045bf994817SAli Bahrami * invalid sections (normally .bss), so for their benefit give 1046bf994817SAli Bahrami * them sufficient information to help analyze the problem. 1047bf994817SAli Bahrami * End users should never see this. 1048bf994817SAli Bahrami */ 1049bf994817SAli Bahrami if (arsp->rel_isdesc->is_indata->d_buf == 0) { 1050bf994817SAli Bahrami Conv_inv_buf_t inv_buf; 1051bf994817SAli Bahrami 10521007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_REL_EMPTYSEC), 1053bf994817SAli Bahrami conv_reloc_amd64_type(arsp->rel_rtype, 0, &inv_buf), 1054bf994817SAli Bahrami ifl_name, ld_reloc_sym_name(arsp), 1055bf994817SAli Bahrami EC_WORD(arsp->rel_isdesc->is_scnndx), 1056bf994817SAli Bahrami arsp->rel_isdesc->is_name); 1057bf994817SAli Bahrami return (S_ERROR); 1058bf994817SAli Bahrami } 1059bf994817SAli Bahrami 1060bf994817SAli Bahrami /* 1061bf994817SAli Bahrami * Get the address of the data item we need to modify. 1062bf994817SAli Bahrami */ 1063bf994817SAli Bahrami addr = (uchar_t *)((uintptr_t)arsp->rel_roffset + 1064bf994817SAli Bahrami (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata)); 1065bf994817SAli Bahrami 1066bf994817SAli Bahrami DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 1067bf994817SAli Bahrami M_MACH, SHT_RELA, arsp, EC_NATPTR(addr), value, 1068bf994817SAli Bahrami ld_reloc_sym_name)); 1069bf994817SAli Bahrami addr += (uintptr_t)osp->os_outdata->d_buf; 1070bf994817SAli Bahrami 1071bf994817SAli Bahrami if ((((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 1072bf994817SAli Bahrami ofl->ofl_size) || (arsp->rel_roffset > 1073bf994817SAli Bahrami osp->os_shdr->sh_size)) { 1074bf994817SAli Bahrami int class; 1075bf994817SAli Bahrami Conv_inv_buf_t inv_buf; 1076bf994817SAli Bahrami 1077bf994817SAli Bahrami if (((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 1078bf994817SAli Bahrami ofl->ofl_size) 1079bf994817SAli Bahrami class = ERR_FATAL; 1080bf994817SAli Bahrami else 1081bf994817SAli Bahrami class = ERR_WARNING; 1082bf994817SAli Bahrami 10831007fd6fSAli Bahrami ld_eprintf(ofl, class, MSG_INTL(MSG_REL_INVALOFFSET), 1084bf994817SAli Bahrami conv_reloc_amd64_type(arsp->rel_rtype, 0, &inv_buf), 1085bf994817SAli Bahrami ifl_name, EC_WORD(arsp->rel_isdesc->is_scnndx), 1086bf994817SAli Bahrami arsp->rel_isdesc->is_name, ld_reloc_sym_name(arsp), 1087bf994817SAli Bahrami EC_ADDR((uintptr_t)addr - 1088bf994817SAli Bahrami (uintptr_t)ofl->ofl_nehdr)); 1089bf994817SAli Bahrami 1090bf994817SAli Bahrami if (class == ERR_FATAL) { 1091bf994817SAli Bahrami return_code = S_ERROR; 1092bf994817SAli Bahrami continue; 10937c478bd9Sstevel@tonic-gate } 1094bf994817SAli Bahrami } 10957c478bd9Sstevel@tonic-gate 1096bf994817SAli Bahrami /* 1097bf994817SAli Bahrami * The relocation is additive. Ignore the previous symbol 1098bf994817SAli Bahrami * value if this local partial symbol is expanded. 1099bf994817SAli Bahrami */ 1100bf994817SAli Bahrami if (moved) 1101bf994817SAli Bahrami value -= *addr; 11027c478bd9Sstevel@tonic-gate 1103bf994817SAli Bahrami /* 1104bf994817SAli Bahrami * If '-z noreloc' is specified - skip the do_reloc_ld stage. 1105bf994817SAli Bahrami */ 1106bf994817SAli Bahrami if (OFL_DO_RELOC(ofl)) { 11077c478bd9Sstevel@tonic-gate /* 1108bf994817SAli Bahrami * If this is a PROGBITS section and the running linker 1109bf994817SAli Bahrami * has a different byte order than the target host, 1110bf994817SAli Bahrami * tell do_reloc_ld() to swap bytes. 11117c478bd9Sstevel@tonic-gate */ 1112bf994817SAli Bahrami if (do_reloc_ld(arsp, addr, &value, ld_reloc_sym_name, 1113bf994817SAli Bahrami ifl_name, OFL_SWAP_RELOC_DATA(ofl, arsp), 11141007fd6fSAli Bahrami ofl->ofl_lml) == 0) { 11151007fd6fSAli Bahrami ofl->ofl_flags |= FLG_OF_FATAL; 1116bf994817SAli Bahrami return_code = S_ERROR; 11171007fd6fSAli Bahrami } 11187c478bd9Sstevel@tonic-gate } 11197c478bd9Sstevel@tonic-gate } 11207c478bd9Sstevel@tonic-gate return (return_code); 11217c478bd9Sstevel@tonic-gate } 11227c478bd9Sstevel@tonic-gate 1123ba2be530Sab static uintptr_t 11245aefb655Srie ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 11257c478bd9Sstevel@tonic-gate { 1126141040e8Srie Rel_desc *orsp; 1127141040e8Srie Sym_desc *sdp = rsp->rel_sym; 11287c478bd9Sstevel@tonic-gate 11297c478bd9Sstevel@tonic-gate /* 11307c478bd9Sstevel@tonic-gate * Static executables *do not* want any relocations against them. 11317c478bd9Sstevel@tonic-gate * Since our engine still creates relocations against a WEAK UNDEFINED 11327c478bd9Sstevel@tonic-gate * symbol in a static executable, it's best to disable them here 11337c478bd9Sstevel@tonic-gate * instead of through out the relocation code. 11347c478bd9Sstevel@tonic-gate */ 1135635216b6SRod Evans if (OFL_IS_STATIC_EXEC(ofl)) 11367c478bd9Sstevel@tonic-gate return (1); 11377c478bd9Sstevel@tonic-gate 11387c478bd9Sstevel@tonic-gate /* 11397c478bd9Sstevel@tonic-gate * If we are adding a output relocation against a section 11407c478bd9Sstevel@tonic-gate * symbol (non-RELATIVE) then mark that section. These sections 11417c478bd9Sstevel@tonic-gate * will be added to the .dynsym symbol table. 11427c478bd9Sstevel@tonic-gate */ 11437c478bd9Sstevel@tonic-gate if (sdp && (rsp->rel_rtype != M_R_RELATIVE) && 11447c478bd9Sstevel@tonic-gate ((flags & FLG_REL_SCNNDX) || 11457c478bd9Sstevel@tonic-gate (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) { 11467c478bd9Sstevel@tonic-gate 11477c478bd9Sstevel@tonic-gate /* 11487c478bd9Sstevel@tonic-gate * If this is a COMMON symbol - no output section 11497c478bd9Sstevel@tonic-gate * exists yet - (it's created as part of sym_validate()). 11507c478bd9Sstevel@tonic-gate * So - we mark here that when it's created it should 11517c478bd9Sstevel@tonic-gate * be tagged with the FLG_OS_OUTREL flag. 11527c478bd9Sstevel@tonic-gate */ 11537c478bd9Sstevel@tonic-gate if ((sdp->sd_flags & FLG_SY_SPECSEC) && 11540bc07c75Srie (sdp->sd_sym->st_shndx == SHN_COMMON)) { 11557c478bd9Sstevel@tonic-gate if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS) 11567c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_BSSOREL; 11577c478bd9Sstevel@tonic-gate else 11587c478bd9Sstevel@tonic-gate ofl->ofl_flags1 |= FLG_OF1_TLSOREL; 1159141040e8Srie } else { 116008278a5eSRod Evans Os_desc *osp; 116108278a5eSRod Evans Is_desc *isp = sdp->sd_isc; 11627c478bd9Sstevel@tonic-gate 116308278a5eSRod Evans if (isp && ((osp = isp->is_osdesc) != NULL) && 116408278a5eSRod Evans ((osp->os_flags & FLG_OS_OUTREL) == 0)) { 11657c478bd9Sstevel@tonic-gate ofl->ofl_dynshdrcnt++; 11667c478bd9Sstevel@tonic-gate osp->os_flags |= FLG_OS_OUTREL; 11677c478bd9Sstevel@tonic-gate } 11687c478bd9Sstevel@tonic-gate } 11697c478bd9Sstevel@tonic-gate } 11707c478bd9Sstevel@tonic-gate 1171bf994817SAli Bahrami /* Enter it into the output relocation cache */ 1172bf994817SAli Bahrami if ((orsp = ld_reloc_enter(ofl, &ofl->ofl_outrels, rsp, flags)) == NULL) 1173bf994817SAli Bahrami return (S_ERROR); 11747c478bd9Sstevel@tonic-gate 11757c478bd9Sstevel@tonic-gate if (flags & FLG_REL_GOT) 11767c478bd9Sstevel@tonic-gate ofl->ofl_relocgotsz += (Xword)sizeof (Rela); 11777c478bd9Sstevel@tonic-gate else if (flags & FLG_REL_PLT) 11787c478bd9Sstevel@tonic-gate ofl->ofl_relocpltsz += (Xword)sizeof (Rela); 11797c478bd9Sstevel@tonic-gate else if (flags & FLG_REL_BSS) 11807c478bd9Sstevel@tonic-gate ofl->ofl_relocbsssz += (Xword)sizeof (Rela); 11817c478bd9Sstevel@tonic-gate else if (flags & FLG_REL_NOINFO) 11827c478bd9Sstevel@tonic-gate ofl->ofl_relocrelsz += (Xword)sizeof (Rela); 11837c478bd9Sstevel@tonic-gate else 1184bf994817SAli Bahrami RELAUX_GET_OSDESC(orsp)->os_szoutrels += (Xword)sizeof (Rela); 11857c478bd9Sstevel@tonic-gate 11867c478bd9Sstevel@tonic-gate if (orsp->rel_rtype == M_R_RELATIVE) 11877c478bd9Sstevel@tonic-gate ofl->ofl_relocrelcnt++; 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate /* 11907c478bd9Sstevel@tonic-gate * We don't perform sorting on PLT relocations because 11917c478bd9Sstevel@tonic-gate * they have already been assigned a PLT index and if we 11927c478bd9Sstevel@tonic-gate * were to sort them we would have to re-assign the plt indexes. 11937c478bd9Sstevel@tonic-gate */ 11947c478bd9Sstevel@tonic-gate if (!(flags & FLG_REL_PLT)) 11957c478bd9Sstevel@tonic-gate ofl->ofl_reloccnt++; 11967c478bd9Sstevel@tonic-gate 1197141040e8Srie /* 1198141040e8Srie * Insure a GLOBAL_OFFSET_TABLE is generated if required. 1199141040e8Srie */ 1200141040e8Srie if (IS_GOT_REQUIRED(orsp->rel_rtype)) 1201141040e8Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 1202141040e8Srie 12037c478bd9Sstevel@tonic-gate /* 12047c478bd9Sstevel@tonic-gate * Identify and possibly warn of a displacement relocation. 12057c478bd9Sstevel@tonic-gate */ 12067c478bd9Sstevel@tonic-gate if (orsp->rel_flags & FLG_REL_DISP) { 12077c478bd9Sstevel@tonic-gate ofl->ofl_dtflags_1 |= DF_1_DISPRELPND; 12087c478bd9Sstevel@tonic-gate 12097c478bd9Sstevel@tonic-gate if (ofl->ofl_flags & FLG_OF_VERBOSE) 12105aefb655Srie ld_disp_errmsg(MSG_INTL(MSG_REL_DISPREL4), orsp, ofl); 12117c478bd9Sstevel@tonic-gate } 12125aefb655Srie DBG_CALL(Dbg_reloc_ors_entry(ofl->ofl_lml, ELF_DBG_LD, SHT_RELA, 12135aefb655Srie M_MACH, orsp)); 12147c478bd9Sstevel@tonic-gate return (1); 12157c478bd9Sstevel@tonic-gate } 12167c478bd9Sstevel@tonic-gate 12177c478bd9Sstevel@tonic-gate /* 12187c478bd9Sstevel@tonic-gate * process relocation for a LOCAL symbol 12197c478bd9Sstevel@tonic-gate */ 1220ba2be530Sab static uintptr_t 12215aefb655Srie ld_reloc_local(Rel_desc * rsp, Ofl_desc * ofl) 12227c478bd9Sstevel@tonic-gate { 12231d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 12247c478bd9Sstevel@tonic-gate Sym_desc *sdp = rsp->rel_sym; 12250bc07c75Srie Word shndx = sdp->sd_sym->st_shndx; 12267c478bd9Sstevel@tonic-gate Word ortype = rsp->rel_rtype; 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate /* 12297c478bd9Sstevel@tonic-gate * if ((shared object) and (not pc relative relocation) and 12307c478bd9Sstevel@tonic-gate * (not against ABS symbol)) 12317c478bd9Sstevel@tonic-gate * then 12327c478bd9Sstevel@tonic-gate * build R_AMD64_RELATIVE 12337c478bd9Sstevel@tonic-gate * fi 12347c478bd9Sstevel@tonic-gate */ 12357c478bd9Sstevel@tonic-gate if ((flags & FLG_OF_SHAROBJ) && (rsp->rel_flags & FLG_REL_LOAD) && 12362926dd2eSrie !(IS_PC_RELATIVE(rsp->rel_rtype)) && !(IS_SIZE(rsp->rel_rtype)) && 12377c478bd9Sstevel@tonic-gate !(IS_GOT_BASED(rsp->rel_rtype)) && 12387c478bd9Sstevel@tonic-gate !(rsp->rel_isdesc != NULL && 12397c478bd9Sstevel@tonic-gate (rsp->rel_isdesc->is_shdr->sh_type == SHT_SUNW_dof)) && 12407c478bd9Sstevel@tonic-gate (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) || 12417c478bd9Sstevel@tonic-gate (shndx != SHN_ABS) || (sdp->sd_aux && sdp->sd_aux->sa_symspec))) { 12427c478bd9Sstevel@tonic-gate 12437c478bd9Sstevel@tonic-gate /* 12447c478bd9Sstevel@tonic-gate * R_AMD64_RELATIVE updates a 64bit address, if this 12457c478bd9Sstevel@tonic-gate * relocation isn't a 64bit binding then we can not 12467c478bd9Sstevel@tonic-gate * simplify it to a RELATIVE relocation. 12477c478bd9Sstevel@tonic-gate */ 12487c478bd9Sstevel@tonic-gate if (reloc_table[ortype].re_fsize != sizeof (Addr)) { 12491d9df23bSab return (ld_add_outrel(0, rsp, ofl)); 12507c478bd9Sstevel@tonic-gate } 12517c478bd9Sstevel@tonic-gate 12527c478bd9Sstevel@tonic-gate rsp->rel_rtype = R_AMD64_RELATIVE; 12535aefb655Srie if (ld_add_outrel(FLG_REL_ADVAL, rsp, ofl) == S_ERROR) 12547c478bd9Sstevel@tonic-gate return (S_ERROR); 12557c478bd9Sstevel@tonic-gate rsp->rel_rtype = ortype; 12567c478bd9Sstevel@tonic-gate return (1); 12577c478bd9Sstevel@tonic-gate } 12587c478bd9Sstevel@tonic-gate 1259b3fbe5e6Sseizo /* 1260b3fbe5e6Sseizo * If the relocation is against a 'non-allocatable' section 1261b3fbe5e6Sseizo * and we can not resolve it now - then give a warning 1262b3fbe5e6Sseizo * message. 1263b3fbe5e6Sseizo * 1264b3fbe5e6Sseizo * We can not resolve the symbol if either: 1265b3fbe5e6Sseizo * a) it's undefined 1266b3fbe5e6Sseizo * b) it's defined in a shared library and a 1267b3fbe5e6Sseizo * COPY relocation hasn't moved it to the executable 1268b3fbe5e6Sseizo * 1269b3fbe5e6Sseizo * Note: because we process all of the relocations against the 1270b3fbe5e6Sseizo * text segment before any others - we know whether 1271b3fbe5e6Sseizo * or not a copy relocation will be generated before 1272b3fbe5e6Sseizo * we get here (see reloc_init()->reloc_segments()). 1273b3fbe5e6Sseizo */ 12747c478bd9Sstevel@tonic-gate if (!(rsp->rel_flags & FLG_REL_LOAD) && 1275b3fbe5e6Sseizo ((shndx == SHN_UNDEF) || 1276b3fbe5e6Sseizo ((sdp->sd_ref == REF_DYN_NEED) && 1277b3fbe5e6Sseizo ((sdp->sd_flags & FLG_SY_MVTOCOMM) == 0)))) { 1278bf994817SAli Bahrami Conv_inv_buf_t inv_buf; 1279bf994817SAli Bahrami Os_desc *osp = RELAUX_GET_OSDESC(rsp); 1280de777a60Sab 1281b3fbe5e6Sseizo /* 1282b3fbe5e6Sseizo * If the relocation is against a SHT_SUNW_ANNOTATE 1283b3fbe5e6Sseizo * section - then silently ignore that the relocation 1284b3fbe5e6Sseizo * can not be resolved. 1285b3fbe5e6Sseizo */ 1286bf994817SAli Bahrami if (osp && (osp->os_shdr->sh_type == SHT_SUNW_ANNOTATE)) 1287b3fbe5e6Sseizo return (0); 12881007fd6fSAli Bahrami ld_eprintf(ofl, ERR_WARNING, MSG_INTL(MSG_REL_EXTERNSYM), 1289de777a60Sab conv_reloc_amd64_type(rsp->rel_rtype, 0, &inv_buf), 12907c478bd9Sstevel@tonic-gate rsp->rel_isdesc->is_file->ifl_name, 1291bf994817SAli Bahrami ld_reloc_sym_name(rsp), osp->os_name); 12927c478bd9Sstevel@tonic-gate return (1); 12937c478bd9Sstevel@tonic-gate } 12947c478bd9Sstevel@tonic-gate 12957c478bd9Sstevel@tonic-gate /* 12967c478bd9Sstevel@tonic-gate * Perform relocation. 12977c478bd9Sstevel@tonic-gate */ 12985aefb655Srie return (ld_add_actrel(NULL, rsp, ofl)); 12997c478bd9Sstevel@tonic-gate } 13007c478bd9Sstevel@tonic-gate 13017c478bd9Sstevel@tonic-gate 1302ba2be530Sab static uintptr_t 13035aefb655Srie ld_reloc_TLS(Boolean local, Rel_desc * rsp, Ofl_desc * ofl) 13047c478bd9Sstevel@tonic-gate { 13057c478bd9Sstevel@tonic-gate Word rtype = rsp->rel_rtype; 13067c478bd9Sstevel@tonic-gate Sym_desc *sdp = rsp->rel_sym; 13071d9df23bSab ofl_flag_t flags = ofl->ofl_flags; 13087c478bd9Sstevel@tonic-gate Gotndx *gnp; 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate /* 1311d326b23bSrie * If we're building an executable - use either the IE or LE access 1312d326b23bSrie * model. If we're building a shared object process any IE model. 13137c478bd9Sstevel@tonic-gate */ 1314d326b23bSrie if ((flags & FLG_OF_EXEC) || (IS_TLS_IE(rtype))) { 13157c478bd9Sstevel@tonic-gate /* 1316d326b23bSrie * Set the DF_STATIC_TLS flag. 13177c478bd9Sstevel@tonic-gate */ 13187c478bd9Sstevel@tonic-gate ofl->ofl_dtflags |= DF_STATIC_TLS; 13197c478bd9Sstevel@tonic-gate 1320d326b23bSrie if (!local || ((flags & FLG_OF_EXEC) == 0)) { 13217c478bd9Sstevel@tonic-gate /* 1322d326b23bSrie * Assign a GOT entry for static TLS references. 13237c478bd9Sstevel@tonic-gate */ 132457ef7aa9SRod Evans if ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 132557ef7aa9SRod Evans GOT_REF_TLSIE, ofl, rsp)) == NULL) { 13267c478bd9Sstevel@tonic-gate 1327d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, 1328d326b23bSrie gnp, GOT_REF_TLSIE, FLG_REL_STLS, 1329d326b23bSrie rtype, R_AMD64_TPOFF64, 0) == S_ERROR) 1330d326b23bSrie return (S_ERROR); 1331d326b23bSrie } 13327c478bd9Sstevel@tonic-gate 13337c478bd9Sstevel@tonic-gate /* 1334d326b23bSrie * IE access model. 13357c478bd9Sstevel@tonic-gate */ 13367c478bd9Sstevel@tonic-gate if (IS_TLS_IE(rtype)) 13375aefb655Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 13387c478bd9Sstevel@tonic-gate 13397c478bd9Sstevel@tonic-gate /* 1340d326b23bSrie * Fixups are required for other executable models. 13417c478bd9Sstevel@tonic-gate */ 13425aefb655Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13437c478bd9Sstevel@tonic-gate rsp, ofl)); 13447c478bd9Sstevel@tonic-gate } 1345d326b23bSrie 13467c478bd9Sstevel@tonic-gate /* 1347d326b23bSrie * LE access model. 13487c478bd9Sstevel@tonic-gate */ 13497c478bd9Sstevel@tonic-gate if (IS_TLS_LE(rtype)) 13505aefb655Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 1351d326b23bSrie 13525aefb655Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13535aefb655Srie rsp, ofl)); 13547c478bd9Sstevel@tonic-gate } 13557c478bd9Sstevel@tonic-gate 13567c478bd9Sstevel@tonic-gate /* 1357d326b23bSrie * Building a shared object. 1358d326b23bSrie * 1359d326b23bSrie * Assign a GOT entry for a dynamic TLS reference. 13607c478bd9Sstevel@tonic-gate */ 136157ef7aa9SRod Evans if (IS_TLS_LD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 136257ef7aa9SRod Evans GOT_REF_TLSLD, ofl, rsp)) == NULL)) { 1363d326b23bSrie 1364d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSLD, 136557ef7aa9SRod Evans FLG_REL_MTLS, rtype, R_AMD64_DTPMOD64, NULL) == S_ERROR) 13667c478bd9Sstevel@tonic-gate return (S_ERROR); 1367d326b23bSrie 13685aefb655Srie } else if (IS_TLS_GD(rtype) && 136957ef7aa9SRod Evans ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, GOT_REF_TLSGD, 137057ef7aa9SRod Evans ofl, rsp)) == NULL)) { 1371d326b23bSrie 1372d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSGD, 1373d326b23bSrie FLG_REL_DTLS, rtype, R_AMD64_DTPMOD64, 1374d326b23bSrie R_AMD64_DTPOFF64) == S_ERROR) 13757c478bd9Sstevel@tonic-gate return (S_ERROR); 13767c478bd9Sstevel@tonic-gate } 13777c478bd9Sstevel@tonic-gate 13787c478bd9Sstevel@tonic-gate if (IS_TLS_LD(rtype)) 13795aefb655Srie return (ld_add_actrel(FLG_REL_MTLS, rsp, ofl)); 13807c478bd9Sstevel@tonic-gate 13815aefb655Srie return (ld_add_actrel(FLG_REL_DTLS, rsp, ofl)); 13827c478bd9Sstevel@tonic-gate } 13837c478bd9Sstevel@tonic-gate 13847c478bd9Sstevel@tonic-gate /* ARGSUSED5 */ 1385ba2be530Sab static uintptr_t 138657ef7aa9SRod Evans ld_assign_got_ndx(Alist **alpp, Gotndx *pgnp, Gotref gref, Ofl_desc *ofl, 138757ef7aa9SRod Evans Rel_desc *rsp, Sym_desc *sdp) 13887c478bd9Sstevel@tonic-gate { 13897c478bd9Sstevel@tonic-gate Xword raddend; 139057ef7aa9SRod Evans Gotndx gn, *gnp; 139157ef7aa9SRod Evans Aliste idx; 13927c478bd9Sstevel@tonic-gate uint_t gotents; 13937c478bd9Sstevel@tonic-gate 13947c478bd9Sstevel@tonic-gate raddend = rsp->rel_raddend; 139557ef7aa9SRod Evans if (pgnp && (pgnp->gn_addend == raddend) && (pgnp->gn_gotref == gref)) 13967c478bd9Sstevel@tonic-gate return (1); 13977c478bd9Sstevel@tonic-gate 13987c478bd9Sstevel@tonic-gate if ((gref == GOT_REF_TLSGD) || (gref == GOT_REF_TLSLD)) 13997c478bd9Sstevel@tonic-gate gotents = 2; 14007c478bd9Sstevel@tonic-gate else 14017c478bd9Sstevel@tonic-gate gotents = 1; 14027c478bd9Sstevel@tonic-gate 140357ef7aa9SRod Evans gn.gn_addend = raddend; 140457ef7aa9SRod Evans gn.gn_gotndx = ofl->ofl_gotcnt; 140557ef7aa9SRod Evans gn.gn_gotref = gref; 14067c478bd9Sstevel@tonic-gate 14077c478bd9Sstevel@tonic-gate ofl->ofl_gotcnt += gotents; 14087c478bd9Sstevel@tonic-gate 14097c478bd9Sstevel@tonic-gate if (gref == GOT_REF_TLSLD) { 141057ef7aa9SRod Evans if (ofl->ofl_tlsldgotndx == NULL) { 141157ef7aa9SRod Evans if ((gnp = libld_malloc(sizeof (Gotndx))) == NULL) 141257ef7aa9SRod Evans return (S_ERROR); 141357ef7aa9SRod Evans (void) memcpy(gnp, &gn, sizeof (Gotndx)); 141457ef7aa9SRod Evans ofl->ofl_tlsldgotndx = gnp; 141557ef7aa9SRod Evans } 14167c478bd9Sstevel@tonic-gate return (1); 14177c478bd9Sstevel@tonic-gate } 14187c478bd9Sstevel@tonic-gate 141957ef7aa9SRod Evans idx = 0; 142057ef7aa9SRod Evans for (ALIST_TRAVERSE(*alpp, idx, gnp)) { 142157ef7aa9SRod Evans if (gnp->gn_addend > raddend) 142257ef7aa9SRod Evans break; 14237c478bd9Sstevel@tonic-gate } 142457ef7aa9SRod Evans 142557ef7aa9SRod Evans /* 142657ef7aa9SRod Evans * GOT indexes are maintained on an Alist, where there is typically 142757ef7aa9SRod Evans * only one index. The usage of this list is to scan the list to find 142857ef7aa9SRod Evans * an index, and then apply that index immediately to a relocation. 142957ef7aa9SRod Evans * Thus there are no external references to these GOT index structures 143057ef7aa9SRod Evans * that can be compromised by the Alist being reallocated. 143157ef7aa9SRod Evans */ 143257ef7aa9SRod Evans if (alist_insert(alpp, &gn, sizeof (Gotndx), 143357ef7aa9SRod Evans AL_CNT_SDP_GOT, idx) == NULL) 143457ef7aa9SRod Evans return (S_ERROR); 143557ef7aa9SRod Evans 14367c478bd9Sstevel@tonic-gate return (1); 14377c478bd9Sstevel@tonic-gate } 14387c478bd9Sstevel@tonic-gate 1439ba2be530Sab static void 14405aefb655Srie ld_assign_plt_ndx(Sym_desc * sdp, Ofl_desc *ofl) 14417c478bd9Sstevel@tonic-gate { 14427c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_PLTndx = 1 + ofl->ofl_pltcnt++; 14437c478bd9Sstevel@tonic-gate sdp->sd_aux->sa_PLTGOTndx = ofl->ofl_gotcnt++; 1444141040e8Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 14457c478bd9Sstevel@tonic-gate } 14467c478bd9Sstevel@tonic-gate 1447b3fbe5e6Sseizo static uchar_t plt0_template[M_PLT_ENTSIZE] = { 14487c478bd9Sstevel@tonic-gate /* 0x00 PUSHQ GOT+8(%rip) */ 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, 14497c478bd9Sstevel@tonic-gate /* 0x06 JMP *GOT+16(%rip) */ 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 14507c478bd9Sstevel@tonic-gate /* 0x0c NOP */ 0x90, 14517c478bd9Sstevel@tonic-gate /* 0x0d NOP */ 0x90, 14527c478bd9Sstevel@tonic-gate /* 0x0e NOP */ 0x90, 14537c478bd9Sstevel@tonic-gate /* 0x0f NOP */ 0x90 14547c478bd9Sstevel@tonic-gate }; 14557c478bd9Sstevel@tonic-gate 14567c478bd9Sstevel@tonic-gate /* 14577c478bd9Sstevel@tonic-gate * Initializes .got[0] with the _DYNAMIC symbol value. 14587c478bd9Sstevel@tonic-gate */ 1459ba2be530Sab static uintptr_t 1460d326b23bSrie ld_fillin_gotplt(Ofl_desc *ofl) 14617c478bd9Sstevel@tonic-gate { 1462ba2be530Sab int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 1463ba2be530Sab 14647c478bd9Sstevel@tonic-gate if (ofl->ofl_osgot) { 1465d326b23bSrie Sym_desc *sdp; 14667c478bd9Sstevel@tonic-gate 14675aefb655Srie if ((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_DYNAMIC_U), 1468635216b6SRod Evans SYM_NOHASH, NULL, ofl)) != NULL) { 1469d326b23bSrie uchar_t *genptr; 1470d326b23bSrie 1471d326b23bSrie genptr = ((uchar_t *)ofl->ofl_osgot->os_outdata->d_buf + 14727c478bd9Sstevel@tonic-gate (M_GOT_XDYNAMIC * M_GOT_ENTSIZE)); 14737c478bd9Sstevel@tonic-gate /* LINTED */ 14747c478bd9Sstevel@tonic-gate *(Xword *)genptr = sdp->sd_sym->st_value; 1475ba2be530Sab if (bswap) 1476ba2be530Sab /* LINTED */ 1477ba2be530Sab *(Xword *)genptr = 1478ba2be530Sab /* LINTED */ 1479ba2be530Sab ld_bswap_Xword(*(Xword *)genptr); 14807c478bd9Sstevel@tonic-gate } 14817c478bd9Sstevel@tonic-gate } 14827c478bd9Sstevel@tonic-gate 14837c478bd9Sstevel@tonic-gate /* 14847c478bd9Sstevel@tonic-gate * Fill in the reserved slot in the procedure linkage table the first 14857c478bd9Sstevel@tonic-gate * entry is: 14867c478bd9Sstevel@tonic-gate * 0x00 PUSHQ GOT+8(%rip) # GOT[1] 14877c478bd9Sstevel@tonic-gate * 0x06 JMP *GOT+16(%rip) # GOT[2] 14887c478bd9Sstevel@tonic-gate * 0x0c NOP 14897c478bd9Sstevel@tonic-gate * 0x0d NOP 14907c478bd9Sstevel@tonic-gate * 0x0e NOP 14917c478bd9Sstevel@tonic-gate * 0x0f NOP 14927c478bd9Sstevel@tonic-gate */ 1493f3324781Sab if ((ofl->ofl_flags & FLG_OF_DYNAMIC) && ofl->ofl_osplt) { 1494d326b23bSrie uchar_t *pltent; 1495d326b23bSrie Xword val1; 14967c478bd9Sstevel@tonic-gate 1497b3fbe5e6Sseizo pltent = (uchar_t *)ofl->ofl_osplt->os_outdata->d_buf; 14987c478bd9Sstevel@tonic-gate bcopy(plt0_template, pltent, sizeof (plt0_template)); 14997c478bd9Sstevel@tonic-gate 1500f3324781Sab /* 1501f3324781Sab * If '-z noreloc' is specified - skip the do_reloc_ld 1502f3324781Sab * stage. 1503f3324781Sab */ 1504f3324781Sab if (!OFL_DO_RELOC(ofl)) 1505f3324781Sab return (1); 1506f3324781Sab 15077c478bd9Sstevel@tonic-gate /* 15087c478bd9Sstevel@tonic-gate * filin: 15097c478bd9Sstevel@tonic-gate * PUSHQ GOT + 8(%rip) 15107c478bd9Sstevel@tonic-gate * 15117c478bd9Sstevel@tonic-gate * Note: 0x06 below represents the offset to the 15127c478bd9Sstevel@tonic-gate * next instruction - which is what %rip will 15137c478bd9Sstevel@tonic-gate * be pointing at. 15147c478bd9Sstevel@tonic-gate */ 15157c478bd9Sstevel@tonic-gate val1 = (ofl->ofl_osgot->os_shdr->sh_addr) + 1516de777a60Sab (M_GOT_XLINKMAP * M_GOT_ENTSIZE) - 1517de777a60Sab ofl->ofl_osplt->os_shdr->sh_addr - 0x06; 15187c478bd9Sstevel@tonic-gate 1519bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x02], 1520bf994817SAli Bahrami &val1, syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), 1521bf994817SAli Bahrami bswap, ofl->ofl_lml) == 0) { 15221007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_PLT_PLT0FAIL)); 1523f3324781Sab return (S_ERROR); 15247c478bd9Sstevel@tonic-gate } 15257c478bd9Sstevel@tonic-gate 15267c478bd9Sstevel@tonic-gate /* 15277c478bd9Sstevel@tonic-gate * filin: 15287c478bd9Sstevel@tonic-gate * JMP *GOT+16(%rip) 15297c478bd9Sstevel@tonic-gate */ 15307c478bd9Sstevel@tonic-gate val1 = (ofl->ofl_osgot->os_shdr->sh_addr) + 1531de777a60Sab (M_GOT_XRTLD * M_GOT_ENTSIZE) - 1532de777a60Sab ofl->ofl_osplt->os_shdr->sh_addr - 0x0c; 1533f3324781Sab 1534bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x08], 1535bf994817SAli Bahrami &val1, syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), 1536bf994817SAli Bahrami bswap, ofl->ofl_lml) == 0) { 15371007fd6fSAli Bahrami ld_eprintf(ofl, ERR_FATAL, MSG_INTL(MSG_PLT_PLT0FAIL)); 1538f3324781Sab return (S_ERROR); 15397c478bd9Sstevel@tonic-gate } 15407c478bd9Sstevel@tonic-gate } 1541f3324781Sab 15427c478bd9Sstevel@tonic-gate return (1); 15437c478bd9Sstevel@tonic-gate } 1544ba2be530Sab 1545ba2be530Sab 1546ba2be530Sab 1547ba2be530Sab /* 1548ba2be530Sab * Template for generating "void (*)(void)" function 1549ba2be530Sab */ 1550ba2be530Sab static const uchar_t nullfunc_tmpl[] = { /* amd64 */ 1551ba2be530Sab /* 0x00 */ 0x55, /* pushq %rbp */ 1552ba2be530Sab /* 0x01 */ 0x48, 0x8b, 0xec, /* movq %rsp,%rbp */ 1553ba2be530Sab /* 0x04 */ 0x48, 0x8b, 0xe5, /* movq %rbp,%rsp */ 1554ba2be530Sab /* 0x07 */ 0x5d, /* popq %rbp */ 1555ba2be530Sab /* 0x08 */ 0xc3 /* ret */ 1556ba2be530Sab }; 1557ba2be530Sab 1558ba2be530Sab 15593c573fccSAli Bahrami /* 15603c573fccSAli Bahrami * Function used to provide fill padding in SHF_EXECINSTR sections 15613c573fccSAli Bahrami * 15623c573fccSAli Bahrami * entry: 15633c573fccSAli Bahrami * 15643c573fccSAli Bahrami * base - base address of section being filled 15653c573fccSAli Bahrami * offset - starting offset for fill within memory referenced by base 15663c573fccSAli Bahrami * cnt - # bytes to be filled 15673c573fccSAli Bahrami * 15683c573fccSAli Bahrami * exit: 15693c573fccSAli Bahrami * The fill has been completed. 15703c573fccSAli Bahrami */ 15713c573fccSAli Bahrami static void 15723c573fccSAli Bahrami execfill(void *base, off_t off, size_t cnt) 15733c573fccSAli Bahrami { 15743c573fccSAli Bahrami /* 15753c573fccSAli Bahrami * 0x90 is an X86 NOP instruction in both 32 and 64-bit worlds. 15763c573fccSAli Bahrami * There are no alignment constraints. 15773c573fccSAli Bahrami */ 15783c573fccSAli Bahrami (void) memset(off + (char *)base, 0x90, cnt); 15793c573fccSAli Bahrami } 15803c573fccSAli Bahrami 15813c573fccSAli Bahrami 1582ba2be530Sab /* 1583ba2be530Sab * Return the ld_targ definition for this target. 1584ba2be530Sab */ 1585ba2be530Sab const Target * 1586ba2be530Sab ld_targ_init_x86(void) 1587ba2be530Sab { 1588ba2be530Sab static const Target _ld_targ = { 1589ba2be530Sab { /* Target_mach */ 1590ba2be530Sab M_MACH, /* m_mach */ 1591ba2be530Sab M_MACHPLUS, /* m_machplus */ 1592ba2be530Sab M_FLAGSPLUS, /* m_flagsplus */ 1593ba2be530Sab M_CLASS, /* m_class */ 1594ba2be530Sab M_DATA, /* m_data */ 1595ba2be530Sab 1596ba2be530Sab M_SEGM_ALIGN, /* m_segm_align */ 1597ba2be530Sab M_SEGM_ORIGIN, /* m_segm_origin */ 1598bb3b4f6cSRod Evans M_SEGM_AORIGIN, /* m_segm_aorigin */ 1599ba2be530Sab M_DATASEG_PERM, /* m_dataseg_perm */ 160069112eddSAli Bahrami M_STACK_PERM, /* m_stack_perm */ 1601ba2be530Sab M_WORD_ALIGN, /* m_word_align */ 1602ba2be530Sab MSG_ORIG(MSG_PTH_RTLD_AMD64), /* m_def_interp */ 1603ba2be530Sab 1604ba2be530Sab /* Relocation type codes */ 1605ba2be530Sab M_R_ARRAYADDR, /* m_r_arrayaddr */ 1606ba2be530Sab M_R_COPY, /* m_r_copy */ 1607ba2be530Sab M_R_GLOB_DAT, /* m_r_glob_dat */ 1608ba2be530Sab M_R_JMP_SLOT, /* m_r_jmp_slot */ 1609ba2be530Sab M_R_NUM, /* m_r_num */ 1610ba2be530Sab M_R_NONE, /* m_r_none */ 1611ba2be530Sab M_R_RELATIVE, /* m_r_relative */ 1612ba2be530Sab M_R_REGISTER, /* m_r_register */ 1613ba2be530Sab 1614ba2be530Sab /* Relocation related constants */ 1615ba2be530Sab M_REL_DT_COUNT, /* m_rel_dt_count */ 1616ba2be530Sab M_REL_DT_ENT, /* m_rel_dt_ent */ 1617ba2be530Sab M_REL_DT_SIZE, /* m_rel_dt_size */ 1618ba2be530Sab M_REL_DT_TYPE, /* m_rel_dt_type */ 1619ba2be530Sab M_REL_SHT_TYPE, /* m_rel_sht_type */ 1620ba2be530Sab 1621ba2be530Sab /* GOT related constants */ 1622ba2be530Sab M_GOT_ENTSIZE, /* m_got_entsize */ 1623ba2be530Sab M_GOT_XNumber, /* m_got_xnumber */ 1624ba2be530Sab 1625ba2be530Sab /* PLT related constants */ 1626ba2be530Sab M_PLT_ALIGN, /* m_plt_align */ 1627ba2be530Sab M_PLT_ENTSIZE, /* m_plt_entsize */ 1628ba2be530Sab M_PLT_RESERVSZ, /* m_plt_reservsz */ 1629ba2be530Sab M_PLT_SHF_FLAGS, /* m_plt_shf_flags */ 1630ba2be530Sab 16317e16fca0SAli Bahrami /* Section type of .eh_frame/.eh_frame_hdr sections */ 16327e16fca0SAli Bahrami SHT_AMD64_UNWIND, /* m_sht_unwind */ 16337e16fca0SAli Bahrami 1634ba2be530Sab M_DT_REGISTER, /* m_dt_register */ 1635ba2be530Sab }, 1636ba2be530Sab { /* Target_machid */ 1637ba2be530Sab M_ID_ARRAY, /* id_array */ 1638ba2be530Sab M_ID_BSS, /* id_bss */ 1639ba2be530Sab M_ID_CAP, /* id_cap */ 164008278a5eSRod Evans M_ID_CAPINFO, /* id_capinfo */ 164108278a5eSRod Evans M_ID_CAPCHAIN, /* id_capchain */ 1642ba2be530Sab M_ID_DATA, /* id_data */ 1643ba2be530Sab M_ID_DYNAMIC, /* id_dynamic */ 1644ba2be530Sab M_ID_DYNSORT, /* id_dynsort */ 1645ba2be530Sab M_ID_DYNSTR, /* id_dynstr */ 1646ba2be530Sab M_ID_DYNSYM, /* id_dynsym */ 1647ba2be530Sab M_ID_DYNSYM_NDX, /* id_dynsym_ndx */ 1648ba2be530Sab M_ID_GOT, /* id_got */ 1649ba2be530Sab M_ID_UNKNOWN, /* id_gotdata (unused) */ 1650ba2be530Sab M_ID_HASH, /* id_hash */ 1651ba2be530Sab M_ID_INTERP, /* id_interp */ 1652ba2be530Sab M_ID_LBSS, /* id_lbss */ 1653ba2be530Sab M_ID_LDYNSYM, /* id_ldynsym */ 1654ba2be530Sab M_ID_NOTE, /* id_note */ 1655ba2be530Sab M_ID_NULL, /* id_null */ 1656ba2be530Sab M_ID_PLT, /* id_plt */ 1657ba2be530Sab M_ID_REL, /* id_rel */ 1658ba2be530Sab M_ID_STRTAB, /* id_strtab */ 1659ba2be530Sab M_ID_SYMINFO, /* id_syminfo */ 1660ba2be530Sab M_ID_SYMTAB, /* id_symtab */ 1661ba2be530Sab M_ID_SYMTAB_NDX, /* id_symtab_ndx */ 1662ba2be530Sab M_ID_TEXT, /* id_text */ 1663ba2be530Sab M_ID_TLS, /* id_tls */ 1664ba2be530Sab M_ID_TLSBSS, /* id_tlsbss */ 1665ba2be530Sab M_ID_UNKNOWN, /* id_unknown */ 1666ba2be530Sab M_ID_UNWIND, /* id_unwind */ 16677e16fca0SAli Bahrami M_ID_UNWINDHDR, /* id_unwindhdr */ 1668ba2be530Sab M_ID_USER, /* id_user */ 1669ba2be530Sab M_ID_VERSION, /* id_version */ 1670ba2be530Sab }, 1671ba2be530Sab { /* Target_nullfunc */ 1672ba2be530Sab nullfunc_tmpl, /* nf_template */ 1673ba2be530Sab sizeof (nullfunc_tmpl), /* nf_size */ 1674ba2be530Sab }, 16753c573fccSAli Bahrami { /* Target_fillfunc */ 16763c573fccSAli Bahrami execfill /* ff_execfill */ 16773c573fccSAli Bahrami }, 1678ba2be530Sab { /* Target_machrel */ 1679ba2be530Sab reloc_table, 1680ba2be530Sab 1681ba2be530Sab ld_init_rel, /* mr_init_rel */ 1682ba2be530Sab ld_mach_eflags, /* mr_mach_eflags */ 1683ba2be530Sab ld_mach_make_dynamic, /* mr_mach_make_dynamic */ 1684ba2be530Sab ld_mach_update_odynamic, /* mr_mach_update_odynamic */ 1685ba2be530Sab ld_calc_plt_addr, /* mr_calc_plt_addr */ 1686ba2be530Sab ld_perform_outreloc, /* mr_perform_outreloc */ 1687ba2be530Sab ld_do_activerelocs, /* mr_do_activerelocs */ 1688ba2be530Sab ld_add_outrel, /* mr_add_outrel */ 1689ba2be530Sab NULL, /* mr_reloc_register */ 1690ba2be530Sab ld_reloc_local, /* mr_reloc_local */ 1691ba2be530Sab NULL, /* mr_reloc_GOTOP */ 1692ba2be530Sab ld_reloc_TLS, /* mr_reloc_TLS */ 1693ba2be530Sab NULL, /* mr_assign_got */ 169457ef7aa9SRod Evans ld_find_got_ndx, /* mr_find_got_ndx */ 1695ba2be530Sab ld_calc_got_offset, /* mr_calc_got_offset */ 1696ba2be530Sab ld_assign_got_ndx, /* mr_assign_got_ndx */ 1697ba2be530Sab ld_assign_plt_ndx, /* mr_assign_plt_ndx */ 1698ba2be530Sab NULL, /* mr_allocate_got */ 1699ba2be530Sab ld_fillin_gotplt, /* mr_fillin_gotplt */ 1700ba2be530Sab }, 1701ba2be530Sab { /* Target_machsym */ 1702ba2be530Sab NULL, /* ms_reg_check */ 1703ba2be530Sab NULL, /* ms_mach_sym_typecheck */ 1704ba2be530Sab NULL, /* ms_is_regsym */ 1705ba2be530Sab NULL, /* ms_reg_find */ 1706ba2be530Sab NULL /* ms_reg_enter */ 1707ba2be530Sab } 1708ba2be530Sab }; 1709ba2be530Sab 1710ba2be530Sab return (&_ld_targ); 1711ba2be530Sab } 1712