11618Srie /* 21618Srie * CDDL HEADER START 31618Srie * 41618Srie * The contents of this file are subject to the terms of the 51618Srie * Common Development and Distribution License (the "License"). 61618Srie * You may not use this file except in compliance with the License. 71618Srie * 81618Srie * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 91618Srie * or http://www.opensolaris.org/os/licensing. 101618Srie * See the License for the specific language governing permissions 111618Srie * and limitations under the License. 121618Srie * 131618Srie * When distributing Covered Code, include this CDDL HEADER in each 141618Srie * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 151618Srie * If applicable, add the following below this CDDL HEADER, with the 161618Srie * fields enclosed by brackets "[]" replaced with your own identifying 171618Srie * information: Portions Copyright [yyyy] [name of copyright owner] 181618Srie * 191618Srie * CDDL HEADER END 201618Srie */ 211618Srie 221618Srie /* 231618Srie * Copyright (c) 1990, 1991 UNIX System Laboratories, Inc. 241618Srie * Copyright (c) 1988 AT&T 251618Srie * All Rights Reserved 261618Srie * 27*12155SAli.Bahrami@Sun.COM * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 281618Srie */ 291618Srie 306206Sab196087 /* Get the x86 version of the relocation engine */ 316206Sab196087 #define DO_RELOC_LIBLD_X86 326206Sab196087 331618Srie #include <string.h> 341618Srie #include <stdio.h> 351618Srie #include <sys/elf_386.h> 361618Srie #include <debug.h> 371618Srie #include <reloc.h> 386206Sab196087 #include <i386/machdep_x86.h> 391618Srie #include "msg.h" 401618Srie #include "_libld.h" 411618Srie 429131SRod.Evans@Sun.COM /* 439131SRod.Evans@Sun.COM * Search the GOT index list for a GOT entry with a matching reference. 449131SRod.Evans@Sun.COM */ 459131SRod.Evans@Sun.COM /* ARGSUSED3 */ 469131SRod.Evans@Sun.COM static Gotndx * 479131SRod.Evans@Sun.COM ld_find_got_ndx(Alist *alp, Gotref gref, Ofl_desc *ofl, Rel_desc *rdesc) 489131SRod.Evans@Sun.COM { 499131SRod.Evans@Sun.COM Aliste idx; 509131SRod.Evans@Sun.COM Gotndx *gnp; 519131SRod.Evans@Sun.COM 529131SRod.Evans@Sun.COM if ((gref == GOT_REF_TLSLD) && ofl->ofl_tlsldgotndx) 539131SRod.Evans@Sun.COM return (ofl->ofl_tlsldgotndx); 549131SRod.Evans@Sun.COM 559131SRod.Evans@Sun.COM for (ALIST_TRAVERSE(alp, idx, gnp)) { 569131SRod.Evans@Sun.COM if (gnp->gn_gotref == gref) 579131SRod.Evans@Sun.COM return (gnp); 589131SRod.Evans@Sun.COM } 599131SRod.Evans@Sun.COM return (NULL); 609131SRod.Evans@Sun.COM } 616206Sab196087 629131SRod.Evans@Sun.COM static Xword 639131SRod.Evans@Sun.COM ld_calc_got_offset(Rel_desc *rdesc, Ofl_desc *ofl) 649131SRod.Evans@Sun.COM { 659131SRod.Evans@Sun.COM Os_desc *osp = ofl->ofl_osgot; 669131SRod.Evans@Sun.COM Sym_desc *sdp = rdesc->rel_sym; 679131SRod.Evans@Sun.COM Xword gotndx; 689131SRod.Evans@Sun.COM Gotref gref; 699131SRod.Evans@Sun.COM Gotndx *gnp; 709131SRod.Evans@Sun.COM 719131SRod.Evans@Sun.COM if (rdesc->rel_flags & FLG_REL_DTLS) 729131SRod.Evans@Sun.COM gref = GOT_REF_TLSGD; 739131SRod.Evans@Sun.COM else if (rdesc->rel_flags & FLG_REL_MTLS) 749131SRod.Evans@Sun.COM gref = GOT_REF_TLSLD; 759131SRod.Evans@Sun.COM else if (rdesc->rel_flags & FLG_REL_STLS) 769131SRod.Evans@Sun.COM gref = GOT_REF_TLSIE; 779131SRod.Evans@Sun.COM else 789131SRod.Evans@Sun.COM gref = GOT_REF_GENERIC; 799131SRod.Evans@Sun.COM 809131SRod.Evans@Sun.COM gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL); 819131SRod.Evans@Sun.COM assert(gnp); 829131SRod.Evans@Sun.COM 839131SRod.Evans@Sun.COM gotndx = (Xword)gnp->gn_gotndx; 849131SRod.Evans@Sun.COM 859131SRod.Evans@Sun.COM if ((rdesc->rel_flags & FLG_REL_DTLS) && 869131SRod.Evans@Sun.COM (rdesc->rel_rtype == R_386_TLS_DTPOFF32)) 879131SRod.Evans@Sun.COM gotndx++; 889131SRod.Evans@Sun.COM 899131SRod.Evans@Sun.COM return ((Xword)(osp->os_shdr->sh_addr + (gotndx * M_GOT_ENTSIZE))); 909131SRod.Evans@Sun.COM } 916206Sab196087 926206Sab196087 static Word 93*12155SAli.Bahrami@Sun.COM ld_init_rel(Rel_desc *reld, Word *typedata, void *reloc) 941618Srie { 959131SRod.Evans@Sun.COM Rel *rel = (Rel *)reloc; 961618Srie 971618Srie /* LINTED */ 986206Sab196087 reld->rel_rtype = (Word)ELF_R_TYPE(rel->r_info, M_MACH); 991618Srie reld->rel_roffset = rel->r_offset; 1001618Srie reld->rel_raddend = 0; 101*12155SAli.Bahrami@Sun.COM *typedata = 0; 1021618Srie 1031618Srie return ((Word)ELF_R_SYM(rel->r_info)); 1041618Srie } 1051618Srie 1066206Sab196087 static void 1071618Srie ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl) 1081618Srie { 1091618Srie ofl->ofl_dehdr->e_flags |= ehdr->e_flags; 1101618Srie } 1111618Srie 1126206Sab196087 static void 1131618Srie ld_mach_make_dynamic(Ofl_desc *ofl, size_t *cnt) 1141618Srie { 1151618Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) { 1161618Srie /* 1171618Srie * Create this entry if we are going to create a PLT table. 1181618Srie */ 1191618Srie if (ofl->ofl_pltcnt) 1201618Srie (*cnt)++; /* DT_PLTGOT */ 1211618Srie } 1221618Srie } 1231618Srie 1246206Sab196087 static void 1252145Srie ld_mach_update_odynamic(Ofl_desc *ofl, Dyn **dyn) 1261618Srie { 1271618Srie if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) && ofl->ofl_pltcnt) { 1281618Srie (*dyn)->d_tag = DT_PLTGOT; 1291618Srie if (ofl->ofl_osgot) 1301618Srie (*dyn)->d_un.d_ptr = ofl->ofl_osgot->os_shdr->sh_addr; 1311618Srie else 1321618Srie (*dyn)->d_un.d_ptr = 0; 1331618Srie (*dyn)++; 1341618Srie } 1351618Srie } 1361618Srie 1376206Sab196087 static Xword 1381618Srie ld_calc_plt_addr(Sym_desc *sdp, Ofl_desc *ofl) 1391618Srie { 1401618Srie Xword value; 1411618Srie 1421618Srie value = (Xword)(ofl->ofl_osplt->os_shdr->sh_addr) + 1431618Srie M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * M_PLT_ENTSIZE); 1441618Srie return (value); 1451618Srie } 1461618Srie 1471618Srie /* 1481618Srie * Build a single plt entry - code is: 1491618Srie * if (building a.out) 1501618Srie * JMP *got_off 1511618Srie * else 1521618Srie * JMP *got_off@GOT(%ebx) 1531618Srie * PUSHL &rel_off 1541618Srie * JMP -n(%pc) # -n is pcrel offset to first plt entry 1551618Srie * 1561618Srie * The got_off@GOT entry gets filled with the address of the PUSHL, 1571618Srie * so the first pass through the plt jumps back here, jumping 1581618Srie * in turn to the first plt entry, which jumps to the dynamic 1591618Srie * linker. The dynamic linker then patches the GOT, rerouting 1601618Srie * future plt calls to the proper destination. 1611618Srie */ 1621618Srie static void 1631618Srie plt_entry(Ofl_desc * ofl, Word rel_off, Sym_desc * sdp) 1641618Srie { 1651618Srie uchar_t *pltent, *gotent; 1661618Srie Sword plt_off; 1671618Srie Word got_off; 1686206Sab196087 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 1691618Srie 1701618Srie got_off = sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 1711618Srie plt_off = M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * 1721618Srie M_PLT_ENTSIZE); 1731618Srie pltent = (uchar_t *)(ofl->ofl_osplt->os_outdata->d_buf) + plt_off; 1741618Srie gotent = (uchar_t *)(ofl->ofl_osgot->os_outdata->d_buf) + got_off; 1751618Srie 1761618Srie /* 1771618Srie * Fill in the got entry with the address of the next instruction. 1781618Srie */ 1791618Srie /* LINTED */ 1801618Srie *(Word *)gotent = ofl->ofl_osplt->os_shdr->sh_addr + plt_off + 1811618Srie M_PLT_INSSIZE; 1826206Sab196087 if (bswap) 1836206Sab196087 /* LINTED */ 1846206Sab196087 *(Word *)gotent = ld_bswap_Word(*(Word *)gotent); 1851618Srie 1861618Srie if (!(ofl->ofl_flags & FLG_OF_SHAROBJ)) { 1871618Srie pltent[0] = M_SPECIAL_INST; 1881618Srie pltent[1] = M_JMP_DISP_IND; 1891618Srie pltent += 2; 1901618Srie /* LINTED */ 1911618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr->sh_addr + 1924734Sab196087 got_off); 1931618Srie } else { 1941618Srie pltent[0] = M_SPECIAL_INST; 1951618Srie pltent[1] = M_JMP_REG_DISP_IND; 1961618Srie pltent += 2; 1971618Srie /* LINTED */ 1981618Srie *(Word *)pltent = (Word)got_off; 1991618Srie } 2006206Sab196087 if (bswap) 2016206Sab196087 /* LINTED */ 2026206Sab196087 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent); 2031618Srie pltent += 4; 2041618Srie 2051618Srie pltent[0] = M_INST_PUSHL; 2061618Srie pltent++; 2071618Srie /* LINTED */ 2081618Srie *(Word *)pltent = (Word)rel_off; 2096206Sab196087 if (bswap) 2106206Sab196087 /* LINTED */ 2116206Sab196087 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent); 2121618Srie pltent += 4; 2131618Srie 2141618Srie plt_off = -(plt_off + 16); /* JMP, PUSHL, JMP take 16 bytes */ 2151618Srie pltent[0] = M_INST_JMP; 2161618Srie pltent++; 2171618Srie /* LINTED */ 2181618Srie *(Word *)pltent = (Word)plt_off; 2196206Sab196087 if (bswap) 2206206Sab196087 /* LINTED */ 2216206Sab196087 *(Word *)pltent = ld_bswap_Word(*(Word *)pltent); 2221618Srie } 2231618Srie 2246206Sab196087 static uintptr_t 2251618Srie ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl) 2261618Srie { 2271618Srie Os_desc * relosp, * osp = 0; 2281618Srie Word ndx, roffset, value; 2291618Srie Rel rea; 2301618Srie char *relbits; 2311618Srie Sym_desc * sdp, * psym = (Sym_desc *)0; 2321618Srie int sectmoved = 0; 2331618Srie 2341618Srie sdp = orsp->rel_sym; 2351618Srie 2361618Srie /* 2371618Srie * If the section this relocation is against has been discarded 2381618Srie * (-zignore), then also discard (skip) the relocation itself. 2391618Srie */ 2401618Srie if (orsp->rel_isdesc && ((orsp->rel_flags & 2411618Srie (FLG_REL_GOT | FLG_REL_BSS | FLG_REL_PLT | FLG_REL_NOINFO)) == 0) && 2421618Srie (orsp->rel_isdesc->is_flags & FLG_IS_DISCARD)) { 2431618Srie DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, orsp)); 2441618Srie return (1); 2451618Srie } 2461618Srie 2471618Srie /* 2481618Srie * If this is a relocation against a move table, or expanded move 2491618Srie * table, adjust the relocation entries. 2501618Srie */ 251*12155SAli.Bahrami@Sun.COM if (RELAUX_GET_MOVE(orsp)) 2521618Srie ld_adj_movereloc(ofl, orsp); 2531618Srie 2541618Srie /* 2551618Srie * If this is a relocation against a section using a partial initialized 2561618Srie * symbol, adjust the embedded symbol info. 2571618Srie * 2581618Srie * The second argument of the am_I_partial() is the value stored at the 2591618Srie * target address relocation is going to be applied. 2601618Srie */ 2611618Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 2629131SRod.Evans@Sun.COM if (ofl->ofl_parsyms && 2631618Srie (sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 2641618Srie /* LINTED */ 2651618Srie (psym = ld_am_I_partial(orsp, *(Xword *) 2661618Srie ((uchar_t *)(orsp->rel_isdesc->is_indata->d_buf) + 2671618Srie orsp->rel_roffset)))) { 2681618Srie DBG_CALL(Dbg_move_outsctadj(ofl->ofl_lml, psym)); 2691618Srie sectmoved = 1; 2704734Sab196087 } 2711618Srie } 2721618Srie 2731618Srie value = sdp->sd_sym->st_value; 2741618Srie 2751618Srie if (orsp->rel_flags & FLG_REL_GOT) { 2761618Srie osp = ofl->ofl_osgot; 2771618Srie roffset = (Word)ld_calc_got_offset(orsp, ofl); 2781618Srie 2791618Srie } else if (orsp->rel_flags & FLG_REL_PLT) { 2801618Srie /* 2811618Srie * Note that relocations for PLT's actually 2821618Srie * cause a relocation againt the GOT. 2831618Srie */ 2841618Srie osp = ofl->ofl_osplt; 2851618Srie roffset = (Word) (ofl->ofl_osgot->os_shdr->sh_addr) + 2861618Srie sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 2871618Srie 2881618Srie plt_entry(ofl, osp->os_relosdesc->os_szoutrels, sdp); 2891618Srie 2901618Srie } else if (orsp->rel_flags & FLG_REL_BSS) { 2911618Srie /* 2921618Srie * This must be a R_386_COPY. For these set the roffset to 2931618Srie * point to the new symbols location. 2941618Srie */ 2951618Srie osp = ofl->ofl_isbss->is_osdesc; 2961618Srie roffset = (Word)value; 2971618Srie } else { 298*12155SAli.Bahrami@Sun.COM osp = RELAUX_GET_OSDESC(orsp); 2991618Srie 3001618Srie /* 3011618Srie * Calculate virtual offset of reference point; equals offset 3021618Srie * into section + vaddr of section for loadable sections, or 3031618Srie * offset plus section displacement for nonloadable sections. 3041618Srie */ 3051618Srie roffset = orsp->rel_roffset + 3061618Srie (Off)_elf_getxoff(orsp->rel_isdesc->is_indata); 3071618Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) 3081618Srie roffset += orsp->rel_isdesc->is_osdesc-> 3091618Srie os_shdr->sh_addr; 3101618Srie } 3111618Srie 3121618Srie if ((osp == 0) || ((relosp = osp->os_relosdesc) == 0)) 3131618Srie relosp = ofl->ofl_osrel; 3141618Srie 3151618Srie /* 3161618Srie * Assign the symbols index for the output relocation. If the 3171618Srie * relocation refers to a SECTION symbol then it's index is based upon 3181618Srie * the output sections symbols index. Otherwise the index can be 3191618Srie * derived from the symbols index itself. 3201618Srie */ 3211618Srie if (orsp->rel_rtype == R_386_RELATIVE) 3221618Srie ndx = STN_UNDEF; 3231618Srie else if ((orsp->rel_flags & FLG_REL_SCNNDX) || 3241618Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION)) { 3251618Srie if (sectmoved == 0) { 3261618Srie /* 3271618Srie * Check for a null input section. This can 3281618Srie * occur if this relocation references a symbol 3291618Srie * generated by sym_add_sym(). 3301618Srie */ 3319131SRod.Evans@Sun.COM if (sdp->sd_isc && sdp->sd_isc->is_osdesc) 3329131SRod.Evans@Sun.COM ndx = sdp->sd_isc->is_osdesc->os_identndx; 3331618Srie else 3341618Srie ndx = sdp->sd_shndx; 3351618Srie } else 3368159SAli.Bahrami@Sun.COM ndx = ofl->ofl_parexpnndx; 3371618Srie } else 3381618Srie ndx = sdp->sd_symndx; 3391618Srie 3405892Sab196087 /* 3415892Sab196087 * If we have a replacement value for the relocation 3425892Sab196087 * target, put it in place now. 3435892Sab196087 */ 3445892Sab196087 if (orsp->rel_flags & FLG_REL_NADDEND) { 3455892Sab196087 Xword addend = orsp->rel_raddend; 3465892Sab196087 uchar_t *addr; 3475892Sab196087 3485892Sab196087 /* 3495892Sab196087 * Get the address of the data item we need to modify. 3505892Sab196087 */ 3515892Sab196087 addr = (uchar_t *)((uintptr_t)orsp->rel_roffset + 3525892Sab196087 (uintptr_t)_elf_getxoff(orsp->rel_isdesc->is_indata)); 353*12155SAli.Bahrami@Sun.COM addr += (uintptr_t)RELAUX_GET_OSDESC(orsp)->os_outdata->d_buf; 3545892Sab196087 if (ld_reloc_targval_set(ofl, orsp, addr, addend) == 0) 3555892Sab196087 return (S_ERROR); 3565892Sab196087 } 3575892Sab196087 3581618Srie relbits = (char *)relosp->os_outdata->d_buf; 3591618Srie 3601618Srie rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); 3611618Srie rea.r_offset = roffset; 3621618Srie DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_REL, &rea, relosp->os_name, 363*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name(orsp))); 3641618Srie 3651618Srie /* 3661618Srie * Assert we haven't walked off the end of our relocation table. 3671618Srie */ 3681618Srie assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); 3691618Srie 3701618Srie (void) memcpy((relbits + relosp->os_szoutrels), 3711618Srie (char *)&rea, sizeof (Rel)); 3721618Srie relosp->os_szoutrels += sizeof (Rel); 3731618Srie 3741618Srie /* 3751618Srie * Determine if this relocation is against a non-writable, allocatable 3761618Srie * section. If so we may need to provide a text relocation diagnostic. 3771618Srie * Note that relocations against the .plt (R_386_JMP_SLOT) actually 3781618Srie * result in modifications to the .got. 3791618Srie */ 3801618Srie if (orsp->rel_rtype == R_386_JMP_SLOT) 3811618Srie osp = ofl->ofl_osgot; 3821618Srie 3831618Srie ld_reloc_remain_entry(orsp, osp, ofl); 3841618Srie return (1); 3851618Srie } 3861618Srie 3871618Srie /* 3881618Srie * i386 Instructions for TLS processing 3891618Srie */ 3901618Srie static uchar_t tlsinstr_gd_ie[] = { 3911618Srie /* 3921618Srie * 0x00 movl %gs:0x0, %eax 3931618Srie */ 3941618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, 3951618Srie /* 3961618Srie * 0x06 addl x(%eax), %eax 3971618Srie * 0x0c ... 3981618Srie */ 3991618Srie 0x03, 0x80, 0x00, 0x00, 0x00, 0x00 4001618Srie }; 4011618Srie 4021618Srie static uchar_t tlsinstr_gd_le[] = { 4031618Srie /* 4041618Srie * 0x00 movl %gs:0x0, %eax 4051618Srie */ 4061618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, 4071618Srie /* 4081618Srie * 0x06 addl $0x0, %eax 4091618Srie */ 4101618Srie 0x05, 0x00, 0x00, 0x00, 0x00, 4111618Srie /* 4121618Srie * 0x0b nop 4131618Srie * 0x0c 4141618Srie */ 4151618Srie 0x90 4161618Srie }; 4171618Srie 4181618Srie static uchar_t tlsinstr_gd_ie_movgs[] = { 4191618Srie /* 4201618Srie * movl %gs:0x0,%eax 4211618Srie */ 4221618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 00 4231618Srie }; 4241618Srie 4251618Srie #define TLS_GD_IE_MOV 0x8b /* movl opcode */ 4261618Srie #define TLS_GD_IE_POP 0x58 /* popl + reg */ 4271618Srie 4281618Srie #define TLS_GD_LE_MOVL 0xb8 /* movl + reg */ 4291618Srie 4301618Srie #define TLS_NOP 0x90 /* NOP instruction */ 4311618Srie 4321618Srie #define MODRM_MSK_MOD 0xc0 4331618Srie #define MODRM_MSK_RO 0x38 4341618Srie #define MODRM_MSK_RM 0x07 4351618Srie 4361618Srie #define SIB_MSK_SS 0xc0 4371618Srie #define SIB_MSK_IND 0x38 4381618Srie #define SIB_MSK_BS 0x07 4391618Srie 4401618Srie static Fixupret 4411618Srie tls_fixups(Ofl_desc *ofl, Rel_desc *arsp) 4421618Srie { 4431618Srie Sym_desc *sdp = arsp->rel_sym; 4441618Srie Word rtype = arsp->rel_rtype; 4451618Srie uchar_t *offset, r1, r2; 4461618Srie 4471618Srie offset = (uchar_t *)((uintptr_t)arsp->rel_roffset + 4481618Srie (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata) + 449*12155SAli.Bahrami@Sun.COM (uintptr_t)RELAUX_GET_OSDESC(arsp)->os_outdata->d_buf); 4501618Srie 4511618Srie if (sdp->sd_ref == REF_DYN_NEED) { 4521618Srie /* 4531618Srie * IE reference model 4541618Srie */ 4551618Srie switch (rtype) { 4561618Srie case R_386_TLS_GD: 4571618Srie /* 4581618Srie * Transition: 4591618Srie * 0x0 leal x@tlsgd(,r1,1), %eax 4601618Srie * 0x7 call ___tls_get_addr 4611618Srie * 0xc 4621618Srie * To: 4631618Srie * 0x0 movl %gs:0, %eax 4641618Srie * 0x6 addl x@gotntpoff(r1), %eax 4651618Srie */ 4661618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 467*12155SAli.Bahrami@Sun.COM R_386_TLS_GOTIE, arsp, ld_reloc_sym_name)); 4681618Srie arsp->rel_rtype = R_386_TLS_GOTIE; 4691618Srie arsp->rel_roffset += 5; 4701618Srie 4711618Srie /* 4723304Srie * Adjust 'offset' to beginning of instruction 4731618Srie * sequence. 4741618Srie */ 4751618Srie offset -= 3; 4761618Srie r1 = (offset[2] & SIB_MSK_IND) >> 3; 4771618Srie (void) memcpy(offset, tlsinstr_gd_ie, 4781618Srie sizeof (tlsinstr_gd_ie)); 4791618Srie 4801618Srie /* 4811618Srie * set register %r1 into the addl 4821618Srie * instruction. 4831618Srie */ 4841618Srie offset[0x7] |= r1; 4851618Srie return (FIX_RELOC); 4861618Srie 4871618Srie case R_386_TLS_GD_PLT: 4881618Srie /* 4891618Srie * Fixup done via the TLS_GD relocation 4901618Srie */ 4911618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 492*12155SAli.Bahrami@Sun.COM R_386_NONE, arsp, ld_reloc_sym_name)); 4931618Srie return (FIX_DONE); 4941618Srie } 4951618Srie } 4961618Srie 4971618Srie /* 4981618Srie * LE reference model 4991618Srie */ 5001618Srie switch (rtype) { 5011618Srie case R_386_TLS_GD: 5021618Srie /* 5031618Srie * Transition: 5041618Srie * 0x0 leal x@tlsgd(,r1,1), %eax 5051618Srie * 0x7 call ___tls_get_addr 5061618Srie * 0xc 5071618Srie * To: 5081618Srie * 0x0 movl %gs:0, %eax 5091618Srie * 0x6 addl $x@ntpoff, %eax 5101618Srie * 0xb nop 5111618Srie * 0xc 5121618Srie */ 5131618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 514*12155SAli.Bahrami@Sun.COM R_386_TLS_LE, arsp, ld_reloc_sym_name)); 5151618Srie 5161618Srie arsp->rel_rtype = R_386_TLS_LE; 5171618Srie arsp->rel_roffset += 4; 5181618Srie 5191618Srie /* 5203304Srie * Adjust 'offset' to beginning of instruction 5211618Srie * sequence. 5221618Srie */ 5231618Srie offset -= 3; 5241618Srie (void) memcpy(offset, tlsinstr_gd_le, 5251618Srie sizeof (tlsinstr_gd_le)); 5261618Srie return (FIX_RELOC); 5271618Srie 5281618Srie case R_386_TLS_GD_PLT: 5291618Srie case R_386_PLT32: 5301618Srie /* 5311618Srie * Fixup done via the TLS_GD relocation 5321618Srie */ 5331618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 534*12155SAli.Bahrami@Sun.COM R_386_NONE, arsp, ld_reloc_sym_name)); 5351618Srie return (FIX_DONE); 5361618Srie 5371618Srie case R_386_TLS_LDM_PLT: 5381618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 539*12155SAli.Bahrami@Sun.COM R_386_NONE, arsp, ld_reloc_sym_name)); 5401618Srie 5411618Srie /* 5421618Srie * Transition: 5431618Srie * call __tls_get_addr() 5441618Srie * to: 5451618Srie * nop 5461618Srie * nop 5471618Srie * nop 5481618Srie * nop 5491618Srie * nop 5501618Srie */ 5511618Srie *(offset - 1) = TLS_NOP; 5521618Srie *(offset) = TLS_NOP; 5531618Srie *(offset + 1) = TLS_NOP; 5541618Srie *(offset + 2) = TLS_NOP; 5551618Srie *(offset + 3) = TLS_NOP; 5561618Srie return (FIX_DONE); 5571618Srie 5581618Srie case R_386_TLS_LDM: 5591618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 560*12155SAli.Bahrami@Sun.COM R_386_NONE, arsp, ld_reloc_sym_name)); 5611618Srie 5621618Srie /* 5631618Srie * Transition: 5641618Srie * 5651618Srie * 0x00 leal x1@tlsldm(%ebx), %eax 5661618Srie * 0x06 call ___tls_get_addr 5671618Srie * 5681618Srie * to: 5691618Srie * 5701618Srie * 0x00 movl %gs:0, %eax 5711618Srie */ 5721618Srie (void) memcpy(offset - 2, tlsinstr_gd_ie_movgs, 5731618Srie sizeof (tlsinstr_gd_ie_movgs)); 5741618Srie return (FIX_DONE); 5751618Srie 5761618Srie case R_386_TLS_LDO_32: 5771618Srie /* 5781618Srie * Instructions: 5791618Srie * 5801618Srie * 0x10 leal x1@dtpoff(%eax), %edx R_386_TLS_LDO_32 5811618Srie * to 5821618Srie * 0x10 leal x1@ntpoff(%eax), %edx R_386_TLS_LE 5831618Srie * 5841618Srie */ 5851618Srie offset -= 2; 5861618Srie 5871618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 588*12155SAli.Bahrami@Sun.COM R_386_TLS_LE, arsp, ld_reloc_sym_name)); 5891618Srie arsp->rel_rtype = R_386_TLS_LE; 5901618Srie return (FIX_RELOC); 5911618Srie 5921618Srie case R_386_TLS_GOTIE: 5931618Srie /* 5941618Srie * These transitions are a little different than the 5951618Srie * others, in that we could have multiple instructions 5961618Srie * pointed to by a single relocation. Depending upon the 5971618Srie * instruction, we perform a different code transition. 5981618Srie * 5991618Srie * Here's the known transitions: 6001618Srie * 6011618Srie * 1) movl foo@gotntpoff(%reg1), %reg2 6021618Srie * 0x8b, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff 6031618Srie * 6041618Srie * 2) addl foo@gotntpoff(%reg1), %reg2 6051618Srie * 0x03, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff 6061618Srie * 6071618Srie * Transitions IE -> LE 6081618Srie * 6091618Srie * 1) movl $foo@ntpoff, %reg2 6101618Srie * 0xc7, 0xc0 | reg2, foo@ntpoff 6111618Srie * 6121618Srie * 2) addl $foo@ntpoff, %reg2 6131618Srie * 0x81, 0xc0 | reg2, foo@ntpoff 6141618Srie * 6151618Srie * Note: reg1 != 4 (%esp) 6161618Srie */ 6171618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 618*12155SAli.Bahrami@Sun.COM R_386_TLS_LE, arsp, ld_reloc_sym_name)); 6191618Srie arsp->rel_rtype = R_386_TLS_LE; 6201618Srie 6211618Srie offset -= 2; 6221618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 6231618Srie if (offset[0] == 0x8b) { 6241618Srie /* case 1 above */ 6251618Srie offset[0] = 0xc7; /* movl */ 6261618Srie offset[1] = 0xc0 | r2; 6271618Srie return (FIX_RELOC); 6281618Srie } 6291618Srie 6301618Srie if (offset[0] == 0x03) { 6311618Srie /* case 2 above */ 6321618Srie assert(offset[0] == 0x03); 6331618Srie offset[0] = 0x81; /* addl */ 6341618Srie offset[1] = 0xc0 | r2; 6351618Srie return (FIX_RELOC); 6361618Srie } 6371618Srie 6381618Srie /* 6391618Srie * Unexpected instruction sequence - fatal error. 6401618Srie */ 6414734Sab196087 { 6424734Sab196087 Conv_inv_buf_t inv_buf; 6434734Sab196087 6444734Sab196087 eprintf(ofl->ofl_lml, ERR_FATAL, 6454734Sab196087 MSG_INTL(MSG_REL_BADTLSINS), 6464734Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf), 6474734Sab196087 arsp->rel_isdesc->is_file->ifl_name, 648*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name(arsp), 6494734Sab196087 arsp->rel_isdesc->is_name, 6504734Sab196087 EC_OFF(arsp->rel_roffset)); 6514734Sab196087 } 6521618Srie return (FIX_ERROR); 6531618Srie 6541618Srie case R_386_TLS_IE: 6551618Srie /* 6561618Srie * These transitions are a little different than the 6571618Srie * others, in that we could have multiple instructions 6581618Srie * pointed to by a single relocation. Depending upon the 6591618Srie * instruction, we perform a different code transition. 6601618Srie * 6611618Srie * Here's the known transitions: 6621618Srie * 1) movl foo@indntpoff, %eax 6631618Srie * 0xa1, foo@indntpoff 6641618Srie * 6651618Srie * 2) movl foo@indntpoff, %eax 6661618Srie * 0x8b, 0x05 | (reg << 3), foo@gotntpoff 6671618Srie * 6681618Srie * 3) addl foo@indntpoff, %eax 6691618Srie * 0x03, 0x05 | (reg << 3), foo@gotntpoff 6701618Srie * 6711618Srie * Transitions IE -> LE 6721618Srie * 6731618Srie * 1) movl $foo@ntpoff, %eax 6741618Srie * 0xb8, foo@ntpoff 6751618Srie * 6761618Srie * 2) movl $foo@ntpoff, %reg 6771618Srie * 0xc7, 0xc0 | reg, foo@ntpoff 6781618Srie * 6791618Srie * 3) addl $foo@ntpoff, %reg 6801618Srie * 0x81, 0xc0 | reg, foo@ntpoff 6811618Srie */ 6821618Srie arsp->rel_rtype = R_386_TLS_LE; 6831618Srie offset--; 6841618Srie if (offset[0] == 0xa1) { 6851618Srie /* case 1 above */ 6861618Srie offset[0] = 0xb8; /* movl */ 6871618Srie return (FIX_RELOC); 6881618Srie } 6891618Srie 6901618Srie offset--; 6911618Srie if (offset[0] == 0x8b) { 6921618Srie /* case 2 above */ 6931618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 6941618Srie offset[0] = 0xc7; /* movl */ 6951618Srie offset[1] = 0xc0 | r2; 6961618Srie return (FIX_RELOC); 6971618Srie } 6981618Srie if (offset[0] == 0x03) { 6991618Srie /* case 3 above */ 7001618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 7011618Srie offset[0] = 0x81; /* addl */ 7021618Srie offset[1] = 0xc0 | r2; 7031618Srie return (FIX_RELOC); 7041618Srie } 7051618Srie /* 7061618Srie * Unexpected instruction sequence - fatal error. 7071618Srie */ 7084734Sab196087 { 7094734Sab196087 Conv_inv_buf_t inv_buf; 7104734Sab196087 7114734Sab196087 eprintf(ofl->ofl_lml, ERR_FATAL, 7124734Sab196087 MSG_INTL(MSG_REL_BADTLSINS), 7134734Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf), 7144734Sab196087 arsp->rel_isdesc->is_file->ifl_name, 715*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name(arsp), 7164734Sab196087 arsp->rel_isdesc->is_name, 7174734Sab196087 EC_OFF(arsp->rel_roffset)); 7184734Sab196087 } 7191618Srie return (FIX_ERROR); 7201618Srie } 7211618Srie return (FIX_RELOC); 7221618Srie } 7231618Srie 7246206Sab196087 static uintptr_t 7251618Srie ld_do_activerelocs(Ofl_desc *ofl) 7261618Srie { 7271618Srie Rel_desc *arsp; 728*12155SAli.Bahrami@Sun.COM Rel_cachebuf *rcbp; 7299131SRod.Evans@Sun.COM Aliste idx; 7301618Srie uintptr_t return_code = 1; 7316299Sab196087 ofl_flag_t flags = ofl->ofl_flags; 7321618Srie 733*12155SAli.Bahrami@Sun.COM if (aplist_nitems(ofl->ofl_actrels.rc_list) != 0) 7342647Srie DBG_CALL(Dbg_reloc_doact_title(ofl->ofl_lml)); 7352647Srie 7361618Srie /* 7371618Srie * Process active relocations. 7381618Srie */ 739*12155SAli.Bahrami@Sun.COM REL_CACHE_TRAVERSE(&ofl->ofl_actrels, idx, rcbp, arsp) { 740*12155SAli.Bahrami@Sun.COM uchar_t *addr; 741*12155SAli.Bahrami@Sun.COM Xword value; 742*12155SAli.Bahrami@Sun.COM Sym_desc *sdp; 743*12155SAli.Bahrami@Sun.COM const char *ifl_name; 744*12155SAli.Bahrami@Sun.COM Xword refaddr; 745*12155SAli.Bahrami@Sun.COM int moved = 0; 746*12155SAli.Bahrami@Sun.COM Gotref gref; 747*12155SAli.Bahrami@Sun.COM Os_desc *osp; 748*12155SAli.Bahrami@Sun.COM 749*12155SAli.Bahrami@Sun.COM /* 750*12155SAli.Bahrami@Sun.COM * If the section this relocation is against has been discarded 751*12155SAli.Bahrami@Sun.COM * (-zignore), then discard (skip) the relocation itself. 752*12155SAli.Bahrami@Sun.COM */ 753*12155SAli.Bahrami@Sun.COM if ((arsp->rel_isdesc->is_flags & FLG_IS_DISCARD) && 754*12155SAli.Bahrami@Sun.COM ((arsp->rel_flags & (FLG_REL_GOT | FLG_REL_BSS | 755*12155SAli.Bahrami@Sun.COM FLG_REL_PLT | FLG_REL_NOINFO)) == 0)) { 756*12155SAli.Bahrami@Sun.COM DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, arsp)); 757*12155SAli.Bahrami@Sun.COM continue; 758*12155SAli.Bahrami@Sun.COM } 7591618Srie 760*12155SAli.Bahrami@Sun.COM /* 761*12155SAli.Bahrami@Sun.COM * We determine what the 'got reference' model (if required) 762*12155SAli.Bahrami@Sun.COM * is at this point. This needs to be done before tls_fixup() 763*12155SAli.Bahrami@Sun.COM * since it may 'transition' our instructions. 764*12155SAli.Bahrami@Sun.COM * 765*12155SAli.Bahrami@Sun.COM * The got table entries have already been assigned, 766*12155SAli.Bahrami@Sun.COM * and we bind to those initial entries. 767*12155SAli.Bahrami@Sun.COM */ 768*12155SAli.Bahrami@Sun.COM if (arsp->rel_flags & FLG_REL_DTLS) 769*12155SAli.Bahrami@Sun.COM gref = GOT_REF_TLSGD; 770*12155SAli.Bahrami@Sun.COM else if (arsp->rel_flags & FLG_REL_MTLS) 771*12155SAli.Bahrami@Sun.COM gref = GOT_REF_TLSLD; 772*12155SAli.Bahrami@Sun.COM else if (arsp->rel_flags & FLG_REL_STLS) 773*12155SAli.Bahrami@Sun.COM gref = GOT_REF_TLSIE; 774*12155SAli.Bahrami@Sun.COM else 775*12155SAli.Bahrami@Sun.COM gref = GOT_REF_GENERIC; 776*12155SAli.Bahrami@Sun.COM 777*12155SAli.Bahrami@Sun.COM /* 778*12155SAli.Bahrami@Sun.COM * Perform any required TLS fixups. 779*12155SAli.Bahrami@Sun.COM */ 780*12155SAli.Bahrami@Sun.COM if (arsp->rel_flags & FLG_REL_TLSFIX) { 781*12155SAli.Bahrami@Sun.COM Fixupret ret; 782*12155SAli.Bahrami@Sun.COM 783*12155SAli.Bahrami@Sun.COM if ((ret = tls_fixups(ofl, arsp)) == FIX_ERROR) 784*12155SAli.Bahrami@Sun.COM return (S_ERROR); 785*12155SAli.Bahrami@Sun.COM if (ret == FIX_DONE) 786*12155SAli.Bahrami@Sun.COM continue; 787*12155SAli.Bahrami@Sun.COM } 788*12155SAli.Bahrami@Sun.COM 789*12155SAli.Bahrami@Sun.COM /* 790*12155SAli.Bahrami@Sun.COM * If this is a relocation against a move table, or 791*12155SAli.Bahrami@Sun.COM * expanded move table, adjust the relocation entries. 792*12155SAli.Bahrami@Sun.COM */ 793*12155SAli.Bahrami@Sun.COM if (RELAUX_GET_MOVE(arsp)) 794*12155SAli.Bahrami@Sun.COM ld_adj_movereloc(ofl, arsp); 795*12155SAli.Bahrami@Sun.COM 796*12155SAli.Bahrami@Sun.COM sdp = arsp->rel_sym; 797*12155SAli.Bahrami@Sun.COM refaddr = arsp->rel_roffset + 798*12155SAli.Bahrami@Sun.COM (Off)_elf_getxoff(arsp->rel_isdesc->is_indata); 799*12155SAli.Bahrami@Sun.COM 800*12155SAli.Bahrami@Sun.COM if (arsp->rel_flags & FLG_REL_CLVAL) 801*12155SAli.Bahrami@Sun.COM value = 0; 802*12155SAli.Bahrami@Sun.COM else if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 8031618Srie /* 804*12155SAli.Bahrami@Sun.COM * The value for a symbol pointing to a SECTION 805*12155SAli.Bahrami@Sun.COM * is based off of that sections position. 8061618Srie */ 807*12155SAli.Bahrami@Sun.COM if (sdp->sd_isc->is_flags & FLG_IS_RELUPD) { 808*12155SAli.Bahrami@Sun.COM Sym_desc *sym; 809*12155SAli.Bahrami@Sun.COM Xword radd; 810*12155SAli.Bahrami@Sun.COM uchar_t *raddr = (uchar_t *) 811*12155SAli.Bahrami@Sun.COM arsp->rel_isdesc->is_indata->d_buf + 812*12155SAli.Bahrami@Sun.COM arsp->rel_roffset; 8131618Srie 8141618Srie /* 815*12155SAli.Bahrami@Sun.COM * This is a REL platform. Hence, the second 816*12155SAli.Bahrami@Sun.COM * argument of ld_am_I_partial() is the value 817*12155SAli.Bahrami@Sun.COM * stored at the target address where the 818*12155SAli.Bahrami@Sun.COM * relocation is going to be applied. 8191618Srie */ 820*12155SAli.Bahrami@Sun.COM if (ld_reloc_targval_get(ofl, arsp, raddr, 821*12155SAli.Bahrami@Sun.COM &radd) == 0) 822*12155SAli.Bahrami@Sun.COM return (S_ERROR); 823*12155SAli.Bahrami@Sun.COM sym = ld_am_I_partial(arsp, radd); 824*12155SAli.Bahrami@Sun.COM if (sym) { 825*12155SAli.Bahrami@Sun.COM Sym *osym = sym->sd_osym; 8268369SAli.Bahrami@Sun.COM 8271618Srie /* 828*12155SAli.Bahrami@Sun.COM * The symbol was moved, so adjust the 829*12155SAli.Bahrami@Sun.COM * value relative to the new section. 8301618Srie */ 831*12155SAli.Bahrami@Sun.COM value = sym->sd_sym->st_value; 832*12155SAli.Bahrami@Sun.COM moved = 1; 8338369SAli.Bahrami@Sun.COM 834*12155SAli.Bahrami@Sun.COM /* 835*12155SAli.Bahrami@Sun.COM * The original raddend covers the 836*12155SAli.Bahrami@Sun.COM * displacement from the section start 837*12155SAli.Bahrami@Sun.COM * to the desired address. The value 838*12155SAli.Bahrami@Sun.COM * computed above gets us from the 839*12155SAli.Bahrami@Sun.COM * section start to the start of the 840*12155SAli.Bahrami@Sun.COM * symbol range. Adjust the old raddend 841*12155SAli.Bahrami@Sun.COM * to remove the offset from section 842*12155SAli.Bahrami@Sun.COM * start to symbol start, leaving the 843*12155SAli.Bahrami@Sun.COM * displacement within the range of 844*12155SAli.Bahrami@Sun.COM * the symbol. 845*12155SAli.Bahrami@Sun.COM */ 846*12155SAli.Bahrami@Sun.COM if (osym->st_value != 0) { 847*12155SAli.Bahrami@Sun.COM radd -= osym->st_value; 848*12155SAli.Bahrami@Sun.COM if (ld_reloc_targval_set(ofl, 849*12155SAli.Bahrami@Sun.COM arsp, raddr, radd) == 0) 850*12155SAli.Bahrami@Sun.COM return (S_ERROR); 8518369SAli.Bahrami@Sun.COM } 8528369SAli.Bahrami@Sun.COM } 853*12155SAli.Bahrami@Sun.COM } 854*12155SAli.Bahrami@Sun.COM if (!moved) { 855*12155SAli.Bahrami@Sun.COM value = _elf_getxoff(sdp->sd_isc->is_indata); 856*12155SAli.Bahrami@Sun.COM if (sdp->sd_isc->is_shdr->sh_flags & SHF_ALLOC) 857*12155SAli.Bahrami@Sun.COM value += sdp->sd_isc-> 858*12155SAli.Bahrami@Sun.COM is_osdesc->os_shdr->sh_addr; 859*12155SAli.Bahrami@Sun.COM } 860*12155SAli.Bahrami@Sun.COM if (sdp->sd_isc->is_shdr->sh_flags & SHF_TLS) 861*12155SAli.Bahrami@Sun.COM value -= ofl->ofl_tlsphdr->p_vaddr; 8622850Srie 863*12155SAli.Bahrami@Sun.COM } else if (IS_SIZE(arsp->rel_rtype)) { 864*12155SAli.Bahrami@Sun.COM /* 865*12155SAli.Bahrami@Sun.COM * Size relocations require the symbols size. 866*12155SAli.Bahrami@Sun.COM */ 867*12155SAli.Bahrami@Sun.COM value = sdp->sd_sym->st_size; 86811827SRod.Evans@Sun.COM 869*12155SAli.Bahrami@Sun.COM } else if ((sdp->sd_flags & FLG_SY_CAP) && 870*12155SAli.Bahrami@Sun.COM sdp->sd_aux && sdp->sd_aux->sa_PLTndx) { 871*12155SAli.Bahrami@Sun.COM /* 872*12155SAli.Bahrami@Sun.COM * If relocation is against a capabilities symbol, we 873*12155SAli.Bahrami@Sun.COM * need to jump to an associated PLT, so that at runtime 874*12155SAli.Bahrami@Sun.COM * ld.so.1 is involved to determine the best binding 875*12155SAli.Bahrami@Sun.COM * choice. Otherwise, the value is the symbols value. 876*12155SAli.Bahrami@Sun.COM */ 877*12155SAli.Bahrami@Sun.COM value = ld_calc_plt_addr(sdp, ofl); 878*12155SAli.Bahrami@Sun.COM 879*12155SAli.Bahrami@Sun.COM } else 880*12155SAli.Bahrami@Sun.COM value = sdp->sd_sym->st_value; 88111827SRod.Evans@Sun.COM 882*12155SAli.Bahrami@Sun.COM /* 883*12155SAli.Bahrami@Sun.COM * Relocation against the GLOBAL_OFFSET_TABLE. 884*12155SAli.Bahrami@Sun.COM */ 885*12155SAli.Bahrami@Sun.COM if ((arsp->rel_flags & FLG_REL_GOT) && 886*12155SAli.Bahrami@Sun.COM !ld_reloc_set_aux_osdesc(ofl, arsp, ofl->ofl_osgot)) 887*12155SAli.Bahrami@Sun.COM return (S_ERROR); 888*12155SAli.Bahrami@Sun.COM osp = RELAUX_GET_OSDESC(arsp); 8891618Srie 890*12155SAli.Bahrami@Sun.COM /* 891*12155SAli.Bahrami@Sun.COM * If loadable and not producing a relocatable object add the 892*12155SAli.Bahrami@Sun.COM * sections virtual address to the reference address. 893*12155SAli.Bahrami@Sun.COM */ 894*12155SAli.Bahrami@Sun.COM if ((arsp->rel_flags & FLG_REL_LOAD) && 895*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) 896*12155SAli.Bahrami@Sun.COM refaddr += 897*12155SAli.Bahrami@Sun.COM arsp->rel_isdesc->is_osdesc->os_shdr->sh_addr; 8981618Srie 899*12155SAli.Bahrami@Sun.COM /* 900*12155SAli.Bahrami@Sun.COM * If this entry has a PLT assigned to it, its value is actually 901*12155SAli.Bahrami@Sun.COM * the address of the PLT (and not the address of the function). 902*12155SAli.Bahrami@Sun.COM */ 903*12155SAli.Bahrami@Sun.COM if (IS_PLT(arsp->rel_rtype)) { 904*12155SAli.Bahrami@Sun.COM if (sdp->sd_aux && sdp->sd_aux->sa_PLTndx) 905*12155SAli.Bahrami@Sun.COM value = ld_calc_plt_addr(sdp, ofl); 906*12155SAli.Bahrami@Sun.COM } 9071618Srie 908*12155SAli.Bahrami@Sun.COM /* 909*12155SAli.Bahrami@Sun.COM * Determine whether the value needs further adjustment. Filter 910*12155SAli.Bahrami@Sun.COM * through the attributes of the relocation to determine what 911*12155SAli.Bahrami@Sun.COM * adjustment is required. Note, many of the following cases 912*12155SAli.Bahrami@Sun.COM * are only applicable when a .got is present. As a .got is 913*12155SAli.Bahrami@Sun.COM * not generated when a relocatable object is being built, 914*12155SAli.Bahrami@Sun.COM * any adjustments that require a .got need to be skipped. 915*12155SAli.Bahrami@Sun.COM */ 916*12155SAli.Bahrami@Sun.COM if ((arsp->rel_flags & FLG_REL_GOT) && 917*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 918*12155SAli.Bahrami@Sun.COM Xword R1addr; 919*12155SAli.Bahrami@Sun.COM uintptr_t R2addr; 920*12155SAli.Bahrami@Sun.COM Word gotndx; 921*12155SAli.Bahrami@Sun.COM Gotndx *gnp; 9221618Srie 9231618Srie /* 924*12155SAli.Bahrami@Sun.COM * Perform relocation against GOT table. Since this 925*12155SAli.Bahrami@Sun.COM * doesn't fit exactly into a relocation we place the 926*12155SAli.Bahrami@Sun.COM * appropriate byte in the GOT directly 927*12155SAli.Bahrami@Sun.COM * 928*12155SAli.Bahrami@Sun.COM * Calculate offset into GOT at which to apply 929*12155SAli.Bahrami@Sun.COM * the relocation. 9301618Srie */ 931*12155SAli.Bahrami@Sun.COM gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL); 932*12155SAli.Bahrami@Sun.COM assert(gnp); 9331618Srie 934*12155SAli.Bahrami@Sun.COM if (arsp->rel_rtype == R_386_TLS_DTPOFF32) 935*12155SAli.Bahrami@Sun.COM gotndx = gnp->gn_gotndx + 1; 936*12155SAli.Bahrami@Sun.COM else 937*12155SAli.Bahrami@Sun.COM gotndx = gnp->gn_gotndx; 9381618Srie 939*12155SAli.Bahrami@Sun.COM R1addr = (Xword)(gotndx * M_GOT_ENTSIZE); 9401618Srie 941*12155SAli.Bahrami@Sun.COM /* 942*12155SAli.Bahrami@Sun.COM * Add the GOTs data's offset. 943*12155SAli.Bahrami@Sun.COM */ 944*12155SAli.Bahrami@Sun.COM R2addr = R1addr + (uintptr_t)osp->os_outdata->d_buf; 9451618Srie 946*12155SAli.Bahrami@Sun.COM DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 947*12155SAli.Bahrami@Sun.COM M_MACH, SHT_REL, arsp, R1addr, value, 948*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name)); 9491618Srie 950*12155SAli.Bahrami@Sun.COM /* 951*12155SAli.Bahrami@Sun.COM * And do it. 952*12155SAli.Bahrami@Sun.COM */ 953*12155SAli.Bahrami@Sun.COM if (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) 954*12155SAli.Bahrami@Sun.COM *(Xword *)R2addr = ld_bswap_Xword(value); 955*12155SAli.Bahrami@Sun.COM else 956*12155SAli.Bahrami@Sun.COM *(Xword *)R2addr = value; 957*12155SAli.Bahrami@Sun.COM continue; 9581618Srie 959*12155SAli.Bahrami@Sun.COM } else if (IS_GOT_BASED(arsp->rel_rtype) && 960*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 961*12155SAli.Bahrami@Sun.COM value -= ofl->ofl_osgot->os_shdr->sh_addr; 9621618Srie 963*12155SAli.Bahrami@Sun.COM } else if (IS_GOT_PC(arsp->rel_rtype) && 964*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 965*12155SAli.Bahrami@Sun.COM value = (Xword)(ofl->ofl_osgot->os_shdr->sh_addr) - 966*12155SAli.Bahrami@Sun.COM refaddr; 9671618Srie 968*12155SAli.Bahrami@Sun.COM } else if ((IS_PC_RELATIVE(arsp->rel_rtype)) && 969*12155SAli.Bahrami@Sun.COM (((flags & FLG_OF_RELOBJ) == 0) || 970*12155SAli.Bahrami@Sun.COM (osp == sdp->sd_isc->is_osdesc))) { 971*12155SAli.Bahrami@Sun.COM value -= refaddr; 9721618Srie 973*12155SAli.Bahrami@Sun.COM } else if (IS_TLS_INS(arsp->rel_rtype) && 974*12155SAli.Bahrami@Sun.COM IS_GOT_RELATIVE(arsp->rel_rtype) && 975*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 976*12155SAli.Bahrami@Sun.COM Gotndx *gnp; 9771618Srie 978*12155SAli.Bahrami@Sun.COM gnp = ld_find_got_ndx(sdp->sd_GOTndxs, gref, ofl, NULL); 979*12155SAli.Bahrami@Sun.COM assert(gnp); 980*12155SAli.Bahrami@Sun.COM value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 981*12155SAli.Bahrami@Sun.COM if (arsp->rel_rtype == R_386_TLS_IE) { 982*12155SAli.Bahrami@Sun.COM value += ofl->ofl_osgot->os_shdr->sh_addr; 9831618Srie } 9841618Srie 985*12155SAli.Bahrami@Sun.COM } else if (IS_GOT_RELATIVE(arsp->rel_rtype) && 986*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 987*12155SAli.Bahrami@Sun.COM Gotndx *gnp; 988*12155SAli.Bahrami@Sun.COM 989*12155SAli.Bahrami@Sun.COM gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 990*12155SAli.Bahrami@Sun.COM GOT_REF_GENERIC, ofl, NULL); 991*12155SAli.Bahrami@Sun.COM assert(gnp); 992*12155SAli.Bahrami@Sun.COM value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 993*12155SAli.Bahrami@Sun.COM 994*12155SAli.Bahrami@Sun.COM } else if ((arsp->rel_flags & FLG_REL_STLS) && 995*12155SAli.Bahrami@Sun.COM ((flags & FLG_OF_RELOBJ) == 0)) { 996*12155SAli.Bahrami@Sun.COM Xword tlsstatsize; 9971618Srie 9981618Srie /* 999*12155SAli.Bahrami@Sun.COM * This is the LE TLS reference model. Static 1000*12155SAli.Bahrami@Sun.COM * offset is hard-coded. 10011618Srie */ 1002*12155SAli.Bahrami@Sun.COM tlsstatsize = S_ROUND(ofl->ofl_tlsphdr->p_memsz, 1003*12155SAli.Bahrami@Sun.COM M_TLSSTATALIGN); 1004*12155SAli.Bahrami@Sun.COM value = tlsstatsize - value; 10051618Srie 10061618Srie /* 1007*12155SAli.Bahrami@Sun.COM * Since this code is fixed up, it assumes a 1008*12155SAli.Bahrami@Sun.COM * negative offset that can be added to the 1009*12155SAli.Bahrami@Sun.COM * thread pointer. 10101618Srie */ 1011*12155SAli.Bahrami@Sun.COM if ((arsp->rel_rtype == R_386_TLS_LDO_32) || 1012*12155SAli.Bahrami@Sun.COM (arsp->rel_rtype == R_386_TLS_LE)) 1013*12155SAli.Bahrami@Sun.COM value = -value; 1014*12155SAli.Bahrami@Sun.COM } 10151618Srie 1016*12155SAli.Bahrami@Sun.COM if (arsp->rel_isdesc->is_file) 1017*12155SAli.Bahrami@Sun.COM ifl_name = arsp->rel_isdesc->is_file->ifl_name; 1018*12155SAli.Bahrami@Sun.COM else 1019*12155SAli.Bahrami@Sun.COM ifl_name = MSG_INTL(MSG_STR_NULL); 10201618Srie 1021*12155SAli.Bahrami@Sun.COM /* 1022*12155SAli.Bahrami@Sun.COM * Make sure we have data to relocate. Compiler and assembler 1023*12155SAli.Bahrami@Sun.COM * developers have been known to generate relocations against 1024*12155SAli.Bahrami@Sun.COM * invalid sections (normally .bss), so for their benefit give 1025*12155SAli.Bahrami@Sun.COM * them sufficient information to help analyze the problem. 1026*12155SAli.Bahrami@Sun.COM * End users should never see this. 1027*12155SAli.Bahrami@Sun.COM */ 1028*12155SAli.Bahrami@Sun.COM if (arsp->rel_isdesc->is_indata->d_buf == 0) { 1029*12155SAli.Bahrami@Sun.COM Conv_inv_buf_t inv_buf; 10301618Srie 1031*12155SAli.Bahrami@Sun.COM eprintf(ofl->ofl_lml, ERR_FATAL, 1032*12155SAli.Bahrami@Sun.COM MSG_INTL(MSG_REL_EMPTYSEC), 1033*12155SAli.Bahrami@Sun.COM conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf), 1034*12155SAli.Bahrami@Sun.COM ifl_name, ld_reloc_sym_name(arsp), 1035*12155SAli.Bahrami@Sun.COM EC_WORD(arsp->rel_isdesc->is_scnndx), 1036*12155SAli.Bahrami@Sun.COM arsp->rel_isdesc->is_name); 1037*12155SAli.Bahrami@Sun.COM return (S_ERROR); 1038*12155SAli.Bahrami@Sun.COM } 10391618Srie 1040*12155SAli.Bahrami@Sun.COM /* 1041*12155SAli.Bahrami@Sun.COM * Get the address of the data item we need to modify. 1042*12155SAli.Bahrami@Sun.COM */ 1043*12155SAli.Bahrami@Sun.COM addr = (uchar_t *)((uintptr_t)arsp->rel_roffset + 1044*12155SAli.Bahrami@Sun.COM (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata)); 1045*12155SAli.Bahrami@Sun.COM 1046*12155SAli.Bahrami@Sun.COM DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD_ACT, 1047*12155SAli.Bahrami@Sun.COM M_MACH, SHT_REL, arsp, EC_NATPTR(addr), value, 1048*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name)); 1049*12155SAli.Bahrami@Sun.COM addr += (uintptr_t)osp->os_outdata->d_buf; 10501618Srie 1051*12155SAli.Bahrami@Sun.COM if ((((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 1052*12155SAli.Bahrami@Sun.COM ofl->ofl_size) || (arsp->rel_roffset > 1053*12155SAli.Bahrami@Sun.COM osp->os_shdr->sh_size)) { 1054*12155SAli.Bahrami@Sun.COM Conv_inv_buf_t inv_buf; 1055*12155SAli.Bahrami@Sun.COM int class; 1056*12155SAli.Bahrami@Sun.COM 1057*12155SAli.Bahrami@Sun.COM if (((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 1058*12155SAli.Bahrami@Sun.COM ofl->ofl_size) 1059*12155SAli.Bahrami@Sun.COM class = ERR_FATAL; 1060*12155SAli.Bahrami@Sun.COM else 1061*12155SAli.Bahrami@Sun.COM class = ERR_WARNING; 10621618Srie 1063*12155SAli.Bahrami@Sun.COM eprintf(ofl->ofl_lml, class, 1064*12155SAli.Bahrami@Sun.COM MSG_INTL(MSG_REL_INVALOFFSET), 1065*12155SAli.Bahrami@Sun.COM conv_reloc_386_type(arsp->rel_rtype, 0, &inv_buf), 1066*12155SAli.Bahrami@Sun.COM ifl_name, EC_WORD(arsp->rel_isdesc->is_scnndx), 1067*12155SAli.Bahrami@Sun.COM arsp->rel_isdesc->is_name, ld_reloc_sym_name(arsp), 1068*12155SAli.Bahrami@Sun.COM EC_ADDR((uintptr_t)addr - 1069*12155SAli.Bahrami@Sun.COM (uintptr_t)ofl->ofl_nehdr)); 1070*12155SAli.Bahrami@Sun.COM 1071*12155SAli.Bahrami@Sun.COM if (class == ERR_FATAL) { 1072*12155SAli.Bahrami@Sun.COM return_code = S_ERROR; 1073*12155SAli.Bahrami@Sun.COM continue; 1074*12155SAli.Bahrami@Sun.COM } 1075*12155SAli.Bahrami@Sun.COM } 10761618Srie 1077*12155SAli.Bahrami@Sun.COM /* 1078*12155SAli.Bahrami@Sun.COM * The relocation is additive. Ignore the previous symbol 1079*12155SAli.Bahrami@Sun.COM * value if this local partial symbol is expanded. 1080*12155SAli.Bahrami@Sun.COM */ 1081*12155SAli.Bahrami@Sun.COM if (moved) 1082*12155SAli.Bahrami@Sun.COM value -= *addr; 10835892Sab196087 1084*12155SAli.Bahrami@Sun.COM /* 1085*12155SAli.Bahrami@Sun.COM * If we have a replacement value for the relocation 1086*12155SAli.Bahrami@Sun.COM * target, put it in place now. 1087*12155SAli.Bahrami@Sun.COM */ 1088*12155SAli.Bahrami@Sun.COM if (arsp->rel_flags & FLG_REL_NADDEND) { 1089*12155SAli.Bahrami@Sun.COM Xword addend = arsp->rel_raddend; 1090*12155SAli.Bahrami@Sun.COM 1091*12155SAli.Bahrami@Sun.COM if (ld_reloc_targval_set(ofl, arsp, addr, addend) == 0) 1092*12155SAli.Bahrami@Sun.COM return (S_ERROR); 1093*12155SAli.Bahrami@Sun.COM } 1094*12155SAli.Bahrami@Sun.COM 1095*12155SAli.Bahrami@Sun.COM /* 1096*12155SAli.Bahrami@Sun.COM * If '-z noreloc' is specified - skip the do_reloc_ld stage. 1097*12155SAli.Bahrami@Sun.COM */ 1098*12155SAli.Bahrami@Sun.COM if (OFL_DO_RELOC(ofl)) { 1099*12155SAli.Bahrami@Sun.COM if (do_reloc_ld(arsp, addr, &value, ld_reloc_sym_name, 1100*12155SAli.Bahrami@Sun.COM ifl_name, OFL_SWAP_RELOC_DATA(ofl, arsp), 1101*12155SAli.Bahrami@Sun.COM ofl->ofl_lml) == 0) 1102*12155SAli.Bahrami@Sun.COM return_code = S_ERROR; 11031618Srie } 11041618Srie } 11051618Srie return (return_code); 11061618Srie } 11071618Srie 11081618Srie /* 11091618Srie * Add an output relocation record. 11101618Srie */ 11116206Sab196087 static uintptr_t 11121618Srie ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 11131618Srie { 11141618Srie Rel_desc *orsp; 11151618Srie Sym_desc *sdp = rsp->rel_sym; 11161618Srie 11171618Srie /* 11181618Srie * Static executables *do not* want any relocations against them. 11191618Srie * Since our engine still creates relocations against a WEAK UNDEFINED 11201618Srie * symbol in a static executable, it's best to disable them here 11211618Srie * instead of through out the relocation code. 11221618Srie */ 112310792SRod.Evans@Sun.COM if (OFL_IS_STATIC_EXEC(ofl)) 11241618Srie return (1); 11251618Srie 11261618Srie /* 11271618Srie * If we are adding a output relocation against a section 11281618Srie * symbol (non-RELATIVE) then mark that section. These sections 11291618Srie * will be added to the .dynsym symbol table. 11301618Srie */ 11311618Srie if (sdp && (rsp->rel_rtype != M_R_RELATIVE) && 11321618Srie ((flags & FLG_REL_SCNNDX) || 11331618Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) { 11341618Srie 11351618Srie /* 11361618Srie * If this is a COMMON symbol - no output section 11371618Srie * exists yet - (it's created as part of sym_validate()). 11381618Srie * So - we mark here that when it's created it should 11391618Srie * be tagged with the FLG_OS_OUTREL flag. 11401618Srie */ 11411618Srie if ((sdp->sd_flags & FLG_SY_SPECSEC) && 11421682Srie (sdp->sd_sym->st_shndx == SHN_COMMON)) { 11431618Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS) 11441618Srie ofl->ofl_flags1 |= FLG_OF1_BSSOREL; 11451618Srie else 11461618Srie ofl->ofl_flags1 |= FLG_OF1_TLSOREL; 11471618Srie } else { 114811827SRod.Evans@Sun.COM Os_desc *osp; 114911827SRod.Evans@Sun.COM Is_desc *isp = sdp->sd_isc; 11501618Srie 115111827SRod.Evans@Sun.COM if (isp && ((osp = isp->is_osdesc) != NULL) && 115211827SRod.Evans@Sun.COM ((osp->os_flags & FLG_OS_OUTREL) == 0)) { 11531618Srie ofl->ofl_dynshdrcnt++; 11541618Srie osp->os_flags |= FLG_OS_OUTREL; 11551618Srie } 11561618Srie } 11571618Srie } 11581618Srie 1159*12155SAli.Bahrami@Sun.COM /* Enter it into the output relocation cache */ 1160*12155SAli.Bahrami@Sun.COM if ((orsp = ld_reloc_enter(ofl, &ofl->ofl_outrels, rsp, flags)) == NULL) 1161*12155SAli.Bahrami@Sun.COM return (S_ERROR); 11621618Srie 11631618Srie if (flags & FLG_REL_GOT) 11641618Srie ofl->ofl_relocgotsz += (Xword)sizeof (Rel); 11651618Srie else if (flags & FLG_REL_PLT) 11661618Srie ofl->ofl_relocpltsz += (Xword)sizeof (Rel); 11671618Srie else if (flags & FLG_REL_BSS) 11681618Srie ofl->ofl_relocbsssz += (Xword)sizeof (Rel); 11691618Srie else if (flags & FLG_REL_NOINFO) 11701618Srie ofl->ofl_relocrelsz += (Xword)sizeof (Rel); 11711618Srie else 1172*12155SAli.Bahrami@Sun.COM RELAUX_GET_OSDESC(orsp)->os_szoutrels += (Xword)sizeof (Rel); 11731618Srie 11741618Srie if (orsp->rel_rtype == M_R_RELATIVE) 11751618Srie ofl->ofl_relocrelcnt++; 11761618Srie 11771618Srie /* 11781618Srie * We don't perform sorting on PLT relocations because 11791618Srie * they have already been assigned a PLT index and if we 11801618Srie * were to sort them we would have to re-assign the plt indexes. 11811618Srie */ 11821618Srie if (!(flags & FLG_REL_PLT)) 11831618Srie ofl->ofl_reloccnt++; 11841618Srie 11851618Srie /* 11861618Srie * Insure a GLOBAL_OFFSET_TABLE is generated if required. 11871618Srie */ 11881618Srie if (IS_GOT_REQUIRED(orsp->rel_rtype)) 11891618Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 11901618Srie 11911618Srie /* 11921618Srie * Identify and possibly warn of a displacement relocation. 11931618Srie */ 11941618Srie if (orsp->rel_flags & FLG_REL_DISP) { 11951618Srie ofl->ofl_dtflags_1 |= DF_1_DISPRELPND; 11961618Srie 11971618Srie if (ofl->ofl_flags & FLG_OF_VERBOSE) 11981618Srie ld_disp_errmsg(MSG_INTL(MSG_REL_DISPREL4), orsp, ofl); 11991618Srie } 12001618Srie DBG_CALL(Dbg_reloc_ors_entry(ofl->ofl_lml, ELF_DBG_LD, SHT_REL, 12011618Srie M_MACH, orsp)); 12021618Srie return (1); 12031618Srie } 12041618Srie 12051618Srie /* 12061618Srie * process relocation for a LOCAL symbol 12071618Srie */ 12086206Sab196087 static uintptr_t 12091618Srie ld_reloc_local(Rel_desc * rsp, Ofl_desc * ofl) 12101618Srie { 12116299Sab196087 ofl_flag_t flags = ofl->ofl_flags; 12121618Srie Sym_desc *sdp = rsp->rel_sym; 12131682Srie Word shndx = sdp->sd_sym->st_shndx; 12141618Srie 12151618Srie /* 12161618Srie * if ((shared object) and (not pc relative relocation) and 12171618Srie * (not against ABS symbol)) 12181618Srie * then 12191618Srie * build R_386_RELATIVE 12201618Srie * fi 12211618Srie */ 12221618Srie if ((flags & FLG_OF_SHAROBJ) && (rsp->rel_flags & FLG_REL_LOAD) && 12232850Srie !(IS_PC_RELATIVE(rsp->rel_rtype)) && !(IS_SIZE(rsp->rel_rtype)) && 12241618Srie !(IS_GOT_BASED(rsp->rel_rtype)) && 12251618Srie !(rsp->rel_isdesc != NULL && 12261618Srie (rsp->rel_isdesc->is_shdr->sh_type == SHT_SUNW_dof)) && 12271618Srie (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) || 12281618Srie (shndx != SHN_ABS) || (sdp->sd_aux && sdp->sd_aux->sa_symspec))) { 12291618Srie Word ortype = rsp->rel_rtype; 12301618Srie 12311618Srie rsp->rel_rtype = R_386_RELATIVE; 12321618Srie if (ld_add_outrel(NULL, rsp, ofl) == S_ERROR) 12331618Srie return (S_ERROR); 12341618Srie rsp->rel_rtype = ortype; 12351618Srie } 12361618Srie 12371618Srie /* 12381618Srie * If the relocation is against a 'non-allocatable' section 12391618Srie * and we can not resolve it now - then give a warning 12401618Srie * message. 12411618Srie * 12421618Srie * We can not resolve the symbol if either: 12431618Srie * a) it's undefined 12441618Srie * b) it's defined in a shared library and a 12451618Srie * COPY relocation hasn't moved it to the executable 12461618Srie * 12471618Srie * Note: because we process all of the relocations against the 12481618Srie * text segment before any others - we know whether 12491618Srie * or not a copy relocation will be generated before 12501618Srie * we get here (see reloc_init()->reloc_segments()). 12511618Srie */ 12521618Srie if (!(rsp->rel_flags & FLG_REL_LOAD) && 12531618Srie ((shndx == SHN_UNDEF) || 12541618Srie ((sdp->sd_ref == REF_DYN_NEED) && 12551618Srie ((sdp->sd_flags & FLG_SY_MVTOCOMM) == 0)))) { 1256*12155SAli.Bahrami@Sun.COM Conv_inv_buf_t inv_buf; 1257*12155SAli.Bahrami@Sun.COM Os_desc *osp = RELAUX_GET_OSDESC(rsp); 12584734Sab196087 12591618Srie /* 12601618Srie * If the relocation is against a SHT_SUNW_ANNOTATE 12611618Srie * section - then silently ignore that the relocation 12621618Srie * can not be resolved. 12631618Srie */ 1264*12155SAli.Bahrami@Sun.COM if (osp && (osp->os_shdr->sh_type == SHT_SUNW_ANNOTATE)) 12651618Srie return (0); 12661618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_REL_EXTERNSYM), 12674734Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0, &inv_buf), 12681618Srie rsp->rel_isdesc->is_file->ifl_name, 1269*12155SAli.Bahrami@Sun.COM ld_reloc_sym_name(rsp), osp->os_name); 12701618Srie return (1); 12711618Srie } 12721618Srie 12731618Srie /* 12741618Srie * Perform relocation. 12751618Srie */ 12761618Srie return (ld_add_actrel(NULL, rsp, ofl)); 12771618Srie } 12781618Srie 12796206Sab196087 static uintptr_t 12801618Srie ld_reloc_TLS(Boolean local, Rel_desc * rsp, Ofl_desc * ofl) 12811618Srie { 12821618Srie Word rtype = rsp->rel_rtype; 12831618Srie Sym_desc *sdp = rsp->rel_sym; 12846299Sab196087 ofl_flag_t flags = ofl->ofl_flags; 12851618Srie Gotndx *gnp; 12861618Srie 12871618Srie /* 12882145Srie * If we're building an executable - use either the IE or LE access 12892145Srie * model. If we're building a shared object process any IE model. 12901618Srie */ 12912145Srie if ((flags & FLG_OF_EXEC) || (IS_TLS_IE(rtype))) { 12921618Srie /* 12932145Srie * Set the DF_STATIC_TLS flag. 12941618Srie */ 12951618Srie ofl->ofl_dtflags |= DF_STATIC_TLS; 12961618Srie 12972145Srie if (!local || ((flags & FLG_OF_EXEC) == 0)) { 12981618Srie /* 12992145Srie * Assign a GOT entry for static TLS references. 13001618Srie */ 13019131SRod.Evans@Sun.COM if ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 13029131SRod.Evans@Sun.COM GOT_REF_TLSIE, ofl, NULL)) == NULL) { 13032145Srie 13042145Srie if (ld_assign_got_TLS(local, rsp, ofl, sdp, 13052145Srie gnp, GOT_REF_TLSIE, FLG_REL_STLS, 13069131SRod.Evans@Sun.COM rtype, R_386_TLS_TPOFF, NULL) == S_ERROR) 13072145Srie return (S_ERROR); 13081618Srie } 13091618Srie 13102145Srie /* 13112145Srie * IE access model. 13122145Srie */ 13132145Srie if (IS_TLS_IE(rtype)) { 13142145Srie if (ld_add_actrel(FLG_REL_STLS, 13152145Srie rsp, ofl) == S_ERROR) 13162145Srie return (S_ERROR); 13172145Srie 13182145Srie /* 13192145Srie * A non-pic shared object needs to adjust the 13202145Srie * active relocation (indntpoff). 13212145Srie */ 13222145Srie if (((flags & FLG_OF_EXEC) == 0) && 13232145Srie (rtype == R_386_TLS_IE)) { 13242145Srie rsp->rel_rtype = R_386_RELATIVE; 13252145Srie return (ld_add_outrel(NULL, rsp, ofl)); 13262145Srie } 13272145Srie return (1); 13282145Srie } 13291618Srie 13301618Srie /* 13312145Srie * Fixups are required for other executable models. 13321618Srie */ 13331618Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13341618Srie rsp, ofl)); 13351618Srie } 13362145Srie 13371618Srie /* 13382145Srie * LE access model. 13391618Srie */ 13401618Srie if (IS_TLS_LE(rtype) || (rtype == R_386_TLS_LDO_32)) 13411618Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 13421618Srie 13431618Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13441618Srie rsp, ofl)); 13451618Srie } 13461618Srie 13471618Srie /* 13482145Srie * Building a shared object. 13492145Srie * 13502145Srie * Assign a GOT entry for a dynamic TLS reference. 13511618Srie */ 13529131SRod.Evans@Sun.COM if (IS_TLS_LD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 13539131SRod.Evans@Sun.COM GOT_REF_TLSLD, ofl, NULL)) == NULL)) { 13542145Srie 13552145Srie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSLD, 13569131SRod.Evans@Sun.COM FLG_REL_MTLS, rtype, R_386_TLS_DTPMOD32, NULL) == S_ERROR) 13572145Srie return (S_ERROR); 13582145Srie 13599131SRod.Evans@Sun.COM } else if (IS_TLS_GD(rtype) && ((gnp = ld_find_got_ndx(sdp->sd_GOTndxs, 13609131SRod.Evans@Sun.COM GOT_REF_TLSGD, ofl, NULL)) == NULL)) { 13612145Srie 13622145Srie if (ld_assign_got_TLS(local, rsp, ofl, sdp, gnp, GOT_REF_TLSGD, 13632145Srie FLG_REL_DTLS, rtype, R_386_TLS_DTPMOD32, 13642145Srie R_386_TLS_DTPOFF32) == S_ERROR) 13652145Srie return (S_ERROR); 13661618Srie } 13671618Srie 13681618Srie /* 13691618Srie * For GD/LD TLS reference - TLS_{GD,LD}_CALL, this will eventually 13702145Srie * cause a call to __tls_get_addr(). Convert this relocation to that 13712145Srie * symbol now, and prepare for the PLT magic. 13721618Srie */ 13731618Srie if ((rtype == R_386_TLS_GD_PLT) || (rtype == R_386_TLS_LDM_PLT)) { 13743862Srie Sym_desc *tlsgetsym; 13751618Srie 13761618Srie if ((tlsgetsym = ld_sym_add_u(MSG_ORIG(MSG_SYM_TLSGETADDR_UU), 13773862Srie ofl, MSG_STR_TLSREL)) == (Sym_desc *)S_ERROR) 13781618Srie return (S_ERROR); 13792145Srie 13801618Srie rsp->rel_sym = tlsgetsym; 13811618Srie rsp->rel_rtype = R_386_PLT32; 13822145Srie 13831618Srie if (ld_reloc_plt(rsp, ofl) == S_ERROR) 13841618Srie return (S_ERROR); 13852145Srie 13861618Srie rsp->rel_sym = sdp; 13871618Srie rsp->rel_rtype = rtype; 13881618Srie return (1); 13891618Srie } 13901618Srie 13911618Srie if (IS_TLS_LD(rtype)) 13921618Srie return (ld_add_actrel(FLG_REL_MTLS, rsp, ofl)); 13931618Srie 13941618Srie return (ld_add_actrel(FLG_REL_DTLS, rsp, ofl)); 13951618Srie } 13961618Srie 13971618Srie /* ARGSUSED4 */ 13986206Sab196087 static uintptr_t 13999131SRod.Evans@Sun.COM ld_assign_got_ndx(Alist **alpp, Gotndx *pgnp, Gotref gref, Ofl_desc *ofl, 14009131SRod.Evans@Sun.COM Rel_desc *rsp, Sym_desc *sdp) 14011618Srie { 14029131SRod.Evans@Sun.COM Gotndx gn, *gnp; 14031618Srie uint_t gotents; 14041618Srie 14051618Srie if (pgnp) 14061618Srie return (1); 14071618Srie 14081618Srie if ((gref == GOT_REF_TLSGD) || (gref == GOT_REF_TLSLD)) 14091618Srie gotents = 2; 14101618Srie else 14111618Srie gotents = 1; 14121618Srie 14139131SRod.Evans@Sun.COM gn.gn_addend = 0; 14149131SRod.Evans@Sun.COM gn.gn_gotndx = ofl->ofl_gotcnt; 14159131SRod.Evans@Sun.COM gn.gn_gotref = gref; 14161618Srie 14171618Srie ofl->ofl_gotcnt += gotents; 14181618Srie 14191618Srie if (gref == GOT_REF_TLSLD) { 14209131SRod.Evans@Sun.COM if (ofl->ofl_tlsldgotndx == NULL) { 14219131SRod.Evans@Sun.COM if ((gnp = libld_malloc(sizeof (Gotndx))) == NULL) 14229131SRod.Evans@Sun.COM return (S_ERROR); 14239131SRod.Evans@Sun.COM (void) memcpy(gnp, &gn, sizeof (Gotndx)); 14249131SRod.Evans@Sun.COM ofl->ofl_tlsldgotndx = gnp; 14259131SRod.Evans@Sun.COM } 14261618Srie return (1); 14271618Srie } 14281618Srie 14299131SRod.Evans@Sun.COM /* 14309131SRod.Evans@Sun.COM * GOT indexes are maintained on an Alist, where there is typically 14319131SRod.Evans@Sun.COM * only one index. The usage of this list is to scan the list to find 14329131SRod.Evans@Sun.COM * an index, and then apply that index immediately to a relocation. 14339131SRod.Evans@Sun.COM * Thus there are no external references to these GOT index structures 14349131SRod.Evans@Sun.COM * that can be compromised by the Alist being reallocated. 14359131SRod.Evans@Sun.COM */ 14369131SRod.Evans@Sun.COM if (alist_append(alpp, &gn, sizeof (Gotndx), AL_CNT_SDP_GOT) == NULL) 14371618Srie return (S_ERROR); 14381618Srie 14391618Srie return (1); 14401618Srie } 14411618Srie 14426206Sab196087 static void 14431618Srie ld_assign_plt_ndx(Sym_desc * sdp, Ofl_desc *ofl) 14441618Srie { 14451618Srie sdp->sd_aux->sa_PLTndx = 1 + ofl->ofl_pltcnt++; 14461618Srie sdp->sd_aux->sa_PLTGOTndx = ofl->ofl_gotcnt++; 14471618Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 14481618Srie } 14491618Srie 14501618Srie /* 14511618Srie * Initializes .got[0] with the _DYNAMIC symbol value. 14521618Srie */ 14536206Sab196087 static uintptr_t 14542145Srie ld_fillin_gotplt(Ofl_desc *ofl) 14551618Srie { 14566299Sab196087 ofl_flag_t flags = ofl->ofl_flags; 14576299Sab196087 int bswap = (ofl->ofl_flags1 & FLG_OF1_ENCDIFF) != 0; 14582145Srie 14591618Srie if (ofl->ofl_osgot) { 14602145Srie Sym_desc *sdp; 14611618Srie 14621618Srie if ((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_DYNAMIC_U), 146310792SRod.Evans@Sun.COM SYM_NOHASH, NULL, ofl)) != NULL) { 14642145Srie uchar_t *genptr; 14652145Srie 14662145Srie genptr = ((uchar_t *)ofl->ofl_osgot->os_outdata->d_buf + 14671618Srie (M_GOT_XDYNAMIC * M_GOT_ENTSIZE)); 14681618Srie /* LINTED */ 14691618Srie *(Word *)genptr = (Word)sdp->sd_sym->st_value; 14706206Sab196087 if (bswap) 14716206Sab196087 /* LINTED */ 14726206Sab196087 *(Word *)genptr = 14736206Sab196087 /* LINTED */ 14746206Sab196087 ld_bswap_Word(*(Word *)genptr); 14751618Srie } 14761618Srie } 14771618Srie 14781618Srie /* 14791618Srie * Fill in the reserved slot in the procedure linkage table the first 14801618Srie * entry is: 14811618Srie * if (building a.out) { 14821618Srie * PUSHL got[1] # the address of the link map entry 14831618Srie * JMP * got[2] # the address of rtbinder 14841618Srie * } else { 14851618Srie * PUSHL got[1]@GOT(%ebx) # the address of the link map entry 14861618Srie * JMP * got[2]@GOT(%ebx) # the address of rtbinder 14871618Srie * } 14881618Srie */ 14892145Srie if ((flags & FLG_OF_DYNAMIC) && ofl->ofl_osplt) { 14901618Srie uchar_t *pltent; 14911618Srie 14921618Srie pltent = (uchar_t *)ofl->ofl_osplt->os_outdata->d_buf; 14932145Srie if (!(flags & FLG_OF_SHAROBJ)) { 14941618Srie pltent[0] = M_SPECIAL_INST; 14951618Srie pltent[1] = M_PUSHL_DISP; 14961618Srie pltent += 2; 14971618Srie /* LINTED */ 14981618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr-> 14994734Sab196087 sh_addr + M_GOT_XLINKMAP * M_GOT_ENTSIZE); 15006206Sab196087 if (bswap) 15016206Sab196087 /* LINTED */ 15026206Sab196087 *(Word *)pltent = 15036206Sab196087 /* LINTED */ 15046206Sab196087 ld_bswap_Word(*(Word *)pltent); 15051618Srie pltent += 4; 15061618Srie pltent[0] = M_SPECIAL_INST; 15071618Srie pltent[1] = M_JMP_DISP_IND; 15081618Srie pltent += 2; 15091618Srie /* LINTED */ 15101618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr-> 15114734Sab196087 sh_addr + M_GOT_XRTLD * M_GOT_ENTSIZE); 15126206Sab196087 if (bswap) 15136206Sab196087 /* LINTED */ 15146206Sab196087 *(Word *)pltent = 15156206Sab196087 /* LINTED */ 15166206Sab196087 ld_bswap_Word(*(Word *)pltent); 15171618Srie } else { 15181618Srie pltent[0] = M_SPECIAL_INST; 15191618Srie pltent[1] = M_PUSHL_REG_DISP; 15201618Srie pltent += 2; 15211618Srie /* LINTED */ 15221618Srie *(Word *)pltent = (Word)(M_GOT_XLINKMAP * 15234734Sab196087 M_GOT_ENTSIZE); 15246206Sab196087 if (bswap) 15256206Sab196087 /* LINTED */ 15266206Sab196087 *(Word *)pltent = 15276206Sab196087 /* LINTED */ 15286206Sab196087 ld_bswap_Word(*(Word *)pltent); 15291618Srie pltent += 4; 15301618Srie pltent[0] = M_SPECIAL_INST; 15311618Srie pltent[1] = M_JMP_REG_DISP_IND; 15321618Srie pltent += 2; 15331618Srie /* LINTED */ 15341618Srie *(Word *)pltent = (Word)(M_GOT_XRTLD * 15354734Sab196087 M_GOT_ENTSIZE); 15366206Sab196087 if (bswap) 15376206Sab196087 /* LINTED */ 15386206Sab196087 *(Word *)pltent = 15396206Sab196087 /* LINTED */ 15406206Sab196087 ld_bswap_Word(*(Word *)pltent); 15411618Srie } 15421618Srie } 15431618Srie return (1); 15441618Srie } 15456206Sab196087 15466206Sab196087 15476206Sab196087 15486206Sab196087 /* 15496206Sab196087 * Template for generating "void (*)(void)" function 15506206Sab196087 */ 15516206Sab196087 static const uchar_t nullfunc_tmpl[] = { /* IA32 */ 15526206Sab196087 /* 0x00 */ 0xc3 /* ret */ 15536206Sab196087 }; 15546206Sab196087 15556206Sab196087 15566206Sab196087 15576206Sab196087 /* 155810809SAli.Bahrami@Sun.COM * Function used to provide fill padding in SHF_EXECINSTR sections 155910809SAli.Bahrami@Sun.COM * 156010809SAli.Bahrami@Sun.COM * entry: 156110809SAli.Bahrami@Sun.COM * 156210809SAli.Bahrami@Sun.COM * base - base address of section being filled 156310809SAli.Bahrami@Sun.COM * offset - starting offset for fill within memory referenced by base 156410809SAli.Bahrami@Sun.COM * cnt - # bytes to be filled 156510809SAli.Bahrami@Sun.COM * 156610809SAli.Bahrami@Sun.COM * exit: 156710809SAli.Bahrami@Sun.COM * The fill has been completed. 156810809SAli.Bahrami@Sun.COM */ 156910809SAli.Bahrami@Sun.COM static void 157010809SAli.Bahrami@Sun.COM execfill(void *base, off_t off, size_t cnt) 157110809SAli.Bahrami@Sun.COM { 157210809SAli.Bahrami@Sun.COM /* 157310809SAli.Bahrami@Sun.COM * 0x90 is an X86 NOP instruction in both 32 and 64-bit worlds. 157410809SAli.Bahrami@Sun.COM * There are no alignment constraints. 157510809SAli.Bahrami@Sun.COM */ 157610809SAli.Bahrami@Sun.COM (void) memset(off + (char *)base, 0x90, cnt); 157710809SAli.Bahrami@Sun.COM } 157810809SAli.Bahrami@Sun.COM 157910809SAli.Bahrami@Sun.COM 158010809SAli.Bahrami@Sun.COM /* 15816206Sab196087 * Return the ld_targ definition for this target. 15826206Sab196087 */ 15836206Sab196087 const Target * 15846206Sab196087 ld_targ_init_x86(void) 15856206Sab196087 { 15866206Sab196087 static const Target _ld_targ = { 15876206Sab196087 { /* Target_mach */ 15886206Sab196087 M_MACH, /* m_mach */ 15896206Sab196087 M_MACHPLUS, /* m_machplus */ 15906206Sab196087 M_FLAGSPLUS, /* m_flagsplus */ 15916206Sab196087 M_CLASS, /* m_class */ 15926206Sab196087 M_DATA, /* m_data */ 15936206Sab196087 15946206Sab196087 M_SEGM_ALIGN, /* m_segm_align */ 15956206Sab196087 M_SEGM_ORIGIN, /* m_segm_origin */ 15968501SRod.Evans@Sun.COM M_SEGM_AORIGIN, /* m_segm_aorigin */ 15976206Sab196087 M_DATASEG_PERM, /* m_dataseg_perm */ 159811734SAli.Bahrami@Sun.COM M_STACK_PERM, /* m_stack_perm */ 15996206Sab196087 M_WORD_ALIGN, /* m_word_align */ 16006206Sab196087 MSG_ORIG(MSG_PTH_RTLD), /* m_def_interp */ 16016206Sab196087 16026206Sab196087 /* Relocation type codes */ 16036206Sab196087 M_R_ARRAYADDR, /* m_r_arrayaddr */ 16046206Sab196087 M_R_COPY, /* m_r_copy */ 16056206Sab196087 M_R_GLOB_DAT, /* m_r_glob_dat */ 16066206Sab196087 M_R_JMP_SLOT, /* m_r_jmp_slot */ 16076206Sab196087 M_R_NUM, /* m_r_num */ 16086206Sab196087 M_R_NONE, /* m_r_none */ 16096206Sab196087 M_R_RELATIVE, /* m_r_relative */ 16106206Sab196087 M_R_REGISTER, /* m_r_register */ 16116206Sab196087 16126206Sab196087 /* Relocation related constants */ 16136206Sab196087 M_REL_DT_COUNT, /* m_rel_dt_count */ 16146206Sab196087 M_REL_DT_ENT, /* m_rel_dt_ent */ 16156206Sab196087 M_REL_DT_SIZE, /* m_rel_dt_size */ 16166206Sab196087 M_REL_DT_TYPE, /* m_rel_dt_type */ 16176206Sab196087 M_REL_SHT_TYPE, /* m_rel_sht_type */ 16186206Sab196087 16196206Sab196087 /* GOT related constants */ 16206206Sab196087 M_GOT_ENTSIZE, /* m_got_entsize */ 16216206Sab196087 M_GOT_XNumber, /* m_got_xnumber */ 16226206Sab196087 16236206Sab196087 /* PLT related constants */ 16246206Sab196087 M_PLT_ALIGN, /* m_plt_align */ 16256206Sab196087 M_PLT_ENTSIZE, /* m_plt_entsize */ 16266206Sab196087 M_PLT_RESERVSZ, /* m_plt_reservsz */ 16276206Sab196087 M_PLT_SHF_FLAGS, /* m_plt_shf_flags */ 16286206Sab196087 16299085SAli.Bahrami@Sun.COM /* Section type of .eh_frame/.eh_frame_hdr sections */ 16309085SAli.Bahrami@Sun.COM SHT_PROGBITS, /* m_sht_unwind */ 16319085SAli.Bahrami@Sun.COM 16326206Sab196087 M_DT_REGISTER, /* m_dt_register */ 16336206Sab196087 }, 16346206Sab196087 { /* Target_machid */ 16356206Sab196087 M_ID_ARRAY, /* id_array */ 16366206Sab196087 M_ID_BSS, /* id_bss */ 16376206Sab196087 M_ID_CAP, /* id_cap */ 163811827SRod.Evans@Sun.COM M_ID_CAPINFO, /* id_capinfo */ 163911827SRod.Evans@Sun.COM M_ID_CAPCHAIN, /* id_capchain */ 16406206Sab196087 M_ID_DATA, /* id_data */ 16416206Sab196087 M_ID_DYNAMIC, /* id_dynamic */ 16426206Sab196087 M_ID_DYNSORT, /* id_dynsort */ 16436206Sab196087 M_ID_DYNSTR, /* id_dynstr */ 16446206Sab196087 M_ID_DYNSYM, /* id_dynsym */ 16456206Sab196087 M_ID_DYNSYM_NDX, /* id_dynsym_ndx */ 16466206Sab196087 M_ID_GOT, /* id_got */ 16476206Sab196087 M_ID_UNKNOWN, /* id_gotdata (unused) */ 16486206Sab196087 M_ID_HASH, /* id_hash */ 16496206Sab196087 M_ID_INTERP, /* id_interp */ 16506206Sab196087 M_ID_LBSS, /* id_lbss */ 16516206Sab196087 M_ID_LDYNSYM, /* id_ldynsym */ 16526206Sab196087 M_ID_NOTE, /* id_note */ 16536206Sab196087 M_ID_NULL, /* id_null */ 16546206Sab196087 M_ID_PLT, /* id_plt */ 16556206Sab196087 M_ID_REL, /* id_rel */ 16566206Sab196087 M_ID_STRTAB, /* id_strtab */ 16576206Sab196087 M_ID_SYMINFO, /* id_syminfo */ 16586206Sab196087 M_ID_SYMTAB, /* id_symtab */ 16596206Sab196087 M_ID_SYMTAB_NDX, /* id_symtab_ndx */ 16606206Sab196087 M_ID_TEXT, /* id_text */ 16616206Sab196087 M_ID_TLS, /* id_tls */ 16626206Sab196087 M_ID_TLSBSS, /* id_tlsbss */ 16636206Sab196087 M_ID_UNKNOWN, /* id_unknown */ 16646206Sab196087 M_ID_UNWIND, /* id_unwind */ 16659085SAli.Bahrami@Sun.COM M_ID_UNWINDHDR, /* id_unwindhdr */ 16666206Sab196087 M_ID_USER, /* id_user */ 16676206Sab196087 M_ID_VERSION, /* id_version */ 16686206Sab196087 }, 16696206Sab196087 { /* Target_nullfunc */ 16706206Sab196087 nullfunc_tmpl, /* nf_template */ 16716206Sab196087 sizeof (nullfunc_tmpl), /* nf_size */ 16726206Sab196087 }, 167310809SAli.Bahrami@Sun.COM { /* Target_fillfunc */ 167410809SAli.Bahrami@Sun.COM execfill /* ff_execfill */ 167510809SAli.Bahrami@Sun.COM }, 16766206Sab196087 { /* Target_machrel */ 16776206Sab196087 reloc_table, 16786206Sab196087 16796206Sab196087 ld_init_rel, /* mr_init_rel */ 16806206Sab196087 ld_mach_eflags, /* mr_mach_eflags */ 16816206Sab196087 ld_mach_make_dynamic, /* mr_mach_make_dynamic */ 16826206Sab196087 ld_mach_update_odynamic, /* mr_mach_update_odynamic */ 16836206Sab196087 ld_calc_plt_addr, /* mr_calc_plt_addr */ 16846206Sab196087 ld_perform_outreloc, /* mr_perform_outreloc */ 16856206Sab196087 ld_do_activerelocs, /* mr_do_activerelocs */ 16866206Sab196087 ld_add_outrel, /* mr_add_outrel */ 16876206Sab196087 NULL, /* mr_reloc_register */ 16886206Sab196087 ld_reloc_local, /* mr_reloc_local */ 16896206Sab196087 NULL, /* mr_reloc_GOTOP */ 16906206Sab196087 ld_reloc_TLS, /* mr_reloc_TLS */ 16916206Sab196087 NULL, /* mr_assign_got */ 16929131SRod.Evans@Sun.COM ld_find_got_ndx, /* mr_find_got_ndx */ 16936206Sab196087 ld_calc_got_offset, /* mr_calc_got_offset */ 16946206Sab196087 ld_assign_got_ndx, /* mr_assign_got_ndx */ 16956206Sab196087 ld_assign_plt_ndx, /* mr_assign_plt_ndx */ 16966206Sab196087 NULL, /* mr_allocate_got */ 16976206Sab196087 ld_fillin_gotplt, /* mr_fillin_gotplt */ 16986206Sab196087 }, 16996206Sab196087 { /* Target_machsym */ 17006206Sab196087 NULL, /* ms_reg_check */ 17016206Sab196087 NULL, /* ms_mach_sym_typecheck */ 17026206Sab196087 NULL, /* ms_is_regsym */ 17036206Sab196087 NULL, /* ms_reg_find */ 17046206Sab196087 NULL /* ms_reg_enter */ 17056206Sab196087 } 17066206Sab196087 }; 17076206Sab196087 17086206Sab196087 return (&_ld_targ); 17096206Sab196087 } 1710