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 * 27bf994817SAli Bahrami * Copyright (c) 1989, 2010, Oracle and/or its affiliates. All rights reserved. 2856726c7eSRobert Mustacchi * Copyright 2022 Oxide Computer Company 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 #ifdef __cplusplus 377c478bd9Sstevel@tonic-gate extern "C" { 387c478bd9Sstevel@tonic-gate #endif 397c478bd9Sstevel@tonic-gate 407c478bd9Sstevel@tonic-gate /* <assert.h> keys off of NDEBUG */ 417c478bd9Sstevel@tonic-gate #ifdef DEBUG 427c478bd9Sstevel@tonic-gate #undef NDEBUG 437c478bd9Sstevel@tonic-gate #else 447c478bd9Sstevel@tonic-gate #define NDEBUG 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate 477c478bd9Sstevel@tonic-gate #ifndef _ASM 487c478bd9Sstevel@tonic-gate #include <sys/types.h> 497c478bd9Sstevel@tonic-gate #include <sys/machelf.h> 50*7dbbfe77SToomas Soome #include <sys/stddef.h> 517c478bd9Sstevel@tonic-gate #include <stdlib.h> 521007fd6fSAli Bahrami #include <stdarg.h> 537c478bd9Sstevel@tonic-gate #include <libelf.h> 547c478bd9Sstevel@tonic-gate #include <assert.h> 557c478bd9Sstevel@tonic-gate #include <alist.h> 567c478bd9Sstevel@tonic-gate #endif /* _ASM */ 577c478bd9Sstevel@tonic-gate 587c478bd9Sstevel@tonic-gate /* 597c478bd9Sstevel@tonic-gate * Software identification. 607c478bd9Sstevel@tonic-gate */ 617c478bd9Sstevel@tonic-gate #define SGS "" 627c478bd9Sstevel@tonic-gate #define SGU_PKG "Software Generation Utilities" 637c478bd9Sstevel@tonic-gate #define SGU_REL "(SGU) Solaris-ELF (4.0)" 647c478bd9Sstevel@tonic-gate 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #ifndef _ASM 677c478bd9Sstevel@tonic-gate 683edf445cSab /* 693edf445cSab * link_ver_string[] contains a version string for use by the link-editor 703edf445cSab * and all other linker components. It is found in libconv, and is 713edf445cSab * generated by sgs/libconv/common/bld_vernote.ksh. That script produces 723edf445cSab * libconv/{plat}/vernote.s, which is in turn assembled/linked into 733edf445cSab * libconv. 743edf445cSab */ 753edf445cSab extern const char link_ver_string[]; 767c478bd9Sstevel@tonic-gate /* 777c478bd9Sstevel@tonic-gate * Macro to round to next double word boundary. 787c478bd9Sstevel@tonic-gate */ 797c478bd9Sstevel@tonic-gate #define S_DROUND(x) (((x) + sizeof (double) - 1) & ~(sizeof (double) - 1)) 807c478bd9Sstevel@tonic-gate 817c478bd9Sstevel@tonic-gate /* 827c478bd9Sstevel@tonic-gate * General align and round macros. 837c478bd9Sstevel@tonic-gate */ 847c478bd9Sstevel@tonic-gate #define S_ALIGN(x, a) ((x) & ~(((a) ? (a) : 1) - 1)) 85*7dbbfe77SToomas Soome #define S_ROUND(x, a) (((x) + (((a) ? (a) : 1) - 1)) & ~(((a) ? (a) : 1) - 1)) 867c478bd9Sstevel@tonic-gate 877c478bd9Sstevel@tonic-gate /* 887c478bd9Sstevel@tonic-gate * Bit manipulation macros; generic bit mask and is `v' in the range 897c478bd9Sstevel@tonic-gate * supportable in `n' bits? 907c478bd9Sstevel@tonic-gate */ 91*7dbbfe77SToomas Soome #define S_MASK(n) ((1 << (n)) - 1) 927c478bd9Sstevel@tonic-gate #define S_INRANGE(v, n) (((-(1 << (n)) - 1) < (v)) && ((v) < (1 << (n)))) 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate 957c478bd9Sstevel@tonic-gate /* 967c478bd9Sstevel@tonic-gate * Yet another definition of the OFFSETOF macro, used with the AVL routines. 977c478bd9Sstevel@tonic-gate */ 98*7dbbfe77SToomas Soome #define SGSOFFSETOF(s, m) offsetof(s, m) 997c478bd9Sstevel@tonic-gate 100c13de8f6Sab /* 101c13de8f6Sab * When casting between integer and pointer types, gcc will complain 102c13de8f6Sab * if the integer type used is not large enough to hold the pointer 103c13de8f6Sab * value without loss. Although a dubious practice in general, this 104c13de8f6Sab * is sometimes done by design. In those cases, the general solution 105c13de8f6Sab * is to introduce an intermediate cast to widen the integer value. The 106c13de8f6Sab * CAST_PTRINT macro does this, and its use documents the fact that 107c13de8f6Sab * the programmer is doing that sort of cast. 108c13de8f6Sab */ 109c13de8f6Sab #ifdef __GNUC__ 110c13de8f6Sab #define CAST_PTRINT(cast, value) ((cast)(uintptr_t)value) 111c13de8f6Sab #else 112c13de8f6Sab #define CAST_PTRINT(cast, value) ((cast)value) 113c13de8f6Sab #endif 114c13de8f6Sab 1157c478bd9Sstevel@tonic-gate /* 1167c478bd9Sstevel@tonic-gate * General typedefs. 1177c478bd9Sstevel@tonic-gate */ 1187c478bd9Sstevel@tonic-gate typedef enum { 1197c478bd9Sstevel@tonic-gate FALSE = 0, 1207c478bd9Sstevel@tonic-gate TRUE = 1 1217c478bd9Sstevel@tonic-gate } Boolean; 1227c478bd9Sstevel@tonic-gate 1237c478bd9Sstevel@tonic-gate /* 1241007fd6fSAli Bahrami * Types of errors (used by veprintf()), together with a generic error return 1257c478bd9Sstevel@tonic-gate * value. 1267c478bd9Sstevel@tonic-gate */ 1277c478bd9Sstevel@tonic-gate typedef enum { 1281007fd6fSAli Bahrami ERR_NONE, /* plain message */ 1291007fd6fSAli Bahrami ERR_WARNING_NF, /* warning that cannot be promoted to fatal */ 1301007fd6fSAli Bahrami ERR_WARNING, /* warning that can be promoted to fatal */ 1311007fd6fSAli Bahrami ERR_GUIDANCE, /* guidance warning that can be promoted */ 1321007fd6fSAli Bahrami ERR_FATAL, /* fatal error */ 1331007fd6fSAli Bahrami ERR_ELF, /* fatal libelf error */ 1341007fd6fSAli Bahrami ERR_NUM /* # of Error codes. Must be last */ 1357c478bd9Sstevel@tonic-gate } Error; 1367c478bd9Sstevel@tonic-gate 13769112eddSAli Bahrami /* 13869112eddSAli Bahrami * Type used to represent line numbers within files, and a corresponding 13969112eddSAli Bahrami * printing macro for it. 14069112eddSAli Bahrami */ 14169112eddSAli Bahrami typedef ulong_t Lineno; 14269112eddSAli Bahrami #define EC_LINENO(_x) EC_XWORD(_x) /* "llu" */ 14369112eddSAli Bahrami 14469112eddSAli Bahrami 1457c478bd9Sstevel@tonic-gate #if defined(_LP64) && !defined(_ELF64) 1467c478bd9Sstevel@tonic-gate #define S_ERROR (~(uint_t)0) 1477c478bd9Sstevel@tonic-gate #else 1487c478bd9Sstevel@tonic-gate #define S_ERROR (~(uintptr_t)0) 1497c478bd9Sstevel@tonic-gate #endif 1507c478bd9Sstevel@tonic-gate 15108278a5eSRod Evans /* 15208278a5eSRod Evans * CTF currently does not handle automatic array variables sized via function 15308278a5eSRod Evans * arguments (VLA arrays) properly, when the code is compiled with gcc. 15408278a5eSRod Evans * Adding 1 to the size is a workaround. VLA_SIZE, and its use, should be 15508278a5eSRod Evans * pulled when CTF is fixed or replaced. 15608278a5eSRod Evans */ 15708278a5eSRod Evans #ifdef __GNUC__ 15808278a5eSRod Evans #define VLA_SIZE(_arg) ((_arg) + 1) 15908278a5eSRod Evans #else 16008278a5eSRod Evans #define VLA_SIZE(_arg) (_arg) 16108278a5eSRod Evans #endif 16208278a5eSRod Evans 1637c478bd9Sstevel@tonic-gate /* 1647c478bd9Sstevel@tonic-gate * Structure to maintain rejected files elf information. Files that are not 1657c478bd9Sstevel@tonic-gate * applicable to the present link-edit are rejected and a search for an 1667c478bd9Sstevel@tonic-gate * appropriate file may be resumed. The first rejected files information is 1677c478bd9Sstevel@tonic-gate * retained so that a better error diagnostic can be given should an appropriate 1687c478bd9Sstevel@tonic-gate * file not be located. 1697c478bd9Sstevel@tonic-gate */ 1707c478bd9Sstevel@tonic-gate typedef struct { 1717c478bd9Sstevel@tonic-gate ushort_t rej_type; /* SGS_REJ_ value */ 17256deab07SRod Evans ushort_t rej_flags; /* additional information */ 1737c478bd9Sstevel@tonic-gate uint_t rej_info; /* numeric and string information */ 1747c478bd9Sstevel@tonic-gate const char *rej_str; /* associated with error */ 1757c478bd9Sstevel@tonic-gate const char *rej_name; /* object name - expanded library */ 1767c478bd9Sstevel@tonic-gate /* name and archive members */ 1777c478bd9Sstevel@tonic-gate } Rej_desc; 1787c478bd9Sstevel@tonic-gate 1797c478bd9Sstevel@tonic-gate #define SGS_REJ_NONE 0 1807c478bd9Sstevel@tonic-gate #define SGS_REJ_MACH 1 /* wrong ELF machine type */ 1817c478bd9Sstevel@tonic-gate #define SGS_REJ_CLASS 2 /* wrong ELF class (32-bit/64-bit) */ 1827c478bd9Sstevel@tonic-gate #define SGS_REJ_DATA 3 /* wrong ELF data format (MSG/LSB) */ 1837c478bd9Sstevel@tonic-gate #define SGS_REJ_TYPE 4 /* bad ELF type */ 1847c478bd9Sstevel@tonic-gate #define SGS_REJ_BADFLAG 5 /* bad ELF flags value */ 1857c478bd9Sstevel@tonic-gate #define SGS_REJ_MISFLAG 6 /* mismatched ELF flags value */ 1867c478bd9Sstevel@tonic-gate #define SGS_REJ_VERSION 7 /* mismatched ELF/lib version */ 1877c478bd9Sstevel@tonic-gate #define SGS_REJ_HAL 8 /* HAL R1 extensions required */ 1887c478bd9Sstevel@tonic-gate #define SGS_REJ_US3 9 /* Sun UltraSPARC III extensions */ 1897c478bd9Sstevel@tonic-gate /* required */ 1907c478bd9Sstevel@tonic-gate #define SGS_REJ_STR 10 /* generic error - info is a string */ 1917c478bd9Sstevel@tonic-gate #define SGS_REJ_UNKFILE 11 /* unknown file type */ 19208278a5eSRod Evans #define SGS_REJ_UNKCAP 12 /* unknown capabilities */ 19308278a5eSRod Evans #define SGS_REJ_HWCAP_1 13 /* hardware capabilities mismatch */ 19408278a5eSRod Evans #define SGS_REJ_SFCAP_1 14 /* software capabilities mismatch */ 19508278a5eSRod Evans #define SGS_REJ_MACHCAP 15 /* machine capability mismatch */ 19608278a5eSRod Evans #define SGS_REJ_PLATCAP 16 /* platform capability mismatch */ 19708278a5eSRod Evans #define SGS_REJ_HWCAP_2 17 /* hardware capabilities mismatch */ 198dc0f59e5SAli Bahrami #define SGS_REJ_ARCHIVE 18 /* archive used in invalid context */ 199b6a0e2cdSRichard Lowe #define SGS_REJ_KMOD 19 /* object is a kernel module */ 20056726c7eSRobert Mustacchi #define SGS_REJ_HWCAP_3 20 /* hardware capabilities mismatch */ 20156726c7eSRobert Mustacchi #define SGS_REJ_NUM 21 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate 204fb12490aSRichard Lowe #define FLG_REJ_ALTER 0x01 /* object name is an alternative */ 205f3ecd616SRichard Lowe 2067c478bd9Sstevel@tonic-gate /* 2077c478bd9Sstevel@tonic-gate * Data structures (defined in libld.h). 2087c478bd9Sstevel@tonic-gate */ 20908278a5eSRod Evans typedef struct audit_desc Audit_desc; 21008278a5eSRod Evans typedef struct audit_info Audit_info; 21108278a5eSRod Evans typedef struct audit_list Audit_list; 21208278a5eSRod Evans typedef struct cap_desc Cap_desc; 2137c478bd9Sstevel@tonic-gate typedef struct ent_desc Ent_desc; 2147c478bd9Sstevel@tonic-gate typedef struct group_desc Group_desc; 2157c478bd9Sstevel@tonic-gate typedef struct ifl_desc Ifl_desc; 2167c478bd9Sstevel@tonic-gate typedef struct is_desc Is_desc; 2177c478bd9Sstevel@tonic-gate typedef struct isa_desc Isa_desc; 2187c478bd9Sstevel@tonic-gate typedef struct isa_opt Isa_opt; 2197c478bd9Sstevel@tonic-gate typedef struct os_desc Os_desc; 22008278a5eSRod Evans typedef struct ofl_desc Ofl_desc; 2217c478bd9Sstevel@tonic-gate typedef struct rel_cache Rel_cache; 222bf994817SAli Bahrami typedef struct rel_cachebuf Rel_cachebuf; 223bf994817SAli Bahrami typedef struct rel_aux_cachebuf Rel_aux_cachebuf; 224bf994817SAli Bahrami typedef struct rel_aux Rel_aux; 225bf994817SAli Bahrami typedef struct rel_desc Rel_desc; 2267c478bd9Sstevel@tonic-gate typedef struct sdf_desc Sdf_desc; 2277c478bd9Sstevel@tonic-gate typedef struct sdv_desc Sdv_desc; 22808278a5eSRod Evans typedef struct sec_order Sec_order; 2297c478bd9Sstevel@tonic-gate typedef struct sg_desc Sg_desc; 2307c478bd9Sstevel@tonic-gate typedef struct sort_desc Sort_desc; 2317c478bd9Sstevel@tonic-gate typedef struct sym_avlnode Sym_avlnode; 23208278a5eSRod Evans typedef struct sym_aux Sym_aux; 23308278a5eSRod Evans typedef struct sym_desc Sym_desc; 2347c478bd9Sstevel@tonic-gate typedef struct uts_desc Uts_desc; 2357c478bd9Sstevel@tonic-gate typedef struct ver_desc Ver_desc; 2367c478bd9Sstevel@tonic-gate typedef struct ver_index Ver_index; 2377c478bd9Sstevel@tonic-gate 2385aefb655Srie /* 2395aefb655Srie * Data structures defined in rtld.h. 2405aefb655Srie */ 2415aefb655Srie typedef struct lm_list Lm_list; 2425aefb655Srie #ifdef _SYSCALL32 2435aefb655Srie typedef struct lm_list32 Lm_list32; 2445aefb655Srie #endif /* _SYSCALL32 */ 2455aefb655Srie 2467c478bd9Sstevel@tonic-gate /* 2477c478bd9Sstevel@tonic-gate * For the various utilities that include sgs.h 2487c478bd9Sstevel@tonic-gate */ 2495aefb655Srie extern int assfail(const char *, const char *, int); 2505aefb655Srie extern void eprintf(Lm_list *, Error, const char *, ...); 2511007fd6fSAli Bahrami extern void veprintf(Lm_list *, Error, const char *, va_list); 2527c478bd9Sstevel@tonic-gate extern uint_t sgs_str_hash(const char *); 2537c478bd9Sstevel@tonic-gate extern uint_t findprime(uint_t); 2547c478bd9Sstevel@tonic-gate 2557c478bd9Sstevel@tonic-gate #endif /* _ASM */ 2567c478bd9Sstevel@tonic-gate 2577c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2587c478bd9Sstevel@tonic-gate } 2597c478bd9Sstevel@tonic-gate #endif 2607c478bd9Sstevel@tonic-gate 2617c478bd9Sstevel@tonic-gate 2627c478bd9Sstevel@tonic-gate #endif /* _SGS_H */ 263