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 * 271618Srie * Copyright 2006 Sun Microsystems, Inc. All rights reserved. 281618Srie * Use is subject to license terms. 291618Srie */ 301618Srie #pragma ident "%Z%%M% %I% %E% SMI" 311618Srie 321618Srie #include <string.h> 331618Srie #include <stdio.h> 341618Srie #include <sys/elf_386.h> 351618Srie #include <debug.h> 361618Srie #include <reloc.h> 371618Srie #include "msg.h" 381618Srie #include "_libld.h" 391618Srie 401618Srie Word 411618Srie ld_init_rel(Rel_desc *reld, void *reloc) 421618Srie { 431618Srie Rel * rel = (Rel *)reloc; 441618Srie 451618Srie /* LINTED */ 461618Srie reld->rel_rtype = (Word)ELF_R_TYPE(rel->r_info); 471618Srie reld->rel_roffset = rel->r_offset; 481618Srie reld->rel_raddend = 0; 491618Srie reld->rel_typedata = 0; 501618Srie 511618Srie return ((Word)ELF_R_SYM(rel->r_info)); 521618Srie } 531618Srie 541618Srie void 551618Srie ld_mach_eflags(Ehdr *ehdr, Ofl_desc *ofl) 561618Srie { 571618Srie ofl->ofl_dehdr->e_flags |= ehdr->e_flags; 581618Srie } 591618Srie 601618Srie void 611618Srie ld_mach_make_dynamic(Ofl_desc *ofl, size_t *cnt) 621618Srie { 631618Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) { 641618Srie /* 651618Srie * Create this entry if we are going to create a PLT table. 661618Srie */ 671618Srie if (ofl->ofl_pltcnt) 681618Srie (*cnt)++; /* DT_PLTGOT */ 691618Srie } 701618Srie } 711618Srie 721618Srie void 731618Srie ld_mach_update_odynamic(Ofl_desc * ofl, Dyn ** dyn) 741618Srie { 751618Srie if (((ofl->ofl_flags & FLG_OF_RELOBJ) == 0) && ofl->ofl_pltcnt) { 761618Srie (*dyn)->d_tag = DT_PLTGOT; 771618Srie if (ofl->ofl_osgot) 781618Srie (*dyn)->d_un.d_ptr = ofl->ofl_osgot->os_shdr->sh_addr; 791618Srie else 801618Srie (*dyn)->d_un.d_ptr = 0; 811618Srie (*dyn)++; 821618Srie } 831618Srie } 841618Srie 851618Srie Xword 861618Srie ld_calc_plt_addr(Sym_desc *sdp, Ofl_desc *ofl) 871618Srie { 881618Srie Xword value; 891618Srie 901618Srie value = (Xword)(ofl->ofl_osplt->os_shdr->sh_addr) + 911618Srie M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * M_PLT_ENTSIZE); 921618Srie return (value); 931618Srie } 941618Srie 951618Srie /* 961618Srie * Build a single plt entry - code is: 971618Srie * if (building a.out) 981618Srie * JMP *got_off 991618Srie * else 1001618Srie * JMP *got_off@GOT(%ebx) 1011618Srie * PUSHL &rel_off 1021618Srie * JMP -n(%pc) # -n is pcrel offset to first plt entry 1031618Srie * 1041618Srie * The got_off@GOT entry gets filled with the address of the PUSHL, 1051618Srie * so the first pass through the plt jumps back here, jumping 1061618Srie * in turn to the first plt entry, which jumps to the dynamic 1071618Srie * linker. The dynamic linker then patches the GOT, rerouting 1081618Srie * future plt calls to the proper destination. 1091618Srie */ 1101618Srie static void 1111618Srie plt_entry(Ofl_desc * ofl, Word rel_off, Sym_desc * sdp) 1121618Srie { 1131618Srie uchar_t *pltent, *gotent; 1141618Srie Sword plt_off; 1151618Srie Word got_off; 1161618Srie 1171618Srie got_off = sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 1181618Srie plt_off = M_PLT_RESERVSZ + ((sdp->sd_aux->sa_PLTndx - 1) * 1191618Srie M_PLT_ENTSIZE); 1201618Srie pltent = (uchar_t *)(ofl->ofl_osplt->os_outdata->d_buf) + plt_off; 1211618Srie gotent = (uchar_t *)(ofl->ofl_osgot->os_outdata->d_buf) + got_off; 1221618Srie 1231618Srie /* 1241618Srie * Fill in the got entry with the address of the next instruction. 1251618Srie */ 1261618Srie /* LINTED */ 1271618Srie *(Word *)gotent = ofl->ofl_osplt->os_shdr->sh_addr + plt_off + 1281618Srie M_PLT_INSSIZE; 1291618Srie 1301618Srie if (!(ofl->ofl_flags & FLG_OF_SHAROBJ)) { 1311618Srie pltent[0] = M_SPECIAL_INST; 1321618Srie pltent[1] = M_JMP_DISP_IND; 1331618Srie pltent += 2; 1341618Srie /* LINTED */ 1351618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr->sh_addr + 1361618Srie got_off); 1371618Srie } else { 1381618Srie pltent[0] = M_SPECIAL_INST; 1391618Srie pltent[1] = M_JMP_REG_DISP_IND; 1401618Srie pltent += 2; 1411618Srie /* LINTED */ 1421618Srie *(Word *)pltent = (Word)got_off; 1431618Srie } 1441618Srie pltent += 4; 1451618Srie 1461618Srie pltent[0] = M_INST_PUSHL; 1471618Srie pltent++; 1481618Srie /* LINTED */ 1491618Srie *(Word *)pltent = (Word)rel_off; 1501618Srie pltent += 4; 1511618Srie 1521618Srie plt_off = -(plt_off + 16); /* JMP, PUSHL, JMP take 16 bytes */ 1531618Srie pltent[0] = M_INST_JMP; 1541618Srie pltent++; 1551618Srie /* LINTED */ 1561618Srie *(Word *)pltent = (Word)plt_off; 1571618Srie } 1581618Srie 1591618Srie uintptr_t 1601618Srie ld_perform_outreloc(Rel_desc * orsp, Ofl_desc * ofl) 1611618Srie { 1621618Srie Os_desc * relosp, * osp = 0; 1631618Srie Word ndx, roffset, value; 1641618Srie Rel rea; 1651618Srie char *relbits; 1661618Srie Sym_desc * sdp, * psym = (Sym_desc *)0; 1671618Srie int sectmoved = 0; 1681618Srie 1691618Srie sdp = orsp->rel_sym; 1701618Srie 1711618Srie /* 1721618Srie * If the section this relocation is against has been discarded 1731618Srie * (-zignore), then also discard (skip) the relocation itself. 1741618Srie */ 1751618Srie if (orsp->rel_isdesc && ((orsp->rel_flags & 1761618Srie (FLG_REL_GOT | FLG_REL_BSS | FLG_REL_PLT | FLG_REL_NOINFO)) == 0) && 1771618Srie (orsp->rel_isdesc->is_flags & FLG_IS_DISCARD)) { 1781618Srie DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, M_MACH, orsp)); 1791618Srie return (1); 1801618Srie } 1811618Srie 1821618Srie /* 1831618Srie * If this is a relocation against a move table, or expanded move 1841618Srie * table, adjust the relocation entries. 1851618Srie */ 1861618Srie if (orsp->rel_move) 1871618Srie ld_adj_movereloc(ofl, orsp); 1881618Srie 1891618Srie /* 1901618Srie * If this is a relocation against a section using a partial initialized 1911618Srie * symbol, adjust the embedded symbol info. 1921618Srie * 1931618Srie * The second argument of the am_I_partial() is the value stored at the 1941618Srie * target address relocation is going to be applied. 1951618Srie */ 1961618Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION) { 1971618Srie if (ofl->ofl_parsym.head && 1981618Srie (sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 1991618Srie /* LINTED */ 2001618Srie (psym = ld_am_I_partial(orsp, *(Xword *) 2011618Srie ((uchar_t *)(orsp->rel_isdesc->is_indata->d_buf) + 2021618Srie orsp->rel_roffset)))) { 2031618Srie DBG_CALL(Dbg_move_outsctadj(ofl->ofl_lml, psym)); 2041618Srie sectmoved = 1; 2051618Srie } 2061618Srie } 2071618Srie 2081618Srie value = sdp->sd_sym->st_value; 2091618Srie 2101618Srie if (orsp->rel_flags & FLG_REL_GOT) { 2111618Srie osp = ofl->ofl_osgot; 2121618Srie roffset = (Word)ld_calc_got_offset(orsp, ofl); 2131618Srie 2141618Srie } else if (orsp->rel_flags & FLG_REL_PLT) { 2151618Srie /* 2161618Srie * Note that relocations for PLT's actually 2171618Srie * cause a relocation againt the GOT. 2181618Srie */ 2191618Srie osp = ofl->ofl_osplt; 2201618Srie roffset = (Word) (ofl->ofl_osgot->os_shdr->sh_addr) + 2211618Srie sdp->sd_aux->sa_PLTGOTndx * M_GOT_ENTSIZE; 2221618Srie 2231618Srie plt_entry(ofl, osp->os_relosdesc->os_szoutrels, sdp); 2241618Srie 2251618Srie } else if (orsp->rel_flags & FLG_REL_BSS) { 2261618Srie /* 2271618Srie * This must be a R_386_COPY. For these set the roffset to 2281618Srie * point to the new symbols location. 2291618Srie */ 2301618Srie osp = ofl->ofl_isbss->is_osdesc; 2311618Srie roffset = (Word)value; 2321618Srie } else { 2331618Srie osp = orsp->rel_osdesc; 2341618Srie 2351618Srie /* 2361618Srie * Calculate virtual offset of reference point; equals offset 2371618Srie * into section + vaddr of section for loadable sections, or 2381618Srie * offset plus section displacement for nonloadable sections. 2391618Srie */ 2401618Srie roffset = orsp->rel_roffset + 2411618Srie (Off)_elf_getxoff(orsp->rel_isdesc->is_indata); 2421618Srie if (!(ofl->ofl_flags & FLG_OF_RELOBJ)) 2431618Srie roffset += orsp->rel_isdesc->is_osdesc-> 2441618Srie os_shdr->sh_addr; 2451618Srie } 2461618Srie 2471618Srie if ((osp == 0) || ((relosp = osp->os_relosdesc) == 0)) 2481618Srie relosp = ofl->ofl_osrel; 2491618Srie 2501618Srie /* 2511618Srie * Assign the symbols index for the output relocation. If the 2521618Srie * relocation refers to a SECTION symbol then it's index is based upon 2531618Srie * the output sections symbols index. Otherwise the index can be 2541618Srie * derived from the symbols index itself. 2551618Srie */ 2561618Srie if (orsp->rel_rtype == R_386_RELATIVE) 2571618Srie ndx = STN_UNDEF; 2581618Srie else if ((orsp->rel_flags & FLG_REL_SCNNDX) || 2591618Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION)) { 2601618Srie if (sectmoved == 0) { 2611618Srie /* 2621618Srie * Check for a null input section. This can 2631618Srie * occur if this relocation references a symbol 2641618Srie * generated by sym_add_sym(). 2651618Srie */ 2661618Srie if ((sdp->sd_isc != 0) && 2671618Srie (sdp->sd_isc->is_osdesc != 0)) 2681618Srie ndx = sdp->sd_isc->is_osdesc->os_scnsymndx; 2691618Srie else 2701618Srie ndx = sdp->sd_shndx; 2711618Srie } else 2721618Srie ndx = ofl->ofl_sunwdata1ndx; 2731618Srie } else 2741618Srie ndx = sdp->sd_symndx; 2751618Srie 2761618Srie relbits = (char *)relosp->os_outdata->d_buf; 2771618Srie 2781618Srie rea.r_info = ELF_R_INFO(ndx, orsp->rel_rtype); 2791618Srie rea.r_offset = roffset; 2801618Srie DBG_CALL(Dbg_reloc_out(ofl, ELF_DBG_LD, SHT_REL, &rea, relosp->os_name, 2811618Srie orsp->rel_sname)); 2821618Srie 2831618Srie /* 2841618Srie * Assert we haven't walked off the end of our relocation table. 2851618Srie */ 2861618Srie assert(relosp->os_szoutrels <= relosp->os_shdr->sh_size); 2871618Srie 2881618Srie (void) memcpy((relbits + relosp->os_szoutrels), 2891618Srie (char *)&rea, sizeof (Rel)); 2901618Srie relosp->os_szoutrels += sizeof (Rel); 2911618Srie 2921618Srie /* 2931618Srie * Determine if this relocation is against a non-writable, allocatable 2941618Srie * section. If so we may need to provide a text relocation diagnostic. 2951618Srie * Note that relocations against the .plt (R_386_JMP_SLOT) actually 2961618Srie * result in modifications to the .got. 2971618Srie */ 2981618Srie if (orsp->rel_rtype == R_386_JMP_SLOT) 2991618Srie osp = ofl->ofl_osgot; 3001618Srie 3011618Srie ld_reloc_remain_entry(orsp, osp, ofl); 3021618Srie return (1); 3031618Srie } 3041618Srie 3051618Srie /* 3061618Srie * i386 Instructions for TLS processing 3071618Srie */ 3081618Srie static uchar_t tlsinstr_gd_ie[] = { 3091618Srie /* 3101618Srie * 0x00 movl %gs:0x0, %eax 3111618Srie */ 3121618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, 3131618Srie /* 3141618Srie * 0x06 addl x(%eax), %eax 3151618Srie * 0x0c ... 3161618Srie */ 3171618Srie 0x03, 0x80, 0x00, 0x00, 0x00, 0x00 3181618Srie }; 3191618Srie 3201618Srie static uchar_t tlsinstr_gd_le[] = { 3211618Srie /* 3221618Srie * 0x00 movl %gs:0x0, %eax 3231618Srie */ 3241618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 0x00, 3251618Srie /* 3261618Srie * 0x06 addl $0x0, %eax 3271618Srie */ 3281618Srie 0x05, 0x00, 0x00, 0x00, 0x00, 3291618Srie /* 3301618Srie * 0x0b nop 3311618Srie * 0x0c 3321618Srie */ 3331618Srie 0x90 3341618Srie }; 3351618Srie 3361618Srie static uchar_t tlsinstr_gd_ie_movgs[] = { 3371618Srie /* 3381618Srie * movl %gs:0x0,%eax 3391618Srie */ 3401618Srie 0x65, 0xa1, 0x00, 0x00, 0x00, 00 3411618Srie }; 3421618Srie 3431618Srie #define TLS_GD_IE_MOV 0x8b /* movl opcode */ 3441618Srie #define TLS_GD_IE_POP 0x58 /* popl + reg */ 3451618Srie 3461618Srie #define TLS_GD_LE_MOVL 0xb8 /* movl + reg */ 3471618Srie 3481618Srie #define TLS_NOP 0x90 /* NOP instruction */ 3491618Srie 3501618Srie #define MODRM_MSK_MOD 0xc0 3511618Srie #define MODRM_MSK_RO 0x38 3521618Srie #define MODRM_MSK_RM 0x07 3531618Srie 3541618Srie #define SIB_MSK_SS 0xc0 3551618Srie #define SIB_MSK_IND 0x38 3561618Srie #define SIB_MSK_BS 0x07 3571618Srie 3581618Srie static Fixupret 3591618Srie tls_fixups(Ofl_desc *ofl, Rel_desc *arsp) 3601618Srie { 3611618Srie Sym_desc *sdp = arsp->rel_sym; 3621618Srie Word rtype = arsp->rel_rtype; 3631618Srie uchar_t *offset, r1, r2; 3641618Srie 3651618Srie offset = (uchar_t *)((uintptr_t)arsp->rel_roffset + 3661618Srie (uintptr_t)_elf_getxoff(arsp->rel_isdesc->is_indata) + 3671618Srie (uintptr_t)arsp->rel_osdesc->os_outdata->d_buf); 3681618Srie 3691618Srie if (sdp->sd_ref == REF_DYN_NEED) { 3701618Srie /* 3711618Srie * IE reference model 3721618Srie */ 3731618Srie switch (rtype) { 3741618Srie case R_386_TLS_GD: 3751618Srie /* 3761618Srie * Transition: 3771618Srie * 0x0 leal x@tlsgd(,r1,1), %eax 3781618Srie * 0x7 call ___tls_get_addr 3791618Srie * 0xc 3801618Srie * To: 3811618Srie * 0x0 movl %gs:0, %eax 3821618Srie * 0x6 addl x@gotntpoff(r1), %eax 3831618Srie */ 3841618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 3851618Srie rtype, R_386_TLS_GOTIE, arsp->rel_roffset, 3861618Srie sdp->sd_name)); 3871618Srie arsp->rel_rtype = R_386_TLS_GOTIE; 3881618Srie arsp->rel_roffset += 5; 3891618Srie 3901618Srie /* 3911618Srie * Addjust 'offset' to beginning of instruction 3921618Srie * sequence. 3931618Srie */ 3941618Srie offset -= 3; 3951618Srie r1 = (offset[2] & SIB_MSK_IND) >> 3; 3961618Srie (void) memcpy(offset, tlsinstr_gd_ie, 3971618Srie sizeof (tlsinstr_gd_ie)); 3981618Srie 3991618Srie /* 4001618Srie * set register %r1 into the addl 4011618Srie * instruction. 4021618Srie */ 4031618Srie offset[0x7] |= r1; 4041618Srie return (FIX_RELOC); 4051618Srie 4061618Srie case R_386_TLS_GD_PLT: 4071618Srie /* 4081618Srie * Fixup done via the TLS_GD relocation 4091618Srie */ 4101618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 4111618Srie rtype, R_386_NONE, arsp->rel_roffset, 4121618Srie sdp->sd_name)); 4131618Srie return (FIX_DONE); 4141618Srie } 4151618Srie } 4161618Srie 4171618Srie /* 4181618Srie * LE reference model 4191618Srie */ 4201618Srie switch (rtype) { 4211618Srie case R_386_TLS_GD: 4221618Srie /* 4231618Srie * Transition: 4241618Srie * 0x0 leal x@tlsgd(,r1,1), %eax 4251618Srie * 0x7 call ___tls_get_addr 4261618Srie * 0xc 4271618Srie * To: 4281618Srie * 0x0 movl %gs:0, %eax 4291618Srie * 0x6 addl $x@ntpoff, %eax 4301618Srie * 0xb nop 4311618Srie * 0xc 4321618Srie */ 4331618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 4341618Srie rtype, R_386_TLS_LE, arsp->rel_roffset, sdp->sd_name)); 4351618Srie 4361618Srie arsp->rel_rtype = R_386_TLS_LE; 4371618Srie arsp->rel_roffset += 4; 4381618Srie 4391618Srie /* 4401618Srie * Addjust 'offset' to beginning of instruction 4411618Srie * sequence. 4421618Srie */ 4431618Srie offset -= 3; 4441618Srie (void) memcpy(offset, tlsinstr_gd_le, 4451618Srie sizeof (tlsinstr_gd_le)); 4461618Srie return (FIX_RELOC); 4471618Srie 4481618Srie case R_386_TLS_GD_PLT: 4491618Srie case R_386_PLT32: 4501618Srie /* 4511618Srie * Fixup done via the TLS_GD relocation 4521618Srie */ 4531618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 4541618Srie rtype, R_386_NONE, arsp->rel_roffset, sdp->sd_name)); 4551618Srie return (FIX_DONE); 4561618Srie 4571618Srie case R_386_TLS_LDM_PLT: 4581618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 4591618Srie rtype, R_386_NONE, arsp->rel_roffset, sdp->sd_name)); 4601618Srie 4611618Srie /* 4621618Srie * Transition: 4631618Srie * call __tls_get_addr() 4641618Srie * to: 4651618Srie * nop 4661618Srie * nop 4671618Srie * nop 4681618Srie * nop 4691618Srie * nop 4701618Srie */ 4711618Srie *(offset - 1) = TLS_NOP; 4721618Srie *(offset) = TLS_NOP; 4731618Srie *(offset + 1) = TLS_NOP; 4741618Srie *(offset + 2) = TLS_NOP; 4751618Srie *(offset + 3) = TLS_NOP; 4761618Srie return (FIX_DONE); 4771618Srie 4781618Srie case R_386_TLS_LDM: 4791618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 4801618Srie rtype, R_386_NONE, arsp->rel_roffset, sdp->sd_name)); 4811618Srie 4821618Srie /* 4831618Srie * Transition: 4841618Srie * 4851618Srie * 0x00 leal x1@tlsldm(%ebx), %eax 4861618Srie * 0x06 call ___tls_get_addr 4871618Srie * 4881618Srie * to: 4891618Srie * 4901618Srie * 0x00 movl %gs:0, %eax 4911618Srie */ 4921618Srie (void) memcpy(offset - 2, tlsinstr_gd_ie_movgs, 4931618Srie sizeof (tlsinstr_gd_ie_movgs)); 4941618Srie return (FIX_DONE); 4951618Srie 4961618Srie case R_386_TLS_LDO_32: 4971618Srie /* 4981618Srie * Instructions: 4991618Srie * 5001618Srie * 0x10 leal x1@dtpoff(%eax), %edx R_386_TLS_LDO_32 5011618Srie * to 5021618Srie * 0x10 leal x1@ntpoff(%eax), %edx R_386_TLS_LE 5031618Srie * 5041618Srie */ 5051618Srie offset -= 2; 5061618Srie 5071618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 5081618Srie rtype, R_386_TLS_LE, arsp->rel_roffset, sdp->sd_name)); 5091618Srie arsp->rel_rtype = R_386_TLS_LE; 5101618Srie return (FIX_RELOC); 5111618Srie 5121618Srie case R_386_TLS_GOTIE: 5131618Srie /* 5141618Srie * These transitions are a little different than the 5151618Srie * others, in that we could have multiple instructions 5161618Srie * pointed to by a single relocation. Depending upon the 5171618Srie * instruction, we perform a different code transition. 5181618Srie * 5191618Srie * Here's the known transitions: 5201618Srie * 5211618Srie * 1) movl foo@gotntpoff(%reg1), %reg2 5221618Srie * 0x8b, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff 5231618Srie * 5241618Srie * 2) addl foo@gotntpoff(%reg1), %reg2 5251618Srie * 0x03, 0x80 | (reg2 << 3) | reg1, foo@gotntpoff 5261618Srie * 5271618Srie * Transitions IE -> LE 5281618Srie * 5291618Srie * 1) movl $foo@ntpoff, %reg2 5301618Srie * 0xc7, 0xc0 | reg2, foo@ntpoff 5311618Srie * 5321618Srie * 2) addl $foo@ntpoff, %reg2 5331618Srie * 0x81, 0xc0 | reg2, foo@ntpoff 5341618Srie * 5351618Srie * Note: reg1 != 4 (%esp) 5361618Srie */ 5371618Srie DBG_CALL(Dbg_reloc_transition(ofl->ofl_lml, M_MACH, 5381618Srie rtype, R_386_TLS_LE, arsp->rel_roffset, sdp->sd_name)); 5391618Srie arsp->rel_rtype = R_386_TLS_LE; 5401618Srie 5411618Srie offset -= 2; 5421618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 5431618Srie if (offset[0] == 0x8b) { 5441618Srie /* case 1 above */ 5451618Srie offset[0] = 0xc7; /* movl */ 5461618Srie offset[1] = 0xc0 | r2; 5471618Srie return (FIX_RELOC); 5481618Srie } 5491618Srie 5501618Srie if (offset[0] == 0x03) { 5511618Srie /* case 2 above */ 5521618Srie assert(offset[0] == 0x03); 5531618Srie offset[0] = 0x81; /* addl */ 5541618Srie offset[1] = 0xc0 | r2; 5551618Srie return (FIX_RELOC); 5561618Srie } 5571618Srie 5581618Srie /* 5591618Srie * Unexpected instruction sequence - fatal error. 5601618Srie */ 5611618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_BADTLSINS), 562*1976Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0), 5631618Srie arsp->rel_isdesc->is_file->ifl_name, 5641618Srie demangle(arsp->rel_sname), arsp->rel_isdesc->is_name, 5651618Srie EC_OFF(arsp->rel_roffset)); 5661618Srie return (FIX_ERROR); 5671618Srie 5681618Srie case R_386_TLS_IE: 5691618Srie /* 5701618Srie * These transitions are a little different than the 5711618Srie * others, in that we could have multiple instructions 5721618Srie * pointed to by a single relocation. Depending upon the 5731618Srie * instruction, we perform a different code transition. 5741618Srie * 5751618Srie * Here's the known transitions: 5761618Srie * 1) movl foo@indntpoff, %eax 5771618Srie * 0xa1, foo@indntpoff 5781618Srie * 5791618Srie * 2) movl foo@indntpoff, %eax 5801618Srie * 0x8b, 0x05 | (reg << 3), foo@gotntpoff 5811618Srie * 5821618Srie * 3) addl foo@indntpoff, %eax 5831618Srie * 0x03, 0x05 | (reg << 3), foo@gotntpoff 5841618Srie * 5851618Srie * Transitions IE -> LE 5861618Srie * 5871618Srie * 1) movl $foo@ntpoff, %eax 5881618Srie * 0xb8, foo@ntpoff 5891618Srie * 5901618Srie * 2) movl $foo@ntpoff, %reg 5911618Srie * 0xc7, 0xc0 | reg, foo@ntpoff 5921618Srie * 5931618Srie * 3) addl $foo@ntpoff, %reg 5941618Srie * 0x81, 0xc0 | reg, foo@ntpoff 5951618Srie */ 5961618Srie arsp->rel_rtype = R_386_TLS_LE; 5971618Srie offset--; 5981618Srie if (offset[0] == 0xa1) { 5991618Srie /* case 1 above */ 6001618Srie offset[0] = 0xb8; /* movl */ 6011618Srie return (FIX_RELOC); 6021618Srie } 6031618Srie 6041618Srie offset--; 6051618Srie if (offset[0] == 0x8b) { 6061618Srie /* case 2 above */ 6071618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 6081618Srie offset[0] = 0xc7; /* movl */ 6091618Srie offset[1] = 0xc0 | r2; 6101618Srie return (FIX_RELOC); 6111618Srie } 6121618Srie if (offset[0] == 0x03) { 6131618Srie /* case 3 above */ 6141618Srie r2 = (offset[1] & MODRM_MSK_RO) >> 3; 6151618Srie offset[0] = 0x81; /* addl */ 6161618Srie offset[1] = 0xc0 | r2; 6171618Srie return (FIX_RELOC); 6181618Srie } 6191618Srie /* 6201618Srie * Unexpected instruction sequence - fatal error. 6211618Srie */ 6221618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_BADTLSINS), 623*1976Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0), 6241618Srie arsp->rel_isdesc->is_file->ifl_name, 6251618Srie demangle(arsp->rel_sname), arsp->rel_isdesc->is_name, 6261618Srie EC_OFF(arsp->rel_roffset)); 6271618Srie return (FIX_ERROR); 6281618Srie } 6291618Srie return (FIX_RELOC); 6301618Srie } 6311618Srie 6321618Srie uintptr_t 6331618Srie ld_do_activerelocs(Ofl_desc *ofl) 6341618Srie { 6351618Srie Rel_desc *arsp; 6361618Srie Rel_cache *rcp; 6371618Srie Listnode *lnp; 6381618Srie uintptr_t return_code = 1; 6391618Srie Word flags = ofl->ofl_flags; 6401618Srie Word dtflags1 = ofl->ofl_dtflags_1; 6411618Srie 6421618Srie DBG_CALL(Dbg_reloc_doact_title(ofl->ofl_lml)); 6431618Srie /* 6441618Srie * Process active relocations. 6451618Srie */ 6461618Srie for (LIST_TRAVERSE(&ofl->ofl_actrels, lnp, rcp)) { 6471618Srie /* LINTED */ 6481618Srie for (arsp = (Rel_desc *)(rcp + 1); 6491618Srie arsp < rcp->rc_free; arsp++) { 6501618Srie uchar_t *addr; 6511618Srie Xword value; 6521618Srie Sym_desc *sdp; 6531618Srie const char *ifl_name; 6541618Srie Xword refaddr; 6551618Srie int moved = 0; 6561618Srie Gotref gref; 6571618Srie 6581618Srie /* 6591618Srie * If the section this relocation is against has been 6601618Srie * discarded (-zignore), then discard (skip) the 6611618Srie * relocation itself. 6621618Srie */ 6631618Srie if ((arsp->rel_isdesc->is_flags & FLG_IS_DISCARD) && 6641618Srie ((arsp->rel_flags & 6651618Srie (FLG_REL_GOT | FLG_REL_BSS | 6661618Srie FLG_REL_PLT | FLG_REL_NOINFO)) == 0)) { 6671618Srie DBG_CALL(Dbg_reloc_discard(ofl->ofl_lml, 6681618Srie M_MACH, arsp)); 6691618Srie continue; 6701618Srie } 6711618Srie 6721618Srie /* 6731618Srie * We deteremine what the 'got reference' 6741618Srie * model (if required) is at this point. This 6751618Srie * needs to be done before tls_fixup() since 6761618Srie * it may 'transition' our instructions. 6771618Srie * 6781618Srie * The got table entries have already been assigned, 6791618Srie * and we bind to those initial entries. 6801618Srie */ 6811618Srie if (arsp->rel_flags & FLG_REL_DTLS) 6821618Srie gref = GOT_REF_TLSGD; 6831618Srie else if (arsp->rel_flags & FLG_REL_MTLS) 6841618Srie gref = GOT_REF_TLSLD; 6851618Srie else if (arsp->rel_flags & FLG_REL_STLS) 6861618Srie gref = GOT_REF_TLSIE; 6871618Srie else 6881618Srie gref = GOT_REF_GENERIC; 6891618Srie 6901618Srie /* 6911618Srie * Perform any required TLS fixups. 6921618Srie */ 6931618Srie if (arsp->rel_flags & FLG_REL_TLSFIX) { 6941618Srie Fixupret ret; 6951618Srie 6961618Srie if ((ret = tls_fixups(ofl, arsp)) == FIX_ERROR) 6971618Srie return (S_ERROR); 6981618Srie if (ret == FIX_DONE) 6991618Srie continue; 7001618Srie } 7011618Srie 7021618Srie /* 7031618Srie * If this is a relocation against a move table, or 7041618Srie * expanded move table, adjust the relocation entries. 7051618Srie */ 7061618Srie if (arsp->rel_move) 7071618Srie ld_adj_movereloc(ofl, arsp); 7081618Srie 7091618Srie sdp = arsp->rel_sym; 7101618Srie refaddr = arsp->rel_roffset + 7111618Srie (Off)_elf_getxoff(arsp->rel_isdesc->is_indata); 7121618Srie 7131618Srie if (arsp->rel_flags & FLG_REL_CLVAL) 7141618Srie value = 0; 7151618Srie else if (ELF_ST_TYPE(sdp->sd_sym->st_info) == 7161618Srie STT_SECTION) { 7171618Srie Sym_desc *sym; 7181618Srie 7191618Srie /* 7201618Srie * The value for a symbol pointing to a SECTION 7211618Srie * is based off of that sections position. 7221618Srie * 7231618Srie * The second argument of the ld_am_I_partial() 7241618Srie * is the value stored at the target address 7251618Srie * relocation is going to be applied. 7261618Srie */ 7271618Srie if ((sdp->sd_isc->is_flags & FLG_IS_RELUPD) && 7281618Srie /* LINTED */ 7291618Srie (sym = ld_am_I_partial(arsp, *(Xword *) 7301618Srie ((uchar_t *) 7311618Srie arsp->rel_isdesc->is_indata->d_buf + 7321618Srie arsp->rel_roffset)))) { 7331618Srie /* 7341618Srie * If the symbol is moved, 7351618Srie * adjust the value 7361618Srie */ 7371618Srie value = sym->sd_sym->st_value; 7381618Srie moved = 1; 7391618Srie } else { 7401618Srie value = _elf_getxoff( 7411618Srie sdp->sd_isc->is_indata); 7421618Srie if (sdp->sd_isc->is_shdr->sh_flags & 7431618Srie SHF_ALLOC) 7441618Srie value += sdp->sd_isc-> 7451618Srie is_osdesc->os_shdr->sh_addr; 7461618Srie } 7471618Srie if (sdp->sd_isc->is_shdr->sh_flags & SHF_TLS) 7481618Srie value -= ofl->ofl_tlsphdr->p_vaddr; 7491618Srie } else { 7501618Srie /* 7511618Srie * else the value is the symbols value 7521618Srie */ 7531618Srie value = sdp->sd_sym->st_value; 7541618Srie } 7551618Srie 7561618Srie /* 7571618Srie * Relocation against the GLOBAL_OFFSET_TABLE. 7581618Srie */ 7591618Srie if (arsp->rel_flags & FLG_REL_GOT) 7601618Srie arsp->rel_osdesc = ofl->ofl_osgot; 7611618Srie 7621618Srie /* 7631618Srie * If loadable and not producing a relocatable object 7641618Srie * add the sections virtual address to the reference 7651618Srie * address. 7661618Srie */ 7671618Srie if ((arsp->rel_flags & FLG_REL_LOAD) && 7681618Srie ((flags & FLG_OF_RELOBJ) == 0)) 7691618Srie refaddr += arsp->rel_isdesc->is_osdesc-> 7701618Srie os_shdr->sh_addr; 7711618Srie 7721618Srie /* 7731618Srie * If this entry has a PLT assigned to it, it's 7741618Srie * value is actually the address of the PLT (and 7751618Srie * not the address of the function). 7761618Srie */ 7771618Srie if (IS_PLT(arsp->rel_rtype)) { 7781618Srie if (sdp->sd_aux && sdp->sd_aux->sa_PLTndx) 7791618Srie value = ld_calc_plt_addr(sdp, ofl); 7801618Srie } 7811618Srie 7821618Srie /* 7831618Srie * Determine whether the value needs further adjustment. 7841618Srie * Filter through the attributes of the relocation to 7851618Srie * determine what adjustment is required. Note, many 7861618Srie * of the following cases are only applicable when a 7871618Srie * .got is present. As a .got is not generated when a 7881618Srie * relocatable object is being built, any adjustments 7891618Srie * that require a .got need to be skipped. 7901618Srie */ 7911618Srie if ((arsp->rel_flags & FLG_REL_GOT) && 7921618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 7931618Srie Xword R1addr; 7941618Srie uintptr_t R2addr; 7951618Srie Word gotndx; 7961618Srie Gotndx *gnp; 7971618Srie 7981618Srie /* 7991618Srie * Perform relocation against GOT table. Since 8001618Srie * this doesn't fit exactly into a relocation 8011618Srie * we place the appropriate byte in the GOT 8021618Srie * directly 8031618Srie * 8041618Srie * Calculate offset into GOT at which to apply 8051618Srie * the relocation. 8061618Srie */ 8071618Srie gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), gref, 8081618Srie ofl, 0); 8091618Srie assert(gnp); 8101618Srie 8111618Srie if (arsp->rel_rtype == R_386_TLS_DTPOFF32) 8121618Srie gotndx = gnp->gn_gotndx + 1; 8131618Srie else 8141618Srie gotndx = gnp->gn_gotndx; 8151618Srie 8161618Srie R1addr = (Xword)(gotndx * M_GOT_ENTSIZE); 8171618Srie 8181618Srie /* 8191618Srie * Add the GOTs data's offset. 8201618Srie */ 8211618Srie R2addr = R1addr + (uintptr_t) 8221618Srie arsp->rel_osdesc->os_outdata->d_buf; 8231618Srie 8241618Srie DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, 8251618Srie ELF_DBG_LD, M_MACH, SHT_REL, 8261618Srie arsp->rel_rtype, R1addr, value, 8271618Srie arsp->rel_sname, arsp->rel_osdesc)); 8281618Srie 8291618Srie /* 8301618Srie * And do it. 8311618Srie */ 8321618Srie *(Xword *)R2addr = value; 8331618Srie continue; 8341618Srie 8351618Srie } else if (IS_GOT_BASED(arsp->rel_rtype) && 8361618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8371618Srie value -= ofl->ofl_osgot->os_shdr->sh_addr; 8381618Srie 8391618Srie } else if (IS_GOT_PC(arsp->rel_rtype) && 8401618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8411618Srie value = 8421618Srie (Xword)(ofl->ofl_osgot->os_shdr->sh_addr) - 8431618Srie refaddr; 8441618Srie 8451618Srie } else if ((IS_PC_RELATIVE(arsp->rel_rtype)) && 8461618Srie (((flags & FLG_OF_RELOBJ) == 0) || 8471618Srie (arsp->rel_osdesc == sdp->sd_isc->is_osdesc))) { 8481618Srie value -= refaddr; 8491618Srie 8501618Srie } else if (IS_TLS_INS(arsp->rel_rtype) && 8511618Srie IS_GOT_RELATIVE(arsp->rel_rtype) && 8521618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8531618Srie Gotndx *gnp; 8541618Srie 8551618Srie gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), gref, 8561618Srie ofl, 0); 8571618Srie assert(gnp); 8581618Srie value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 8591618Srie if (arsp->rel_rtype == R_386_TLS_IE) { 8601618Srie value += 8611618Srie ofl->ofl_osgot->os_shdr->sh_addr; 8621618Srie } 8631618Srie 8641618Srie } else if (IS_GOT_RELATIVE(arsp->rel_rtype) && 8651618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8661618Srie Gotndx *gnp; 8671618Srie 8681618Srie gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), 8691618Srie GOT_REF_GENERIC, ofl, 0); 8701618Srie assert(gnp); 8711618Srie value = (Xword)gnp->gn_gotndx * M_GOT_ENTSIZE; 8721618Srie 8731618Srie } else if ((arsp->rel_flags & FLG_REL_STLS) && 8741618Srie ((flags & FLG_OF_RELOBJ) == 0)) { 8751618Srie Xword tlsstatsize; 8761618Srie 8771618Srie /* 8781618Srie * This is the LE TLS reference model. Static 8791618Srie * offset is hard-coded. 8801618Srie */ 8811618Srie tlsstatsize = 8821618Srie S_ROUND(ofl->ofl_tlsphdr->p_memsz, 8831618Srie M_TLSSTATALIGN); 8841618Srie value = tlsstatsize - value; 8851618Srie 8861618Srie /* 8871618Srie * Since this code is fixed up, it assumes a 8881618Srie * negative offset that can be added to the 8891618Srie * thread pointer. 8901618Srie */ 8911618Srie if ((arsp->rel_rtype == R_386_TLS_LDO_32) || 8921618Srie (arsp->rel_rtype == R_386_TLS_LE)) 8931618Srie value = -value; 8941618Srie } 8951618Srie 8961618Srie if (arsp->rel_isdesc->is_file) 8971618Srie ifl_name = arsp->rel_isdesc->is_file->ifl_name; 8981618Srie else 8991618Srie ifl_name = MSG_INTL(MSG_STR_NULL); 9001618Srie 9011618Srie /* 9021618Srie * Make sure we have data to relocate. Compiler and 9031618Srie * assembler developers have been known to generate 9041618Srie * relocations against invalid sections (normally .bss), 9051618Srie * so for their benefit give them sufficient information 9061618Srie * to help analyze the problem. End users should never 9071618Srie * see this. 9081618Srie */ 9091618Srie if (arsp->rel_isdesc->is_indata->d_buf == 0) { 9101618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 9111618Srie MSG_INTL(MSG_REL_EMPTYSEC), 912*1976Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0), 9131618Srie ifl_name, demangle(arsp->rel_sname), 9141618Srie arsp->rel_isdesc->is_name); 9151618Srie return (S_ERROR); 9161618Srie } 9171618Srie 9181618Srie /* 9191618Srie * Get the address of the data item we need to modify. 9201618Srie */ 9211618Srie addr = (uchar_t *)((uintptr_t)arsp->rel_roffset + 9221618Srie (uintptr_t)_elf_getxoff(arsp->rel_isdesc-> 9231618Srie is_indata)); 9241618Srie 9251618Srie DBG_CALL(Dbg_reloc_doact(ofl->ofl_lml, ELF_DBG_LD, 9261618Srie M_MACH, SHT_REL, arsp->rel_rtype, EC_NATPTR(addr), 9271618Srie value, arsp->rel_sname, arsp->rel_osdesc)); 9281618Srie addr += (uintptr_t)arsp->rel_osdesc->os_outdata->d_buf; 9291618Srie 9301618Srie if ((((uintptr_t)addr - (uintptr_t)ofl->ofl_nehdr) > 9311618Srie ofl->ofl_size) || (arsp->rel_roffset > 9321618Srie arsp->rel_osdesc->os_shdr->sh_size)) { 9331618Srie int class; 9341618Srie 9351618Srie if (((uintptr_t)addr - 9361618Srie (uintptr_t)ofl->ofl_nehdr) > ofl->ofl_size) 9371618Srie class = ERR_FATAL; 9381618Srie else 9391618Srie class = ERR_WARNING; 9401618Srie 9411618Srie eprintf(ofl->ofl_lml, class, 9421618Srie MSG_INTL(MSG_REL_INVALOFFSET), 943*1976Sab196087 conv_reloc_386_type(arsp->rel_rtype, 0), 9441618Srie ifl_name, arsp->rel_isdesc->is_name, 9451618Srie demangle(arsp->rel_sname), 9461618Srie EC_ADDR((uintptr_t)addr - 9471618Srie (uintptr_t)ofl->ofl_nehdr)); 9481618Srie 9491618Srie if (class == ERR_FATAL) { 9501618Srie return_code = S_ERROR; 9511618Srie continue; 9521618Srie } 9531618Srie } 9541618Srie 9551618Srie /* 9561618Srie * The relocation is additive. Ignore the previous 9571618Srie * symbol value if this local partial symbol is 9581618Srie * expanded. 9591618Srie */ 9601618Srie if (moved) 9611618Srie value -= *addr; 9621618Srie 9631618Srie /* 9641618Srie * If '-z noreloc' is specified - skip the do_reloc 9651618Srie * stage. 9661618Srie */ 9671618Srie if ((flags & FLG_OF_RELOBJ) || 9681618Srie !(dtflags1 & DF_1_NORELOC)) { 9691618Srie if (do_reloc((uchar_t)arsp->rel_rtype, addr, 9701618Srie &value, arsp->rel_sname, ifl_name, 9711618Srie ofl->ofl_lml) == 0) 9721618Srie return_code = S_ERROR; 9731618Srie } 9741618Srie } 9751618Srie } 9761618Srie return (return_code); 9771618Srie } 9781618Srie 9791618Srie /* 9801618Srie * Add an output relocation record. 9811618Srie */ 9821618Srie uintptr_t 9831618Srie ld_add_outrel(Word flags, Rel_desc *rsp, Ofl_desc *ofl) 9841618Srie { 9851618Srie Rel_desc *orsp; 9861618Srie Rel_cache *rcp; 9871618Srie Sym_desc *sdp = rsp->rel_sym; 9881618Srie 9891618Srie /* 9901618Srie * Static executables *do not* want any relocations against them. 9911618Srie * Since our engine still creates relocations against a WEAK UNDEFINED 9921618Srie * symbol in a static executable, it's best to disable them here 9931618Srie * instead of through out the relocation code. 9941618Srie */ 9951618Srie if ((ofl->ofl_flags & (FLG_OF_STATIC | FLG_OF_EXEC)) == 9961618Srie (FLG_OF_STATIC | FLG_OF_EXEC)) 9971618Srie return (1); 9981618Srie 9991618Srie /* 10001618Srie * If no relocation cache structures are available allocate 10011618Srie * a new one and link it into the cache list. 10021618Srie */ 10031618Srie if ((ofl->ofl_outrels.tail == 0) || 10041618Srie ((rcp = (Rel_cache *)ofl->ofl_outrels.tail->data) == 0) || 10051618Srie ((orsp = rcp->rc_free) == rcp->rc_end)) { 10061618Srie static size_t nextsize = 0; 10071618Srie size_t size; 10081618Srie 10091618Srie /* 10101618Srie * Output relocation numbers can vary considerably between 10111618Srie * building executables or shared objects (pic vs. non-pic), 10121618Srie * etc. But, they typically aren't very large, so for these 10131618Srie * objects use a standard bucket size. For building relocatable 10141618Srie * objects, typically there will be an output relocation for 10151618Srie * every input relocation. 10161618Srie */ 10171618Srie if (nextsize == 0) { 10181618Srie if (ofl->ofl_flags & FLG_OF_RELOBJ) { 10191618Srie if ((size = ofl->ofl_relocincnt) == 0) 10201618Srie size = REL_LOIDESCNO; 10211618Srie if (size > REL_HOIDESCNO) 10221618Srie nextsize = REL_HOIDESCNO; 10231618Srie else 10241618Srie nextsize = REL_LOIDESCNO; 10251618Srie } else 10261618Srie nextsize = size = REL_HOIDESCNO; 10271618Srie } else 10281618Srie size = nextsize; 10291618Srie 10301618Srie size = size * sizeof (Rel_desc); 10311618Srie 10321618Srie if (((rcp = libld_malloc(sizeof (Rel_cache) + size)) == 0) || 10331618Srie (list_appendc(&ofl->ofl_outrels, rcp) == 0)) 10341618Srie return (S_ERROR); 10351618Srie 10361618Srie /* LINTED */ 10371618Srie rcp->rc_free = orsp = (Rel_desc *)(rcp + 1); 10381618Srie /* LINTED */ 10391618Srie rcp->rc_end = (Rel_desc *)((char *)rcp->rc_free + size); 10401618Srie } 10411618Srie 10421618Srie /* 10431618Srie * If we are adding a output relocation against a section 10441618Srie * symbol (non-RELATIVE) then mark that section. These sections 10451618Srie * will be added to the .dynsym symbol table. 10461618Srie */ 10471618Srie if (sdp && (rsp->rel_rtype != M_R_RELATIVE) && 10481618Srie ((flags & FLG_REL_SCNNDX) || 10491618Srie (ELF_ST_TYPE(sdp->sd_sym->st_info) == STT_SECTION))) { 10501618Srie 10511618Srie /* 10521618Srie * If this is a COMMON symbol - no output section 10531618Srie * exists yet - (it's created as part of sym_validate()). 10541618Srie * So - we mark here that when it's created it should 10551618Srie * be tagged with the FLG_OS_OUTREL flag. 10561618Srie */ 10571618Srie if ((sdp->sd_flags & FLG_SY_SPECSEC) && 10581682Srie (sdp->sd_sym->st_shndx == SHN_COMMON)) { 10591618Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS) 10601618Srie ofl->ofl_flags1 |= FLG_OF1_BSSOREL; 10611618Srie else 10621618Srie ofl->ofl_flags1 |= FLG_OF1_TLSOREL; 10631618Srie } else { 10641618Srie Os_desc *osp = sdp->sd_isc->is_osdesc; 10651618Srie 10661618Srie if ((osp->os_flags & FLG_OS_OUTREL) == 0) { 10671618Srie ofl->ofl_dynshdrcnt++; 10681618Srie osp->os_flags |= FLG_OS_OUTREL; 10691618Srie } 10701618Srie } 10711618Srie } 10721618Srie 10731618Srie *orsp = *rsp; 10741618Srie orsp->rel_flags |= flags; 10751618Srie 10761618Srie rcp->rc_free++; 10771618Srie ofl->ofl_outrelscnt++; 10781618Srie 10791618Srie if (flags & FLG_REL_GOT) 10801618Srie ofl->ofl_relocgotsz += (Xword)sizeof (Rel); 10811618Srie else if (flags & FLG_REL_PLT) 10821618Srie ofl->ofl_relocpltsz += (Xword)sizeof (Rel); 10831618Srie else if (flags & FLG_REL_BSS) 10841618Srie ofl->ofl_relocbsssz += (Xword)sizeof (Rel); 10851618Srie else if (flags & FLG_REL_NOINFO) 10861618Srie ofl->ofl_relocrelsz += (Xword)sizeof (Rel); 10871618Srie else 10881618Srie orsp->rel_osdesc->os_szoutrels += (Xword)sizeof (Rel); 10891618Srie 10901618Srie if (orsp->rel_rtype == M_R_RELATIVE) 10911618Srie ofl->ofl_relocrelcnt++; 10921618Srie 10931618Srie /* 10941618Srie * We don't perform sorting on PLT relocations because 10951618Srie * they have already been assigned a PLT index and if we 10961618Srie * were to sort them we would have to re-assign the plt indexes. 10971618Srie */ 10981618Srie if (!(flags & FLG_REL_PLT)) 10991618Srie ofl->ofl_reloccnt++; 11001618Srie 11011618Srie /* 11021618Srie * Insure a GLOBAL_OFFSET_TABLE is generated if required. 11031618Srie */ 11041618Srie if (IS_GOT_REQUIRED(orsp->rel_rtype)) 11051618Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 11061618Srie 11071618Srie /* 11081618Srie * Identify and possibly warn of a displacement relocation. 11091618Srie */ 11101618Srie if (orsp->rel_flags & FLG_REL_DISP) { 11111618Srie ofl->ofl_dtflags_1 |= DF_1_DISPRELPND; 11121618Srie 11131618Srie if (ofl->ofl_flags & FLG_OF_VERBOSE) 11141618Srie ld_disp_errmsg(MSG_INTL(MSG_REL_DISPREL4), orsp, ofl); 11151618Srie } 11161618Srie DBG_CALL(Dbg_reloc_ors_entry(ofl->ofl_lml, ELF_DBG_LD, SHT_REL, 11171618Srie M_MACH, orsp)); 11181618Srie return (1); 11191618Srie } 11201618Srie 11211618Srie /* 11221618Srie * Stub routine since register symbols are not supported on i386. 11231618Srie */ 11241618Srie /* ARGSUSED */ 11251618Srie uintptr_t 11261618Srie ld_reloc_register(Rel_desc * rsp, Is_desc * isp, Ofl_desc * ofl) 11271618Srie { 11281618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_NOREG)); 11291618Srie return (S_ERROR); 11301618Srie } 11311618Srie 11321618Srie /* 11331618Srie * process relocation for a LOCAL symbol 11341618Srie */ 11351618Srie uintptr_t 11361618Srie ld_reloc_local(Rel_desc * rsp, Ofl_desc * ofl) 11371618Srie { 11381618Srie Word flags = ofl->ofl_flags; 11391618Srie Sym_desc *sdp = rsp->rel_sym; 11401682Srie Word shndx = sdp->sd_sym->st_shndx; 11411618Srie 11421618Srie /* 11431618Srie * if ((shared object) and (not pc relative relocation) and 11441618Srie * (not against ABS symbol)) 11451618Srie * then 11461618Srie * build R_386_RELATIVE 11471618Srie * fi 11481618Srie */ 11491618Srie if ((flags & FLG_OF_SHAROBJ) && (rsp->rel_flags & FLG_REL_LOAD) && 11501618Srie !(IS_PC_RELATIVE(rsp->rel_rtype)) && 11511618Srie !(IS_GOT_BASED(rsp->rel_rtype)) && 11521618Srie !(rsp->rel_isdesc != NULL && 11531618Srie (rsp->rel_isdesc->is_shdr->sh_type == SHT_SUNW_dof)) && 11541618Srie (((sdp->sd_flags & FLG_SY_SPECSEC) == 0) || 11551618Srie (shndx != SHN_ABS) || (sdp->sd_aux && sdp->sd_aux->sa_symspec))) { 11561618Srie Word ortype = rsp->rel_rtype; 11571618Srie 11581618Srie rsp->rel_rtype = R_386_RELATIVE; 11591618Srie if (ld_add_outrel(NULL, rsp, ofl) == S_ERROR) 11601618Srie return (S_ERROR); 11611618Srie rsp->rel_rtype = ortype; 11621618Srie } 11631618Srie 11641618Srie /* 11651618Srie * If the relocation is against a 'non-allocatable' section 11661618Srie * and we can not resolve it now - then give a warning 11671618Srie * message. 11681618Srie * 11691618Srie * We can not resolve the symbol if either: 11701618Srie * a) it's undefined 11711618Srie * b) it's defined in a shared library and a 11721618Srie * COPY relocation hasn't moved it to the executable 11731618Srie * 11741618Srie * Note: because we process all of the relocations against the 11751618Srie * text segment before any others - we know whether 11761618Srie * or not a copy relocation will be generated before 11771618Srie * we get here (see reloc_init()->reloc_segments()). 11781618Srie */ 11791618Srie if (!(rsp->rel_flags & FLG_REL_LOAD) && 11801618Srie ((shndx == SHN_UNDEF) || 11811618Srie ((sdp->sd_ref == REF_DYN_NEED) && 11821618Srie ((sdp->sd_flags & FLG_SY_MVTOCOMM) == 0)))) { 11831618Srie /* 11841618Srie * If the relocation is against a SHT_SUNW_ANNOTATE 11851618Srie * section - then silently ignore that the relocation 11861618Srie * can not be resolved. 11871618Srie */ 11881618Srie if (rsp->rel_osdesc && 11891618Srie (rsp->rel_osdesc->os_shdr->sh_type == SHT_SUNW_ANNOTATE)) 11901618Srie return (0); 11911618Srie eprintf(ofl->ofl_lml, ERR_WARNING, MSG_INTL(MSG_REL_EXTERNSYM), 1192*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 11931618Srie rsp->rel_isdesc->is_file->ifl_name, 11941618Srie demangle(rsp->rel_sname), rsp->rel_osdesc->os_name); 11951618Srie return (1); 11961618Srie } 11971618Srie 11981618Srie /* 11991618Srie * Perform relocation. 12001618Srie */ 12011618Srie return (ld_add_actrel(NULL, rsp, ofl)); 12021618Srie } 12031618Srie 12041618Srie uintptr_t 12051618Srie /* ARGSUSED */ 12061618Srie ld_reloc_GOTOP(Boolean local, Rel_desc * rsp, Ofl_desc * ofl) 12071618Srie { 12081618Srie /* 12091618Srie * Stub routine for common code compatibility, we shouldn't 12101618Srie * actually get here on x86. 12111618Srie */ 12121618Srie assert(0); 12131618Srie return (S_ERROR); 12141618Srie } 12151618Srie 12161618Srie uintptr_t 12171618Srie ld_reloc_TLS(Boolean local, Rel_desc * rsp, Ofl_desc * ofl) 12181618Srie { 12191618Srie Word rtype = rsp->rel_rtype; 12201618Srie Sym_desc *sdp = rsp->rel_sym; 12211618Srie Word flags = ofl->ofl_flags; 12221618Srie Word rflags; 12231618Srie Gotndx *gnp; 12241618Srie 12251618Srie /* 12261618Srie * all TLS relocations are illegal in a static executable. 12271618Srie */ 12281618Srie if ((ofl->ofl_flags & (FLG_OF_STATIC | FLG_OF_EXEC)) == 12291618Srie (FLG_OF_STATIC | FLG_OF_EXEC)) { 12301618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_TLSSTAT), 1231*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 12321618Srie rsp->rel_isdesc->is_file->ifl_name, 12331618Srie demangle(rsp->rel_sname)); 12341618Srie return (S_ERROR); 12351618Srie } 12361618Srie 12371618Srie /* 12381618Srie * Any TLS relocation must be against a STT_TLS symbol, all others 12391618Srie * are illegal. 12401618Srie */ 12411618Srie if (ELF_ST_TYPE(sdp->sd_sym->st_info) != STT_TLS) { 12421618Srie Ifl_desc *ifl = rsp->rel_isdesc->is_file; 12431618Srie 12441618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_TLSBADSYM), 1245*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 12461618Srie ifl->ifl_name, demangle(rsp->rel_sname), 12471618Srie conv_sym_info_type(ifl->ifl_ehdr->e_machine, 1248*1976Sab196087 ELF_ST_TYPE(sdp->sd_sym->st_info), 0)); 12491618Srie return (S_ERROR); 12501618Srie } 12511618Srie 12521618Srie /* 12531618Srie * We're a executable - use either the IE or LE 12541618Srie * access model. 12551618Srie */ 12561618Srie if (flags & FLG_OF_EXEC) { 12571618Srie /* 12581618Srie * If we are using either IE or LE reference 12591618Srie * model set the DF_STATIC_TLS flag. 12601618Srie */ 12611618Srie ofl->ofl_dtflags |= DF_STATIC_TLS; 12621618Srie 12631618Srie if (!local) { 12641618Srie Gotref gref; 12651618Srie /* 12661618Srie * IE access model 12671618Srie */ 12681618Srie /* 12691618Srie * It's not possible for LD or LE reference 12701618Srie * models to reference a symbol external to 12711618Srie * the current object. 12721618Srie */ 12731618Srie if (IS_TLS_LD(rtype) || IS_TLS_LE(rtype)) { 12741618Srie eprintf(ofl->ofl_lml, ERR_FATAL, 12751618Srie MSG_INTL(MSG_REL_TLSBND), 1276*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 12771618Srie rsp->rel_isdesc->is_file->ifl_name, 12781618Srie demangle(rsp->rel_sname), 12791618Srie sdp->sd_file->ifl_name); 12801618Srie return (S_ERROR); 12811618Srie } 12821618Srie 12831618Srie gref = GOT_REF_TLSIE; 12841618Srie 12851618Srie /* 12861618Srie * Assign a GOT entry for static TLS references 12871618Srie */ 12881618Srie if ((gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), 12891618Srie gref, ofl, 0)) == 0) { 12901618Srie if (ld_assign_gotndx(&(sdp->sd_GOTndxs), 12911618Srie gnp, gref, ofl, rsp, sdp) == S_ERROR) 12921618Srie return (S_ERROR); 12931618Srie rsp->rel_rtype = R_386_TLS_TPOFF; 12941618Srie if (ld_add_outrel((FLG_REL_GOT | FLG_REL_STLS), 12951618Srie rsp, ofl) == S_ERROR) 12961618Srie return (S_ERROR); 12971618Srie rsp->rel_rtype = rtype; 12981618Srie } 12991618Srie if (IS_TLS_IE(rtype)) 13001618Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 13011618Srie 13021618Srie /* 13031618Srie * If (GD or LD) reference models - fixups 13041618Srie * are required. 13051618Srie */ 13061618Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13071618Srie rsp, ofl)); 13081618Srie } 13091618Srie /* 13101618Srie * LE access model 13111618Srie */ 13121618Srie if (IS_TLS_LE(rtype) || (rtype == R_386_TLS_LDO_32)) 13131618Srie return (ld_add_actrel(FLG_REL_STLS, rsp, ofl)); 13141618Srie 13151618Srie return (ld_add_actrel((FLG_REL_TLSFIX | FLG_REL_STLS), 13161618Srie rsp, ofl)); 13171618Srie } 13181618Srie 13191618Srie /* 13201618Srie * Building a shared object 13211618Srie */ 13221618Srie 13231618Srie /* 13241618Srie * Building a shared object - only GD & LD access models 13251618Srie * will work here. 13261618Srie */ 13271618Srie if (IS_TLS_IE(rtype) || IS_TLS_LE(rtype)) { 13281618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_TLSIE), 1329*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 13301618Srie rsp->rel_isdesc->is_file->ifl_name, 13311618Srie demangle(rsp->rel_sname)); 13321618Srie return (S_ERROR); 13331618Srie } 13341618Srie 13351618Srie /* 13361618Srie * LD access mode can only bind to local symbols. 13371618Srie */ 13381618Srie if (!local && IS_TLS_LD(rtype)) { 13391618Srie eprintf(ofl->ofl_lml, ERR_FATAL, MSG_INTL(MSG_REL_TLSBND), 1340*1976Sab196087 conv_reloc_386_type(rsp->rel_rtype, 0), 13411618Srie rsp->rel_isdesc->is_file->ifl_name, 13421618Srie demangle(rsp->rel_sname), 13431618Srie sdp->sd_file->ifl_name); 13441618Srie return (S_ERROR); 13451618Srie } 13461618Srie 13471618Srie 13481618Srie if (IS_TLS_LD(rtype) && ((gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), 13491618Srie GOT_REF_TLSLD, ofl, 0)) == 0)) { 13501618Srie if (ld_assign_gotndx(&(sdp->sd_GOTndxs), gnp, GOT_REF_TLSLD, 13511618Srie ofl, rsp, sdp) == S_ERROR) 13521618Srie return (S_ERROR); 13531618Srie rflags = FLG_REL_GOT | FLG_REL_MTLS; 13541618Srie if (local) 13551618Srie rflags |= FLG_REL_SCNNDX; 13561618Srie rsp->rel_rtype = R_386_TLS_DTPMOD32; 13571618Srie if (ld_add_outrel(rflags, rsp, ofl) == S_ERROR) 13581618Srie return (S_ERROR); 13591618Srie rsp->rel_rtype = rtype; 13601618Srie } else if (IS_TLS_GD(rtype) && 13611618Srie ((gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), GOT_REF_TLSGD, 13621618Srie ofl, 0)) == 0)) { 13631618Srie if (ld_assign_gotndx(&(sdp->sd_GOTndxs), gnp, GOT_REF_TLSGD, 13641618Srie ofl, rsp, sdp) == S_ERROR) 13651618Srie return (S_ERROR); 13661618Srie rflags = FLG_REL_GOT | FLG_REL_DTLS; 13671618Srie if (local) 13681618Srie rflags |= FLG_REL_SCNNDX; 13691618Srie rsp->rel_rtype = R_386_TLS_DTPMOD32; 13701618Srie if (ld_add_outrel(rflags, rsp, ofl) == S_ERROR) 13711618Srie return (S_ERROR); 13721618Srie if (local == TRUE) { 13731618Srie rsp->rel_rtype = R_386_TLS_DTPOFF32; 13741618Srie if (ld_add_actrel((FLG_REL_GOT | FLG_REL_DTLS), rsp, 13751618Srie ofl) == S_ERROR) 13761618Srie return (S_ERROR); 13771618Srie } else { 13781618Srie rsp->rel_rtype = R_386_TLS_DTPOFF32; 13791618Srie if (ld_add_outrel((FLG_REL_GOT | FLG_REL_DTLS), rsp, 13801618Srie ofl) == S_ERROR) 13811618Srie return (S_ERROR); 13821618Srie } 13831618Srie rsp->rel_rtype = rtype; 13841618Srie } 13851618Srie /* 13861618Srie * For GD/LD TLS reference - TLS_{GD,LD}_CALL, this will eventually 13871618Srie * cause a call to __tls_get_addr(). Let's convert this 13881618Srie * relocation to that symbol now, and prepare for the PLT magic. 13891618Srie */ 13901618Srie if ((rtype == R_386_TLS_GD_PLT) || (rtype == R_386_TLS_LDM_PLT)) { 13911618Srie Sym_desc * tlsgetsym; 13921618Srie 13931618Srie if ((tlsgetsym = ld_sym_add_u(MSG_ORIG(MSG_SYM_TLSGETADDR_UU), 13941618Srie ofl)) == (Sym_desc *)S_ERROR) 13951618Srie return (S_ERROR); 13961618Srie rsp->rel_sym = tlsgetsym; 13971618Srie rsp->rel_sname = tlsgetsym->sd_name; 13981618Srie rsp->rel_rtype = R_386_PLT32; 13991618Srie if (ld_reloc_plt(rsp, ofl) == S_ERROR) 14001618Srie return (S_ERROR); 14011618Srie rsp->rel_sym = sdp; 14021618Srie rsp->rel_sname = sdp->sd_name; 14031618Srie rsp->rel_rtype = rtype; 14041618Srie return (1); 14051618Srie } 14061618Srie 14071618Srie if (IS_TLS_LD(rtype)) 14081618Srie return (ld_add_actrel(FLG_REL_MTLS, rsp, ofl)); 14091618Srie 14101618Srie return (ld_add_actrel(FLG_REL_DTLS, rsp, ofl)); 14111618Srie } 14121618Srie 14131618Srie /* ARGSUSED3 */ 14141618Srie Gotndx * 14151618Srie ld_find_gotndx(List * lst, Gotref gref, Ofl_desc * ofl, Rel_desc * rdesc) 14161618Srie { 14171618Srie Listnode * lnp; 14181618Srie Gotndx * gnp; 14191618Srie 14201618Srie if ((gref == GOT_REF_TLSLD) && ofl->ofl_tlsldgotndx) 14211618Srie return (ofl->ofl_tlsldgotndx); 14221618Srie 14231618Srie for (LIST_TRAVERSE(lst, lnp, gnp)) { 14241618Srie if (gnp->gn_gotref == gref) 14251618Srie return (gnp); 14261618Srie } 14271618Srie return ((Gotndx *)0); 14281618Srie } 14291618Srie 14301618Srie Xword 14311618Srie ld_calc_got_offset(Rel_desc * rdesc, Ofl_desc * ofl) 14321618Srie { 14331618Srie Os_desc *osp = ofl->ofl_osgot; 14341618Srie Sym_desc *sdp = rdesc->rel_sym; 14351618Srie Xword gotndx; 14361618Srie Gotref gref; 14371618Srie Gotndx *gnp; 14381618Srie 14391618Srie if (rdesc->rel_flags & FLG_REL_DTLS) 14401618Srie gref = GOT_REF_TLSGD; 14411618Srie else if (rdesc->rel_flags & FLG_REL_MTLS) 14421618Srie gref = GOT_REF_TLSLD; 14431618Srie else if (rdesc->rel_flags & FLG_REL_STLS) 14441618Srie gref = GOT_REF_TLSIE; 14451618Srie else 14461618Srie gref = GOT_REF_GENERIC; 14471618Srie 14481618Srie gnp = ld_find_gotndx(&(sdp->sd_GOTndxs), gref, ofl, 0); 14491618Srie assert(gnp); 14501618Srie 14511618Srie gotndx = (Xword)gnp->gn_gotndx; 14521618Srie 14531618Srie if ((rdesc->rel_flags & FLG_REL_DTLS) && 14541618Srie (rdesc->rel_rtype == R_386_TLS_DTPOFF32)) 14551618Srie gotndx++; 14561618Srie 14571618Srie return ((Xword)(osp->os_shdr->sh_addr + (gotndx * M_GOT_ENTSIZE))); 14581618Srie } 14591618Srie 14601618Srie 14611618Srie /* ARGSUSED4 */ 14621618Srie uintptr_t 14631618Srie ld_assign_gotndx(List * lst, Gotndx * pgnp, Gotref gref, Ofl_desc * ofl, 14641618Srie Rel_desc * rsp, Sym_desc * sdp) 14651618Srie { 14661618Srie Gotndx *gnp; 14671618Srie uint_t gotents; 14681618Srie 14691618Srie if (pgnp) 14701618Srie return (1); 14711618Srie 14721618Srie if ((gref == GOT_REF_TLSGD) || (gref == GOT_REF_TLSLD)) 14731618Srie gotents = 2; 14741618Srie else 14751618Srie gotents = 1; 14761618Srie 14771618Srie if ((gnp = libld_calloc(sizeof (Gotndx), 1)) == 0) 14781618Srie return (S_ERROR); 14791618Srie gnp->gn_gotndx = ofl->ofl_gotcnt; 14801618Srie gnp->gn_gotref = gref; 14811618Srie 14821618Srie ofl->ofl_gotcnt += gotents; 14831618Srie 14841618Srie if (gref == GOT_REF_TLSLD) { 14851618Srie ofl->ofl_tlsldgotndx = gnp; 14861618Srie return (1); 14871618Srie } 14881618Srie 14891618Srie if (list_appendc(lst, (void *)gnp) == 0) 14901618Srie return (S_ERROR); 14911618Srie 14921618Srie return (1); 14931618Srie } 14941618Srie 14951618Srie void 14961618Srie ld_assign_plt_ndx(Sym_desc * sdp, Ofl_desc *ofl) 14971618Srie { 14981618Srie sdp->sd_aux->sa_PLTndx = 1 + ofl->ofl_pltcnt++; 14991618Srie sdp->sd_aux->sa_PLTGOTndx = ofl->ofl_gotcnt++; 15001618Srie ofl->ofl_flags |= FLG_OF_BLDGOT; 15011618Srie } 15021618Srie 15031618Srie /* 15041618Srie * Initializes .got[0] with the _DYNAMIC symbol value. 15051618Srie */ 15061618Srie uintptr_t 15071618Srie ld_fillin_gotplt(Ofl_desc * ofl) 15081618Srie { 15091618Srie if (ofl->ofl_osgot) { 15101618Srie Sym_desc * sdp; 15111618Srie 15121618Srie if ((sdp = ld_sym_find(MSG_ORIG(MSG_SYM_DYNAMIC_U), 15131618Srie SYM_NOHASH, 0, ofl)) != NULL) { 15141618Srie uchar_t *genptr = ((uchar_t *) 15151618Srie ofl->ofl_osgot->os_outdata->d_buf + 15161618Srie (M_GOT_XDYNAMIC * M_GOT_ENTSIZE)); 15171618Srie /* LINTED */ 15181618Srie *(Word *)genptr = (Word)sdp->sd_sym->st_value; 15191618Srie } 15201618Srie } 15211618Srie 15221618Srie /* 15231618Srie * Fill in the reserved slot in the procedure linkage table the first 15241618Srie * entry is: 15251618Srie * if (building a.out) { 15261618Srie * PUSHL got[1] # the address of the link map entry 15271618Srie * JMP * got[2] # the address of rtbinder 15281618Srie * } else { 15291618Srie * PUSHL got[1]@GOT(%ebx) # the address of the link map entry 15301618Srie * JMP * got[2]@GOT(%ebx) # the address of rtbinder 15311618Srie * } 15321618Srie */ 15331618Srie if ((ofl->ofl_flags & FLG_OF_DYNAMIC) && ofl->ofl_osplt) { 15341618Srie uchar_t *pltent; 15351618Srie 15361618Srie pltent = (uchar_t *)ofl->ofl_osplt->os_outdata->d_buf; 15371618Srie if (!(ofl->ofl_flags & FLG_OF_SHAROBJ)) { 15381618Srie pltent[0] = M_SPECIAL_INST; 15391618Srie pltent[1] = M_PUSHL_DISP; 15401618Srie pltent += 2; 15411618Srie /* LINTED */ 15421618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr-> 15431618Srie sh_addr + M_GOT_XLINKMAP * M_GOT_ENTSIZE); 15441618Srie pltent += 4; 15451618Srie pltent[0] = M_SPECIAL_INST; 15461618Srie pltent[1] = M_JMP_DISP_IND; 15471618Srie pltent += 2; 15481618Srie /* LINTED */ 15491618Srie *(Word *)pltent = (Word)(ofl->ofl_osgot->os_shdr-> 15501618Srie sh_addr + M_GOT_XRTLD * M_GOT_ENTSIZE); 15511618Srie } else { 15521618Srie pltent[0] = M_SPECIAL_INST; 15531618Srie pltent[1] = M_PUSHL_REG_DISP; 15541618Srie pltent += 2; 15551618Srie /* LINTED */ 15561618Srie *(Word *)pltent = (Word)(M_GOT_XLINKMAP * 15571618Srie M_GOT_ENTSIZE); 15581618Srie pltent += 4; 15591618Srie pltent[0] = M_SPECIAL_INST; 15601618Srie pltent[1] = M_JMP_REG_DISP_IND; 15611618Srie pltent += 2; 15621618Srie /* LINTED */ 15631618Srie *(Word *)pltent = (Word)(M_GOT_XRTLD * 15641618Srie M_GOT_ENTSIZE); 15651618Srie } 15661618Srie } 15671618Srie return (1); 15681618Srie } 1569