xref: /titanic_44/usr/src/cmd/sgs/include/sgs.h (revision b7f45089ccbe01bab3d7c7377b49d80d2ae18a69)
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, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1988 AT&T
24  *	  All Rights Reserved
25  *
26  *
27  * Copyright 2004 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 #pragma ident	"%Z%%M%	%I%	%E% SMI"
37 
38 
39 #ifdef	__cplusplus
40 extern "C" {
41 #endif
42 
43 /* <assert.h> keys off of NDEBUG */
44 #ifdef	DEBUG
45 #undef	NDEBUG
46 #else
47 #define	NDEBUG
48 #endif
49 
50 #ifndef	_ASM
51 #include <sys/types.h>
52 #include <sys/machelf.h>
53 #include <stdlib.h>
54 #include <libelf.h>
55 #include <assert.h>
56 #include <alist.h>
57 #endif	/* _ASM */
58 
59 /*
60  * Software identification.
61  */
62 #define	SGS		""
63 #define	SGU_PKG		"Software Generation Utilities"
64 #define	SGU_REL		"(SGU) Solaris-ELF (4.0)"
65 
66 
67 #ifndef _ASM
68 
69 extern const char link_ver_string[];	/* Linker version id  */
70 					/*   see libconv/{plat}/vernote.s */
71 /*
72  * Macro to round to next double word boundary.
73  */
74 #define	S_DROUND(x)	(((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))
75 
76 /*
77  * General align and round macros.
78  */
79 #define	S_ALIGN(x, a)	((x) & ~(((a) ? (a) : 1) - 1))
80 #define	S_ROUND(x, a)   ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))
81 
82 /*
83  * Bit manipulation macros; generic bit mask and is `v' in the range
84  * supportable in `n' bits?
85  */
86 #define	S_MASK(n)	((1 << (n)) -1)
87 #define	S_INRANGE(v, n)	(((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))
88 
89 
90 /*
91  * Yet another definition of the OFFSETOF macro, used with the AVL routines.
92  */
93 #define	SGSOFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
94 
95 /*
96  * General typedefs.
97  */
98 typedef enum {
99 	FALSE = 0,
100 	TRUE = 1
101 } Boolean;
102 
103 /*
104  * Types of errors (used by eprintf()), together with a generic error return
105  * value.
106  */
107 typedef enum {
108 	ERR_NONE,
109 	ERR_WARNING,
110 	ERR_FATAL,
111 	ERR_ELF,
112 	ERR_NUM				/* Must be last */
113 } Error;
114 
115 #if defined(_LP64) && !defined(_ELF64)
116 #define	S_ERROR		(~(uint_t)0)
117 #else
118 #define	S_ERROR		(~(uintptr_t)0)
119 #endif
120 
121 /*
122  * LIST_TRAVERSE() is used as the only "argument" of a "for" loop to
123  * traverse a linked list. The node pointer `node' is set to each node in
124  * turn and the corresponding data pointer is copied to `data'.  The macro
125  * is used as in
126  * 	for (LIST_TRAVERSE(List *list, Listnode *node, void *data)) {
127  *		process(data);
128  *	}
129  */
130 #define	LIST_TRAVERSE(L, N, D) \
131 	(void) (((N) = (L)->head) != NULL && ((D) = (N)->data) != NULL); \
132 	(N) != NULL; \
133 	(void) (((N) = (N)->next) != NULL && ((D) = (N)->data) != NULL)
134 
135 typedef	struct listnode	Listnode;
136 typedef	struct list	List;
137 
138 struct	listnode {			/* a node on a linked list */
139 	void		*data;		/* the data item */
140 	Listnode	*next;		/* the next element */
141 };
142 
143 struct	list {				/* a linked list */
144 	Listnode	*head;		/* the first element */
145 	Listnode	*tail;		/* the last element */
146 };
147 
148 
149 #ifdef _SYSCALL32
150 typedef	struct listnode32	Listnode32;
151 typedef	struct list32		List32;
152 
153 struct	listnode32 {			/* a node on a linked list */
154 	Elf32_Addr	data;		/* the data item */
155 	Elf32_Addr	next;		/* the next element */
156 };
157 
158 struct	list32 {			/* a linked list */
159 	Elf32_Addr	head;		/* the first element */
160 	Elf32_Addr	tail;		/* the last element */
161 };
162 #endif	/* _SYSCALL32 */
163 
164 
165 /*
166  * Structure to maintain rejected files elf information.  Files that are not
167  * applicable to the present link-edit are rejected and a search for an
168  * appropriate file may be resumed.  The first rejected files information is
169  * retained so that a better error diagnostic can be given should an appropriate
170  * file not be located.
171  */
172 typedef struct {
173 	ushort_t	rej_type;	/* SGS_REJ_ value */
174 	ushort_t	rej_flag;	/* additional information */
175 	uint_t		rej_info;	/* numeric and string information */
176 	const char	*rej_str;	/*	associated with error */
177 	const char	*rej_name;	/* object name - expanded library */
178 					/*	name and archive members */
179 } Rej_desc;
180 
181 #define	SGS_REJ_NONE		0
182 #define	SGS_REJ_MACH		1	/* wrong ELF machine type */
183 #define	SGS_REJ_CLASS		2	/* wrong ELF class (32-bit/64-bit) */
184 #define	SGS_REJ_DATA		3	/* wrong ELF data format (MSG/LSB) */
185 #define	SGS_REJ_TYPE		4	/* bad ELF type */
186 #define	SGS_REJ_BADFLAG		5	/* bad ELF flags value */
187 #define	SGS_REJ_MISFLAG		6	/* mismatched ELF flags value */
188 #define	SGS_REJ_VERSION		7	/* mismatched ELF/lib version */
189 #define	SGS_REJ_HAL		8	/* HAL R1 extensions required */
190 #define	SGS_REJ_US3		9	/* Sun UltraSPARC III extensions */
191 					/*	required */
192 #define	SGS_REJ_STR		10	/* generic error - info is a string */
193 #define	SGS_REJ_UNKFILE		11	/* unknown file type */
194 #define	SGS_REJ_HWCAP_1		12	/* hardware capabilities mismatch */
195 
196 /*
197  * For those source files used both inside and outside of the
198  * libld source base (tools/common/string_table.c) we can
199  * automatically switch between the allocation models
200  * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
201  */
202 #ifdef	USE_LIBLD_MALLOC
203 #define	calloc(x, a)		libld_malloc(((size_t)x) * ((size_t)a))
204 #define	free			libld_free
205 #define	malloc			libld_malloc
206 #define	realloc			libld_realloc
207 
208 #define	libld_calloc(x, a)	libld_malloc(((size_t)x) * ((size_t)a))
209 extern void		libld_free(void *);
210 extern void		*libld_malloc(size_t);
211 extern void		*libld_realloc(void *, size_t);
212 #endif
213 
214 
215 /*
216  * Data structures (defined in libld.h).
217  */
218 typedef struct ent_desc		Ent_desc;
219 typedef	struct group_desc	Group_desc;
220 typedef struct ifl_desc		Ifl_desc;
221 typedef struct is_desc		Is_desc;
222 typedef struct isa_desc		Isa_desc;
223 typedef struct isa_opt		Isa_opt;
224 typedef struct mv_desc		Mv_desc;
225 typedef struct ofl_desc		Ofl_desc;
226 typedef struct os_desc		Os_desc;
227 typedef	struct rel_cache	Rel_cache;
228 typedef	struct sdf_desc		Sdf_desc;
229 typedef	struct sdv_desc		Sdv_desc;
230 typedef struct sg_desc		Sg_desc;
231 typedef struct sort_desc	Sort_desc;
232 typedef struct sec_order	Sec_order;
233 typedef struct sym_desc		Sym_desc;
234 typedef struct sym_aux		Sym_aux;
235 typedef	struct sym_avlnode	Sym_avlnode;
236 typedef	struct uts_desc		Uts_desc;
237 typedef struct ver_desc		Ver_desc;
238 typedef struct ver_index	Ver_index;
239 typedef	struct audit_desc	Audit_desc;
240 typedef	struct audit_info	Audit_info;
241 typedef	struct audit_list	Audit_list;
242 
243 /*
244  * Data structures defined in machrel.h.
245  */
246 typedef struct rel_desc		Rel_desc;
247 
248 /*
249  * For the various utilities that include sgs.h
250  */
251 extern char	*sgs_demangle(char *);
252 extern uint_t	sgs_str_hash(const char *);
253 extern uint_t	findprime(uint_t);
254 extern int	assfail(const char *, const char *, int);
255 
256 #endif /* _ASM */
257 
258 #ifdef	__cplusplus
259 }
260 #endif
261 
262 
263 #endif /* _SGS_H */
264