xref: /illumos-gate/usr/src/cmd/sgs/include/sgs.h (revision 3edf445c)
17c478bd9Sstevel@tonic-gate /*
27c478bd9Sstevel@tonic-gate  * CDDL HEADER START
37c478bd9Sstevel@tonic-gate  *
47c478bd9Sstevel@tonic-gate  * The contents of this file are subject to the terms of the
55aefb655Srie  * Common Development and Distribution License (the "License").
65aefb655Srie  * You may not use this file except in compliance with the License.
77c478bd9Sstevel@tonic-gate  *
87c478bd9Sstevel@tonic-gate  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bd9Sstevel@tonic-gate  * or http://www.opensolaris.org/os/licensing.
107c478bd9Sstevel@tonic-gate  * See the License for the specific language governing permissions
117c478bd9Sstevel@tonic-gate  * and limitations under the License.
127c478bd9Sstevel@tonic-gate  *
137c478bd9Sstevel@tonic-gate  * When distributing Covered Code, include this CDDL HEADER in each
147c478bd9Sstevel@tonic-gate  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bd9Sstevel@tonic-gate  * If applicable, add the following below this CDDL HEADER, with the
167c478bd9Sstevel@tonic-gate  * fields enclosed by brackets "[]" replaced with your own identifying
177c478bd9Sstevel@tonic-gate  * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bd9Sstevel@tonic-gate  *
197c478bd9Sstevel@tonic-gate  * CDDL HEADER END
207c478bd9Sstevel@tonic-gate  */
215aefb655Srie 
227c478bd9Sstevel@tonic-gate /*
237c478bd9Sstevel@tonic-gate  *	Copyright (c) 1988 AT&T
247c478bd9Sstevel@tonic-gate  *	  All Rights Reserved
257c478bd9Sstevel@tonic-gate  *
267c478bd9Sstevel@tonic-gate  *
27*3edf445cSab  * Copyright 2008 Sun Microsystems, Inc.  All rights reserved.
287c478bd9Sstevel@tonic-gate  * Use is subject to license terms.
297c478bd9Sstevel@tonic-gate  *
307c478bd9Sstevel@tonic-gate  * Global include file for all sgs.
317c478bd9Sstevel@tonic-gate  */
327c478bd9Sstevel@tonic-gate 
337c478bd9Sstevel@tonic-gate #ifndef	_SGS_H
347c478bd9Sstevel@tonic-gate #define	_SGS_H
357c478bd9Sstevel@tonic-gate 
367c478bd9Sstevel@tonic-gate #pragma ident	"%Z%%M%	%I%	%E% SMI"
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate 
397c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
407c478bd9Sstevel@tonic-gate extern "C" {
417c478bd9Sstevel@tonic-gate #endif
427c478bd9Sstevel@tonic-gate 
437c478bd9Sstevel@tonic-gate /* <assert.h> keys off of NDEBUG */
447c478bd9Sstevel@tonic-gate #ifdef	DEBUG
457c478bd9Sstevel@tonic-gate #undef	NDEBUG
467c478bd9Sstevel@tonic-gate #else
477c478bd9Sstevel@tonic-gate #define	NDEBUG
487c478bd9Sstevel@tonic-gate #endif
497c478bd9Sstevel@tonic-gate 
507c478bd9Sstevel@tonic-gate #ifndef	_ASM
517c478bd9Sstevel@tonic-gate #include <sys/types.h>
527c478bd9Sstevel@tonic-gate #include <sys/machelf.h>
537c478bd9Sstevel@tonic-gate #include <stdlib.h>
547c478bd9Sstevel@tonic-gate #include <libelf.h>
557c478bd9Sstevel@tonic-gate #include <assert.h>
567c478bd9Sstevel@tonic-gate #include <alist.h>
577c478bd9Sstevel@tonic-gate #endif	/* _ASM */
587c478bd9Sstevel@tonic-gate 
597c478bd9Sstevel@tonic-gate /*
607c478bd9Sstevel@tonic-gate  * Software identification.
617c478bd9Sstevel@tonic-gate  */
627c478bd9Sstevel@tonic-gate #define	SGS		""
637c478bd9Sstevel@tonic-gate #define	SGU_PKG		"Software Generation Utilities"
647c478bd9Sstevel@tonic-gate #define	SGU_REL		"(SGU) Solaris-ELF (4.0)"
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate 
677c478bd9Sstevel@tonic-gate #ifndef _ASM
687c478bd9Sstevel@tonic-gate 
69*3edf445cSab /*
70*3edf445cSab  * link_ver_string[] contains a version string for use by the link-editor
71*3edf445cSab  * and all other linker components. It is found in libconv, and is
72*3edf445cSab  * generated by sgs/libconv/common/bld_vernote.ksh. That script produces
73*3edf445cSab  * libconv/{plat}/vernote.s, which is in turn assembled/linked into
74*3edf445cSab  * libconv.
75*3edf445cSab  */
76*3edf445cSab extern const char link_ver_string[];
777c478bd9Sstevel@tonic-gate /*
787c478bd9Sstevel@tonic-gate  * Macro to round to next double word boundary.
797c478bd9Sstevel@tonic-gate  */
807c478bd9Sstevel@tonic-gate #define	S_DROUND(x)	(((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate /*
837c478bd9Sstevel@tonic-gate  * General align and round macros.
847c478bd9Sstevel@tonic-gate  */
857c478bd9Sstevel@tonic-gate #define	S_ALIGN(x, a)	((x) & ~(((a) ? (a) : 1) - 1))
867c478bd9Sstevel@tonic-gate #define	S_ROUND(x, a)   ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))
877c478bd9Sstevel@tonic-gate 
887c478bd9Sstevel@tonic-gate /*
897c478bd9Sstevel@tonic-gate  * Bit manipulation macros; generic bit mask and is `v' in the range
907c478bd9Sstevel@tonic-gate  * supportable in `n' bits?
917c478bd9Sstevel@tonic-gate  */
927c478bd9Sstevel@tonic-gate #define	S_MASK(n)	((1 << (n)) -1)
937c478bd9Sstevel@tonic-gate #define	S_INRANGE(v, n)	(((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))
947c478bd9Sstevel@tonic-gate 
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate /*
977c478bd9Sstevel@tonic-gate  * Yet another definition of the OFFSETOF macro, used with the AVL routines.
987c478bd9Sstevel@tonic-gate  */
997c478bd9Sstevel@tonic-gate #define	SGSOFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
1007c478bd9Sstevel@tonic-gate 
101c13de8f6Sab /*
102c13de8f6Sab  * When casting between integer and pointer types, gcc will complain
103c13de8f6Sab  * if the integer type used is not large enough to hold the pointer
104c13de8f6Sab  * value without loss. Although a dubious practice in general, this
105c13de8f6Sab  * is sometimes done by design. In those cases, the general solution
106c13de8f6Sab  * is to introduce an intermediate cast to widen the integer value. The
107c13de8f6Sab  * CAST_PTRINT macro does this, and its use documents the fact that
108c13de8f6Sab  * the programmer is doing that sort of cast.
109c13de8f6Sab  */
110c13de8f6Sab #ifdef __GNUC__
111c13de8f6Sab #define	CAST_PTRINT(cast, value) ((cast)(uintptr_t)value)
112c13de8f6Sab #else
113c13de8f6Sab #define	CAST_PTRINT(cast, value) ((cast)value)
114c13de8f6Sab #endif
115c13de8f6Sab 
1167c478bd9Sstevel@tonic-gate /*
1177c478bd9Sstevel@tonic-gate  * General typedefs.
1187c478bd9Sstevel@tonic-gate  */
1197c478bd9Sstevel@tonic-gate typedef enum {
1207c478bd9Sstevel@tonic-gate 	FALSE = 0,
1217c478bd9Sstevel@tonic-gate 	TRUE = 1
1227c478bd9Sstevel@tonic-gate } Boolean;
1237c478bd9Sstevel@tonic-gate 
1247c478bd9Sstevel@tonic-gate /*
1257c478bd9Sstevel@tonic-gate  * Types of errors (used by eprintf()), together with a generic error return
1267c478bd9Sstevel@tonic-gate  * value.
1277c478bd9Sstevel@tonic-gate  */
1287c478bd9Sstevel@tonic-gate typedef enum {
1297c478bd9Sstevel@tonic-gate 	ERR_NONE,
1307c478bd9Sstevel@tonic-gate 	ERR_WARNING,
1317c478bd9Sstevel@tonic-gate 	ERR_FATAL,
1327c478bd9Sstevel@tonic-gate 	ERR_ELF,
1337c478bd9Sstevel@tonic-gate 	ERR_NUM				/* Must be last */
1347c478bd9Sstevel@tonic-gate } Error;
1357c478bd9Sstevel@tonic-gate 
1367c478bd9Sstevel@tonic-gate #if defined(_LP64) && !defined(_ELF64)
1377c478bd9Sstevel@tonic-gate #define	S_ERROR		(~(uint_t)0)
1387c478bd9Sstevel@tonic-gate #else
1397c478bd9Sstevel@tonic-gate #define	S_ERROR		(~(uintptr_t)0)
1407c478bd9Sstevel@tonic-gate #endif
1417c478bd9Sstevel@tonic-gate 
1427c478bd9Sstevel@tonic-gate /*
1437c478bd9Sstevel@tonic-gate  * LIST_TRAVERSE() is used as the only "argument" of a "for" loop to
1447c478bd9Sstevel@tonic-gate  * traverse a linked list. The node pointer `node' is set to each node in
1457c478bd9Sstevel@tonic-gate  * turn and the corresponding data pointer is copied to `data'.  The macro
1467c478bd9Sstevel@tonic-gate  * is used as in
1477c478bd9Sstevel@tonic-gate  * 	for (LIST_TRAVERSE(List *list, Listnode *node, void *data)) {
1487c478bd9Sstevel@tonic-gate  *		process(data);
1497c478bd9Sstevel@tonic-gate  *	}
1507c478bd9Sstevel@tonic-gate  */
1517c478bd9Sstevel@tonic-gate #define	LIST_TRAVERSE(L, N, D) \
1527c478bd9Sstevel@tonic-gate 	(void) (((N) = (L)->head) != NULL && ((D) = (N)->data) != NULL); \
1537c478bd9Sstevel@tonic-gate 	(N) != NULL; \
1547c478bd9Sstevel@tonic-gate 	(void) (((N) = (N)->next) != NULL && ((D) = (N)->data) != NULL)
1557c478bd9Sstevel@tonic-gate 
1567c478bd9Sstevel@tonic-gate typedef	struct listnode	Listnode;
1577c478bd9Sstevel@tonic-gate typedef	struct list	List;
1587c478bd9Sstevel@tonic-gate 
1597c478bd9Sstevel@tonic-gate struct	listnode {			/* a node on a linked list */
1607c478bd9Sstevel@tonic-gate 	void		*data;		/* the data item */
1617c478bd9Sstevel@tonic-gate 	Listnode	*next;		/* the next element */
1627c478bd9Sstevel@tonic-gate };
1637c478bd9Sstevel@tonic-gate 
1647c478bd9Sstevel@tonic-gate struct	list {				/* a linked list */
1657c478bd9Sstevel@tonic-gate 	Listnode	*head;		/* the first element */
1667c478bd9Sstevel@tonic-gate 	Listnode	*tail;		/* the last element */
1677c478bd9Sstevel@tonic-gate };
1687c478bd9Sstevel@tonic-gate 
1697c478bd9Sstevel@tonic-gate 
1707c478bd9Sstevel@tonic-gate #ifdef _SYSCALL32
1717c478bd9Sstevel@tonic-gate typedef	struct listnode32	Listnode32;
1727c478bd9Sstevel@tonic-gate typedef	struct list32		List32;
1737c478bd9Sstevel@tonic-gate 
1747c478bd9Sstevel@tonic-gate struct	listnode32 {			/* a node on a linked list */
1757c478bd9Sstevel@tonic-gate 	Elf32_Addr	data;		/* the data item */
1767c478bd9Sstevel@tonic-gate 	Elf32_Addr	next;		/* the next element */
1777c478bd9Sstevel@tonic-gate };
1787c478bd9Sstevel@tonic-gate 
1797c478bd9Sstevel@tonic-gate struct	list32 {			/* a linked list */
1807c478bd9Sstevel@tonic-gate 	Elf32_Addr	head;		/* the first element */
1817c478bd9Sstevel@tonic-gate 	Elf32_Addr	tail;		/* the last element */
1827c478bd9Sstevel@tonic-gate };
1837c478bd9Sstevel@tonic-gate #endif	/* _SYSCALL32 */
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 
1867c478bd9Sstevel@tonic-gate /*
1877c478bd9Sstevel@tonic-gate  * Structure to maintain rejected files elf information.  Files that are not
1887c478bd9Sstevel@tonic-gate  * applicable to the present link-edit are rejected and a search for an
1897c478bd9Sstevel@tonic-gate  * appropriate file may be resumed.  The first rejected files information is
1907c478bd9Sstevel@tonic-gate  * retained so that a better error diagnostic can be given should an appropriate
1917c478bd9Sstevel@tonic-gate  * file not be located.
1927c478bd9Sstevel@tonic-gate  */
1937c478bd9Sstevel@tonic-gate typedef struct {
1947c478bd9Sstevel@tonic-gate 	ushort_t	rej_type;	/* SGS_REJ_ value */
1957c478bd9Sstevel@tonic-gate 	ushort_t	rej_flag;	/* additional information */
1967c478bd9Sstevel@tonic-gate 	uint_t		rej_info;	/* numeric and string information */
1977c478bd9Sstevel@tonic-gate 	const char	*rej_str;	/*	associated with error */
1987c478bd9Sstevel@tonic-gate 	const char	*rej_name;	/* object name - expanded library */
1997c478bd9Sstevel@tonic-gate 					/*	name and archive members */
2007c478bd9Sstevel@tonic-gate } Rej_desc;
2017c478bd9Sstevel@tonic-gate 
2027c478bd9Sstevel@tonic-gate #define	SGS_REJ_NONE		0
2037c478bd9Sstevel@tonic-gate #define	SGS_REJ_MACH		1	/* wrong ELF machine type */
2047c478bd9Sstevel@tonic-gate #define	SGS_REJ_CLASS		2	/* wrong ELF class (32-bit/64-bit) */
2057c478bd9Sstevel@tonic-gate #define	SGS_REJ_DATA		3	/* wrong ELF data format (MSG/LSB) */
2067c478bd9Sstevel@tonic-gate #define	SGS_REJ_TYPE		4	/* bad ELF type */
2077c478bd9Sstevel@tonic-gate #define	SGS_REJ_BADFLAG		5	/* bad ELF flags value */
2087c478bd9Sstevel@tonic-gate #define	SGS_REJ_MISFLAG		6	/* mismatched ELF flags value */
2097c478bd9Sstevel@tonic-gate #define	SGS_REJ_VERSION		7	/* mismatched ELF/lib version */
2107c478bd9Sstevel@tonic-gate #define	SGS_REJ_HAL		8	/* HAL R1 extensions required */
2117c478bd9Sstevel@tonic-gate #define	SGS_REJ_US3		9	/* Sun UltraSPARC III extensions */
2127c478bd9Sstevel@tonic-gate 					/*	required */
2137c478bd9Sstevel@tonic-gate #define	SGS_REJ_STR		10	/* generic error - info is a string */
2147c478bd9Sstevel@tonic-gate #define	SGS_REJ_UNKFILE		11	/* unknown file type */
2157c478bd9Sstevel@tonic-gate #define	SGS_REJ_HWCAP_1		12	/* hardware capabilities mismatch */
2167c478bd9Sstevel@tonic-gate 
2177c478bd9Sstevel@tonic-gate /*
2187c478bd9Sstevel@tonic-gate  * For those source files used both inside and outside of the
2197c478bd9Sstevel@tonic-gate  * libld source base (tools/common/string_table.c) we can
2207c478bd9Sstevel@tonic-gate  * automatically switch between the allocation models
2217c478bd9Sstevel@tonic-gate  * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
2227c478bd9Sstevel@tonic-gate  */
2237c478bd9Sstevel@tonic-gate #ifdef	USE_LIBLD_MALLOC
2247c478bd9Sstevel@tonic-gate #define	calloc(x, a)		libld_malloc(((size_t)x) * ((size_t)a))
2257c478bd9Sstevel@tonic-gate #define	free			libld_free
2267c478bd9Sstevel@tonic-gate #define	malloc			libld_malloc
2277c478bd9Sstevel@tonic-gate #define	realloc			libld_realloc
2287c478bd9Sstevel@tonic-gate 
2297c478bd9Sstevel@tonic-gate #define	libld_calloc(x, a)	libld_malloc(((size_t)x) * ((size_t)a))
2307c478bd9Sstevel@tonic-gate extern void		libld_free(void *);
2317c478bd9Sstevel@tonic-gate extern void		*libld_malloc(size_t);
2327c478bd9Sstevel@tonic-gate extern void		*libld_realloc(void *, size_t);
2337c478bd9Sstevel@tonic-gate #endif
2347c478bd9Sstevel@tonic-gate 
2357c478bd9Sstevel@tonic-gate 
2367c478bd9Sstevel@tonic-gate /*
2377c478bd9Sstevel@tonic-gate  * Data structures (defined in libld.h).
2387c478bd9Sstevel@tonic-gate  */
2397c478bd9Sstevel@tonic-gate typedef struct ent_desc		Ent_desc;
2407c478bd9Sstevel@tonic-gate typedef	struct group_desc	Group_desc;
2417c478bd9Sstevel@tonic-gate typedef struct ifl_desc		Ifl_desc;
2427c478bd9Sstevel@tonic-gate typedef struct is_desc		Is_desc;
2437c478bd9Sstevel@tonic-gate typedef struct isa_desc		Isa_desc;
2447c478bd9Sstevel@tonic-gate typedef struct isa_opt		Isa_opt;
2457c478bd9Sstevel@tonic-gate typedef struct mv_desc		Mv_desc;
2467c478bd9Sstevel@tonic-gate typedef struct ofl_desc		Ofl_desc;
2477c478bd9Sstevel@tonic-gate typedef struct os_desc		Os_desc;
2487c478bd9Sstevel@tonic-gate typedef	struct rel_cache	Rel_cache;
2497c478bd9Sstevel@tonic-gate typedef	struct sdf_desc		Sdf_desc;
2507c478bd9Sstevel@tonic-gate typedef	struct sdv_desc		Sdv_desc;
2517c478bd9Sstevel@tonic-gate typedef struct sg_desc		Sg_desc;
2527c478bd9Sstevel@tonic-gate typedef struct sort_desc	Sort_desc;
2537c478bd9Sstevel@tonic-gate typedef struct sec_order	Sec_order;
2547c478bd9Sstevel@tonic-gate typedef struct sym_desc		Sym_desc;
2557c478bd9Sstevel@tonic-gate typedef struct sym_aux		Sym_aux;
2567c478bd9Sstevel@tonic-gate typedef	struct sym_avlnode	Sym_avlnode;
2577c478bd9Sstevel@tonic-gate typedef	struct uts_desc		Uts_desc;
2587c478bd9Sstevel@tonic-gate typedef struct ver_desc		Ver_desc;
2597c478bd9Sstevel@tonic-gate typedef struct ver_index	Ver_index;
2607c478bd9Sstevel@tonic-gate typedef	struct audit_desc	Audit_desc;
2617c478bd9Sstevel@tonic-gate typedef	struct audit_info	Audit_info;
2627c478bd9Sstevel@tonic-gate typedef	struct audit_list	Audit_list;
2637c478bd9Sstevel@tonic-gate 
2647c478bd9Sstevel@tonic-gate /*
2657c478bd9Sstevel@tonic-gate  * Data structures defined in machrel.h.
2667c478bd9Sstevel@tonic-gate  */
2677c478bd9Sstevel@tonic-gate typedef struct rel_desc		Rel_desc;
2687c478bd9Sstevel@tonic-gate 
2695aefb655Srie /*
2705aefb655Srie  * Data structures defined in rtld.h.
2715aefb655Srie  */
2725aefb655Srie typedef struct lm_list		Lm_list;
2735aefb655Srie #ifdef _SYSCALL32
2745aefb655Srie typedef struct lm_list32	Lm_list32;
2755aefb655Srie #endif	/* _SYSCALL32 */
2765aefb655Srie 
2777c478bd9Sstevel@tonic-gate /*
2787c478bd9Sstevel@tonic-gate  * For the various utilities that include sgs.h
2797c478bd9Sstevel@tonic-gate  */
2805aefb655Srie extern int	assfail(const char *, const char *, int);
2815aefb655Srie extern void	eprintf(Lm_list *, Error, const char *, ...);
2827c478bd9Sstevel@tonic-gate extern char	*sgs_demangle(char *);
2837c478bd9Sstevel@tonic-gate extern uint_t	sgs_str_hash(const char *);
2847c478bd9Sstevel@tonic-gate extern uint_t	findprime(uint_t);
2857c478bd9Sstevel@tonic-gate 
2867c478bd9Sstevel@tonic-gate #endif /* _ASM */
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate #ifdef	__cplusplus
2897c478bd9Sstevel@tonic-gate }
2907c478bd9Sstevel@tonic-gate #endif
2917c478bd9Sstevel@tonic-gate 
2927c478bd9Sstevel@tonic-gate 
2937c478bd9Sstevel@tonic-gate #endif /* _SGS_H */
294