aboutsummaryrefslogtreecommitdiff
path: root/cddl/contrib/opensolaris/cmd/sgs/include/sgs.h
blob: 9c37af2a1d4a18790657c937ff61435f6d95ce77 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
/*
 * CDDL HEADER START
 *
 * The contents of this file are subject to the terms of the
 * Common Development and Distribution License (the "License").
 * You may not use this file except in compliance with the License.
 *
 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
 * or http://www.opensolaris.org/os/licensing.
 * See the License for the specific language governing permissions
 * and limitations under the License.
 *
 * When distributing Covered Code, include this CDDL HEADER in each
 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
 * If applicable, add the following below this CDDL HEADER, with the
 * fields enclosed by brackets "[]" replaced with your own identifying
 * information: Portions Copyright [yyyy] [name of copyright owner]
 *
 * CDDL HEADER END
 */

/*
 *	Copyright (c) 1988 AT&T
 *	  All Rights Reserved
 *
 *
 * Copyright 2006 Sun Microsystems, Inc.  All rights reserved.
 * Use is subject to license terms.
 *
 * Global include file for all sgs.
 */

#ifndef	_SGS_H
#define	_SGS_H

#pragma ident	"%Z%%M%	%I%	%E% SMI"

#ifdef	__cplusplus
extern "C" {
#endif

/* <assert.h> keys off of NDEBUG */
#ifdef	DEBUG
#undef	NDEBUG
#else
#define	NDEBUG
#endif

#ifndef	_ASM
#include <sys/types.h>
#if defined(sun)
#include <sys/machelf.h>
#else
#include <elf.h>
#endif
#include <stdlib.h>
#include <libelf.h>
#include <assert.h>
#include <alist.h>
#endif	/* _ASM */

/*
 * Software identification.
 */
#define	SGS		""
#define	SGU_PKG		"Software Generation Utilities"
#define	SGU_REL		"(SGU) Solaris-ELF (4.0)"


#ifndef _ASM

/*
 * link_ver_string[] contains a version string for use by the link-editor
 * and all other linker components. It is found in libconv, and is
 * generated by sgs/libconv/common/bld_vernote.ksh. That script produces
 * libconv/{plat}/vernote.s, which is in turn assembled/linked into
 * libconv.
 */
extern const char link_ver_string[];
/*
 * Macro to round to next double word boundary.
 */
#define	S_DROUND(x)	(((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))

/*
 * General align and round macros.
 */
#define	S_ALIGN(x, a)	((x) & ~(((a) ? (a) : 1) - 1))
#define	S_ROUND(x, a)   ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))

/*
 * Bit manipulation macros; generic bit mask and is `v' in the range
 * supportable in `n' bits?
 */
#define	S_MASK(n)	((1 << (n)) -1)
#define	S_INRANGE(v, n)	(((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))


/*
 * Yet another definition of the OFFSETOF macro, used with the AVL routines.
 */
#define	SGSOFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))

/*
 * When casting between integer and pointer types, gcc will complain
 * if the integer type used is not large enough to hold the pointer
 * value without loss. Although a dubious practice in general, this
 * is sometimes done by design. In those cases, the general solution
 * is to introduce an intermediate cast to widen the integer value. The
 * CAST_PTRINT macro does this, and its use documents the fact that
 * the programmer is doing that sort of cast.
 */
#ifdef __GNUC__
#define	CAST_PTRINT(cast, value) ((cast)(uintptr_t)value)
#else
#define	CAST_PTRINT(cast, value) ((cast)value)
#endif

/*
 * General typedefs.
 */
typedef enum {
	FALSE = 0,
	TRUE = 1
} Boolean;

/*
 * Types of errors (used by eprintf()), together with a generic error return
 * value.
 */
typedef enum {
	ERR_NONE,
	ERR_WARNING,
	ERR_FATAL,
	ERR_ELF,
	ERR_NUM				/* Must be last */
} Error;

#if defined(_LP64) && !defined(_ELF64)
#define	S_ERROR		(~(uint_t)0)
#else
#define	S_ERROR		(~(uintptr_t)0)
#endif

/*
 * LIST_TRAVERSE() is used as the only "argument" of a "for" loop to
 * traverse a linked list. The node pointer `node' is set to each node in
 * turn and the corresponding data pointer is copied to `data'.  The macro
 * is used as in
 * 	for (LIST_TRAVERSE(List *list, Listnode *node, void *data)) {
 *		process(data);
 *	}
 */
#define	LIST_TRAVERSE(L, N, D) \
	(void) (((N) = (L)->head) != NULL && ((D) = (N)->data) != NULL); \
	(N) != NULL; \
	(void) (((N) = (N)->next) != NULL && ((D) = (N)->data) != NULL)

typedef	struct listnode	Listnode;
typedef	struct list	List;

struct	listnode {			/* a node on a linked list */
	void		*data;		/* the data item */
	Listnode	*next;		/* the next element */
};

struct	list {				/* a linked list */
	Listnode	*head;		/* the first element */
	Listnode	*tail;		/* the last element */
};


#ifdef _SYSCALL32
typedef	struct listnode32	Listnode32;
typedef	struct list32		List32;

struct	listnode32 {			/* a node on a linked list */
	Elf32_Addr	data;		/* the data item */
	Elf32_Addr	next;		/* the next element */
};

struct	list32 {			/* a linked list */
	Elf32_Addr	head;		/* the first element */
	Elf32_Addr	tail;		/* the last element */
};
#endif	/* _SYSCALL32 */


/*
 * Structure to maintain rejected files elf information.  Files that are not
 * applicable to the present link-edit are rejected and a search for an
 * appropriate file may be resumed.  The first rejected files information is
 * retained so that a better error diagnostic can be given should an appropriate
 * file not be located.
 */
typedef struct {
	ushort_t	rej_type;	/* SGS_REJ_ value */
	ushort_t	rej_flag;	/* additional information */
	uint_t		rej_info;	/* numeric and string information */
	const char	*rej_str;	/*	associated with error */
	const char	*rej_name;	/* object name - expanded library */
					/*	name and archive members */
} Rej_desc;

#define	SGS_REJ_NONE		0
#define	SGS_REJ_MACH		1	/* wrong ELF machine type */
#define	SGS_REJ_CLASS		2	/* wrong ELF class (32-bit/64-bit) */
#define	SGS_REJ_DATA		3	/* wrong ELF data format (MSG/LSB) */
#define	SGS_REJ_TYPE		4	/* bad ELF type */
#define	SGS_REJ_BADFLAG		5	/* bad ELF flags value */
#define	SGS_REJ_MISFLAG		6	/* mismatched ELF flags value */
#define	SGS_REJ_VERSION		7	/* mismatched ELF/lib version */
#define	SGS_REJ_HAL		8	/* HAL R1 extensions required */
#define	SGS_REJ_US3		9	/* Sun UltraSPARC III extensions */
					/*	required */
#define	SGS_REJ_STR		10	/* generic error - info is a string */
#define	SGS_REJ_UNKFILE		11	/* unknown file type */
#define	SGS_REJ_HWCAP_1		12	/* hardware capabilities mismatch */

/*
 * For those source files used both inside and outside of the
 * libld source base (tools/common/string_table.c) we can
 * automatically switch between the allocation models
 * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
 */
#ifdef	USE_LIBLD_MALLOC
#define	calloc(x, a)		libld_malloc(((size_t)x) * ((size_t)a))
#define	free			libld_free
#define	malloc			libld_malloc
#define	realloc			libld_realloc

#define	libld_calloc(x, a)	libld_malloc(((size_t)x) * ((size_t)a))
extern void		libld_free(void *);
extern void		*libld_malloc(size_t);
extern void		*libld_realloc(void *, size_t);
#endif


/*
 * Data structures (defined in libld.h).
 */
typedef struct ent_desc		Ent_desc;
typedef	struct group_desc	Group_desc;
typedef struct ifl_desc		Ifl_desc;
typedef struct is_desc		Is_desc;
typedef struct isa_desc		Isa_desc;
typedef struct isa_opt		Isa_opt;
typedef struct mv_desc		Mv_desc;
typedef struct ofl_desc		Ofl_desc;
typedef struct os_desc		Os_desc;
typedef	struct rel_cache	Rel_cache;
typedef	struct sdf_desc		Sdf_desc;
typedef	struct sdv_desc		Sdv_desc;
typedef struct sg_desc		Sg_desc;
typedef struct sort_desc	Sort_desc;
typedef struct sec_order	Sec_order;
typedef struct sym_desc		Sym_desc;
typedef struct sym_aux		Sym_aux;
typedef	struct sym_avlnode	Sym_avlnode;
typedef	struct uts_desc		Uts_desc;
typedef struct ver_desc		Ver_desc;
typedef struct ver_index	Ver_index;
typedef	struct audit_desc	Audit_desc;
typedef	struct audit_info	Audit_info;
typedef	struct audit_list	Audit_list;

/*
 * Data structures defined in machrel.h.
 */
typedef struct rel_desc		Rel_desc;

/*
 * Data structures defined in rtld.h.
 */
typedef struct lm_list		Lm_list;
#ifdef _SYSCALL32
typedef struct lm_list32	Lm_list32;
#endif	/* _SYSCALL32 */

/*
 * For the various utilities that include sgs.h
 */
extern int	assfail(const char *, const char *, int);
extern void	eprintf(Lm_list *, Error, const char *, ...);
extern char	*sgs_demangle(char *);
extern uint_t	sgs_str_hash(const char *);
extern uint_t	findprime(uint_t);

#endif /* _ASM */

#ifdef	__cplusplus
}
#endif


#endif /* _SGS_H */