4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
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.
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]
23 * Copyright (c) 1988 AT&T
27 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
28 * Use is subject to license terms.
30 * Global include file for all sgs.
36 #pragma ident "%Z%%M% %I% %E% SMI"
42 /* <assert.h> keys off of NDEBUG */
50 #include <sys/types.h>
52 #include <sys/machelf.h>
63 * Software identification.
66 #define SGU_PKG "Software Generation Utilities"
67 #define SGU_REL "(SGU) Solaris-ELF (4.0)"
73 * link_ver_string[] contains a version string for use by the link-editor
74 * and all other linker components. It is found in libconv, and is
75 * generated by sgs/libconv/common/bld_vernote.ksh. That script produces
76 * libconv/{plat}/vernote.s, which is in turn assembled/linked into
79 extern const char link_ver_string[];
81 * Macro to round to next double word boundary.
83 #define S_DROUND(x) (((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))
86 * General align and round macros.
88 #define S_ALIGN(x, a) ((x) & ~(((a) ? (a) : 1) - 1))
89 #define S_ROUND(x, a) ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))
92 * Bit manipulation macros; generic bit mask and is `v' in the range
93 * supportable in `n' bits?
95 #define S_MASK(n) ((1 << (n)) -1)
96 #define S_INRANGE(v, n) (((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))
100 * Yet another definition of the OFFSETOF macro, used with the AVL routines.
102 #define SGSOFFSETOF(s, m) ((size_t)(&(((s *)0)->m)))
105 * When casting between integer and pointer types, gcc will complain
106 * if the integer type used is not large enough to hold the pointer
107 * value without loss. Although a dubious practice in general, this
108 * is sometimes done by design. In those cases, the general solution
109 * is to introduce an intermediate cast to widen the integer value. The
110 * CAST_PTRINT macro does this, and its use documents the fact that
111 * the programmer is doing that sort of cast.
114 #define CAST_PTRINT(cast, value) ((cast)(uintptr_t)value)
116 #define CAST_PTRINT(cast, value) ((cast)value)
128 * Types of errors (used by eprintf()), together with a generic error return
136 ERR_NUM /* Must be last */
139 #if defined(_LP64) && !defined(_ELF64)
140 #define S_ERROR (~(uint_t)0)
142 #define S_ERROR (~(uintptr_t)0)
146 * LIST_TRAVERSE() is used as the only "argument" of a "for" loop to
147 * traverse a linked list. The node pointer `node' is set to each node in
148 * turn and the corresponding data pointer is copied to `data'. The macro
150 * for (LIST_TRAVERSE(List *list, Listnode *node, void *data)) {
154 #define LIST_TRAVERSE(L, N, D) \
155 (void) (((N) = (L)->head) != NULL && ((D) = (N)->data) != NULL); \
157 (void) (((N) = (N)->next) != NULL && ((D) = (N)->data) != NULL)
159 typedef struct listnode Listnode;
160 typedef struct list List;
162 struct listnode { /* a node on a linked list */
163 void *data; /* the data item */
164 Listnode *next; /* the next element */
167 struct list { /* a linked list */
168 Listnode *head; /* the first element */
169 Listnode *tail; /* the last element */
174 typedef struct listnode32 Listnode32;
175 typedef struct list32 List32;
177 struct listnode32 { /* a node on a linked list */
178 Elf32_Addr data; /* the data item */
179 Elf32_Addr next; /* the next element */
182 struct list32 { /* a linked list */
183 Elf32_Addr head; /* the first element */
184 Elf32_Addr tail; /* the last element */
186 #endif /* _SYSCALL32 */
190 * Structure to maintain rejected files elf information. Files that are not
191 * applicable to the present link-edit are rejected and a search for an
192 * appropriate file may be resumed. The first rejected files information is
193 * retained so that a better error diagnostic can be given should an appropriate
194 * file not be located.
197 ushort_t rej_type; /* SGS_REJ_ value */
198 ushort_t rej_flag; /* additional information */
199 uint_t rej_info; /* numeric and string information */
200 const char *rej_str; /* associated with error */
201 const char *rej_name; /* object name - expanded library */
202 /* name and archive members */
205 #define SGS_REJ_NONE 0
206 #define SGS_REJ_MACH 1 /* wrong ELF machine type */
207 #define SGS_REJ_CLASS 2 /* wrong ELF class (32-bit/64-bit) */
208 #define SGS_REJ_DATA 3 /* wrong ELF data format (MSG/LSB) */
209 #define SGS_REJ_TYPE 4 /* bad ELF type */
210 #define SGS_REJ_BADFLAG 5 /* bad ELF flags value */
211 #define SGS_REJ_MISFLAG 6 /* mismatched ELF flags value */
212 #define SGS_REJ_VERSION 7 /* mismatched ELF/lib version */
213 #define SGS_REJ_HAL 8 /* HAL R1 extensions required */
214 #define SGS_REJ_US3 9 /* Sun UltraSPARC III extensions */
216 #define SGS_REJ_STR 10 /* generic error - info is a string */
217 #define SGS_REJ_UNKFILE 11 /* unknown file type */
218 #define SGS_REJ_HWCAP_1 12 /* hardware capabilities mismatch */
221 * For those source files used both inside and outside of the
222 * libld source base (tools/common/string_table.c) we can
223 * automatically switch between the allocation models
224 * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
226 #ifdef USE_LIBLD_MALLOC
227 #define calloc(x, a) libld_malloc(((size_t)x) * ((size_t)a))
228 #define free libld_free
229 #define malloc libld_malloc
230 #define realloc libld_realloc
232 #define libld_calloc(x, a) libld_malloc(((size_t)x) * ((size_t)a))
233 extern void libld_free(void *);
234 extern void *libld_malloc(size_t);
235 extern void *libld_realloc(void *, size_t);
240 * Data structures (defined in libld.h).
242 typedef struct ent_desc Ent_desc;
243 typedef struct group_desc Group_desc;
244 typedef struct ifl_desc Ifl_desc;
245 typedef struct is_desc Is_desc;
246 typedef struct isa_desc Isa_desc;
247 typedef struct isa_opt Isa_opt;
248 typedef struct mv_desc Mv_desc;
249 typedef struct ofl_desc Ofl_desc;
250 typedef struct os_desc Os_desc;
251 typedef struct rel_cache Rel_cache;
252 typedef struct sdf_desc Sdf_desc;
253 typedef struct sdv_desc Sdv_desc;
254 typedef struct sg_desc Sg_desc;
255 typedef struct sort_desc Sort_desc;
256 typedef struct sec_order Sec_order;
257 typedef struct sym_desc Sym_desc;
258 typedef struct sym_aux Sym_aux;
259 typedef struct sym_avlnode Sym_avlnode;
260 typedef struct uts_desc Uts_desc;
261 typedef struct ver_desc Ver_desc;
262 typedef struct ver_index Ver_index;
263 typedef struct audit_desc Audit_desc;
264 typedef struct audit_info Audit_info;
265 typedef struct audit_list Audit_list;
268 * Data structures defined in machrel.h.
270 typedef struct rel_desc Rel_desc;
273 * Data structures defined in rtld.h.
275 typedef struct lm_list Lm_list;
277 typedef struct lm_list32 Lm_list32;
278 #endif /* _SYSCALL32 */
281 * For the various utilities that include sgs.h
283 extern int assfail(const char *, const char *, int);
284 extern void eprintf(Lm_list *, Error, const char *, ...);
285 extern char *sgs_demangle(char *);
286 extern uint_t sgs_str_hash(const char *);
287 extern uint_t findprime(uint_t);