17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 55aefb655Srie * Common Development and Distribution License (the "License"). 65aefb655Srie * You may not use this file except in compliance with the License. 77c478bd9Sstevel@tonic-gate * 87c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 97c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 107c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 117c478bd9Sstevel@tonic-gate * and limitations under the License. 127c478bd9Sstevel@tonic-gate * 137c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 147c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 157c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 167c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 177c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 187c478bd9Sstevel@tonic-gate * 197c478bd9Sstevel@tonic-gate * CDDL HEADER END 207c478bd9Sstevel@tonic-gate */ 21552ff457Srie 227c478bd9Sstevel@tonic-gate /* 23*f3324781Sab196087 * Copyright 2007 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 26552ff457Srie 277c478bd9Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 287c478bd9Sstevel@tonic-gate 297c478bd9Sstevel@tonic-gate #if defined(_KERNEL) 307c478bd9Sstevel@tonic-gate #include <sys/types.h> 317c478bd9Sstevel@tonic-gate #include "reloc.h" 327c478bd9Sstevel@tonic-gate #else 337c478bd9Sstevel@tonic-gate #include <stdio.h> 347c478bd9Sstevel@tonic-gate #include "sgs.h" 357c478bd9Sstevel@tonic-gate #include "machdep.h" 367c478bd9Sstevel@tonic-gate #include "libld.h" 377c478bd9Sstevel@tonic-gate #include "reloc.h" 387c478bd9Sstevel@tonic-gate #include "conv.h" 397c478bd9Sstevel@tonic-gate #include "msg.h" 407c478bd9Sstevel@tonic-gate #endif 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 43552ff457Srie * This table represents the current relocations that do_reloc() is able to 44552ff457Srie * process. The relocations below that are marked SPECIAL are relocations that 45552ff457Srie * take special processing and shouldn't actually ever be passed to do_reloc(). 467c478bd9Sstevel@tonic-gate */ 477c478bd9Sstevel@tonic-gate const Rel_entry reloc_table[R_386_NUM] = { 48552ff457Srie /* R_386_NONE */ {FLG_RE_NOTREL, 0}, 497c478bd9Sstevel@tonic-gate /* R_386_32 */ {FLG_RE_NOTREL, 4}, 507c478bd9Sstevel@tonic-gate /* R_386_PC32 */ {FLG_RE_PCREL, 4}, 517c478bd9Sstevel@tonic-gate /* R_386_GOT32 */ {FLG_RE_GOTADD, 4}, 527c478bd9Sstevel@tonic-gate /* R_386_PLT32 */ {FLG_RE_PLTREL | FLG_RE_PCREL, 4}, 53552ff457Srie /* R_386_COPY */ {FLG_RE_NOTREL, 0}, /* SPECIAL */ 547c478bd9Sstevel@tonic-gate /* R_386_GLOB_DAT */ {FLG_RE_NOTREL, 4}, 55552ff457Srie /* R_386_JMP_SLOT */ {FLG_RE_NOTREL, 4}, /* SPECIAL */ 567c478bd9Sstevel@tonic-gate /* R_386_RELATIVE */ {FLG_RE_NOTREL, 4}, 577c478bd9Sstevel@tonic-gate /* R_386_GOTOFF */ {FLG_RE_GOTREL, 4}, 587c478bd9Sstevel@tonic-gate /* R_386_GOTPC */ {FLG_RE_PCREL | FLG_RE_GOTPC | FLG_RE_LOCLBND, 4}, 597c478bd9Sstevel@tonic-gate /* R_386_32PLT */ {FLG_RE_PLTREL, 4}, 60d326b23bSrie /* R_386_TLS_GD_PLT */ {FLG_RE_PLTREL | FLG_RE_PCREL | FLG_RE_TLSGD, 4}, 61d326b23bSrie /* R_386_TLS_LDM_PLT */ {FLG_RE_PLTREL | FLG_RE_PCREL | FLG_RE_TLSLD, 4}, 627c478bd9Sstevel@tonic-gate /* R_386_TLS_TPOFF */ {FLG_RE_NOTREL, 4}, 63d326b23bSrie /* R_386_TLS_IE */ {FLG_RE_GOTADD | FLG_RE_TLSIE, 4}, 64d326b23bSrie /* R_386_TLS_GOTIE */ {FLG_RE_GOTADD | FLG_RE_TLSIE, 4}, 65d326b23bSrie /* R_386_TLS_LE */ {FLG_RE_TLSLE, 4}, 66d326b23bSrie /* R_386_TLS_GD */ {FLG_RE_GOTADD | FLG_RE_TLSGD, 4}, 67d326b23bSrie /* R_386_TLS_LDM */ {FLG_RE_GOTADD | FLG_RE_TLSLD, 4}, 68552ff457Srie /* R_386_16 */ {FLG_RE_NOTREL, 2}, 69552ff457Srie /* R_386_PC16 */ {FLG_RE_PCREL, 2}, 70552ff457Srie /* R_386_8 */ {FLG_RE_NOTREL, 1}, 71552ff457Srie /* R_386_PC8 */ {FLG_RE_PCREL, 1}, 727c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN24 */ {FLG_RE_NOTSUP, 0}, 737c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN25 */ {FLG_RE_NOTSUP, 0}, 747c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN26 */ {FLG_RE_NOTSUP, 0}, 757c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN27 */ {FLG_RE_NOTSUP, 0}, 767c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN28 */ {FLG_RE_NOTSUP, 0}, 777c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN29 */ {FLG_RE_NOTSUP, 0}, 787c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN30 */ {FLG_RE_NOTSUP, 0}, 797c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN31 */ {FLG_RE_NOTSUP, 0}, 80d326b23bSrie /* R_386_TLS_LDO_32 */ {FLG_RE_TLSLD, 4}, 817c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN33 */ {FLG_RE_NOTSUP, 0}, 827c478bd9Sstevel@tonic-gate /* R_386_UNKNOWN34 */ {FLG_RE_NOTSUP, 0}, 837c478bd9Sstevel@tonic-gate /* R_386_TLS_DTPMOD32 */ {FLG_RE_NOTREL, 4}, 847c478bd9Sstevel@tonic-gate /* R_386_TLS_DTPOFF32 */ {FLG_RE_NOTREL, 4}, 852926dd2eSrie /* R_386_UNKONWN37 */ {FLG_RE_NOTSUP, 0}, 862926dd2eSrie /* R_386_SIZE32 */ {FLG_RE_SIZE | FLG_RE_VERIFY, 4} 877c478bd9Sstevel@tonic-gate }; 887c478bd9Sstevel@tonic-gate 897c478bd9Sstevel@tonic-gate /* 907c478bd9Sstevel@tonic-gate * Write a single relocated value to its reference location. 91552ff457Srie * We assume we wish to add the relocation amount, value, to the 927c478bd9Sstevel@tonic-gate * value of the address already present at the offset. 937c478bd9Sstevel@tonic-gate * 947c478bd9Sstevel@tonic-gate * NAME VALUE FIELD CALCULATION 957c478bd9Sstevel@tonic-gate * 967c478bd9Sstevel@tonic-gate * R_386_NONE 0 none none 977c478bd9Sstevel@tonic-gate * R_386_32 1 word32 S + A 987c478bd9Sstevel@tonic-gate * R_386_PC32 2 word32 S + A - P 997c478bd9Sstevel@tonic-gate * R_386_GOT32 3 word32 G + A - P 1007c478bd9Sstevel@tonic-gate * R_386_PLT32 4 word32 L + A - P 1017c478bd9Sstevel@tonic-gate * R_386_COPY 5 none none 1027c478bd9Sstevel@tonic-gate * R_386_GLOB_DAT 6 word32 S 1037c478bd9Sstevel@tonic-gate * R_386_JMP_SLOT 7 word32 S 1047c478bd9Sstevel@tonic-gate * R_386_RELATIVE 8 word32 B + A 1057c478bd9Sstevel@tonic-gate * R_386_GOTOFF 9 word32 S + A - GOT 1067c478bd9Sstevel@tonic-gate * R_386_GOTPC 10 word32 GOT + A - P 1077c478bd9Sstevel@tonic-gate * R_386_32PLT 11 word32 L + A 1087c478bd9Sstevel@tonic-gate * R_386_TLS_GD_PLT 12 word32 @tlsgdplt 1097c478bd9Sstevel@tonic-gate * R_386_TLS_LDM_PLT 13 word32 @tlsldmplt 1107c478bd9Sstevel@tonic-gate * R_386_TLS_TPOFF 14 word32 @ntpoff(S) 1117c478bd9Sstevel@tonic-gate * R_386_TLS_IE 15 word32 @indntpoff(S) 1127c478bd9Sstevel@tonic-gate * R_386_TLS_GD 18 word32 @tlsgd(S) 1137c478bd9Sstevel@tonic-gate * R_386_TLS_LDM 19 word32 @tlsldm(S) 114552ff457Srie * R_386_16 20 word16 S + A 115552ff457Srie * R_386_PC16 21 word16 S + A - P 116552ff457Srie * R_386_8 22 word8 S + A 117552ff457Srie * R_386_PC8 23 word8 S + A - P 1187c478bd9Sstevel@tonic-gate * R_386_TLS_LDO_32 32 word32 @dtpoff(S) 1197c478bd9Sstevel@tonic-gate * R_386_TLS_DTPMOD32 35 word32 @dtpmod(S) 1207c478bd9Sstevel@tonic-gate * R_386_TLS_DTPOFF32 36 word32 @dtpoff(S) 1212926dd2eSrie * R_386_SIZE32 38 word32 Z + A 1227c478bd9Sstevel@tonic-gate * 123552ff457Srie * Relocations 0-10 are from Figure 4-4: Relocation Types from the 1247c478bd9Sstevel@tonic-gate * intel ABI. Relocation 11 (R_386_32PLT) is from the C++ intel abi 1257c478bd9Sstevel@tonic-gate * and is in the process of being registered with intel ABI (1/13/94). 1267c478bd9Sstevel@tonic-gate * 1277c478bd9Sstevel@tonic-gate * Relocations R_386_TLS_* are added to support Thread-Local storage 1287c478bd9Sstevel@tonic-gate * as recorded in PSARC/2001/509 1297c478bd9Sstevel@tonic-gate * 1307c478bd9Sstevel@tonic-gate * Relocation calculations: 1317c478bd9Sstevel@tonic-gate * 1327c478bd9Sstevel@tonic-gate * CALCULATION uses the following notation: 1337c478bd9Sstevel@tonic-gate * A the addend used 1347c478bd9Sstevel@tonic-gate * B the base address of the shared object in memory 1357c478bd9Sstevel@tonic-gate * G the offset into the global offset table 1367c478bd9Sstevel@tonic-gate * GOT the address of teh global offset table 1377c478bd9Sstevel@tonic-gate * L the procedure linkage entry 1387c478bd9Sstevel@tonic-gate * P the place of the storage unit being relocated 1397c478bd9Sstevel@tonic-gate * S the value of the symbol 1402926dd2eSrie * Z the size of the symbol whose index resides in the relocation 1412926dd2eSrie * entry 1427c478bd9Sstevel@tonic-gate * 1437c478bd9Sstevel@tonic-gate * @dtlndx(x): Allocate two contiguous entries in the GOT table to hold 1447c478bd9Sstevel@tonic-gate * a Tls_index structure (for passing to __tls_get_addr()). The 1457c478bd9Sstevel@tonic-gate * instructions referencing this entry will be bound to the first 1467c478bd9Sstevel@tonic-gate * of the two GOT entries. 1477c478bd9Sstevel@tonic-gate * 1487c478bd9Sstevel@tonic-gate * @tmndx(x): Allocate two contiguous entries in the GOT table to hold 1497c478bd9Sstevel@tonic-gate * a Tls_index structure (for passing to __tls_get_addr()). The 1507c478bd9Sstevel@tonic-gate * ti_offset field of the Tls_index will be set to 0 (zero) and the 1517c478bd9Sstevel@tonic-gate * ti_module will be filled in at run-time. The call to 1527c478bd9Sstevel@tonic-gate * __tls_get_addr() will return the starting offset of the dynamic 1537c478bd9Sstevel@tonic-gate * TLS block. 1547c478bd9Sstevel@tonic-gate * 1557c478bd9Sstevel@tonic-gate * @dtpoff(x): calculate the tlsoffset relative to the TLS block. 1567c478bd9Sstevel@tonic-gate * 1577c478bd9Sstevel@tonic-gate * @tpoff(x): calculate the tlsoffset relative to the TLS block. 1587c478bd9Sstevel@tonic-gate * 1597c478bd9Sstevel@tonic-gate * @dtpmod(x): calculate the module id of the object containing symbol x. 1607c478bd9Sstevel@tonic-gate * 1617c478bd9Sstevel@tonic-gate * The calculations in the CALCULATION column are assumed to have 1627c478bd9Sstevel@tonic-gate * been performed before calling this function except for the addition of 1637c478bd9Sstevel@tonic-gate * the addresses in the instructions. 1647c478bd9Sstevel@tonic-gate */ 165*f3324781Sab196087 #if defined(_KERNEL) 166*f3324781Sab196087 #define lml 0 /* Needed by arglist of REL_ERR_* macros */ 1677c478bd9Sstevel@tonic-gate int 168*f3324781Sab196087 do_reloc_krtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym, 169*f3324781Sab196087 const char *file) 170*f3324781Sab196087 #elif defined(DO_RELOC_LIBLD) 171*f3324781Sab196087 int 172*f3324781Sab196087 do_reloc_ld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym, 173*f3324781Sab196087 const char *file, int bswap, void *lml) 174*f3324781Sab196087 #else 175*f3324781Sab196087 int 176*f3324781Sab196087 do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym, 1775aefb655Srie const char *file, void *lml) 178*f3324781Sab196087 #endif 1797c478bd9Sstevel@tonic-gate { 1807c478bd9Sstevel@tonic-gate const Rel_entry *rep; 1817c478bd9Sstevel@tonic-gate 182*f3324781Sab196087 #if defined(DO_RELOC_LIBLD) 183*f3324781Sab196087 /* 184*f3324781Sab196087 * We do not support building the X86 linker as a cross linker 185*f3324781Sab196087 * at this time. 186*f3324781Sab196087 */ 187*f3324781Sab196087 if (bswap) { 188*f3324781Sab196087 REL_ERR_NOSWAP(lml, file, sym, rtype); 189*f3324781Sab196087 return (0); 190*f3324781Sab196087 } 191*f3324781Sab196087 #endif 192*f3324781Sab196087 1937c478bd9Sstevel@tonic-gate rep = &reloc_table[rtype]; 194552ff457Srie 195552ff457Srie switch (rep->re_fsize) { 196552ff457Srie case 1: 197552ff457Srie /* LINTED */ 198552ff457Srie *((uchar_t *)off) += (uchar_t)(*value); 199552ff457Srie break; 200552ff457Srie case 2: 201552ff457Srie /* LINTED */ 202552ff457Srie *((Half *)off) += (Half)(*value); 203552ff457Srie break; 204552ff457Srie case 4: 2057c478bd9Sstevel@tonic-gate /* LINTED */ 2067c478bd9Sstevel@tonic-gate *((Xword *)off) += *value; 207552ff457Srie break; 208552ff457Srie default: 209552ff457Srie /* 210552ff457Srie * To keep chkmsg() happy: MSG_INTL(MSG_REL_UNSUPSZ) 211552ff457Srie */ 2125aefb655Srie REL_ERR_UNSUPSZ(lml, file, sym, rtype, rep->re_fsize); 213552ff457Srie return (0); 214552ff457Srie } 2157c478bd9Sstevel@tonic-gate return (1); 2167c478bd9Sstevel@tonic-gate } 217