xref: /titanic_41/usr/src/cmd/sgs/include/sgs.h (revision 8475e04352e630e4bd0f59a283286ee2475a14ce)
1 /*
2  * CDDL HEADER START
3  *
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.
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) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  *
27  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
28  * Use is subject to license terms.
29  *
30  * Global include file for all sgs.
31  */
32 
33 #ifndef	_SGS_H
34 #define	_SGS_H
35 
36 #ifdef	__cplusplus
37 extern "C" {
38 #endif
39 
40 /* <assert.h> keys off of NDEBUG */
41 #ifdef	DEBUG
42 #undef	NDEBUG
43 #else
44 #define	NDEBUG
45 #endif
46 
47 #ifndef	_ASM
48 #include <sys/types.h>
49 #include <sys/machelf.h>
50 #include <stdlib.h>
51 #include <libelf.h>
52 #include <assert.h>
53 #include <alist.h>
54 #endif	/* _ASM */
55 
56 /*
57  * Software identification.
58  */
59 #define	SGS		""
60 #define	SGU_PKG		"Software Generation Utilities"
61 #define	SGU_REL		"(SGU) Solaris-ELF (4.0)"
62 
63 
64 #ifndef _ASM
65 
66 /*
67  * link_ver_string[] contains a version string for use by the link-editor
68  * and all other linker components. It is found in libconv, and is
69  * generated by sgs/libconv/common/bld_vernote.ksh. That script produces
70  * libconv/{plat}/vernote.s, which is in turn assembled/linked into
71  * libconv.
72  */
73 extern const char link_ver_string[];
74 /*
75  * Macro to round to next double word boundary.
76  */
77 #define	S_DROUND(x)	(((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))
78 
79 /*
80  * General align and round macros.
81  */
82 #define	S_ALIGN(x, a)	((x) & ~(((a) ? (a) : 1) - 1))
83 #define	S_ROUND(x, a)   ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))
84 
85 /*
86  * Bit manipulation macros; generic bit mask and is `v' in the range
87  * supportable in `n' bits?
88  */
89 #define	S_MASK(n)	((1 << (n)) -1)
90 #define	S_INRANGE(v, n)	(((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))
91 
92 
93 /*
94  * Yet another definition of the OFFSETOF macro, used with the AVL routines.
95  */
96 #define	SGSOFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
97 
98 /*
99  * When casting between integer and pointer types, gcc will complain
100  * if the integer type used is not large enough to hold the pointer
101  * value without loss. Although a dubious practice in general, this
102  * is sometimes done by design. In those cases, the general solution
103  * is to introduce an intermediate cast to widen the integer value. The
104  * CAST_PTRINT macro does this, and its use documents the fact that
105  * the programmer is doing that sort of cast.
106  */
107 #ifdef __GNUC__
108 #define	CAST_PTRINT(cast, value) ((cast)(uintptr_t)value)
109 #else
110 #define	CAST_PTRINT(cast, value) ((cast)value)
111 #endif
112 
113 /*
114  * General typedefs.
115  */
116 typedef enum {
117 	FALSE = 0,
118 	TRUE = 1
119 } Boolean;
120 
121 /*
122  * Types of errors (used by eprintf()), together with a generic error return
123  * value.
124  */
125 typedef enum {
126 	ERR_NONE,
127 	ERR_WARNING,
128 	ERR_FATAL,
129 	ERR_ELF,
130 	ERR_NUM				/* Must be last */
131 } Error;
132 
133 #if defined(_LP64) && !defined(_ELF64)
134 #define	S_ERROR		(~(uint_t)0)
135 #else
136 #define	S_ERROR		(~(uintptr_t)0)
137 #endif
138 
139 /*
140  * LIST_TRAVERSE() is used as the only "argument" of a "for" loop to
141  * traverse a linked list. The node pointer `node' is set to each node in
142  * turn and the corresponding data pointer is copied to `data'.  The macro
143  * is used as in
144  * 	for (LIST_TRAVERSE(List *list, Listnode *node, void *data)) {
145  *		process(data);
146  *	}
147  */
148 #define	LIST_TRAVERSE(L, N, D) \
149 	(void) (((N) = (L)->head) != NULL && ((D) = (N)->data) != NULL); \
150 	(N) != NULL; \
151 	(void) (((N) = (N)->next) != NULL && ((D) = (N)->data) != NULL)
152 
153 typedef	struct listnode	Listnode;
154 typedef	struct list	List;
155 
156 struct	listnode {			/* a node on a linked list */
157 	void		*data;		/* the data item */
158 	Listnode	*next;		/* the next element */
159 };
160 
161 struct	list {				/* a linked list */
162 	Listnode	*head;		/* the first element */
163 	Listnode	*tail;		/* the last element */
164 };
165 
166 
167 #ifdef _SYSCALL32
168 typedef	struct listnode32	Listnode32;
169 typedef	struct list32		List32;
170 
171 struct	listnode32 {			/* a node on a linked list */
172 	Elf32_Addr	data;		/* the data item */
173 	Elf32_Addr	next;		/* the next element */
174 };
175 
176 struct	list32 {			/* a linked list */
177 	Elf32_Addr	head;		/* the first element */
178 	Elf32_Addr	tail;		/* the last element */
179 };
180 #endif	/* _SYSCALL32 */
181 
182 
183 /*
184  * Structure to maintain rejected files elf information.  Files that are not
185  * applicable to the present link-edit are rejected and a search for an
186  * appropriate file may be resumed.  The first rejected files information is
187  * retained so that a better error diagnostic can be given should an appropriate
188  * file not be located.
189  */
190 typedef struct {
191 	ushort_t	rej_type;	/* SGS_REJ_ value */
192 	ushort_t	rej_flags;	/* additional information */
193 	uint_t		rej_info;	/* numeric and string information */
194 	const char	*rej_str;	/*	associated with error */
195 	const char	*rej_name;	/* object name - expanded library */
196 					/*	name and archive members */
197 } Rej_desc;
198 
199 #define	SGS_REJ_NONE		0
200 #define	SGS_REJ_MACH		1	/* wrong ELF machine type */
201 #define	SGS_REJ_CLASS		2	/* wrong ELF class (32-bit/64-bit) */
202 #define	SGS_REJ_DATA		3	/* wrong ELF data format (MSG/LSB) */
203 #define	SGS_REJ_TYPE		4	/* bad ELF type */
204 #define	SGS_REJ_BADFLAG		5	/* bad ELF flags value */
205 #define	SGS_REJ_MISFLAG		6	/* mismatched ELF flags value */
206 #define	SGS_REJ_VERSION		7	/* mismatched ELF/lib version */
207 #define	SGS_REJ_HAL		8	/* HAL R1 extensions required */
208 #define	SGS_REJ_US3		9	/* Sun UltraSPARC III extensions */
209 					/*	required */
210 #define	SGS_REJ_STR		10	/* generic error - info is a string */
211 #define	SGS_REJ_UNKFILE		11	/* unknown file type */
212 #define	SGS_REJ_HWCAP_1		12	/* hardware capabilities mismatch */
213 #define	SGS_REJ_SFCAP_1		13	/* software capabilities mismatch */
214 
215 #define	FLG_REJ_ALTER		0x01	/* object name is an alternative */
216 
217 /*
218  * For those source files used both inside and outside of the
219  * libld source base (tools/common/string_table.c) we can
220  * automatically switch between the allocation models
221  * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
222  */
223 #ifdef	USE_LIBLD_MALLOC
224 #define	calloc(x, a)		libld_malloc(((size_t)x) * ((size_t)a))
225 #define	free			libld_free
226 #define	malloc			libld_malloc
227 #define	realloc			libld_realloc
228 
229 #define	libld_calloc(x, a)	libld_malloc(((size_t)x) * ((size_t)a))
230 extern void			libld_free(void *);
231 extern void			*libld_malloc(size_t);
232 extern void			*libld_realloc(void *, size_t);
233 #endif
234 
235 /*
236  * Data structures (defined in libld.h).
237  */
238 typedef struct ent_desc		Ent_desc;
239 typedef	struct group_desc	Group_desc;
240 typedef struct ifl_desc		Ifl_desc;
241 typedef struct is_desc		Is_desc;
242 typedef struct isa_desc		Isa_desc;
243 typedef struct isa_opt		Isa_opt;
244 typedef struct mv_desc		Mv_desc;
245 typedef struct ofl_desc		Ofl_desc;
246 typedef struct os_desc		Os_desc;
247 typedef	struct rel_cache	Rel_cache;
248 typedef	struct sdf_desc		Sdf_desc;
249 typedef	struct sdv_desc		Sdv_desc;
250 typedef struct sg_desc		Sg_desc;
251 typedef struct sort_desc	Sort_desc;
252 typedef struct sec_order	Sec_order;
253 typedef struct sym_desc		Sym_desc;
254 typedef struct sym_aux		Sym_aux;
255 typedef	struct sym_avlnode	Sym_avlnode;
256 typedef	struct uts_desc		Uts_desc;
257 typedef struct ver_desc		Ver_desc;
258 typedef struct ver_index	Ver_index;
259 typedef	struct audit_desc	Audit_desc;
260 typedef	struct audit_info	Audit_info;
261 typedef	struct audit_list	Audit_list;
262 
263 /*
264  * Data structures defined in machrel.h.
265  */
266 typedef struct rel_desc		Rel_desc;
267 
268 /*
269  * Data structures defined in rtld.h.
270  */
271 typedef struct lm_list		Lm_list;
272 #ifdef _SYSCALL32
273 typedef struct lm_list32	Lm_list32;
274 #endif	/* _SYSCALL32 */
275 
276 /*
277  * For the various utilities that include sgs.h
278  */
279 extern int	assfail(const char *, const char *, int);
280 extern void	eprintf(Lm_list *, Error, const char *, ...);
281 extern uint_t	sgs_str_hash(const char *);
282 extern uint_t	findprime(uint_t);
283 
284 #endif /* _ASM */
285 
286 #ifdef	__cplusplus
287 }
288 #endif
289 
290 
291 #endif /* _SGS_H */
292