15aefb655Srie /* 25aefb655Srie * CDDL HEADER START 35aefb655Srie * 45aefb655Srie * 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. 75aefb655Srie * 85aefb655Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 95aefb655Srie * or http://www.opensolaris.org/os/licensing. 105aefb655Srie * See the License for the specific language governing permissions 115aefb655Srie * and limitations under the License. 125aefb655Srie * 135aefb655Srie * When distributing Covered Code, include this CDDL HEADER in each 145aefb655Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 155aefb655Srie * If applicable, add the following below this CDDL HEADER, with the 165aefb655Srie * fields enclosed by brackets "[]" replaced with your own identifying 175aefb655Srie * information: Portions Copyright [yyyy] [name of copyright owner] 185aefb655Srie * 195aefb655Srie * CDDL HEADER END 205aefb655Srie */ 215aefb655Srie 225aefb655Srie /* 23*bf994817SAli Bahrami * Copyright (c) 2004, 2010, Oracle and/or its affiliates. All rights reserved. 245aefb655Srie */ 255aefb655Srie 26ba2be530Sab196087 /* Get the x86 version of the relocation engine */ 27ba2be530Sab196087 #define DO_RELOC_LIBLD_X86 28ba2be530Sab196087 295aefb655Srie #include <string.h> 305aefb655Srie #include <stdio.h> 315aefb655Srie #include <strings.h> 325aefb655Srie #include <sys/elf_amd64.h> 335aefb655Srie #include <debug.h> 345aefb655Srie #include <reloc.h> 35ba2be530Sab196087 #include <i386/machdep_x86.h> 365aefb655Srie #include "msg.h" 375aefb655Srie #include "_libld.h" 385aefb655Srie 3957ef7aa9SRod Evans /* 40*bf994817SAli Bahrami * This module uses do_reloc_ld() to execute several synthesized relocations. 41*bf994817SAli Bahrami * That function expects to be passed two things that we need to construct 42*bf994817SAli Bahrami * here: 43*bf994817SAli Bahrami * 44*bf994817SAli Bahrami * 1) A Rel_desc descriptor for each relocation type, from which the 45*bf994817SAli Bahrami * rel_rtype field, and nothing else, is obtained. This is easily 46*bf994817SAli Bahrami * handled by constructing the necessary descriptors. 47*bf994817SAli Bahrami * 48*bf994817SAli Bahrami * 2) A function, which called with the Rel_desc descriptor, returns 49*bf994817SAli Bahrami * a string representing the name of the symbol associated with 50*bf994817SAli Bahrami * the descriptor. The usual function for this is ld_reloc_sym_name(). 51*bf994817SAli Bahrami * However, that function will not work in this case, as these synthetic 52*bf994817SAli Bahrami * relocations do not have an associated symbol. We supply the 53*bf994817SAli Bahrami * syn_rdesc_sym_name() function to simply return the fixed name. 54*bf994817SAli Bahrami */ 55*bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_gotpcrel = { 56*bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_GOTPCREL }; 57*bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_32 = { 58*bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_32 }; 59*bf994817SAli Bahrami static Rel_desc rdesc_r_amd64_pc32 = { 60*bf994817SAli Bahrami NULL, NULL, NULL, 0, 0, 0, R_AMD64_PC32 }; 61*bf994817SAli Bahrami 62*bf994817SAli Bahrami /*ARGSUSED*/ 63*bf994817SAli Bahrami static const char * 64*bf994817SAli Bahrami syn_rdesc_sym_name(Rel_desc *rdesc) 65*bf994817SAli Bahrami { 66*bf994817SAli Bahrami return (MSG_ORIG(MSG_SYM_PLTENT)); 67*bf994817SAli Bahrami } 68*bf994817SAli Bahrami 69*bf994817SAli Bahrami /* 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; 78ba2be530Sab196087 7957ef7aa9SRod Evans assert(rdesc != 0); 80ba2be530Sab196087 8157ef7aa9SRod Evans if ((gref == GOT_REF_TLSLD) && ofl->ofl_tlsldgotndx) 8257ef7aa9SRod Evans return (ofl->ofl_tlsldgotndx); 8357ef7aa9SRod Evans 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 } 9257ef7aa9SRod Evans 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 } 122ba2be530Sab196087 123ba2be530Sab196087 static Word 124*bf994817SAli Bahrami ld_init_rel(Rel_desc *reld, Word *typedata, void *reloc) 1255aefb655Srie { 1265aefb655Srie Rela *rel = (Rela *)reloc; 1275aefb655Srie 1285aefb655Srie /* LINTED */ 129ba2be530Sab196087 reld->rel_rtype = (Word)ELF_R_TYPE(rel->r_info, M_MACH); 1305aefb655Srie reld->rel_roffset = rel->r_offset; 1315aefb655Srie reld->rel_raddend = rel->r_addend; 132*bf994817SAli Bahrami *typedata = 0; 1335aefb655Srie 1345aefb655Srie reld->rel_flags |= FLG_REL_RELA; 1355aefb655Srie 1365aefb655Srie return ((Word)ELF_R_SYM(rel->r_info)); 1375aefb655Srie } 1385aefb655Srie 139ba2be530Sab196087 static void 1405aefb655Srie ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl) 1415aefb655Srie { 1425aefb655Srie ofl->ofl_dehdr->e_flags |= ehdr->e_flags; 1435aefb655Srie } 1445aefb655Srie 145ba2be530Sab196087 static void 1465aefb655Srie ld_mach_make_dynamic(Ofl_desc *ofl, size_t *cnt) 1475aefb655Srie { 1485aefb655Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) { 1495aefb655Srie /* 1505aefb655Srie * Create this entry if we are going to create a PLT table. 1515aefb655Srie */ 1525aefb655Srie if (ofl->ofl_pltcnt) 1535aefb655Srie (*cnt)++; /* DT_PLTGOT */ 1545aefb655Srie } 1555aefb655Srie } 1565aefb655Srie 157ba2be530Sab196087 static void 1585aefb655Srie ld_mach_update_odynamic(Ofl_desc *ofl, Dyn **dyn) 1595aefb655Srie { 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)++; 1675aefb655Srie } 1685aefb655Srie } 1695aefb655Srie 170ba2be530Sab196087 static Xword 1715aefb655Srie ld_calc_plt_addr(Sym_desc *sdp, Ofl_desc *ofl) 1725aefb655Srie { 1735aefb655Srie Xword value; 1745aefb655Srie 1755aefb655Srie value = (Xword)(ofl->ofl_osplt->os_shdr->sh_addr) + 1765aefb655Srie M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * M_PLT_ENTSIZE); 1775aefb655Srie return (value); 1785aefb655Srie } 1795aefb655Srie 1805aefb655Srie /* 1815aefb655Srie * Build a single plt entry - code is: 1825aefb655Srie * JMP *name1@GOTPCREL(%rip) 1835aefb655Srie * PUSHL $index 1845aefb655Srie * JMP .PLT0 1855aefb655Srie */ 1865aefb655Srie static uchar_t pltn_entry[M_PLT_ENTSIZE] = { 1875aefb655Srie /* 0x00 jmpq *name1@GOTPCREL(%rip) */ 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 1885aefb655Srie /* 0x06 pushq $index */ 0x68, 0x00, 0x00, 0x00, 0x00, 1895aefb655Srie /* 0x0b jmpq .plt0(%rip) */ 0xe9, 0x00, 0x00, 0x00, 0x00 1905aefb655Srie /* 0x10 */ 1915aefb655Srie }; 1925aefb655Srie 1935aefb655Srie static uintptr_t 1945aefb655Srie plt_entry(Ofl_desc * ofl, Sym_desc * sdp) 1955aefb655Srie { 1965aefb655Srie uchar_t *plt0, *pltent, *gotent; 1975aefb655Srie Sword plt_off; 1985aefb655Srie Word got_off; 1995aefb655Srie Xword val1; 200ba2be530Sab196087 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 2015aefb655Srie 2025aefb655Srie got_off = sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 2035aefb655Srie plt_off = M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * 2045aefb655Srie M_PLT_ENTSIZE); 2055aefb655Srie plt0 = (uchar_t *)(ofl->ofl_osplt->os_outdata->d_buf); 2065aefb655Srie pltent = plt0 + plt_off; 2075aefb655Srie gotent = (uchar_t *)(ofl->ofl_osgot->os_outdata->d_buf) + got_off; 2085aefb655Srie 2095aefb655Srie bcopy(pltn_entry, pltent, sizeof (pltn_entry)); 2105aefb655Srie /* 2115aefb655Srie * Fill in the got entry with the address of the next instruction. 2125aefb655Srie */ 2135aefb655Srie /* LINTED */ 2145aefb655Srie *(Word *)gotent = ofl->ofl_osplt->os_shdr->sh_addr + plt_off + 2155aefb655Srie M_PLT_INSSIZE; 216ba2be530Sab196087 if (bswap) 217ba2be530Sab196087 /* LINTED */ 218ba2be530Sab196087 *(Word *)gotent = ld_bswap_Word(*(Word *)gotent); 2195aefb655Srie 2205aefb655Srie /* 221f3324781Sab196087 * If '-z noreloc' is specified - skip the do_reloc_ld 222f3324781Sab196087 * stage. 223f3324781Sab196087 */ 224f3324781Sab196087 if (!OFL_DO_RELOC(ofl)) 225f3324781Sab196087 return (1); 226f3324781Sab196087 227f3324781Sab196087 /* 2285aefb655Srie * patchup: 2295aefb655Srie * jmpq *name1@gotpcrel(%rip) 2305aefb655Srie * 2315aefb655Srie * NOTE: 0x06 represents next instruction. 2325aefb655Srie */ 2335aefb655Srie val1 = (ofl->ofl_osgot->os_shdr->sh_addr + got_off) - 2345aefb655Srie (ofl->ofl_osplt->os_shdr->sh_addr + plt_off) - 0x06; 2355aefb655Srie 236*bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x02], &val1, 237*bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 238*bf994817SAli Bahrami ofl->ofl_lml) == 0) { 239f3324781Sab196087 eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 240f3324781Sab196087 sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 2415aefb655Srie return (S_ERROR); 2425aefb655Srie } 2435aefb655Srie 2445aefb655Srie /* 2455aefb655Srie * patchup: 2465aefb655Srie * pushq $pltndx 2475aefb655Srie */ 2485aefb655Srie val1 = (Xword)(sdp->sd_aux->sa_PLTndx - 1); 249f3324781Sab196087 250*bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_32, &pltent[0x07], &val1, 251*bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 252*bf994817SAli Bahrami ofl->ofl_lml) == 0) { 253f3324781Sab196087 eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 254f3324781Sab196087 sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 2555aefb655Srie return (S_ERROR); 2565aefb655Srie } 2575aefb655Srie 2585aefb655Srie /* 2595aefb655Srie * patchup: 2605aefb655Srie * jmpq .plt0(%rip) 261f3324781Sab196087 * NOTE: 0x10 represents next instruction. The rather complex 262f3324781Sab196087 * series of casts is necessary to sign extend an offset into 263f3324781Sab196087 * a 64-bit value while satisfying various compiler error 264f3324781Sab196087 * checks. Handle with care. 2655aefb655Srie */ 2665aefb655Srie val1 = (Xword)((intptr_t)((uintptr_t)plt0 - 2675aefb655Srie (uintptr_t)(&pltent[0x10]))); 2685aefb655Srie 269*bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_pc32, &pltent[0x0c], &val1, 270*bf994817SAli Bahrami syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), bswap, 271*bf994817SAli Bahrami ofl->ofl_lml) == 0) { 272f3324781Sab196087 eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_PLT_PLTNFAIL), 273f3324781Sab196087 sdp->sd_aux->sa_PLTndx, demangle(sdp->sd_name)); 2745aefb655Srie return (S_ERROR); 2755aefb655Srie } 276f3324781Sab196087 2775aefb655Srie return (1); 2785aefb655Srie } 2795aefb655Srie 280ba2be530Sab196087 static uintptr_t 2815aefb655Srie ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl) 2825aefb655Srie { 2835aefb655Srie Os_desc * relosp, * osp = 0; 2845aefb655Srie Word ndx; 2855aefb655Srie Xword roffset, value; 2865aefb655Srie Sxword raddend; 2875aefb655Srie Rela rea; 2885aefb655Srie char *relbits; 2895aefb655Srie Sym_desc * sdp, * psym = (Sym_desc *)0; 2905aefb655Srie int sectmoved = 0; 2915aefb655Srie 2925aefb655Srie raddend = orsp->rel_raddend; 2935aefb655Srie sdp = orsp->rel_sym; 2945aefb655Srie 2955aefb655Srie /* 2965aefb655Srie * If the section this relocation is against has been discarded 2975aefb655Srie * (-zignore), then also discard (skip) the relocation itself. 2985aefb655Srie */ 2995aefb655Srie if (orsp->rel_isdesc && ((orsp->rel_flags & 3005aefb655Srie (FLG_REL_GOT | FLG_REL_BSS | FLG_REL_PLT | FLG_REL_NOINFO)) == 0) && 3015aefb655Srie (orsp->rel_isdesc->is_flags & FLG_IS_DISCARD)) { 3025aefb655Srie DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, orsp)); 3035aefb655Srie return (1); 3045aefb655Srie } 3055aefb655Srie 3065aefb655Srie /* 3075aefb655Srie * If this is a relocation against a move table, or expanded move 3085aefb655Srie * table, adjust the relocation entries. 3095aefb655Srie */ 310*bf994817SAli Bahrami if (RELAUX_GET_MOVE(orsp)) 3115aefb655Srie ld_adj_movereloc(ofl, orsp); 3125aefb655Srie 3135aefb655Srie /* 3145aefb655Srie * If this is a relocation against a section then we need to adjust the 3155aefb655Srie * raddend field to compensate for the new position of the input section 3165aefb655Srie * within the new output section. 3175aefb655Srie */ 3185aefb655Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 31957ef7aa9SRod Evans if (ofl->ofl_parsyms && 3205aefb655Srie (sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 3215aefb655Srie /* LINTED */ 3225aefb655Srie (psym = ld_am_I_partial(orsp, orsp->rel_raddend))) { 3235aefb655Srie DBG_CALL(Dbg_move_outsctadj(ofl->ofl_lml, psym)); 3245aefb655Srie sectmoved = 1; 3255aefb655Srie if (ofl->ofl_flags & FLG_OF_RELOBJ) 3265aefb655Srie raddend = psym->sd_sym->st_value; 3275aefb655Srie else 3285aefb655Srie raddend = psym->sd_sym->st_value - 3295aefb655Srie psym->sd_isc->is_osdesc->os_shdr->sh_addr; 3305aefb655Srie /* LINTED */ 3315aefb655Srie raddend += (Off)_elf_getxoff(psym->sd_isc->is_indata); 3325aefb655Srie if (psym->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 3335aefb655Srie raddend += 3345aefb655Srie psym->sd_isc->is_osdesc->os_shdr->sh_addr; 3355aefb655Srie } else { 3365aefb655Srie /* LINTED */ 3375aefb655Srie raddend += (Off)_elf_getxoff(sdp->sd_isc->is_indata); 3385aefb655Srie if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 3395aefb655Srie raddend += 3405aefb655Srie sdp->sd_isc->is_osdesc->os_shdr->sh_addr; 3415aefb655Srie } 3425aefb655Srie } 3435aefb655Srie 3445aefb655Srie value = sdp->sd_sym->st_value; 3455aefb655Srie 3465aefb655Srie if (orsp->rel_flags & FLG_REL_GOT) { 3475aefb655Srie /* 3485aefb655Srie * Note: for GOT relative relocations on amd64 3495aefb655Srie * we discard the addend. It was relevant 3505aefb655Srie * to the reference - not to the data item 3515aefb655Srie * being referenced (ie: that -4 thing). 3525aefb655Srie */ 3535aefb655Srie raddend = 0; 3545aefb655Srie osp = ofl->ofl_osgot; 3555aefb655Srie roffset = ld_calc_got_offset(orsp, ofl); 3565aefb655Srie 3575aefb655Srie } else if (orsp->rel_flags & FLG_REL_PLT) { 3585aefb655Srie /* 3595aefb655Srie * Note that relocations for PLT's actually 3605aefb655Srie * cause a relocation againt the GOT. 3615aefb655Srie */ 3625aefb655Srie osp = ofl->ofl_osplt; 3635aefb655Srie roffset = (ofl->ofl_osgot->os_shdr->sh_addr) + 3645aefb655Srie sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 3655aefb655Srie raddend = 0; 3665aefb655Srie if (plt_entry(ofl, sdp) == S_ERROR) 3675aefb655Srie return (S_ERROR); 3685aefb655Srie 3695aefb655Srie } else if (orsp->rel_flags & FLG_REL_BSS) { 3705aefb655Srie /* 3715aefb655Srie * This must be a R_AMD64_COPY. For these set the roffset to 3725aefb655Srie * point to the new symbols location. 3735aefb655Srie */ 3745aefb655Srie osp = ofl->ofl_isbss->is_osdesc; 3755aefb655Srie roffset = value; 3765aefb655Srie 3775aefb655Srie /* 3785aefb655Srie * The raddend doesn't mean anything in a R_SPARC_COPY 3795aefb655Srie * relocation. Null it out because it can confuse people. 3805aefb655Srie */ 3815aefb655Srie raddend = 0; 3825aefb655Srie } else { 383*bf994817SAli Bahrami osp = RELAUX_GET_OSDESC(orsp); 3845aefb655Srie 3855aefb655Srie /* 3865aefb655Srie * Calculate virtual offset of reference point; equals offset 3875aefb655Srie * into section + vaddr of section for loadable sections, or 3885aefb655Srie * offset plus section displacement for nonloadable sections. 3895aefb655Srie */ 3905aefb655Srie roffset = orsp->rel_roffset + 3915aefb655Srie (Off)_elf_getxoff(orsp->rel_isdesc->is_indata); 3925aefb655Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) 3935aefb655Srie roffset += orsp->rel_isdesc->is_osdesc-> 3945aefb655Srie os_shdr->sh_addr; 3955aefb655Srie } 3965aefb655Srie 3975aefb655Srie if ((osp == 0) || ((relosp = osp->os_relosdesc) == 0)) 3985aefb655Srie relosp = ofl->ofl_osrel; 3995aefb655Srie 4005aefb655Srie /* 4015aefb655Srie * Assign the symbols index for the output relocation. If the 4025aefb655Srie * relocation refers to a SECTION symbol then it's index is based upon 4035aefb655Srie * the output sections symbols index. Otherwise the index can be 4045aefb655Srie * derived from the symbols index itself. 4055aefb655Srie */ 4065aefb655Srie if (orsp->rel_rtype == R_AMD64_RELATIVE) 4075aefb655Srie ndx = STN_UNDEF; 4085aefb655Srie else if ((orsp->rel_flags & FLG_REL_SCNNDX) || 4095aefb655Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION)) { 4105aefb655Srie if (sectmoved == 0) { 4115aefb655Srie /* 4125aefb655Srie * Check for a null input section. This can 4135aefb655Srie * occur if this relocation references a symbol 4145aefb655Srie * generated by sym_add_sym(). 4155aefb655Srie */ 41657ef7aa9SRod Evans if (sdp->sd_isc && sdp->sd_isc->is_osdesc) 41757ef7aa9SRod Evans ndx = sdp->sd_isc->is_osdesc->os_identndx; 4185aefb655Srie else 4195aefb655Srie ndx = sdp->sd_shndx; 4205aefb655Srie } else 42135450702SAli Bahrami ndx = ofl->ofl_parexpnndx; 4225aefb655Srie } else 4235aefb655Srie ndx = sdp->sd_symndx; 4245aefb655Srie 4255aefb655Srie /* 4265aefb655Srie * Add the symbols 'value' to the addend field. 4275aefb655Srie */ 4285aefb655Srie if (orsp->rel_flags & FLG_REL_ADVAL) 4295aefb655Srie raddend += value; 4305aefb655Srie 4315aefb655Srie /* 4327010c12aSrie * The addend field for R_AMD64_DTPMOD64 means nothing. The addend 4337010c12aSrie * is propagated in the corresponding R_AMD64_DTPOFF64 relocation. 4345aefb655Srie */ 4355aefb655Srie if (orsp->rel_rtype == R_AMD64_DTPMOD64) 4365aefb655Srie raddend = 0; 4375aefb655Srie 4385aefb655Srie relbits = (char *)relosp->os_outdata->d_buf; 4395aefb655Srie 4405aefb655Srie rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); 4415aefb655Srie rea.r_offset = roffset; 4425aefb655Srie rea.r_addend = raddend; 4435aefb655Srie DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_RELA, &rea, relosp->os_name, 444*bf994817SAli Bahrami ld_reloc_sym_name(orsp))); 4455aefb655Srie 4465aefb655Srie /* 4475aefb655Srie * Assert we haven't walked off the end of our relocation table. 4485aefb655Srie */ 4495aefb655Srie assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); 4505aefb655Srie 4515aefb655Srie (void) memcpy((relbits + relosp->os_szoutrels), 4525aefb655Srie (char *)&rea, sizeof (Rela)); 4535aefb655Srie relosp->os_szoutrels += (Xword)sizeof (Rela); 4545aefb655Srie 4555aefb655Srie /* 4565aefb655Srie * Determine if this relocation is against a non-writable, allocatable 4575aefb655Srie * section. If so we may need to provide a text relocation diagnostic. 4585aefb655Srie * Note that relocations against the .plt (R_AMD64_JUMP_SLOT) actually 4595aefb655Srie * result in modifications to the .got. 4605aefb655Srie */ 4615aefb655Srie if (orsp->rel_rtype == R_AMD64_JUMP_SLOT) 4625aefb655Srie osp = ofl->ofl_osgot; 4635aefb655Srie 4645aefb655Srie ld_reloc_remain_entry(orsp, osp, ofl); 4655aefb655Srie return (1); 4665aefb655Srie } 4675aefb655Srie 4685aefb655Srie /* 4695aefb655Srie * amd64 Instructions for TLS processing 4705aefb655Srie */ 4715aefb655Srie static uchar_t tlsinstr_gd_ie[] = { 4725aefb655Srie /* 4735aefb655Srie * 0x00 movq %fs:0, %rax 4745aefb655Srie */ 4755aefb655Srie 0x64, 0x48, 0x8b, 0x04, 0x25, 4765aefb655Srie 0x00, 0x00, 0x00, 0x00, 4775aefb655Srie /* 4785aefb655Srie * 0x09 addq x@gottpoff(%rip), %rax 4795aefb655Srie */ 4805aefb655Srie 0x48, 0x03, 0x05, 0x00, 0x00, 4815aefb655Srie 0x00, 0x00 4825aefb655Srie }; 4835aefb655Srie 4845aefb655Srie static uchar_t tlsinstr_gd_le[] = { 4855aefb655Srie /* 4865aefb655Srie * 0x00 movq %fs:0, %rax 4875aefb655Srie */ 4885aefb655Srie 0x64, 0x48, 0x8b, 0x04, 0x25, 4895aefb655Srie 0x00, 0x00, 0x00, 0x00, 4905aefb655Srie /* 4915aefb655Srie * 0x09 leaq x@gottpoff(%rip), %rax 4925aefb655Srie */ 4935aefb655Srie 0x48, 0x8d, 0x80, 0x00, 0x00, 4945aefb655Srie 0x00, 0x00 4955aefb655Srie }; 4965aefb655Srie 4975aefb655Srie static uchar_t tlsinstr_ld_le[] = { 4985aefb655Srie /* 4995aefb655Srie * .byte 0x66 5005aefb655Srie */ 5015aefb655Srie 0x66, 5025aefb655Srie /* 5035aefb655Srie * .byte 0x66 5045aefb655Srie */ 5055aefb655Srie 0x66, 5065aefb655Srie /* 5075aefb655Srie * .byte 0x66 5085aefb655Srie */ 5095aefb655Srie 0x66, 5105aefb655Srie /* 5115aefb655Srie * movq %fs:0, %rax 5125aefb655Srie */ 5135aefb655Srie 0x64, 0x48, 0x8b, 0x04, 0x25, 5145aefb655Srie 0x00, 0x00, 0x00, 0x00 5155aefb655Srie }; 5165aefb655Srie 5175aefb655Srie 5185aefb655Srie static Fixupret 5195aefb655Srie tls_fixups(Ofl_desc *ofl, Rel_desc *arsp) 5205aefb655Srie { 5215aefb655Srie Sym_desc *sdp = arsp->rel_sym; 5225aefb655Srie Word rtype = arsp->rel_rtype; 5235aefb655Srie uchar_t *offset; 5245aefb655Srie 5255aefb655Srie offset = (uchar_t *)((uintptr_t)arsp->rel_roffset + 5265aefb655Srie (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata) + 527*bf994817SAli Bahrami (uintptr_t)RELAUX_GET_OSDESC(arsp)->os_outdata->d_buf); 5285aefb655Srie 5295aefb655Srie if (sdp->sd_ref == REF_DYN_NEED) { 5305aefb655Srie /* 5315aefb655Srie * IE reference model 5325aefb655Srie */ 5335aefb655Srie switch (rtype) { 5345aefb655Srie case R_AMD64_TLSGD: 5355aefb655Srie /* 5365aefb655Srie * GD -> IE 5375aefb655Srie * 5385aefb655Srie * Transition: 5395aefb655Srie * 0x00 .byte 0x66 5405aefb655Srie * 0x01 leaq x@tlsgd(%rip), %rdi 5415aefb655Srie * 0x08 .word 0x6666 5425aefb655Srie * 0x0a rex64 5435aefb655Srie * 0x0b call __tls_get_addr@plt 5445aefb655Srie * 0x10 5455aefb655Srie * To: 5465aefb655Srie * 0x00 movq %fs:0, %rax 5475aefb655Srie * 0x09 addq x@gottpoff(%rip), %rax 5485aefb655Srie * 0x10 5495aefb655Srie */ 5505aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 551*bf994817SAli Bahrami R_AMD64_GOTTPOFF, arsp, ld_reloc_sym_name)); 5525aefb655Srie arsp->rel_rtype = R_AMD64_GOTTPOFF; 5535aefb655Srie arsp->rel_roffset += 8; 5545aefb655Srie arsp->rel_raddend = (Sxword)-4; 5555aefb655Srie 5565aefb655Srie /* 557051d39bbSrie * Adjust 'offset' to beginning of instruction 5585aefb655Srie * sequence. 5595aefb655Srie */ 5605aefb655Srie offset -= 4; 5615aefb655Srie (void) memcpy(offset, tlsinstr_gd_ie, 5625aefb655Srie sizeof (tlsinstr_gd_ie)); 5635aefb655Srie return (FIX_RELOC); 5645aefb655Srie 5655aefb655Srie case R_AMD64_PLT32: 5665aefb655Srie /* 567051d39bbSrie * Fixup done via the TLS_GD relocation. 5685aefb655Srie */ 5695aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 570*bf994817SAli Bahrami R_AMD64_NONE, arsp, ld_reloc_sym_name)); 5715aefb655Srie return (FIX_DONE); 5725aefb655Srie } 5735aefb655Srie } 5745aefb655Srie 5755aefb655Srie /* 5765aefb655Srie * LE reference model 5775aefb655Srie */ 5785aefb655Srie switch (rtype) { 5795aefb655Srie case R_AMD64_TLSGD: 5805aefb655Srie /* 5815aefb655Srie * GD -> LE 5825aefb655Srie * 5835aefb655Srie * Transition: 5845aefb655Srie * 0x00 .byte 0x66 5855aefb655Srie * 0x01 leaq x@tlsgd(%rip), %rdi 5865aefb655Srie * 0x08 .word 0x6666 5875aefb655Srie * 0x0a rex64 5885aefb655Srie * 0x0b call __tls_get_addr@plt 5895aefb655Srie * 0x10 5905aefb655Srie * To: 5915aefb655Srie * 0x00 movq %fs:0, %rax 5925aefb655Srie * 0x09 leaq x@tpoff(%rax), %rax 5935aefb655Srie * 0x10 5945aefb655Srie */ 5955aefb655Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 596*bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 5975aefb655Srie arsp->rel_rtype = R_AMD64_TPOFF32; 5985aefb655Srie arsp->rel_roffset += 8; 5995aefb655Srie arsp->rel_raddend = 0; 6005aefb655Srie 6015aefb655Srie /* 602051d39bbSrie * Adjust 'offset' to beginning of instruction sequence. 6035aefb655Srie */ 6045aefb655Srie offset -= 4; 6055aefb655Srie (void) memcpy(offset, tlsinstr_gd_le, sizeof (tlsinstr_gd_le)); 6065aefb655Srie return (FIX_RELOC); 6075aefb655Srie 6085aefb655Srie case R_AMD64_GOTTPOFF: 6095aefb655Srie /* 6105aefb655Srie * IE -> LE 6115aefb655Srie * 6125aefb655Srie * Transition: 6135aefb655Srie * 0x00 movq %fs:0, %rax 6145aefb655Srie * 0x09 addq x@gottopoff(%rip), %rax 6155aefb655Srie * 0x10 6165aefb655Srie * To: 6175aefb655Srie * 0x00 movq %fs:0, %rax 6185aefb655Srie * 0x09 leaq x@tpoff(%rax), %rax 6195aefb655Srie * 0x10 6205aefb655Srie */ 621051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 622*bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 6235aefb655Srie arsp->rel_rtype = R_AMD64_TPOFF32; 6245aefb655Srie arsp->rel_raddend = 0; 6255aefb655Srie 6265aefb655Srie /* 627051d39bbSrie * Adjust 'offset' to beginning of instruction sequence. 6285aefb655Srie */ 6295aefb655Srie offset -= 12; 6305aefb655Srie 6315aefb655Srie /* 632051d39bbSrie * Same code sequence used in the GD -> LE transition. 6335aefb655Srie */ 6345aefb655Srie (void) memcpy(offset, tlsinstr_gd_le, sizeof (tlsinstr_gd_le)); 6355aefb655Srie return (FIX_RELOC); 6365aefb655Srie 6375aefb655Srie case R_AMD64_TLSLD: 6385aefb655Srie /* 6395aefb655Srie * LD -> LE 6405aefb655Srie * 6415aefb655Srie * Transition 6425aefb655Srie * 0x00 leaq x1@tlsgd(%rip), %rdi 6435aefb655Srie * 0x07 call __tls_get_addr@plt 6445aefb655Srie * 0x0c 6455aefb655Srie * To: 6465aefb655Srie * 0x00 .byte 0x66 6475aefb655Srie * 0x01 .byte 0x66 6485aefb655Srie * 0x02 .byte 0x66 6495aefb655Srie * 0x03 movq %fs:0, %rax 6505aefb655Srie */ 651051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 652*bf994817SAli Bahrami R_AMD64_NONE, arsp, ld_reloc_sym_name)); 6535aefb655Srie offset -= 3; 6545aefb655Srie (void) memcpy(offset, tlsinstr_ld_le, sizeof (tlsinstr_ld_le)); 6555aefb655Srie return (FIX_DONE); 6565aefb655Srie 6575aefb655Srie case R_AMD64_DTPOFF32: 6585aefb655Srie /* 6595aefb655Srie * LD->LE 6605aefb655Srie * 6615aefb655Srie * Transition: 6625aefb655Srie * 0x00 leaq x1@dtpoff(%rax), %rcx 6635aefb655Srie * To: 6645aefb655Srie * 0x00 leaq x1@tpoff(%rax), %rcx 6655aefb655Srie */ 666051d39bbSrie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 667*bf994817SAli Bahrami R_AMD64_TPOFF32, arsp, ld_reloc_sym_name)); 6685aefb655Srie arsp->rel_rtype = R_AMD64_TPOFF32; 6695aefb655Srie arsp->rel_raddend = 0; 6705aefb655Srie return (FIX_RELOC); 6715aefb655Srie } 6725aefb655Srie 6735aefb655Srie return (FIX_RELOC); 6745aefb655Srie } 6755aefb655Srie 676ba2be530Sab196087 static uintptr_t 6775aefb655Srie ld_do_activerelocs(Ofl_desc *ofl) 6785aefb655Srie { 6795aefb655Srie Rel_desc *arsp; 680*bf994817SAli Bahrami Rel_cachebuf *rcbp; 68157ef7aa9SRod Evans Aliste idx; 6825aefb655Srie uintptr_t return_code = 1; 6831d9df23bSab196087 ofl_flag_t flags = ofl->ofl_flags; 6845aefb655Srie 685*bf994817SAli Bahrami if (aplist_nitems(ofl->ofl_actrels.rc_list) != 0) 6865aefb655Srie DBG_CALL(Dbg_reloc_doact_title(ofl->ofl_lml)); 6877010c12aSrie 6885aefb655Srie /* 6895aefb655Srie * Process active relocations. 6905aefb655Srie */ 691*bf994817SAli Bahrami REL_CACHE_TRAVERSE(&ofl->ofl_actrels, idx, rcbp, arsp) { 6925aefb655Srie uchar_t *addr; 6935aefb655Srie Xword value; 6945aefb655Srie Sym_desc *sdp; 6955aefb655Srie const char *ifl_name; 6965aefb655Srie Xword refaddr; 6975aefb655Srie int moved = 0; 6985aefb655Srie Gotref gref; 699*bf994817SAli Bahrami Os_desc *osp; 7005aefb655Srie 7015aefb655Srie /* 702*bf994817SAli Bahrami * If the section this relocation is against has been discarded 703*bf994817SAli Bahrami * (-zignore), then discard (skip) the relocation itself. 7045aefb655Srie */ 7055aefb655Srie if ((arsp->rel_isdesc->is_flags & FLG_IS_DISCARD) && 706*bf994817SAli Bahrami ((arsp->rel_flags & (FLG_REL_GOT | FLG_REL_BSS | 7075aefb655Srie FLG_REL_PLT | FLG_REL_NOINFO)) == 0)) { 708*bf994817SAli Bahrami DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, arsp)); 7095aefb655Srie continue; 7105aefb655Srie } 7115aefb655Srie 7125aefb655Srie /* 713*bf994817SAli Bahrami * We determine what the 'got reference' model (if required) 714*bf994817SAli Bahrami * is at this point. This needs to be done before tls_fixup() 715*bf994817SAli Bahrami * since it may 'transition' our instructions. 7165aefb655Srie * 7175aefb655Srie * The got table entries have already been assigned, 7185aefb655Srie * and we bind to those initial entries. 7195aefb655Srie */ 7205aefb655Srie if (arsp->rel_flags & FLG_REL_DTLS) 7215aefb655Srie gref = GOT_REF_TLSGD; 7225aefb655Srie else if (arsp->rel_flags & FLG_REL_MTLS) 7235aefb655Srie gref = GOT_REF_TLSLD; 7245aefb655Srie else if (arsp->rel_flags & FLG_REL_STLS) 7255aefb655Srie gref = GOT_REF_TLSIE; 7265aefb655Srie else 7275aefb655Srie gref = GOT_REF_GENERIC; 7285aefb655Srie 7295aefb655Srie /* 7305aefb655Srie * Perform any required TLS fixups. 7315aefb655Srie */ 7325aefb655Srie if (arsp->rel_flags & FLG_REL_TLSFIX) { 7335aefb655Srie Fixupret ret; 7345aefb655Srie 7355aefb655Srie if ((ret = tls_fixups(ofl, arsp)) == FIX_ERROR) 7365aefb655Srie return (S_ERROR); 7375aefb655Srie if (ret == FIX_DONE) 7385aefb655Srie continue; 7395aefb655Srie } 7405aefb655Srie 7415aefb655Srie /* 7425aefb655Srie * If this is a relocation against a move table, or 7435aefb655Srie * expanded move table, adjust the relocation entries. 7445aefb655Srie */ 745*bf994817SAli Bahrami if (RELAUX_GET_MOVE(arsp)) 7465aefb655Srie ld_adj_movereloc(ofl, arsp); 7475aefb655Srie 7485aefb655Srie sdp = arsp->rel_sym; 7495aefb655Srie refaddr = arsp->rel_roffset + 7505aefb655Srie (Off)_elf_getxoff(arsp->rel_isdesc->is_indata); 7515aefb655Srie 7525aefb655Srie if ((arsp->rel_flags & FLG_REL_CLVAL) || 7535aefb655Srie (arsp->rel_flags & FLG_REL_GOTCL)) 7545aefb655Srie value = 0; 755*bf994817SAli Bahrami else if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 7565aefb655Srie Sym_desc *sym; 7575aefb655Srie 7585aefb655Srie /* 7595aefb655Srie * The value for a symbol pointing to a SECTION 7605aefb655Srie * is based off of that sections position. 7615aefb655Srie */ 7625aefb655Srie if ((sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 7635aefb655Srie /* LINTED */ 764*bf994817SAli Bahrami (sym = ld_am_I_partial(arsp, arsp->rel_raddend))) { 7655aefb655Srie /* 766*bf994817SAli Bahrami * The symbol was moved, so adjust the value 767*bf994817SAli Bahrami * relative to the new section. 7685aefb655Srie */ 7695aefb655Srie value = sym->sd_sym->st_value; 7705aefb655Srie moved = 1; 771b26cc8daSAli Bahrami 772b26cc8daSAli Bahrami /* 773*bf994817SAli Bahrami * The original raddend covers the displacement 774*bf994817SAli Bahrami * from the section start to the desired 775*bf994817SAli Bahrami * address. The value computed above gets us 776*bf994817SAli Bahrami * from the section start to the start of the 777*bf994817SAli Bahrami * symbol range. Adjust the old raddend to 778*bf994817SAli Bahrami * remove the offset from section start to 779*bf994817SAli Bahrami * symbol start, leaving the displacement 780*bf994817SAli Bahrami * within the range of the symbol. 781b26cc8daSAli Bahrami */ 782*bf994817SAli Bahrami arsp->rel_raddend -= sym->sd_osym->st_value; 7835aefb655Srie } else { 784*bf994817SAli Bahrami value = _elf_getxoff(sdp->sd_isc->is_indata); 785*bf994817SAli Bahrami if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 786*bf994817SAli Bahrami value += sdp->sd_isc->is_osdesc-> 7875aefb655Srie os_shdr->sh_addr; 7885aefb655Srie } 7895aefb655Srie if (sdp->sd_isc->is_shdr->sh_flags & SHF_TLS) 7905aefb655Srie value -= ofl->ofl_tlsphdr->p_vaddr; 7912926dd2eSrie 7922926dd2eSrie } else if (IS_SIZE(arsp->rel_rtype)) { 7932926dd2eSrie /* 7942926dd2eSrie * Size relocations require the symbols size. 7952926dd2eSrie */ 7962926dd2eSrie value = sdp->sd_sym->st_size; 79708278a5eSRod Evans 79808278a5eSRod Evans } else if ((sdp->sd_flags & FLG_SY_CAP) && 79908278a5eSRod Evans sdp->sd_aux && sdp->sd_aux->sa_PLTndx) { 8005aefb655Srie /* 801*bf994817SAli Bahrami * If relocation is against a capabilities symbol, we 802*bf994817SAli Bahrami * need to jump to an associated PLT, so that at runtime 803*bf994817SAli Bahrami * ld.so.1 is involved to determine the best binding 804*bf994817SAli Bahrami * choice. Otherwise, the value is the symbols value. 8055aefb655Srie */ 80608278a5eSRod Evans value = ld_calc_plt_addr(sdp, ofl); 80708278a5eSRod Evans } else 8085aefb655Srie value = sdp->sd_sym->st_value; 8095aefb655Srie 8105aefb655Srie /* 8115aefb655Srie * Relocation against the GLOBAL_OFFSET_TABLE. 8125aefb655Srie */ 813*bf994817SAli Bahrami if ((arsp->rel_flags & FLG_REL_GOT) && 814*bf994817SAli Bahrami !ld_reloc_set_aux_osdesc(ofl, arsp, ofl->ofl_osgot)) 815*bf994817SAli Bahrami return (S_ERROR); 816*bf994817SAli Bahrami osp = RELAUX_GET_OSDESC(arsp); 8175aefb655Srie 8185aefb655Srie /* 819*bf994817SAli Bahrami * If loadable and not producing a relocatable object add the 820*bf994817SAli Bahrami * sections virtual address to the reference address. 8215aefb655Srie */ 8225aefb655Srie if ((arsp->rel_flags & FLG_REL_LOAD) && 8235aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) 8245aefb655Srie refaddr += arsp->rel_isdesc->is_osdesc-> 8255aefb655Srie os_shdr->sh_addr; 8265aefb655Srie 8275aefb655Srie /* 828*bf994817SAli Bahrami * If this entry has a PLT assigned to it, its value is actually 829*bf994817SAli Bahrami * the address of the PLT (and not the address of the function). 8305aefb655Srie */ 8315aefb655Srie if (IS_PLT(arsp->rel_rtype)) { 8325aefb655Srie if (sdp->sd_aux && sdp->sd_aux->sa_PLTndx) 8335aefb655Srie value = ld_calc_plt_addr(sdp, ofl); 8345aefb655Srie } 8355aefb655Srie 8365aefb655Srie /* 8375aefb655Srie * Add relocations addend to value. Add extra 8385aefb655Srie * relocation addend if needed. 8395aefb655Srie * 840*bf994817SAli Bahrami * Note: For GOT relative relocations on amd64 we discard the 841*bf994817SAli Bahrami * addend. It was relevant to the reference - not to the 842*bf994817SAli Bahrami * data item being referenced (ie: that -4 thing). 8435aefb655Srie */ 8445aefb655Srie if ((arsp->rel_flags & FLG_REL_GOT) == 0) 845bf2f215aSAli Bahrami value += arsp->rel_raddend; 8465aefb655Srie 8475aefb655Srie /* 848*bf994817SAli Bahrami * Determine whether the value needs further adjustment. Filter 849*bf994817SAli Bahrami * through the attributes of the relocation to determine what 850*bf994817SAli Bahrami * adjustment is required. Note, many of the following cases 851*bf994817SAli Bahrami * are only applicable when a .got is present. As a .got is 852*bf994817SAli Bahrami * not generated when a relocatable object is being built, 853*bf994817SAli Bahrami * any adjustments that require a .got need to be skipped. 8545aefb655Srie */ 8555aefb655Srie if ((arsp->rel_flags & FLG_REL_GOT) && 8565aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8575aefb655Srie Xword R1addr; 8585aefb655Srie uintptr_t R2addr; 8595aefb655Srie Word gotndx; 8605aefb655Srie Gotndx *gnp; 8615aefb655Srie 8625aefb655Srie /* 863*bf994817SAli Bahrami * Perform relocation against GOT table. Since this 864*bf994817SAli Bahrami * doesn't fit exactly into a relocation we place the 865*bf994817SAli Bahrami * appropriate byte in the GOT directly 8665aefb655Srie * 8675aefb655Srie * Calculate offset into GOT at which to apply 8685aefb655Srie * the relocation. 8695aefb655Srie */ 870*bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 8715aefb655Srie assert(gnp); 8725aefb655Srie 8735aefb655Srie if (arsp->rel_rtype == R_AMD64_DTPOFF64) 8745aefb655Srie gotndx = gnp->gn_gotndx + 1; 8755aefb655Srie else 8765aefb655Srie gotndx = gnp->gn_gotndx; 8775aefb655Srie 8785aefb655Srie R1addr = (Xword)(gotndx * M_GOT_ENTSIZE); 8795aefb655Srie 8805aefb655Srie /* 8815aefb655Srie * Add the GOTs data's offset. 8825aefb655Srie */ 883*bf994817SAli Bahrami R2addr = R1addr + (uintptr_t)osp->os_outdata->d_buf; 8845aefb655Srie 885*bf994817SAli Bahrami DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 886*bf994817SAli Bahrami M_MACH, SHT_RELA, arsp, R1addr, value, 887*bf994817SAli Bahrami ld_reloc_sym_name)); 8885aefb655Srie 8895aefb655Srie /* 8905aefb655Srie * And do it. 8915aefb655Srie */ 892f3324781Sab196087 if (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) 893*bf994817SAli Bahrami *(Xword *)R2addr = ld_bswap_Xword(value); 894f3324781Sab196087 else 8955aefb655Srie *(Xword *)R2addr = value; 8965aefb655Srie continue; 8975aefb655Srie 8985aefb655Srie } else if (IS_GOT_BASED(arsp->rel_rtype) && 8995aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9005aefb655Srie value -= ofl->ofl_osgot->os_shdr->sh_addr; 9015aefb655Srie 9025aefb655Srie } else if (IS_GOTPCREL(arsp->rel_rtype) && 9035aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9045aefb655Srie Gotndx *gnp; 9055aefb655Srie 9065aefb655Srie /* 9075aefb655Srie * Calculation: 9085aefb655Srie * G + GOT + A - P 9095aefb655Srie */ 910*bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 9115aefb655Srie assert(gnp); 912*bf994817SAli Bahrami value = (Xword)(ofl->ofl_osgot->os_shdr-> sh_addr) + 913*bf994817SAli Bahrami ((Xword)gnp->gn_gotndx * M_GOT_ENTSIZE) + 914*bf994817SAli Bahrami arsp->rel_raddend - refaddr; 9155aefb655Srie 9165aefb655Srie } else if (IS_GOT_PC(arsp->rel_rtype) && 9175aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9185aefb655Srie value = (Xword)(ofl->ofl_osgot->os_shdr-> 9195aefb655Srie sh_addr) - refaddr + arsp->rel_raddend; 9205aefb655Srie 9215aefb655Srie } else if ((IS_PC_RELATIVE(arsp->rel_rtype)) && 9225aefb655Srie (((flags & FLG_OF_RELOBJ) == 0) || 923*bf994817SAli Bahrami (osp == sdp->sd_isc->is_osdesc))) { 9245aefb655Srie value -= refaddr; 9255aefb655Srie 9265aefb655Srie } else if (IS_TLS_INS(arsp->rel_rtype) && 9275aefb655Srie IS_GOT_RELATIVE(arsp->rel_rtype) && 9285aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9295aefb655Srie Gotndx *gnp; 9305aefb655Srie 931*bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 9325aefb655Srie assert(gnp); 9335aefb655Srie value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 9345aefb655Srie 9355aefb655Srie } else if (IS_GOT_RELATIVE(arsp->rel_rtype) && 9365aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9375aefb655Srie Gotndx *gnp; 9385aefb655Srie 939*bf994817SAli Bahrami gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, arsp); 9405aefb655Srie assert(gnp); 9415aefb655Srie value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 9425aefb655Srie 9435aefb655Srie } else if ((arsp->rel_flags & FLG_REL_STLS) && 9445aefb655Srie ((flags & FLG_OF_RELOBJ) == 0)) { 9455aefb655Srie Xword tlsstatsize; 9465aefb655Srie 9475aefb655Srie /* 9485aefb655Srie * This is the LE TLS reference model. Static 9495aefb655Srie * offset is hard-coded. 9505aefb655Srie */ 951*bf994817SAli Bahrami tlsstatsize = S_ROUND(ofl->ofl_tlsphdr->p_memsz, 9525aefb655Srie M_TLSSTATALIGN); 9535aefb655Srie value = tlsstatsize - value; 9545aefb655Srie 9555aefb655Srie /* 956*bf994817SAli Bahrami * Since this code is fixed up, it assumes a negative 957*bf994817SAli Bahrami * offset that can be added to the thread pointer. 9585aefb655Srie */ 9595aefb655Srie if (arsp->rel_rtype == R_AMD64_TPOFF32) 9605aefb655Srie value = -value; 9615aefb655Srie } 9625aefb655Srie 9635aefb655Srie if (arsp->rel_isdesc->is_file) 9645aefb655Srie ifl_name = arsp->rel_isdesc->is_file->ifl_name; 9655aefb655Srie else 9665aefb655Srie ifl_name = MSG_INTL(MSG_STR_NULL); 9675aefb655Srie 9685aefb655Srie /* 969*bf994817SAli Bahrami * Make sure we have data to relocate. Compiler and assembler 970*bf994817SAli Bahrami * developers have been known to generate relocations against 971*bf994817SAli Bahrami * invalid sections (normally .bss), so for their benefit give 972*bf994817SAli Bahrami * them sufficient information to help analyze the problem. 973*bf994817SAli Bahrami * End users should never see this. 9745aefb655Srie */ 9755aefb655Srie if (arsp->rel_isdesc->is_indata->d_buf == 0) { 976de777a60Sab196087 Conv_inv_buf_t inv_buf; 977de777a60Sab196087 9785aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 9795aefb655Srie MSG_INTL(MSG_REL_EMPTYSEC), 980*bf994817SAli Bahrami conv_reloc_amd64_type(arsp->rel_rtype, 0, &inv_buf), 981*bf994817SAli Bahrami ifl_name, ld_reloc_sym_name(arsp), 9824a8d0ea7SAli Bahrami EC_WORD(arsp->rel_isdesc->is_scnndx), 9835aefb655Srie arsp->rel_isdesc->is_name); 9845aefb655Srie return (S_ERROR); 9855aefb655Srie } 9865aefb655Srie 9875aefb655Srie /* 9885aefb655Srie * Get the address of the data item we need to modify. 9895aefb655Srie */ 9905aefb655Srie addr = (uchar_t *)((uintptr_t)arsp->rel_roffset + 991*bf994817SAli Bahrami (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata)); 9925aefb655Srie 993635216b6SRod Evans DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 994*bf994817SAli Bahrami M_MACH, SHT_RELA, arsp, EC_NATPTR(addr), value, 995*bf994817SAli Bahrami ld_reloc_sym_name)); 996*bf994817SAli Bahrami addr += (uintptr_t)osp->os_outdata->d_buf; 9975aefb655Srie 9985aefb655Srie if ((((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 9995aefb655Srie ofl->ofl_size) || (arsp->rel_roffset > 1000*bf994817SAli Bahrami osp->os_shdr->sh_size)) { 10015aefb655Srie int class; 1002de777a60Sab196087 Conv_inv_buf_t inv_buf; 10035aefb655Srie 1004*bf994817SAli Bahrami if (((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 1005*bf994817SAli Bahrami ofl->ofl_size) 10065aefb655Srie class = ERR_FATAL; 10075aefb655Srie else 10085aefb655Srie class = ERR_WARNING; 10095aefb655Srie 10105aefb655Srie eprintf(ofl->ofl_lml, class, 10115aefb655Srie MSG_INTL(MSG_REL_INVALOFFSET), 1012*bf994817SAli Bahrami conv_reloc_amd64_type(arsp->rel_rtype, 0, &inv_buf), 1013*bf994817SAli Bahrami ifl_name, EC_WORD(arsp->rel_isdesc->is_scnndx), 1014*bf994817SAli Bahrami arsp->rel_isdesc->is_name, ld_reloc_sym_name(arsp), 10155aefb655Srie EC_ADDR((uintptr_t)addr - 10165aefb655Srie (uintptr_t)ofl->ofl_nehdr)); 10175aefb655Srie 10185aefb655Srie if (class == ERR_FATAL) { 10195aefb655Srie return_code = S_ERROR; 10205aefb655Srie continue; 10215aefb655Srie } 10225aefb655Srie } 10235aefb655Srie 10245aefb655Srie /* 1025*bf994817SAli Bahrami * The relocation is additive. Ignore the previous symbol 1026*bf994817SAli Bahrami * value if this local partial symbol is expanded. 10275aefb655Srie */ 10285aefb655Srie if (moved) 10295aefb655Srie value -= *addr; 10305aefb655Srie 10315aefb655Srie /* 1032*bf994817SAli Bahrami * If '-z noreloc' is specified - skip the do_reloc_ld stage. 10335aefb655Srie */ 1034f3324781Sab196087 if (OFL_DO_RELOC(ofl)) { 1035f3324781Sab196087 /* 1036*bf994817SAli Bahrami * If this is a PROGBITS section and the running linker 1037*bf994817SAli Bahrami * has a different byte order than the target host, 1038*bf994817SAli Bahrami * tell do_reloc_ld() to swap bytes. 1039f3324781Sab196087 */ 1040*bf994817SAli Bahrami if (do_reloc_ld(arsp, addr, &value, ld_reloc_sym_name, 1041*bf994817SAli Bahrami ifl_name, OFL_SWAP_RELOC_DATA(ofl, arsp), 10425aefb655Srie ofl->ofl_lml) == 0) 10435aefb655Srie return_code = S_ERROR; 10445aefb655Srie } 10455aefb655Srie } 10465aefb655Srie return (return_code); 10475aefb655Srie } 10485aefb655Srie 1049ba2be530Sab196087 static uintptr_t 10505aefb655Srie ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 10515aefb655Srie { 10525aefb655Srie Rel_desc *orsp; 10535aefb655Srie Sym_desc *sdp = rsp->rel_sym; 10545aefb655Srie 10555aefb655Srie /* 10565aefb655Srie * Static executables *do not* want any relocations against them. 10575aefb655Srie * Since our engine still creates relocations against a WEAK UNDEFINED 10585aefb655Srie * symbol in a static executable, it's best to disable them here 10595aefb655Srie * instead of through out the relocation code. 10605aefb655Srie */ 1061635216b6SRod Evans if (OFL_IS_STATIC_EXEC(ofl)) 10625aefb655Srie return (1); 10635aefb655Srie 10645aefb655Srie /* 10655aefb655Srie * If we are adding a output relocation against a section 10665aefb655Srie * symbol (non-RELATIVE) then mark that section. These sections 10675aefb655Srie * will be added to the .dynsym symbol table. 10685aefb655Srie */ 10695aefb655Srie if (sdp && (rsp->rel_rtype != M_R_RELATIVE) && 10705aefb655Srie ((flags & FLG_REL_SCNNDX) || 10715aefb655Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) { 10725aefb655Srie 10735aefb655Srie /* 10745aefb655Srie * If this is a COMMON symbol - no output section 10755aefb655Srie * exists yet - (it's created as part of sym_validate()). 10765aefb655Srie * So - we mark here that when it's created it should 10775aefb655Srie * be tagged with the FLG_OS_OUTREL flag. 10785aefb655Srie */ 10795aefb655Srie if ((sdp->sd_flags & FLG_SY_SPECSEC) && 10800bc07c75Srie (sdp->sd_sym->st_shndx == SHN_COMMON)) { 10815aefb655Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS) 10825aefb655Srie ofl->ofl_flags1 |= FLG_OF1_BSSOREL; 10835aefb655Srie else 10845aefb655Srie ofl->ofl_flags1 |= FLG_OF1_TLSOREL; 10855aefb655Srie } else { 108608278a5eSRod Evans Os_desc *osp; 108708278a5eSRod Evans Is_desc *isp = sdp->sd_isc; 10885aefb655Srie 108908278a5eSRod Evans if (isp && ((osp = isp->is_osdesc) != NULL) && 109008278a5eSRod Evans ((osp->os_flags & FLG_OS_OUTREL) == 0)) { 10915aefb655Srie ofl->ofl_dynshdrcnt++; 10925aefb655Srie osp->os_flags |= FLG_OS_OUTREL; 10935aefb655Srie } 10945aefb655Srie } 10955aefb655Srie } 10965aefb655Srie 1097*bf994817SAli Bahrami /* Enter it into the output relocation cache */ 1098*bf994817SAli Bahrami if ((orsp = ld_reloc_enter(ofl, &ofl->ofl_outrels, rsp, flags)) == NULL) 1099*bf994817SAli Bahrami return (S_ERROR); 11005aefb655Srie 11015aefb655Srie if (flags & FLG_REL_GOT) 11025aefb655Srie ofl->ofl_relocgotsz += (Xword)sizeof (Rela); 11035aefb655Srie else if (flags & FLG_REL_PLT) 11045aefb655Srie ofl->ofl_relocpltsz += (Xword)sizeof (Rela); 11055aefb655Srie else if (flags & FLG_REL_BSS) 11065aefb655Srie ofl->ofl_relocbsssz += (Xword)sizeof (Rela); 11075aefb655Srie else if (flags & FLG_REL_NOINFO) 11085aefb655Srie ofl->ofl_relocrelsz += (Xword)sizeof (Rela); 11095aefb655Srie else 1110*bf994817SAli Bahrami RELAUX_GET_OSDESC(orsp)->os_szoutrels += (Xword)sizeof (Rela); 11115aefb655Srie 11125aefb655Srie if (orsp->rel_rtype == M_R_RELATIVE) 11135aefb655Srie ofl->ofl_relocrelcnt++; 11145aefb655Srie 11155aefb655Srie /* 11165aefb655Srie * We don't perform sorting on PLT relocations because 11175aefb655Srie * they have already been assigned a PLT index and if we 11185aefb655Srie * were to sort them we would have to re-assign the plt indexes. 11195aefb655Srie */ 11205aefb655Srie if (!(flags & FLG_REL_PLT)) 11215aefb655Srie ofl->ofl_reloccnt++; 11225aefb655Srie 11235aefb655Srie /* 11245aefb655Srie * Insure a GLOBAL_OFFSET_TABLE is generated if required. 11255aefb655Srie */ 11265aefb655Srie if (IS_GOT_REQUIRED(orsp->rel_rtype)) 11275aefb655Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 11285aefb655Srie 11295aefb655Srie /* 11305aefb655Srie * Identify and possibly warn of a displacement relocation. 11315aefb655Srie */ 11325aefb655Srie if (orsp->rel_flags & FLG_REL_DISP) { 11335aefb655Srie ofl->ofl_dtflags_1 |= DF_1_DISPRELPND; 11345aefb655Srie 11355aefb655Srie if (ofl->ofl_flags & FLG_OF_VERBOSE) 11365aefb655Srie ld_disp_errmsg(MSG_INTL(MSG_REL_DISPREL4), orsp, ofl); 11375aefb655Srie } 11385aefb655Srie DBG_CALL(Dbg_reloc_ors_entry(ofl->ofl_lml, ELF_DBG_LD, SHT_RELA, 11395aefb655Srie M_MACH, orsp)); 11405aefb655Srie return (1); 11415aefb655Srie } 11425aefb655Srie 11435aefb655Srie /* 11445aefb655Srie * process relocation for a LOCAL symbol 11455aefb655Srie */ 1146ba2be530Sab196087 static uintptr_t 11475aefb655Srie ld_reloc_local(Rel_desc * rsp, Ofl_desc * ofl) 11485aefb655Srie { 11491d9df23bSab196087 ofl_flag_t flags = ofl->ofl_flags; 11505aefb655Srie Sym_desc *sdp = rsp->rel_sym; 11510bc07c75Srie Word shndx = sdp->sd_sym->st_shndx; 11525aefb655Srie Word ortype = rsp->rel_rtype; 11535aefb655Srie 11545aefb655Srie /* 11555aefb655Srie * if ((shared object) and (not pc relative relocation) and 11565aefb655Srie * (not against ABS symbol)) 11575aefb655Srie * then 11585aefb655Srie * build R_AMD64_RELATIVE 11595aefb655Srie * fi 11605aefb655Srie */ 11615aefb655Srie if ((flags & FLG_OF_SHAROBJ) && (rsp->rel_flags & FLG_REL_LOAD) && 11622926dd2eSrie !(IS_PC_RELATIVE(rsp->rel_rtype)) && !(IS_SIZE(rsp->rel_rtype)) && 11635aefb655Srie !(IS_GOT_BASED(rsp->rel_rtype)) && 11645aefb655Srie !(rsp->rel_isdesc != NULL && 11655aefb655Srie (rsp->rel_isdesc->is_shdr->sh_type == SHT_SUNW_dof)) && 11665aefb655Srie (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) || 11675aefb655Srie (shndx != SHN_ABS) || (sdp->sd_aux && sdp->sd_aux->sa_symspec))) { 11685aefb655Srie 11695aefb655Srie /* 11705aefb655Srie * R_AMD64_RELATIVE updates a 64bit address, if this 11715aefb655Srie * relocation isn't a 64bit binding then we can not 11725aefb655Srie * simplify it to a RELATIVE relocation. 11735aefb655Srie */ 11745aefb655Srie if (reloc_table[ortype].re_fsize != sizeof (Addr)) { 11751d9df23bSab196087 return (ld_add_outrel(0, rsp, ofl)); 11765aefb655Srie } 11775aefb655Srie 11785aefb655Srie rsp->rel_rtype = R_AMD64_RELATIVE; 11795aefb655Srie if (ld_add_outrel(FLG_REL_ADVAL, rsp, ofl) == S_ERROR) 11805aefb655Srie return (S_ERROR); 11815aefb655Srie rsp->rel_rtype = ortype; 11825aefb655Srie return (1); 11835aefb655Srie } 11845aefb655Srie 11855aefb655Srie /* 11865aefb655Srie * If the relocation is against a 'non-allocatable' section 11875aefb655Srie * and we can not resolve it now - then give a warning 11885aefb655Srie * message. 11895aefb655Srie * 11905aefb655Srie * We can not resolve the symbol if either: 11915aefb655Srie * a) it's undefined 11925aefb655Srie * b) it's defined in a shared library and a 11935aefb655Srie * COPY relocation hasn't moved it to the executable 11945aefb655Srie * 11955aefb655Srie * Note: because we process all of the relocations against the 11965aefb655Srie * text segment before any others - we know whether 11975aefb655Srie * or not a copy relocation will be generated before 11985aefb655Srie * we get here (see reloc_init()->reloc_segments()). 11995aefb655Srie */ 12005aefb655Srie if (!(rsp->rel_flags & FLG_REL_LOAD) && 12015aefb655Srie ((shndx == SHN_UNDEF) || 12025aefb655Srie ((sdp->sd_ref == REF_DYN_NEED) && 12035aefb655Srie ((sdp->sd_flags & FLG_SY_MVTOCOMM) == 0)))) { 1204de777a60Sab196087 Conv_inv_buf_t inv_buf; 1205*bf994817SAli Bahrami Os_desc *osp = RELAUX_GET_OSDESC(rsp); 1206de777a60Sab196087 12075aefb655Srie /* 12085aefb655Srie * If the relocation is against a SHT_SUNW_ANNOTATE 12095aefb655Srie * section - then silently ignore that the relocation 12105aefb655Srie * can not be resolved. 12115aefb655Srie */ 1212*bf994817SAli Bahrami if (osp && (osp->os_shdr->sh_type == SHT_SUNW_ANNOTATE)) 12135aefb655Srie return (0); 12145aefb655Srie (void) eprintf(ofl->ofl_lml, ERR_WARNING, 12155aefb655Srie MSG_INTL(MSG_REL_EXTERNSYM), 1216de777a60Sab196087 conv_reloc_amd64_type(rsp->rel_rtype, 0, &inv_buf), 12175aefb655Srie rsp->rel_isdesc->is_file->ifl_name, 1218*bf994817SAli Bahrami ld_reloc_sym_name(rsp), osp->os_name); 12195aefb655Srie return (1); 12205aefb655Srie } 12215aefb655Srie 12225aefb655Srie /* 12235aefb655Srie * Perform relocation. 12245aefb655Srie */ 12255aefb655Srie return (ld_add_actrel(NULL, rsp, ofl)); 12265aefb655Srie } 12275aefb655Srie 12285aefb655Srie 1229ba2be530Sab196087 static uintptr_t 12305aefb655Srie ld_reloc_TLS(Boolean local, Rel_desc * rsp, Ofl_desc * ofl) 12315aefb655Srie { 12325aefb655Srie Word rtype = rsp->rel_rtype; 12335aefb655Srie Sym_desc *sdp = rsp->rel_sym; 12341d9df23bSab196087 ofl_flag_t flags = ofl->ofl_flags; 12355aefb655Srie Gotndx *gnp; 12365aefb655Srie 12375aefb655Srie /* 1238d326b23bSrie * If we're building an executable - use either the IE or LE access 1239d326b23bSrie * model. If we're building a shared object process any IE model. 12405aefb655Srie */ 1241d326b23bSrie if ((flags & FLG_OF_EXEC) || (IS_TLS_IE(rtype))) { 12425aefb655Srie /* 1243d326b23bSrie * Set the DF_STATIC_TLS flag. 12445aefb655Srie */ 12455aefb655Srie ofl->ofl_dtflags |= DF_STATIC_TLS; 12465aefb655Srie 1247d326b23bSrie if (!local || ((flags & FLG_OF_EXEC) == 0)) { 12485aefb655Srie /* 1249d326b23bSrie * Assign a GOT entry for static TLS references. 12505aefb655Srie */ 125157ef7aa9SRod Evans if ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 125257ef7aa9SRod Evans GOT_REF_TLSIE, ofl, rsp)) == NULL) { 1253d326b23bSrie 1254d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, 1255d326b23bSrie gnp, GOT_REF_TLSIE, FLG_REL_STLS, 1256d326b23bSrie rtype, R_AMD64_TPOFF64, 0) == S_ERROR) 12575aefb655Srie return (S_ERROR); 12585aefb655Srie } 1259d326b23bSrie 1260d326b23bSrie /* 1261d326b23bSrie * IE access model. 1262d326b23bSrie */ 12635aefb655Srie if (IS_TLS_IE(rtype)) 12645aefb655Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 12655aefb655Srie 12665aefb655Srie /* 1267d326b23bSrie * Fixups are required for other executable models. 12685aefb655Srie */ 12695aefb655Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 12705aefb655Srie rsp, ofl)); 12715aefb655Srie } 1272d326b23bSrie 12735aefb655Srie /* 1274d326b23bSrie * LE access model. 12755aefb655Srie */ 12765aefb655Srie if (IS_TLS_LE(rtype)) 12775aefb655Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 1278d326b23bSrie 12795aefb655Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 12805aefb655Srie rsp, ofl)); 12815aefb655Srie } 12825aefb655Srie 12835aefb655Srie /* 1284d326b23bSrie * Building a shared object. 1285d326b23bSrie * 1286d326b23bSrie * Assign a GOT entry for a dynamic TLS reference. 12875aefb655Srie */ 128857ef7aa9SRod Evans if (IS_TLS_LD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 128957ef7aa9SRod Evans GOT_REF_TLSLD, ofl, rsp)) == NULL)) { 1290d326b23bSrie 1291d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSLD, 129257ef7aa9SRod Evans FLG_REL_MTLS, rtype, R_AMD64_DTPMOD64, NULL) == S_ERROR) 12935aefb655Srie return (S_ERROR); 1294d326b23bSrie 12955aefb655Srie } else if (IS_TLS_GD(rtype) && 129657ef7aa9SRod Evans ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, GOT_REF_TLSGD, 129757ef7aa9SRod Evans ofl, rsp)) == NULL)) { 1298d326b23bSrie 1299d326b23bSrie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSGD, 1300d326b23bSrie FLG_REL_DTLS, rtype, R_AMD64_DTPMOD64, 1301d326b23bSrie R_AMD64_DTPOFF64) == S_ERROR) 13025aefb655Srie return (S_ERROR); 13035aefb655Srie } 13045aefb655Srie 13055aefb655Srie if (IS_TLS_LD(rtype)) 13065aefb655Srie return (ld_add_actrel(FLG_REL_MTLS, rsp, ofl)); 13075aefb655Srie 13085aefb655Srie return (ld_add_actrel(FLG_REL_DTLS, rsp, ofl)); 13095aefb655Srie } 13105aefb655Srie 13115aefb655Srie /* ARGSUSED5 */ 1312ba2be530Sab196087 static uintptr_t 131357ef7aa9SRod Evans ld_assign_got_ndx(Alist **alpp, Gotndx *pgnp, Gotref gref, Ofl_desc *ofl, 13145aefb655Srie Rel_desc *rsp, Sym_desc *sdp) 13155aefb655Srie { 13165aefb655Srie Xword raddend; 131757ef7aa9SRod Evans Gotndx gn, *gnp; 131857ef7aa9SRod Evans Aliste idx; 13195aefb655Srie uint_t gotents; 13205aefb655Srie 13215aefb655Srie raddend = rsp->rel_raddend; 132257ef7aa9SRod Evans if (pgnp && (pgnp->gn_addend == raddend) && (pgnp->gn_gotref == gref)) 13235aefb655Srie return (1); 13245aefb655Srie 13255aefb655Srie if ((gref == GOT_REF_TLSGD) || (gref == GOT_REF_TLSLD)) 13265aefb655Srie gotents = 2; 13275aefb655Srie else 13285aefb655Srie gotents = 1; 13295aefb655Srie 133057ef7aa9SRod Evans gn.gn_addend = raddend; 133157ef7aa9SRod Evans gn.gn_gotndx = ofl->ofl_gotcnt; 133257ef7aa9SRod Evans gn.gn_gotref = gref; 13335aefb655Srie 13345aefb655Srie ofl->ofl_gotcnt += gotents; 13355aefb655Srie 13365aefb655Srie if (gref == GOT_REF_TLSLD) { 133757ef7aa9SRod Evans if (ofl->ofl_tlsldgotndx == NULL) { 133857ef7aa9SRod Evans if ((gnp = libld_malloc(sizeof (Gotndx))) == NULL) 133957ef7aa9SRod Evans return (S_ERROR); 134057ef7aa9SRod Evans (void) memcpy(gnp, &gn, sizeof (Gotndx)); 13415aefb655Srie ofl->ofl_tlsldgotndx = gnp; 134257ef7aa9SRod Evans } 13435aefb655Srie return (1); 13445aefb655Srie } 13455aefb655Srie 134657ef7aa9SRod Evans idx = 0; 134757ef7aa9SRod Evans for (ALIST_TRAVERSE(*alpp, idx, gnp)) { 134857ef7aa9SRod Evans if (gnp->gn_addend > raddend) 134957ef7aa9SRod Evans break; 13505aefb655Srie } 135157ef7aa9SRod Evans 135257ef7aa9SRod Evans /* 135357ef7aa9SRod Evans * GOT indexes are maintained on an Alist, where there is typically 135457ef7aa9SRod Evans * only one index. The usage of this list is to scan the list to find 135557ef7aa9SRod Evans * an index, and then apply that index immediately to a relocation. 135657ef7aa9SRod Evans * Thus there are no external references to these GOT index structures 135757ef7aa9SRod Evans * that can be compromised by the Alist being reallocated. 135857ef7aa9SRod Evans */ 135957ef7aa9SRod Evans if (alist_insert(alpp, &gn, sizeof (Gotndx), 136057ef7aa9SRod Evans AL_CNT_SDP_GOT, idx) == NULL) 136157ef7aa9SRod Evans return (S_ERROR); 136257ef7aa9SRod Evans 13635aefb655Srie return (1); 13645aefb655Srie } 13655aefb655Srie 1366ba2be530Sab196087 static void 13675aefb655Srie ld_assign_plt_ndx(Sym_desc * sdp, Ofl_desc *ofl) 13685aefb655Srie { 13695aefb655Srie sdp->sd_aux->sa_PLTndx = 1 + ofl->ofl_pltcnt++; 13705aefb655Srie sdp->sd_aux->sa_PLTGOTndx = ofl->ofl_gotcnt++; 13715aefb655Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 13725aefb655Srie } 13735aefb655Srie 13745aefb655Srie static uchar_t plt0_template[M_PLT_ENTSIZE] = { 13755aefb655Srie /* 0x00 PUSHQ GOT+8(%rip) */ 0xff, 0x35, 0x00, 0x00, 0x00, 0x00, 13765aefb655Srie /* 0x06 JMP *GOT+16(%rip) */ 0xff, 0x25, 0x00, 0x00, 0x00, 0x00, 13775aefb655Srie /* 0x0c NOP */ 0x90, 13785aefb655Srie /* 0x0d NOP */ 0x90, 13795aefb655Srie /* 0x0e NOP */ 0x90, 13805aefb655Srie /* 0x0f NOP */ 0x90 13815aefb655Srie }; 13825aefb655Srie 13835aefb655Srie /* 13845aefb655Srie * Initializes .got[0] with the _DYNAMIC symbol value. 13855aefb655Srie */ 1386ba2be530Sab196087 static uintptr_t 13875aefb655Srie ld_fillin_gotplt(Ofl_desc *ofl) 13885aefb655Srie { 1389ba2be530Sab196087 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 1390ba2be530Sab196087 13915aefb655Srie if (ofl->ofl_osgot) { 13925aefb655Srie Sym_desc *sdp; 13935aefb655Srie 13945aefb655Srie if ((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_DYNAMIC_U), 1395635216b6SRod Evans SYM_NOHASH, NULL, ofl)) != NULL) { 1396d326b23bSrie uchar_t *genptr; 1397d326b23bSrie 1398d326b23bSrie genptr = ((uchar_t *)ofl->ofl_osgot->os_outdata->d_buf + 13995aefb655Srie (M_GOT_XDYNAMIC * M_GOT_ENTSIZE)); 14005aefb655Srie /* LINTED */ 14015aefb655Srie *(Xword *)genptr = sdp->sd_sym->st_value; 1402ba2be530Sab196087 if (bswap) 1403ba2be530Sab196087 /* LINTED */ 1404ba2be530Sab196087 *(Xword *)genptr = 1405ba2be530Sab196087 /* LINTED */ 1406ba2be530Sab196087 ld_bswap_Xword(*(Xword *)genptr); 14075aefb655Srie } 14085aefb655Srie } 14095aefb655Srie 14105aefb655Srie /* 14115aefb655Srie * Fill in the reserved slot in the procedure linkage table the first 14125aefb655Srie * entry is: 14135aefb655Srie * 0x00 PUSHQ GOT+8(%rip) # GOT[1] 14145aefb655Srie * 0x06 JMP *GOT+16(%rip) # GOT[2] 14155aefb655Srie * 0x0c NOP 14165aefb655Srie * 0x0d NOP 14175aefb655Srie * 0x0e NOP 14185aefb655Srie * 0x0f NOP 14195aefb655Srie */ 1420f3324781Sab196087 if ((ofl->ofl_flags & FLG_OF_DYNAMIC) && ofl->ofl_osplt) { 14215aefb655Srie uchar_t *pltent; 14225aefb655Srie Xword val1; 14235aefb655Srie 14245aefb655Srie pltent = (uchar_t *)ofl->ofl_osplt->os_outdata->d_buf; 14255aefb655Srie bcopy(plt0_template, pltent, sizeof (plt0_template)); 14265aefb655Srie 14275aefb655Srie /* 1428f3324781Sab196087 * If '-z noreloc' is specified - skip the do_reloc_ld 1429f3324781Sab196087 * stage. 1430f3324781Sab196087 */ 1431f3324781Sab196087 if (!OFL_DO_RELOC(ofl)) 1432f3324781Sab196087 return (1); 1433f3324781Sab196087 1434f3324781Sab196087 /* 14355aefb655Srie * filin: 14365aefb655Srie * PUSHQ GOT + 8(%rip) 14375aefb655Srie * 14385aefb655Srie * Note: 0x06 below represents the offset to the 14395aefb655Srie * next instruction - which is what %rip will 14405aefb655Srie * be pointing at. 14415aefb655Srie */ 14425aefb655Srie val1 = (ofl->ofl_osgot->os_shdr->sh_addr) + 14435aefb655Srie (M_GOT_XLINKMAP * M_GOT_ENTSIZE) - 14445aefb655Srie ofl->ofl_osplt->os_shdr->sh_addr - 0x06; 14455aefb655Srie 1446*bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x02], 1447*bf994817SAli Bahrami &val1, syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), 1448*bf994817SAli Bahrami bswap, ofl->ofl_lml) == 0) { 14495aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 14505aefb655Srie MSG_INTL(MSG_PLT_PLT0FAIL)); 14515aefb655Srie return (S_ERROR); 14525aefb655Srie } 14535aefb655Srie 14545aefb655Srie /* 14555aefb655Srie * filin: 14565aefb655Srie * JMP *GOT+16(%rip) 14575aefb655Srie */ 14585aefb655Srie val1 = (ofl->ofl_osgot->os_shdr->sh_addr) + 14595aefb655Srie (M_GOT_XRTLD * M_GOT_ENTSIZE) - 14605aefb655Srie ofl->ofl_osplt->os_shdr->sh_addr - 0x0c; 1461f3324781Sab196087 1462*bf994817SAli Bahrami if (do_reloc_ld(&rdesc_r_amd64_gotpcrel, &pltent[0x08], 1463*bf994817SAli Bahrami &val1, syn_rdesc_sym_name, MSG_ORIG(MSG_SPECFIL_PLTENT), 1464*bf994817SAli Bahrami bswap, ofl->ofl_lml) == 0) { 14655aefb655Srie eprintf(ofl->ofl_lml, ERR_FATAL, 14665aefb655Srie MSG_INTL(MSG_PLT_PLT0FAIL)); 14675aefb655Srie return (S_ERROR); 14685aefb655Srie } 14695aefb655Srie } 1470f3324781Sab196087 14715aefb655Srie return (1); 14725aefb655Srie } 1473ba2be530Sab196087 1474ba2be530Sab196087 1475ba2be530Sab196087 1476ba2be530Sab196087 /* 1477ba2be530Sab196087 * Template for generating "void (*)(void)" function 1478ba2be530Sab196087 */ 1479ba2be530Sab196087 static const uchar_t nullfunc_tmpl[] = { /* amd64 */ 1480ba2be530Sab196087 /* 0x00 */ 0x55, /* pushq %rbp */ 1481ba2be530Sab196087 /* 0x01 */ 0x48, 0x8b, 0xec, /* movq %rsp,%rbp */ 1482ba2be530Sab196087 /* 0x04 */ 0x48, 0x8b, 0xe5, /* movq %rbp,%rsp */ 1483ba2be530Sab196087 /* 0x07 */ 0x5d, /* popq %rbp */ 1484ba2be530Sab196087 /* 0x08 */ 0xc3 /* ret */ 1485ba2be530Sab196087 }; 1486ba2be530Sab196087 1487ba2be530Sab196087 1488ba2be530Sab196087 /* 14893c573fccSAli Bahrami * Function used to provide fill padding in SHF_EXECINSTR sections 14903c573fccSAli Bahrami * 14913c573fccSAli Bahrami * entry: 14923c573fccSAli Bahrami * 14933c573fccSAli Bahrami * base - base address of section being filled 14943c573fccSAli Bahrami * offset - starting offset for fill within memory referenced by base 14953c573fccSAli Bahrami * cnt - # bytes to be filled 14963c573fccSAli Bahrami * 14973c573fccSAli Bahrami * exit: 14983c573fccSAli Bahrami * The fill has been completed. 14993c573fccSAli Bahrami */ 15003c573fccSAli Bahrami static void 15013c573fccSAli Bahrami execfill(void *base, off_t off, size_t cnt) 15023c573fccSAli Bahrami { 15033c573fccSAli Bahrami /* 15043c573fccSAli Bahrami * 0x90 is an X86 NOP instruction in both 32 and 64-bit worlds. 15053c573fccSAli Bahrami * There are no alignment constraints. 15063c573fccSAli Bahrami */ 15073c573fccSAli Bahrami (void) memset(off + (char *)base, 0x90, cnt); 15083c573fccSAli Bahrami } 15093c573fccSAli Bahrami 15103c573fccSAli Bahrami 15113c573fccSAli Bahrami /* 1512ba2be530Sab196087 * Return the ld_targ definition for this target. 1513ba2be530Sab196087 */ 1514ba2be530Sab196087 const Target * 1515ba2be530Sab196087 ld_targ_init_x86(void) 1516ba2be530Sab196087 { 1517ba2be530Sab196087 static const Target _ld_targ = { 1518ba2be530Sab196087 { /* Target_mach */ 1519ba2be530Sab196087 M_MACH, /* m_mach */ 1520ba2be530Sab196087 M_MACHPLUS, /* m_machplus */ 1521ba2be530Sab196087 M_FLAGSPLUS, /* m_flagsplus */ 1522ba2be530Sab196087 M_CLASS, /* m_class */ 1523ba2be530Sab196087 M_DATA, /* m_data */ 1524ba2be530Sab196087 1525ba2be530Sab196087 M_SEGM_ALIGN, /* m_segm_align */ 1526ba2be530Sab196087 M_SEGM_ORIGIN, /* m_segm_origin */ 1527bb3b4f6cSRod Evans M_SEGM_AORIGIN, /* m_segm_aorigin */ 1528ba2be530Sab196087 M_DATASEG_PERM, /* m_dataseg_perm */ 152969112eddSAli Bahrami M_STACK_PERM, /* m_stack_perm */ 1530ba2be530Sab196087 M_WORD_ALIGN, /* m_word_align */ 1531ba2be530Sab196087 MSG_ORIG(MSG_PTH_RTLD_AMD64), /* m_def_interp */ 1532ba2be530Sab196087 1533ba2be530Sab196087 /* Relocation type codes */ 1534ba2be530Sab196087 M_R_ARRAYADDR, /* m_r_arrayaddr */ 1535ba2be530Sab196087 M_R_COPY, /* m_r_copy */ 1536ba2be530Sab196087 M_R_GLOB_DAT, /* m_r_glob_dat */ 1537ba2be530Sab196087 M_R_JMP_SLOT, /* m_r_jmp_slot */ 1538ba2be530Sab196087 M_R_NUM, /* m_r_num */ 1539ba2be530Sab196087 M_R_NONE, /* m_r_none */ 1540ba2be530Sab196087 M_R_RELATIVE, /* m_r_relative */ 1541ba2be530Sab196087 M_R_REGISTER, /* m_r_register */ 1542ba2be530Sab196087 1543ba2be530Sab196087 /* Relocation related constants */ 1544ba2be530Sab196087 M_REL_DT_COUNT, /* m_rel_dt_count */ 1545ba2be530Sab196087 M_REL_DT_ENT, /* m_rel_dt_ent */ 1546ba2be530Sab196087 M_REL_DT_SIZE, /* m_rel_dt_size */ 1547ba2be530Sab196087 M_REL_DT_TYPE, /* m_rel_dt_type */ 1548ba2be530Sab196087 M_REL_SHT_TYPE, /* m_rel_sht_type */ 1549ba2be530Sab196087 1550ba2be530Sab196087 /* GOT related constants */ 1551ba2be530Sab196087 M_GOT_ENTSIZE, /* m_got_entsize */ 1552ba2be530Sab196087 M_GOT_XNumber, /* m_got_xnumber */ 1553ba2be530Sab196087 1554ba2be530Sab196087 /* PLT related constants */ 1555ba2be530Sab196087 M_PLT_ALIGN, /* m_plt_align */ 1556ba2be530Sab196087 M_PLT_ENTSIZE, /* m_plt_entsize */ 1557ba2be530Sab196087 M_PLT_RESERVSZ, /* m_plt_reservsz */ 1558ba2be530Sab196087 M_PLT_SHF_FLAGS, /* m_plt_shf_flags */ 1559ba2be530Sab196087 15607e16fca0SAli Bahrami /* Section type of .eh_frame/.eh_frame_hdr sections */ 15617e16fca0SAli Bahrami SHT_AMD64_UNWIND, /* m_sht_unwind */ 15627e16fca0SAli Bahrami 1563ba2be530Sab196087 M_DT_REGISTER, /* m_dt_register */ 1564ba2be530Sab196087 }, 1565ba2be530Sab196087 { /* Target_machid */ 1566ba2be530Sab196087 M_ID_ARRAY, /* id_array */ 1567ba2be530Sab196087 M_ID_BSS, /* id_bss */ 1568ba2be530Sab196087 M_ID_CAP, /* id_cap */ 156908278a5eSRod Evans M_ID_CAPINFO, /* id_capinfo */ 157008278a5eSRod Evans M_ID_CAPCHAIN, /* id_capchain */ 1571ba2be530Sab196087 M_ID_DATA, /* id_data */ 1572ba2be530Sab196087 M_ID_DYNAMIC, /* id_dynamic */ 1573ba2be530Sab196087 M_ID_DYNSORT, /* id_dynsort */ 1574ba2be530Sab196087 M_ID_DYNSTR, /* id_dynstr */ 1575ba2be530Sab196087 M_ID_DYNSYM, /* id_dynsym */ 1576ba2be530Sab196087 M_ID_DYNSYM_NDX, /* id_dynsym_ndx */ 1577ba2be530Sab196087 M_ID_GOT, /* id_got */ 1578ba2be530Sab196087 M_ID_UNKNOWN, /* id_gotdata (unused) */ 1579ba2be530Sab196087 M_ID_HASH, /* id_hash */ 1580ba2be530Sab196087 M_ID_INTERP, /* id_interp */ 1581ba2be530Sab196087 M_ID_LBSS, /* id_lbss */ 1582ba2be530Sab196087 M_ID_LDYNSYM, /* id_ldynsym */ 1583ba2be530Sab196087 M_ID_NOTE, /* id_note */ 1584ba2be530Sab196087 M_ID_NULL, /* id_null */ 1585ba2be530Sab196087 M_ID_PLT, /* id_plt */ 1586ba2be530Sab196087 M_ID_REL, /* id_rel */ 1587ba2be530Sab196087 M_ID_STRTAB, /* id_strtab */ 1588ba2be530Sab196087 M_ID_SYMINFO, /* id_syminfo */ 1589ba2be530Sab196087 M_ID_SYMTAB, /* id_symtab */ 1590ba2be530Sab196087 M_ID_SYMTAB_NDX, /* id_symtab_ndx */ 1591ba2be530Sab196087 M_ID_TEXT, /* id_text */ 1592ba2be530Sab196087 M_ID_TLS, /* id_tls */ 1593ba2be530Sab196087 M_ID_TLSBSS, /* id_tlsbss */ 1594ba2be530Sab196087 M_ID_UNKNOWN, /* id_unknown */ 1595ba2be530Sab196087 M_ID_UNWIND, /* id_unwind */ 15967e16fca0SAli Bahrami M_ID_UNWINDHDR, /* id_unwindhdr */ 1597ba2be530Sab196087 M_ID_USER, /* id_user */ 1598ba2be530Sab196087 M_ID_VERSION, /* id_version */ 1599ba2be530Sab196087 }, 1600ba2be530Sab196087 { /* Target_nullfunc */ 1601ba2be530Sab196087 nullfunc_tmpl, /* nf_template */ 1602ba2be530Sab196087 sizeof (nullfunc_tmpl), /* nf_size */ 1603ba2be530Sab196087 }, 16043c573fccSAli Bahrami { /* Target_fillfunc */ 16053c573fccSAli Bahrami execfill /* ff_execfill */ 16063c573fccSAli Bahrami }, 1607ba2be530Sab196087 { /* Target_machrel */ 1608ba2be530Sab196087 reloc_table, 1609ba2be530Sab196087 1610ba2be530Sab196087 ld_init_rel, /* mr_init_rel */ 1611ba2be530Sab196087 ld_mach_eflags, /* mr_mach_eflags */ 1612ba2be530Sab196087 ld_mach_make_dynamic, /* mr_mach_make_dynamic */ 1613ba2be530Sab196087 ld_mach_update_odynamic, /* mr_mach_update_odynamic */ 1614ba2be530Sab196087 ld_calc_plt_addr, /* mr_calc_plt_addr */ 1615ba2be530Sab196087 ld_perform_outreloc, /* mr_perform_outreloc */ 1616ba2be530Sab196087 ld_do_activerelocs, /* mr_do_activerelocs */ 1617ba2be530Sab196087 ld_add_outrel, /* mr_add_outrel */ 1618ba2be530Sab196087 NULL, /* mr_reloc_register */ 1619ba2be530Sab196087 ld_reloc_local, /* mr_reloc_local */ 1620ba2be530Sab196087 NULL, /* mr_reloc_GOTOP */ 1621ba2be530Sab196087 ld_reloc_TLS, /* mr_reloc_TLS */ 1622ba2be530Sab196087 NULL, /* mr_assign_got */ 162357ef7aa9SRod Evans ld_find_got_ndx, /* mr_find_got_ndx */ 1624ba2be530Sab196087 ld_calc_got_offset, /* mr_calc_got_offset */ 1625ba2be530Sab196087 ld_assign_got_ndx, /* mr_assign_got_ndx */ 1626ba2be530Sab196087 ld_assign_plt_ndx, /* mr_assign_plt_ndx */ 1627ba2be530Sab196087 NULL, /* mr_allocate_got */ 1628ba2be530Sab196087 ld_fillin_gotplt, /* mr_fillin_gotplt */ 1629ba2be530Sab196087 }, 1630ba2be530Sab196087 { /* Target_machsym */ 1631ba2be530Sab196087 NULL, /* ms_reg_check */ 1632ba2be530Sab196087 NULL, /* ms_mach_sym_typecheck */ 1633ba2be530Sab196087 NULL, /* ms_is_regsym */ 1634ba2be530Sab196087 NULL, /* ms_reg_find */ 1635ba2be530Sab196087 NULL /* ms_reg_enter */ 1636ba2be530Sab196087 } 1637ba2be530Sab196087 }; 1638ba2be530Sab196087 1639ba2be530Sab196087 return (&_ld_targ); 1640ba2be530Sab196087 } 1641