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