Print this page
10925 remove 32-bit krtld
Reviewed by: Andy Stormont <astormont@racktopsystems.com>
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/intel/ia32/krtld/doreloc.c
+++ new/usr/src/uts/intel/ia32/krtld/doreloc.c
1 1 /*
2 2 * CDDL HEADER START
3 3 *
4 4 * The contents of this file are subject to the terms of the
5 5 * Common Development and Distribution License (the "License").
6 6 * You may not use this file except in compliance with the License.
7 7 *
8 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 9 * or http://www.opensolaris.org/os/licensing.
10 10 * See the License for the specific language governing permissions
11 11 * and limitations under the License.
12 12 *
13 13 * When distributing Covered Code, include this CDDL HEADER in each
14 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 15 * If applicable, add the following below this CDDL HEADER, with the
↓ open down ↓ |
15 lines elided |
↑ open up ↑ |
16 16 * fields enclosed by brackets "[]" replaced with your own identifying
17 17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 18 *
19 19 * CDDL HEADER END
20 20 */
21 21
22 22 /*
23 23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24 24 */
25 25
26 -#if defined(_KERNEL)
27 -#include <sys/types.h>
28 -#include "reloc.h"
29 -#else
26 +/*
27 + * Copyright 2019 Joyent, Inc.
28 + */
29 +
30 +/*
31 + * While this is no longer relevant to the kernel, we keep it in its
32 + * traditional location to match the other variants, used from the ld
33 + * code.
34 + */
35 +
30 36 #define ELF_TARGET_386
31 37 #if defined(DO_RELOC_LIBLD)
32 38 #undef DO_RELOC_LIBLD
33 39 #define DO_RELOC_LIBLD_X86
34 40 #endif
35 41 #include <stdio.h>
36 42 #include "sgs.h"
37 43 #include "machdep.h"
38 44 #include "libld.h"
39 45 #include "reloc.h"
40 46 #include "conv.h"
41 47 #include "msg.h"
42 -#endif
43 48
44 49 /*
45 50 * We need to build this code differently when it is used for
46 51 * cross linking:
47 52 * - Data alignment requirements can differ from those
48 53 * of the running system, so we can't access data
49 54 * in units larger than a byte
50 55 * - We have to include code to do byte swapping when the
51 56 * target and linker host use different byte ordering,
52 57 * but such code is a waste when running natively.
53 58 */
54 59 #if !defined(DO_RELOC_LIBLD) || defined(__i386) || defined(__amd64)
55 60 #define DORELOC_NATIVE
56 61 #endif
57 62
58 63 /*
59 64 * This table represents the current relocations that do_reloc() is able to
60 65 * process. The relocations below that are marked SPECIAL are relocations that
61 66 * take special processing and shouldn't actually ever be passed to do_reloc().
62 67 */
63 68 const Rel_entry reloc_table[R_386_NUM] = {
64 69 /* R_386_NONE */ {0, FLG_RE_NOTREL, 0, 0, 0},
65 70 /* R_386_32 */ {0, FLG_RE_NOTREL, 4, 0, 0},
66 71 /* R_386_PC32 */ {0, FLG_RE_PCREL, 4, 0, 0},
67 72 /* R_386_GOT32 */ {0, FLG_RE_GOTADD, 4, 0, 0},
68 73 /* R_386_PLT32 */ {0, FLG_RE_PLTREL | FLG_RE_PCREL, 4, 0, 0},
69 74 /* R_386_COPY */ {0, FLG_RE_NOTREL, 0, 0, 0}, /* SPECIAL */
70 75 /* R_386_GLOB_DAT */ {0, FLG_RE_NOTREL, 4, 0, 0},
71 76 /* R_386_JMP_SLOT */ {0, FLG_RE_NOTREL, 4, 0, 0}, /* SPECIAL */
72 77 /* R_386_RELATIVE */ {0, FLG_RE_NOTREL, 4, 0, 0},
73 78 /* R_386_GOTOFF */ {0, FLG_RE_GOTREL, 4, 0, 0},
74 79 /* R_386_GOTPC */ {0, FLG_RE_PCREL | FLG_RE_GOTPC | FLG_RE_LOCLBND, 4,
75 80 0, 0},
76 81 /* R_386_32PLT */ {0, FLG_RE_PLTREL, 4, 0, 0},
77 82 /* R_386_TLS_GD_PLT */ {0, FLG_RE_PLTREL | FLG_RE_PCREL | FLG_RE_TLSGD, 4,
78 83 0, 0},
79 84 /* R_386_TLS_LDM_PLT */ {0, FLG_RE_PLTREL | FLG_RE_PCREL | FLG_RE_TLSLD, 4,
80 85 0, 0},
81 86 /* R_386_TLS_TPOFF */ {0, FLG_RE_NOTREL, 4, 0, 0},
82 87 /* R_386_TLS_IE */ {0, FLG_RE_GOTADD | FLG_RE_TLSIE, 4, 0, 0},
83 88 /* R_386_TLS_GOTIE */ {0, FLG_RE_GOTADD | FLG_RE_TLSIE, 4, 0, 0},
84 89 /* R_386_TLS_LE */ {0, FLG_RE_TLSLE, 4, 0, 0},
85 90 /* R_386_TLS_GD */ {0, FLG_RE_GOTADD | FLG_RE_TLSGD, 4, 0, 0},
86 91 /* R_386_TLS_LDM */ {0, FLG_RE_GOTADD | FLG_RE_TLSLD, 4, 0, 0},
87 92 /* R_386_16 */ {0, FLG_RE_NOTREL, 2, 0, 0},
88 93 /* R_386_PC16 */ {0, FLG_RE_PCREL, 2, 0, 0},
89 94 /* R_386_8 */ {0, FLG_RE_NOTREL, 1, 0, 0},
90 95 /* R_386_PC8 */ {0, FLG_RE_PCREL, 1, 0, 0},
91 96 /* R_386_UNKNOWN24 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
92 97 /* R_386_UNKNOWN25 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
93 98 /* R_386_UNKNOWN26 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
94 99 /* R_386_UNKNOWN27 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
95 100 /* R_386_UNKNOWN28 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
96 101 /* R_386_UNKNOWN29 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
97 102 /* R_386_UNKNOWN30 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
98 103 /* R_386_UNKNOWN31 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
99 104 /* R_386_TLS_LDO_32 */ {0, FLG_RE_TLSLD, 4, 0, 0},
100 105 /* R_386_UNKNOWN33 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
101 106 /* R_386_UNKNOWN34 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
102 107 /* R_386_TLS_DTPMOD32 */ {0, FLG_RE_NOTREL, 4, 0, 0},
103 108 /* R_386_TLS_DTPOFF32 */ {0, FLG_RE_NOTREL, 4, 0, 0},
104 109 /* R_386_UNKONWN37 */ {0, FLG_RE_NOTSUP, 0, 0, 0},
105 110 /* R_386_SIZE32 */ {0, FLG_RE_SIZE | FLG_RE_VERIFY, 4, 0, 0}
106 111 };
107 112
108 113 /*
109 114 * Write a single relocated value to its reference location.
110 115 * We assume we wish to add the relocation amount, value, to the
111 116 * value of the address already present at the offset.
112 117 *
113 118 * NAME VALUE FIELD CALCULATION
114 119 *
115 120 * R_386_NONE 0 none none
116 121 * R_386_32 1 word32 S + A
117 122 * R_386_PC32 2 word32 S + A - P
118 123 * R_386_GOT32 3 word32 G + A - P
119 124 * R_386_PLT32 4 word32 L + A - P
120 125 * R_386_COPY 5 none none
121 126 * R_386_GLOB_DAT 6 word32 S
122 127 * R_386_JMP_SLOT 7 word32 S
123 128 * R_386_RELATIVE 8 word32 B + A
124 129 * R_386_GOTOFF 9 word32 S + A - GOT
125 130 * R_386_GOTPC 10 word32 GOT + A - P
126 131 * R_386_32PLT 11 word32 L + A
127 132 * R_386_TLS_GD_PLT 12 word32 @tlsgdplt
128 133 * R_386_TLS_LDM_PLT 13 word32 @tlsldmplt
129 134 * R_386_TLS_TPOFF 14 word32 @ntpoff(S)
130 135 * R_386_TLS_IE 15 word32 @indntpoff(S)
131 136 * R_386_TLS_GD 18 word32 @tlsgd(S)
132 137 * R_386_TLS_LDM 19 word32 @tlsldm(S)
133 138 * R_386_16 20 word16 S + A
134 139 * R_386_PC16 21 word16 S + A - P
135 140 * R_386_8 22 word8 S + A
136 141 * R_386_PC8 23 word8 S + A - P
137 142 * R_386_TLS_LDO_32 32 word32 @dtpoff(S)
138 143 * R_386_TLS_DTPMOD32 35 word32 @dtpmod(S)
139 144 * R_386_TLS_DTPOFF32 36 word32 @dtpoff(S)
140 145 * R_386_SIZE32 38 word32 Z + A
141 146 *
142 147 * Relocations 0-10 are from Figure 4-4: Relocation Types from the
143 148 * intel ABI. Relocation 11 (R_386_32PLT) is from the C++ intel abi
144 149 * and is in the process of being registered with intel ABI (1/13/94).
145 150 *
146 151 * Relocations R_386_TLS_* are added to support Thread-Local storage
147 152 * as recorded in PSARC/2001/509
148 153 *
149 154 * Relocation calculations:
150 155 *
151 156 * CALCULATION uses the following notation:
152 157 * A the addend used
153 158 * B the base address of the shared object in memory
154 159 * G the offset into the global offset table
155 160 * GOT the address of teh global offset table
156 161 * L the procedure linkage entry
157 162 * P the place of the storage unit being relocated
158 163 * S the value of the symbol
159 164 * Z the size of the symbol whose index resides in the relocation
160 165 * entry
161 166 *
162 167 * @dtlndx(x): Allocate two contiguous entries in the GOT table to hold
163 168 * a Tls_index structure (for passing to __tls_get_addr()). The
164 169 * instructions referencing this entry will be bound to the first
165 170 * of the two GOT entries.
166 171 *
167 172 * @tmndx(x): Allocate two contiguous entries in the GOT table to hold
168 173 * a Tls_index structure (for passing to __tls_get_addr()). The
169 174 * ti_offset field of the Tls_index will be set to 0 (zero) and the
170 175 * ti_module will be filled in at run-time. The call to
171 176 * __tls_get_addr() will return the starting offset of the dynamic
172 177 * TLS block.
173 178 *
↓ open down ↓ |
121 lines elided |
↑ open up ↑ |
174 179 * @dtpoff(x): calculate the tlsoffset relative to the TLS block.
175 180 *
176 181 * @tpoff(x): calculate the tlsoffset relative to the TLS block.
177 182 *
178 183 * @dtpmod(x): calculate the module id of the object containing symbol x.
179 184 *
180 185 * The calculations in the CALCULATION column are assumed to have
181 186 * been performed before calling this function except for the addition of
182 187 * the addresses in the instructions.
183 188 */
184 -#if defined(_KERNEL)
185 -#define lml 0 /* Needed by arglist of REL_ERR_* macros */
186 -int
187 -do_reloc_krtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
188 - const char *file)
189 -#elif defined(DO_RELOC_LIBLD)
189 +#if defined(DO_RELOC_LIBLD)
190 190 /*ARGSUSED5*/
191 191 int
192 192 do_reloc_ld(Rel_desc *rdesc, uchar_t *off, Xword *value,
193 193 rel_desc_sname_func_t rel_desc_sname_func,
194 194 const char *file, int bswap, void *lml)
195 195 #else
196 196 int
197 197 do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
198 198 const char *file, void *lml)
199 199 #endif
200 200 {
201 201 #ifdef DO_RELOC_LIBLD
202 202 #define sym (* rel_desc_sname_func)(rdesc)
203 203 uchar_t rtype = rdesc->rel_rtype;
204 204 #endif
205 205 const Rel_entry *rep;
206 206
207 207 rep = &reloc_table[rtype];
208 208
209 209 switch (rep->re_fsize) {
210 210 case 1:
211 211 /* LINTED */
212 212 *((uchar_t *)off) += (uchar_t)(*value);
213 213 break;
214 214
215 215 case 2:
216 216 #if defined(DORELOC_NATIVE)
217 217 /* LINTED */
218 218 *((Half *)off) += (Half)(*value);
219 219 #else
220 220 {
221 221 Half v;
222 222 uchar_t *v_bytes = (uchar_t *)&v;
223 223
224 224 if (bswap) {
225 225 UL_ASSIGN_BSWAP_HALF(v_bytes, off);
226 226 v += *value;
227 227 UL_ASSIGN_BSWAP_HALF(off, v_bytes);
228 228 } else {
229 229 UL_ASSIGN_HALF(v_bytes, off);
230 230 v += *value;
231 231 UL_ASSIGN_HALF(off, v_bytes);
232 232 }
233 233 }
234 234 #endif
235 235 break;
236 236
237 237 case 4:
238 238 #if defined(DORELOC_NATIVE)
239 239 /* LINTED */
240 240 *((Xword *)off) += *value;
241 241 #else
242 242 {
243 243 Word v;
244 244 uchar_t *v_bytes = (uchar_t *)&v;
245 245
246 246 if (bswap) {
247 247 UL_ASSIGN_BSWAP_WORD(v_bytes, off);
248 248 v += *value;
249 249 UL_ASSIGN_BSWAP_WORD(off, v_bytes);
250 250 } else {
251 251 UL_ASSIGN_WORD(v_bytes, off);
252 252 v += *value;
253 253 UL_ASSIGN_WORD(off, v_bytes);
254 254 }
255 255 }
256 256 #endif
257 257 break;
258 258 default:
259 259 /*
260 260 * To keep chkmsg() happy: MSG_INTL(MSG_REL_UNSUPSZ)
261 261 */
262 262 REL_ERR_UNSUPSZ(lml, file, sym, rtype, rep->re_fsize);
263 263 return (0);
264 264 }
265 265 return (1);
266 266
267 267 #ifdef DO_RELOC_LIBLD
268 268 #undef sym
269 269 #endif
270 270 }
↓ open down ↓ |
71 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX