6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
26 #if defined(_KERNEL)
27 #include <sys/types.h>
28 #include "reloc.h"
29 #else
30 #define ELF_TARGET_386
31 #if defined(DO_RELOC_LIBLD)
32 #undef DO_RELOC_LIBLD
33 #define DO_RELOC_LIBLD_X86
34 #endif
35 #include <stdio.h>
36 #include "sgs.h"
37 #include "machdep.h"
38 #include "libld.h"
39 #include "reloc.h"
40 #include "conv.h"
41 #include "msg.h"
42 #endif
43
44 /*
45 * We need to build this code differently when it is used for
46 * cross linking:
47 * - Data alignment requirements can differ from those
48 * of the running system, so we can't access data
49 * in units larger than a byte
50 * - We have to include code to do byte swapping when the
51 * target and linker host use different byte ordering,
52 * but such code is a waste when running natively.
53 */
54 #if !defined(DO_RELOC_LIBLD) || defined(__i386) || defined(__amd64)
55 #define DORELOC_NATIVE
56 #endif
57
58 /*
59 * This table represents the current relocations that do_reloc() is able to
60 * process. The relocations below that are marked SPECIAL are relocations that
61 * take special processing and shouldn't actually ever be passed to do_reloc().
62 */
164 * instructions referencing this entry will be bound to the first
165 * of the two GOT entries.
166 *
167 * @tmndx(x): Allocate two contiguous entries in the GOT table to hold
168 * a Tls_index structure (for passing to __tls_get_addr()). The
169 * ti_offset field of the Tls_index will be set to 0 (zero) and the
170 * ti_module will be filled in at run-time. The call to
171 * __tls_get_addr() will return the starting offset of the dynamic
172 * TLS block.
173 *
174 * @dtpoff(x): calculate the tlsoffset relative to the TLS block.
175 *
176 * @tpoff(x): calculate the tlsoffset relative to the TLS block.
177 *
178 * @dtpmod(x): calculate the module id of the object containing symbol x.
179 *
180 * The calculations in the CALCULATION column are assumed to have
181 * been performed before calling this function except for the addition of
182 * the addresses in the instructions.
183 */
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)
190 /*ARGSUSED5*/
191 int
192 do_reloc_ld(Rel_desc *rdesc, uchar_t *off, Xword *value,
193 rel_desc_sname_func_t rel_desc_sname_func,
194 const char *file, int bswap, void *lml)
195 #else
196 int
197 do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
198 const char *file, void *lml)
199 #endif
200 {
201 #ifdef DO_RELOC_LIBLD
202 #define sym (* rel_desc_sname_func)(rdesc)
203 uchar_t rtype = rdesc->rel_rtype;
204 #endif
205 const Rel_entry *rep;
206
207 rep = &reloc_table[rtype];
208
209 switch (rep->re_fsize) {
|
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
12 *
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22 /*
23 * Copyright (c) 1995, 2010, Oracle and/or its affiliates. All rights reserved.
24 */
25
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
36 #define ELF_TARGET_386
37 #if defined(DO_RELOC_LIBLD)
38 #undef DO_RELOC_LIBLD
39 #define DO_RELOC_LIBLD_X86
40 #endif
41 #include <stdio.h>
42 #include "sgs.h"
43 #include "machdep.h"
44 #include "libld.h"
45 #include "reloc.h"
46 #include "conv.h"
47 #include "msg.h"
48
49 /*
50 * We need to build this code differently when it is used for
51 * cross linking:
52 * - Data alignment requirements can differ from those
53 * of the running system, so we can't access data
54 * in units larger than a byte
55 * - We have to include code to do byte swapping when the
56 * target and linker host use different byte ordering,
57 * but such code is a waste when running natively.
58 */
59 #if !defined(DO_RELOC_LIBLD) || defined(__i386) || defined(__amd64)
60 #define DORELOC_NATIVE
61 #endif
62
63 /*
64 * This table represents the current relocations that do_reloc() is able to
65 * process. The relocations below that are marked SPECIAL are relocations that
66 * take special processing and shouldn't actually ever be passed to do_reloc().
67 */
169 * instructions referencing this entry will be bound to the first
170 * of the two GOT entries.
171 *
172 * @tmndx(x): Allocate two contiguous entries in the GOT table to hold
173 * a Tls_index structure (for passing to __tls_get_addr()). The
174 * ti_offset field of the Tls_index will be set to 0 (zero) and the
175 * ti_module will be filled in at run-time. The call to
176 * __tls_get_addr() will return the starting offset of the dynamic
177 * TLS block.
178 *
179 * @dtpoff(x): calculate the tlsoffset relative to the TLS block.
180 *
181 * @tpoff(x): calculate the tlsoffset relative to the TLS block.
182 *
183 * @dtpmod(x): calculate the module id of the object containing symbol x.
184 *
185 * The calculations in the CALCULATION column are assumed to have
186 * been performed before calling this function except for the addition of
187 * the addresses in the instructions.
188 */
189 #if defined(DO_RELOC_LIBLD)
190 /*ARGSUSED5*/
191 int
192 do_reloc_ld(Rel_desc *rdesc, uchar_t *off, Xword *value,
193 rel_desc_sname_func_t rel_desc_sname_func,
194 const char *file, int bswap, void *lml)
195 #else
196 int
197 do_reloc_rtld(uchar_t rtype, uchar_t *off, Xword *value, const char *sym,
198 const char *file, void *lml)
199 #endif
200 {
201 #ifdef DO_RELOC_LIBLD
202 #define sym (* rel_desc_sname_func)(rdesc)
203 uchar_t rtype = rdesc->rel_rtype;
204 #endif
205 const Rel_entry *rep;
206
207 rep = &reloc_table[rtype];
208
209 switch (rep->re_fsize) {
|