17c478bdstevel@tonic-gate/*
27c478bdstevel@tonic-gate * CDDL HEADER START
37c478bdstevel@tonic-gate *
47c478bdstevel@tonic-gate * The contents of this file are subject to the terms of the
55aefb65rie * Common Development and Distribution License (the "License").
65aefb65rie * You may not use this file except in compliance with the License.
77c478bdstevel@tonic-gate *
87c478bdstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
97c478bdstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
107c478bdstevel@tonic-gate * See the License for the specific language governing permissions
117c478bdstevel@tonic-gate * and limitations under the License.
127c478bdstevel@tonic-gate *
137c478bdstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
147c478bdstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
157c478bdstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
167c478bdstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
177c478bdstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
187c478bdstevel@tonic-gate *
197c478bdstevel@tonic-gate * CDDL HEADER END
207c478bdstevel@tonic-gate */
215aefb65rie
227c478bdstevel@tonic-gate/*
237c478bdstevel@tonic-gate *	Copyright (c) 1988 AT&T
247c478bdstevel@tonic-gate *	  All Rights Reserved
257c478bdstevel@tonic-gate *
267c478bdstevel@tonic-gate *
27bf99481Ali Bahrami * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved.
287c478bdstevel@tonic-gate *
297c478bdstevel@tonic-gate * Global include file for all sgs.
307c478bdstevel@tonic-gate */
317c478bdstevel@tonic-gate
327c478bdstevel@tonic-gate#ifndef	_SGS_H
337c478bdstevel@tonic-gate#define	_SGS_H
347c478bdstevel@tonic-gate
357c478bdstevel@tonic-gate#ifdef	__cplusplus
367c478bdstevel@tonic-gateextern "C" {
377c478bdstevel@tonic-gate#endif
387c478bdstevel@tonic-gate
397c478bdstevel@tonic-gate/* <assert.h> keys off of NDEBUG */
407c478bdstevel@tonic-gate#ifdef	DEBUG
417c478bdstevel@tonic-gate#undef	NDEBUG
427c478bdstevel@tonic-gate#else
437c478bdstevel@tonic-gate#define	NDEBUG
447c478bdstevel@tonic-gate#endif
457c478bdstevel@tonic-gate
467c478bdstevel@tonic-gate#ifndef	_ASM
477c478bdstevel@tonic-gate#include <sys/types.h>
487c478bdstevel@tonic-gate#include <sys/machelf.h>
497c478bdstevel@tonic-gate#include <stdlib.h>
501007fd6Ali Bahrami#include <stdarg.h>
517c478bdstevel@tonic-gate#include <libelf.h>
527c478bdstevel@tonic-gate#include <assert.h>
537c478bdstevel@tonic-gate#include <alist.h>
547c478bdstevel@tonic-gate#endif	/* _ASM */
557c478bdstevel@tonic-gate
567c478bdstevel@tonic-gate/*
577c478bdstevel@tonic-gate * Software identification.
587c478bdstevel@tonic-gate */
597c478bdstevel@tonic-gate#define	SGS		""
607c478bdstevel@tonic-gate#define	SGU_PKG		"Software Generation Utilities"
617c478bdstevel@tonic-gate#define	SGU_REL		"(SGU) Solaris-ELF (4.0)"
627c478bdstevel@tonic-gate
637c478bdstevel@tonic-gate
647c478bdstevel@tonic-gate#ifndef _ASM
657c478bdstevel@tonic-gate
663edf445ab/*
673edf445ab * link_ver_string[] contains a version string for use by the link-editor
683edf445ab * and all other linker components. It is found in libconv, and is
693edf445ab * generated by sgs/libconv/common/bld_vernote.ksh. That script produces
703edf445ab * libconv/{plat}/vernote.s, which is in turn assembled/linked into
713edf445ab * libconv.
723edf445ab */
733edf445abextern const char link_ver_string[];
747c478bdstevel@tonic-gate/*
757c478bdstevel@tonic-gate * Macro to round to next double word boundary.
767c478bdstevel@tonic-gate */
777c478bdstevel@tonic-gate#define	S_DROUND(x)	(((x) + sizeof (double) - 1) & ~(sizeof (double) - 1))
787c478bdstevel@tonic-gate
797c478bdstevel@tonic-gate/*
807c478bdstevel@tonic-gate * General align and round macros.
817c478bdstevel@tonic-gate */
827c478bdstevel@tonic-gate#define	S_ALIGN(x, a)	((x) & ~(((a) ? (a) : 1) - 1))
837c478bdstevel@tonic-gate#define	S_ROUND(x, a)   ((x) + (((a) ? (a) : 1) - 1) & ~(((a) ? (a) : 1) - 1))
847c478bdstevel@tonic-gate
857c478bdstevel@tonic-gate/*
867c478bdstevel@tonic-gate * Bit manipulation macros; generic bit mask and is `v' in the range
877c478bdstevel@tonic-gate * supportable in `n' bits?
887c478bdstevel@tonic-gate */
897c478bdstevel@tonic-gate#define	S_MASK(n)	((1 << (n)) -1)
907c478bdstevel@tonic-gate#define	S_INRANGE(v, n)	(((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n))))
917c478bdstevel@tonic-gate
927c478bdstevel@tonic-gate
937c478bdstevel@tonic-gate/*
947c478bdstevel@tonic-gate * Yet another definition of the OFFSETOF macro, used with the AVL routines.
957c478bdstevel@tonic-gate */
967c478bdstevel@tonic-gate#define	SGSOFFSETOF(s, m)	((size_t)(&(((s *)0)->m)))
977c478bdstevel@tonic-gate
987c478bdstevel@tonic-gate/*
99c13de8fab * When casting between integer and pointer types, gcc will complain
100c13de8fab * if the integer type used is not large enough to hold the pointer
101c13de8fab * value without loss. Although a dubious practice in general, this
102c13de8fab * is sometimes done by design. In those cases, the general solution
103c13de8fab * is to introduce an intermediate cast to widen the integer value. The
104c13de8fab * CAST_PTRINT macro does this, and its use documents the fact that
105c13de8fab * the programmer is doing that sort of cast.
106c13de8fab */
107c13de8fab#ifdef __GNUC__
108c13de8fab#define	CAST_PTRINT(cast, value) ((cast)(uintptr_t)value)
109c13de8fab#else
110c13de8fab#define	CAST_PTRINT(cast, value) ((cast)value)
111c13de8fab#endif
112c13de8fab
113c13de8fab/*
1147c478bdstevel@tonic-gate * General typedefs.
1157c478bdstevel@tonic-gate */
1167c478bdstevel@tonic-gatetypedef enum {
1177c478bdstevel@tonic-gate	FALSE = 0,
1187c478bdstevel@tonic-gate	TRUE = 1
1197c478bdstevel@tonic-gate} Boolean;
1207c478bdstevel@tonic-gate
1217c478bdstevel@tonic-gate/*
1221007fd6Ali Bahrami * Types of errors (used by veprintf()), together with a generic error return
1237c478bdstevel@tonic-gate * value.
1247c478bdstevel@tonic-gate */
1257c478bdstevel@tonic-gatetypedef enum {
1261007fd6Ali Bahrami	ERR_NONE,		/* plain message */
1271007fd6Ali Bahrami	ERR_WARNING_NF,		/* warning that cannot be promoted to fatal */
1281007fd6Ali Bahrami	ERR_WARNING,		/* warning that can be promoted to fatal */
1291007fd6Ali Bahrami	ERR_GUIDANCE,		/* guidance warning that can be promoted */
1301007fd6Ali Bahrami	ERR_FATAL,		/* fatal error */
1311007fd6Ali Bahrami	ERR_ELF,		/* fatal libelf error */
1321007fd6Ali Bahrami	ERR_NUM			/* # of Error codes. Must be last */
1337c478bdstevel@tonic-gate} Error;
1347c478bdstevel@tonic-gate
13569112edAli Bahrami/*
13669112edAli Bahrami * Type used to represent line numbers within files, and a corresponding
13769112edAli Bahrami * printing macro for it.
13869112edAli Bahrami */
13969112edAli Bahramitypedef ulong_t Lineno;
14069112edAli Bahrami#define	EC_LINENO(_x) EC_XWORD(_x)			/* "llu" */
14169112edAli Bahrami
14269112edAli Bahrami
1437c478bdstevel@tonic-gate#if defined(_LP64) && !defined(_ELF64)
1447c478bdstevel@tonic-gate#define	S_ERROR		(~(uint_t)0)
1457c478bdstevel@tonic-gate#else
1467c478bdstevel@tonic-gate#define	S_ERROR		(~(uintptr_t)0)
1477c478bdstevel@tonic-gate#endif
1487c478bdstevel@tonic-gate
1497c478bdstevel@tonic-gate/*
15008278a5Rod Evans * CTF currently does not handle automatic array variables sized via function
15108278a5Rod Evans * arguments (VLA arrays) properly, when the code is compiled with gcc.
15208278a5Rod Evans * Adding 1 to the size is a workaround.  VLA_SIZE, and its use, should be
15308278a5Rod Evans * pulled when CTF is fixed or replaced.
15408278a5Rod Evans */
15508278a5Rod Evans#ifdef __GNUC__
15608278a5Rod Evans#define	VLA_SIZE(_arg)	((_arg) + 1)
15708278a5Rod Evans#else
15808278a5Rod Evans#define	VLA_SIZE(_arg)	(_arg)
15908278a5Rod Evans#endif
16008278a5Rod Evans
16108278a5Rod Evans/*
1627c478bdstevel@tonic-gate * Structure to maintain rejected files elf information.  Files that are not
1637c478bdstevel@tonic-gate * applicable to the present link-edit are rejected and a search for an
1647c478bdstevel@tonic-gate * appropriate file may be resumed.  The first rejected files information is
1657c478bdstevel@tonic-gate * retained so that a better error diagnostic can be given should an appropriate
1667c478bdstevel@tonic-gate * file not be located.
1677c478bdstevel@tonic-gate */
1687c478bdstevel@tonic-gatetypedef struct {
1697c478bdstevel@tonic-gate	ushort_t	rej_type;	/* SGS_REJ_ value */
17056deab0Rod Evans	ushort_t	rej_flags;	/* additional information */
1717c478bdstevel@tonic-gate	uint_t		rej_info;	/* numeric and string information */
1727c478bdstevel@tonic-gate	const char	*rej_str;	/*	associated with error */
1737c478bdstevel@tonic-gate	const char	*rej_name;	/* object name - expanded library */
1747c478bdstevel@tonic-gate					/*	name and archive members */
1757c478bdstevel@tonic-gate} Rej_desc;
1767c478bdstevel@tonic-gate
1777c478bdstevel@tonic-gate#define	SGS_REJ_NONE		0
1787c478bdstevel@tonic-gate#define	SGS_REJ_MACH		1	/* wrong ELF machine type */
1797c478bdstevel@tonic-gate#define	SGS_REJ_CLASS		2	/* wrong ELF class (32-bit/64-bit) */
1807c478bdstevel@tonic-gate#define	SGS_REJ_DATA		3	/* wrong ELF data format (MSG/LSB) */
1817c478bdstevel@tonic-gate#define	SGS_REJ_TYPE		4	/* bad ELF type */
1827c478bdstevel@tonic-gate#define	SGS_REJ_BADFLAG		5	/* bad ELF flags value */
1837c478bdstevel@tonic-gate#define	SGS_REJ_MISFLAG		6	/* mismatched ELF flags value */
1847c478bdstevel@tonic-gate#define	SGS_REJ_VERSION		7	/* mismatched ELF/lib version */
1857c478bdstevel@tonic-gate#define	SGS_REJ_HAL		8	/* HAL R1 extensions required */
1867c478bdstevel@tonic-gate#define	SGS_REJ_US3		9	/* Sun UltraSPARC III extensions */
1877c478bdstevel@tonic-gate					/*	required */
1887c478bdstevel@tonic-gate#define	SGS_REJ_STR		10	/* generic error - info is a string */
1897c478bdstevel@tonic-gate#define	SGS_REJ_UNKFILE		11	/* unknown file type */
19008278a5Rod Evans#define	SGS_REJ_UNKCAP		12	/* unknown capabilities */
19108278a5Rod Evans#define	SGS_REJ_HWCAP_1		13	/* hardware capabilities mismatch */
19208278a5Rod Evans#define	SGS_REJ_SFCAP_1		14	/* software capabilities mismatch */
19308278a5Rod Evans#define	SGS_REJ_MACHCAP		15	/* machine capability mismatch */
19408278a5Rod Evans#define	SGS_REJ_PLATCAP		16	/* platform capability mismatch */
19508278a5Rod Evans#define	SGS_REJ_HWCAP_2		17	/* hardware capabilities mismatch */
196dc0f59eAli Bahrami#define	SGS_REJ_ARCHIVE		18	/* archive used in invalid context */
197b6a0e2cRichard Lowe#define	SGS_REJ_KMOD		19	/* object is a kernel module */
198b6a0e2cRichard Lowe#define	SGS_REJ_NUM		20
1997c478bdstevel@tonic-gate
20056deab0Rod Evans#define	FLG_REJ_ALTER		0x01	/* object name is an alternative */
20156deab0Rod Evans
2027c478bdstevel@tonic-gate/*
2037c478bdstevel@tonic-gate * For those source files used both inside and outside of the
2047c478bdstevel@tonic-gate * libld source base (tools/common/string_table.c) we can
2057c478bdstevel@tonic-gate * automatically switch between the allocation models
2067c478bdstevel@tonic-gate * based off of the 'cc -DUSE_LIBLD_MALLOC' flag.
2077c478bdstevel@tonic-gate */
2087c478bdstevel@tonic-gate#ifdef	USE_LIBLD_MALLOC
2097c478bdstevel@tonic-gate#define	calloc(x, a)		libld_malloc(((size_t)x) * ((size_t)a))
2107c478bdstevel@tonic-gate#define	free			libld_free
2117c478bdstevel@tonic-gate#define	malloc			libld_malloc
2127c478bdstevel@tonic-gate#define	realloc			libld_realloc
2137c478bdstevel@tonic-gate
2147c478bdstevel@tonic-gate#define	libld_calloc(x, a)	libld_malloc(((size_t)x) * ((size_t)a))
2150e23348Rod Evansextern void			libld_free(void *);
2160e23348Rod Evansextern void			*libld_malloc(size_t);
2170e23348Rod Evansextern void			*libld_realloc(void *, size_t);
2187c478bdstevel@tonic-gate#endif
2197c478bdstevel@tonic-gate
2207c478bdstevel@tonic-gate/*
2217c478bdstevel@tonic-gate * Data structures (defined in libld.h).
2227c478bdstevel@tonic-gate */
22308278a5Rod Evanstypedef	struct audit_desc	Audit_desc;
22408278a5Rod Evanstypedef	struct audit_info	Audit_info;
22508278a5Rod Evanstypedef	struct audit_list	Audit_list;
22608278a5Rod Evanstypedef struct cap_desc		Cap_desc;
2277c478bdstevel@tonic-gatetypedef struct ent_desc		Ent_desc;
2287c478bdstevel@tonic-gatetypedef	struct group_desc	Group_desc;
2297c478bdstevel@tonic-gatetypedef struct ifl_desc		Ifl_desc;
2307c478bdstevel@tonic-gatetypedef struct is_desc		Is_desc;
2317c478bdstevel@tonic-gatetypedef struct isa_desc		Isa_desc;
2327c478bdstevel@tonic-gatetypedef struct isa_opt		Isa_opt;
2337c478bdstevel@tonic-gatetypedef struct os_desc		Os_desc;
23408278a5Rod Evanstypedef struct ofl_desc		Ofl_desc;
2357c478bdstevel@tonic-gatetypedef	struct rel_cache	Rel_cache;
236bf99481Ali Bahramitypedef	struct rel_cachebuf	Rel_cachebuf;
237bf99481Ali Bahramitypedef	struct rel_aux_cachebuf	Rel_aux_cachebuf;
238bf99481Ali Bahramitypedef struct rel_aux		Rel_aux;
239bf99481Ali Bahramitypedef struct rel_desc		Rel_desc;
2407c478bdstevel@tonic-gatetypedef	struct sdf_desc		Sdf_desc;
2417c478bdstevel@tonic-gatetypedef	struct sdv_desc		Sdv_desc;
24208278a5Rod Evanstypedef struct sec_order	Sec_order;
2437c478bdstevel@tonic-gatetypedef struct sg_desc		Sg_desc;
2447c478bdstevel@tonic-gatetypedef struct sort_desc	Sort_desc;
2457c478bdstevel@tonic-gatetypedef	struct sym_avlnode	Sym_avlnode;
24608278a5Rod Evanstypedef struct sym_aux		Sym_aux;
24708278a5Rod Evanstypedef struct sym_desc		Sym_desc;
2487c478bdstevel@tonic-gatetypedef	struct uts_desc		Uts_desc;
2497c478bdstevel@tonic-gatetypedef struct ver_desc		Ver_desc;
2507c478bdstevel@tonic-gatetypedef struct ver_index	Ver_index;
2517c478bdstevel@tonic-gate
2527c478bdstevel@tonic-gate/*
2535aefb65rie * Data structures defined in rtld.h.
2545aefb65rie */
2555aefb65rietypedef struct lm_list		Lm_list;
2565aefb65rie#ifdef _SYSCALL32
2575aefb65rietypedef struct lm_list32	Lm_list32;
2585aefb65rie#endif	/* _SYSCALL32 */
2595aefb65rie
2605aefb65rie/*
2617c478bdstevel@tonic-gate * For the various utilities that include sgs.h
2627c478bdstevel@tonic-gate */
2635aefb65rieextern int	assfail(const char *, const char *, int);
2645aefb65rieextern void	eprintf(Lm_list *, Error, const char *, ...);
2651007fd6Ali Bahramiextern void	veprintf(Lm_list *, Error, const char *, va_list);
2667c478bdstevel@tonic-gateextern uint_t	sgs_str_hash(const char *);
2677c478bdstevel@tonic-gateextern uint_t	findprime(uint_t);
2687c478bdstevel@tonic-gate
2697c478bdstevel@tonic-gate#endif /* _ASM */
2707c478bdstevel@tonic-gate
2717c478bdstevel@tonic-gate#ifdef	__cplusplus
2727c478bdstevel@tonic-gate}
2737c478bdstevel@tonic-gate#endif
2747c478bdstevel@tonic-gate
2757c478bdstevel@tonic-gate
2767c478bdstevel@tonic-gate#endif /* _SGS_H */
277