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