Print this page
12399 kobj printf functions should be checked
Split |
Close |
Expand all |
Collapse all |
--- old/usr/src/uts/common/krtld/reloc.h
+++ new/usr/src/uts/common/krtld/reloc.h
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
↓ open down ↓ |
13 lines elided |
↑ open up ↑ |
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
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 + *
25 + * Copyright 2020 Joyent, Inc.
24 26 */
25 27
26 28 #ifndef _RELOC_DOT_H
27 29 #define _RELOC_DOT_H
28 30
29 31 #if defined(_KERNEL)
30 32 #include <sys/bootconf.h>
31 33 #include <sys/kobj.h>
32 34 #include <sys/kobj_impl.h>
33 35 #else
34 36 #include <rtld.h>
35 37 #include <conv.h>
36 38 #endif /* _KERNEL */
37 39
38 40 #include "reloc_defs.h"
39 41
40 42 #ifdef __cplusplus
41 43 extern "C" {
42 44 #endif
43 45
44 46 /*
45 47 * Global include file for relocation common code.
46 48 */
47 49
48 50 /*
49 51 * In user land, redefine the relocation table and relocation engine to be
50 52 * class/machine specific if necessary. This allows multiple engines to
51 53 * reside within a single instance of libld.
52 54 */
53 55 #if !defined(_KERNEL)
54 56
55 57 #if defined(DO_RELOC_LIBLD)
56 58 #undef DO_RELOC_LIBLD
57 59 #endif
58 60
59 61 #if defined(DO_RELOC_LIBLD_X86)
60 62
61 63 #define DO_RELOC_LIBLD
62 64 #if defined(_ELF64)
63 65 #define do_reloc_ld do64_reloc_ld_x86
64 66 #define reloc_table reloc64_table_x86
65 67 #else
66 68 #define do_reloc_ld do32_reloc_ld_x86
67 69 #define reloc_table reloc32_table_x86
68 70 #endif
69 71
70 72 #elif defined(DO_RELOC_LIBLD_SPARC)
71 73
72 74 #define DO_RELOC_LIBLD
73 75 #if defined(_ELF64)
74 76 #define do_reloc_ld do64_reloc_ld_sparc
75 77 #define reloc_table reloc64_table_sparc
76 78 #else
77 79 #define do_reloc_ld do32_reloc_ld_sparc
78 80 #define reloc_table reloc32_table_sparc
79 81 #endif
80 82
81 83 #else /* rtld */
82 84
83 85 #if defined(_ELF64)
84 86 #define do_reloc_rtld do64_reloc_rtld
85 87 #define reloc_table reloc64_table
86 88 #else
87 89 #define do_reloc_rtld do32_reloc_rtld
88 90 #define reloc_table reloc32_table
89 91 #endif
90 92
91 93 #endif
92 94
93 95 #endif /* !_KERNEL */
94 96
95 97 /*
96 98 * Relocation table and macros for testing relocation table flags.
97 99 */
98 100 extern const Rel_entry reloc_table[];
99 101
100 102 #define IS_PLT(X) RELTAB_IS_PLT(X, reloc_table)
101 103 #define IS_GOT_RELATIVE(X) RELTAB_IS_GOT_RELATIVE(X, reloc_table)
102 104 #define IS_GOT_PC(X) RELTAB_IS_GOT_PC(X, reloc_table)
103 105 #define IS_GOTPCREL(X) RELTAB_IS_GOTPCREL(X, reloc_table)
104 106 #define IS_GOT_BASED(X) RELTAB_IS_GOT_BASED(X, reloc_table)
105 107 #define IS_GOT_OPINS(X) RELTAB_IS_GOT_OPINS(X, reloc_table)
106 108 #define IS_GOT_REQUIRED(X) RELTAB_IS_GOT_REQUIRED(X, reloc_table)
107 109 #define IS_PC_RELATIVE(X) RELTAB_IS_PC_RELATIVE(X, reloc_table)
108 110 #define IS_ADD_RELATIVE(X) RELTAB_IS_ADD_RELATIVE(X, reloc_table)
109 111 #define IS_REGISTER(X) RELTAB_IS_REGISTER(X, reloc_table)
110 112 #define IS_NOTSUP(X) RELTAB_IS_NOTSUP(X, reloc_table)
111 113 #define IS_SEG_RELATIVE(X) RELTAB_IS_SEG_RELATIVE(X, reloc_table)
112 114 #define IS_EXTOFFSET(X) RELTAB_IS_EXTOFFSET(X, reloc_table)
113 115 #define IS_SEC_RELATIVE(X) RELTAB_IS_SEC_RELATIVE(X, reloc_table)
114 116 #define IS_TLS_INS(X) RELTAB_IS_TLS_INS(X, reloc_table)
115 117 #define IS_TLS_GD(X) RELTAB_IS_TLS_GD(X, reloc_table)
116 118 #define IS_TLS_LD(X) RELTAB_IS_TLS_LD(X, reloc_table)
117 119 #define IS_TLS_IE(X) RELTAB_IS_TLS_IE(X, reloc_table)
118 120 #define IS_TLS_LE(X) RELTAB_IS_TLS_LE(X, reloc_table)
119 121 #define IS_LOCALBND(X) RELTAB_IS_LOCALBND(X, reloc_table)
120 122 #define IS_SIZE(X) RELTAB_IS_SIZE(X, reloc_table)
121 123
122 124 /*
123 125 * Relocation engine.
124 126 *
125 127 * The do_reloc() code is used in three different places: The kernel,
126 128 * the link-editor, and the runtime linker. All three convey the same
127 129 * basic information with the first 5 arguments:
128 130 *
129 131 * 1) Relocation type. The kernel and runtime linker pass this as
130 132 * an integer value, while the link-editor passes it as a Rel_desc
131 133 * descriptor. The relocation engine only looks at the rel_rtype
132 134 * field of this descriptor, and does not examine the other fields,
133 135 * which are explicitly allowed to contain garbage.
134 136 * 2) Address of offset
135 137 * 3) Address of value
136 138 * 4) Name of symbol associated with the relocation, used if it is
137 139 * necessary to report an error. The kernel and runtime linker pass
138 140 * directly as a string pointer. The link-editor passes the address
139 141 * of a rel_desc_sname_func_t function, which can be called by do_reloc(),
140 142 * passing it the Rel_desc pointer (argument 1, above), to obtain the
141 143 * string pointer.
142 144 * 5) String giving the source file for the relocation.
143 145 *
144 146 * In addition:
145 147 * - The linker and rtld want a link map pointer argument
146 148 * - The linker wants to pass a byte swap argument that tells
147 149 * the relocation engine that the data it is relocating
148 150 * has the opposite byte order of the system running the
149 151 * linker.
150 152 * - The linker is a cross-linker, meaning that it can examine
151 153 * relocation records for target hosts other than that of
152 154 * the currently running system. This means that multiple
153 155 * versions of the relocation code must be able to reside
154 156 * in a single program, without namespace clashes.
155 157 *
156 158 * To ensure that there is never any confusion about which version is
157 159 * being linked to, we give each variant a different name, even though
158 160 * each one is generated from the same source code.
159 161 *
160 162 * do_reloc_krtld()
161 163 * The kernel version is provided if the _KERNEL macro is defined.
162 164 *
163 165 * do_reloc_ld()
164 166 * The ld version is provided if the DO_RELOC_LIBLD_ macro is defined.
165 167 *
166 168 * do_reloc_rtld()
167 169 * The rtld version is provided if neither _KERNEL or DO_RELOC_LIBLD
168 170 * are defined.
169 171 *
170 172 * Implementations of do_reloc() should use these same macros to
171 173 * conditionalize any code not used by all three versions.
172 174 */
173 175 #if defined(_KERNEL)
174 176 extern int do_reloc_krtld(uchar_t, uchar_t *, Xword *, const char *,
175 177 const char *);
176 178 #elif defined(DO_RELOC_LIBLD)
177 179 extern int do_reloc_ld(Rel_desc *, uchar_t *, Xword *,
178 180 rel_desc_sname_func_t, const char *, int, void *);
179 181 #else
180 182 extern int do_reloc_rtld(uchar_t, uchar_t *, Xword *, const char *,
181 183 const char *, void *);
182 184 #endif
183 185
184 186 #if defined(_KERNEL)
185 187 /*
186 188 * These are macro's that are only needed for krtld. Many of these are already
187 189 * defined in the sgs/include files referenced by ld and rtld
188 190 */
189 191 #define S_MASK(n) ((1l << (n)) - 1l)
190 192 #define S_INRANGE(v, n) (((-(1l << (n)) - 1l) < (v)) && ((v) < (1l << (n))))
191 193
192 194 /*
193 195 * Message strings used by doreloc().
194 196 */
195 197 #define MSG_STR_UNKNOWN "(unknown)"
196 198
197 199 #define MSG_REL_PREGEN "relocation error: %s: "
198 200 #define MSG_REL_PREFIL "relocation error: file %s: "
199 201 #define MSG_REL_FILE "file %s: "
200 202 #define MSG_REL_SYM "symbol %s: "
201 203 #define MSG_REL_VALUE "value 0x%llx "
202 204 #define MSG_REL_LOSEBITS "loses %d bits at "
203 205
204 206 #define MSG_REL_UNIMPL "unimplemented relocation type: %d"
205 207 #define MSG_REL_UNSUPSZ "offset size (%d bytes) is not supported"
206 208 #define MSG_REL_NONALIGN "offset 0x%llx is non-aligned"
207 209 #define MSG_REL_UNNOBITS "unsupported number of bits: %d"
208 210 #define MSG_REL_OFFSET "offset 0x%llx"
209 211 #define MSG_REL_NOFIT "value 0x%llx does not fit"
210 212
211 213 /*
212 214 * Provide a macro to select the appropriate conversion routine for this
213 215 * architecture.
214 216 */
215 217 #if defined(__amd64)
216 218
217 219 extern const char *conv_reloc_amd64_type(Word);
218 220 #define CONV_RELOC_TYPE conv_reloc_amd64_type
219 221
220 222 #elif defined(__i386)
221 223
222 224 extern const char *conv_reloc_386_type(Word);
223 225 #define CONV_RELOC_TYPE conv_reloc_386_type
224 226
225 227 #elif defined(__sparc)
226 228
227 229 extern const char *conv_reloc_SPARC_type(Word);
228 230 #define CONV_RELOC_TYPE conv_reloc_SPARC_type
229 231
230 232 #else
231 233 #error platform not defined!
232 234 #endif
233 235
234 236
235 237 /*
236 238 * Note: dlerror() only keeps track of a single error string, and therefore
237 239 * must have errors reported through a single eprintf() call. The kernel's
238 240 * _kobj_printf is somewhat more limited, and must receive messages with only
239 241 * one argument to the format string. The following macros account for these
240 242 * differences, as krtld and rtld share the same do_reloc() source.
241 243 */
242 244 #define REL_ERR_UNIMPL(lml, file, sym, rtype) \
243 245 _kobj_printf(ops, MSG_REL_PREFIL, (file)); \
244 246 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
245 247 _kobj_printf(ops, MSG_REL_UNIMPL, (int)(rtype))
246 248
247 249 #define REL_ERR_UNSUPSZ(lml, file, sym, rtype, size) \
248 250 _kobj_printf(ops, MSG_REL_PREGEN, CONV_RELOC_TYPE((rtype))); \
249 251 _kobj_printf(ops, MSG_REL_FILE, (file)); \
250 252 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
251 253 _kobj_printf(ops, MSG_REL_UNSUPSZ, (int)(size))
252 254
253 255 #define REL_ERR_NONALIGN(lml, file, sym, rtype, off) \
254 256 _kobj_printf(ops, MSG_REL_PREGEN, CONV_RELOC_TYPE((rtype))); \
255 257 _kobj_printf(ops, MSG_REL_FILE, (file)); \
256 258 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
257 259 _kobj_printf(ops, MSG_REL_NONALIGN, EC_OFF((off)))
258 260
259 261 #define REL_ERR_UNNOBITS(lml, file, sym, rtype, nbits) \
260 262 _kobj_printf(ops, MSG_REL_PREGEN, CONV_RELOC_TYPE((rtype))); \
261 263 _kobj_printf(ops, MSG_REL_FILE, (file)); \
262 264 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
263 265 _kobj_printf(ops, MSG_REL_UNNOBITS, (nbits))
264 266
265 267 #define REL_ERR_LOSEBITS(lml, file, sym, rtype, uvalue, nbits, off) \
266 268 _kobj_printf(ops, MSG_REL_PREGEN, CONV_RELOC_TYPE((rtype))); \
↓ open down ↓ |
233 lines elided |
↑ open up ↑ |
267 269 _kobj_printf(ops, MSG_REL_FILE, (file)); \
268 270 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
269 271 _kobj_printf(ops, MSG_REL_VALUE, EC_XWORD((uvalue))); \
270 272 _kobj_printf(ops, MSG_REL_LOSEBITS, (int)(nbits)); \
271 273 _kobj_printf(ops, MSG_REL_OFFSET, EC_NATPTR((off)))
272 274
273 275 #define REL_ERR_NOFIT(lml, file, sym, rtype, uvalue) \
274 276 _kobj_printf(ops, MSG_REL_PREGEN, CONV_RELOC_TYPE((rtype))); \
275 277 _kobj_printf(ops, MSG_REL_FILE, (file)); \
276 278 _kobj_printf(ops, MSG_REL_SYM, ((sym) ? (sym) : MSG_STR_UNKNOWN)); \
277 - _kobj_printf(ops, MSG_REL_NOFIT, EC_XWORD((uvalue)))
279 + _kobj_printf(ops, MSG_REL_NOFIT, (u_longlong_t)EC_XWORD((uvalue)))
278 280
279 281
280 282 #else /* !_KERNEL */
281 283
282 284 extern const char *demangle(const char *);
283 285
284 286 #define REL_ERR_UNIMPL(lml, file, sym, rtype) \
285 287 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_UNIMPL), (file), \
286 288 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), (int)(rtype)))
287 289
288 290 #define REL_ERR_UNSUPSZ(lml, file, sym, rtype, size) \
289 291 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_UNSUPSZ), \
290 292 conv_reloc_type_static(M_MACH, (rtype), 0), (file), \
291 293 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), (int)(size)))
292 294
293 295 #define REL_ERR_NONALIGN(lml, file, sym, rtype, off) \
294 296 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_NONALIGN), \
295 297 conv_reloc_type_static(M_MACH, (rtype), 0), (file), \
296 298 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), EC_OFF((off))))
297 299
298 300 #define REL_ERR_UNNOBITS(lml, file, sym, rtype, nbits) \
299 301 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_UNNOBITS), \
300 302 conv_reloc_type_static(M_MACH, (rtype), 0), (file), \
301 303 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), (nbits)))
302 304
303 305 #define REL_ERR_LOSEBITS(lml, file, sym, rtype, uvalue, nbits, off) \
304 306 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_LOSEBITS), \
305 307 conv_reloc_type_static(M_MACH, (rtype), 0), (file), \
306 308 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), \
307 309 EC_XWORD((uvalue)), (nbits), EC_NATPTR((off))))
308 310
309 311 #define REL_ERR_NOFIT(lml, file, sym, rtype, uvalue) \
310 312 (eprintf(lml, ERR_FATAL, MSG_INTL(MSG_REL_NOFIT), \
311 313 conv_reloc_type_static(M_MACH, (rtype), 0), (file), \
312 314 ((sym) ? demangle(sym) : MSG_INTL(MSG_STR_UNKNOWN)), \
313 315 EC_XWORD((uvalue))))
314 316
315 317 #endif /* _KERNEL */
316 318
317 319 #ifdef __cplusplus
318 320 }
319 321 #endif
320 322
321 323 #endif /* _RELOC_DOT_H */
↓ open down ↓ |
34 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX