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 */ 21c174926fSrie 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright (c) 1988 AT&T 247c478bd9Sstevel@tonic-gate * All Rights Reserved 257c478bd9Sstevel@tonic-gate * 2669112eddSAli Bahrami * Copyright 2010 Sun Microsystems, Inc. All rights reserved. 277c478bd9Sstevel@tonic-gate * Use is subject to license terms. 287c478bd9Sstevel@tonic-gate */ 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifndef _LIBLD_H 317c478bd9Sstevel@tonic-gate #define _LIBLD_H 327c478bd9Sstevel@tonic-gate 337c478bd9Sstevel@tonic-gate #include <stdlib.h> 347c478bd9Sstevel@tonic-gate #include <libelf.h> 357c478bd9Sstevel@tonic-gate #include <sgs.h> 36ba2be530Sab196087 #include <_machelf.h> 377c478bd9Sstevel@tonic-gate #include <string_table.h> 387c478bd9Sstevel@tonic-gate #include <sys/avl.h> 397c478bd9Sstevel@tonic-gate #include <alist.h> 4069112eddSAli Bahrami #include <elfcap.h> 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate #ifdef __cplusplus 437c478bd9Sstevel@tonic-gate extern "C" { 447c478bd9Sstevel@tonic-gate #endif 457c478bd9Sstevel@tonic-gate 467c478bd9Sstevel@tonic-gate /* 477c478bd9Sstevel@tonic-gate * Default directory search path manipulation for the link-editor. YLDIR 487c478bd9Sstevel@tonic-gate * indicates which directory in LIBPATH is replaced by the -YL option to cc 497c478bd9Sstevel@tonic-gate * and ld. YUDIR indicates which directory is replaced by -YU. 507c478bd9Sstevel@tonic-gate */ 517c478bd9Sstevel@tonic-gate #define YLDIR 1 527c478bd9Sstevel@tonic-gate #define YUDIR 2 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate /* 557c478bd9Sstevel@tonic-gate * Define a hash value that can never be returned from elf_hash(). 567c478bd9Sstevel@tonic-gate */ 577c478bd9Sstevel@tonic-gate #define SYM_NOHASH (~(Word)0) 587c478bd9Sstevel@tonic-gate 597c478bd9Sstevel@tonic-gate /* 60240e56feSab196087 * Macro that can be used to represent both ORDER flags 61240e56feSab196087 * in a section header. 627c478bd9Sstevel@tonic-gate */ 637c478bd9Sstevel@tonic-gate #define ALL_SHF_ORDER (SHF_ORDERED | SHF_LINK_ORDER) 64240e56feSab196087 65240e56feSab196087 /* 66240e56feSab196087 * The linker merges (concatenates) sections with the same name and 67240e56feSab196087 * compatible section header flags. When comparing these flags, 68240e56feSab196087 * there are some that should not be included in the decision. 69240e56feSab196087 * The ALL_SHF_IGNORE constant defines these flags. 70240e56feSab196087 * 71240e56feSab196087 * NOTE: SHF_MERGE|SHF_STRINGS: 72240e56feSab196087 * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in 73240e56feSab196087 * order to tell the linker that: 74240e56feSab196087 * 75240e56feSab196087 * 1) There is nothing in the section except null terminated strings. 76cce0e03bSab196087 * 2) Those strings do not contain NULL bytes, except as termination. 77cce0e03bSab196087 * 3) All references to these strings occur via standard relocation 78cce0e03bSab196087 * records. 79cce0e03bSab196087 * 80cce0e03bSab196087 * As a result, if two compatible sections both have these flags set, it is 81cce0e03bSab196087 * OK to combine the strings they contain into a single merged string table 82cce0e03bSab196087 * with duplicates removed and tail strings merged. 83240e56feSab196087 * 84240e56feSab196087 * This is a different meaning than the simple concatenating of sections 85240e56feSab196087 * that the linker always does. It is a hint that an additional optimization 86240e56feSab196087 * is possible, but not required. This means that sections that do not 87cce0e03bSab196087 * share the same SHF_MERGE|SHF_STRINGS values can be concatenated, 88cce0e03bSab196087 * but cannot have their duplicate strings combined. Hence, the 89cce0e03bSab196087 * SHF_MERGE|SHF_STRINGS flags should be ignored when deciding whether 90cce0e03bSab196087 * two sections can be concatenated. 91240e56feSab196087 */ 92240e56feSab196087 #define ALL_SHF_IGNORE (ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS) 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * Define symbol reference types for use in symbol resolution. 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate typedef enum { 987c478bd9Sstevel@tonic-gate REF_DYN_SEEN, /* a .so symbol has been seen */ 997c478bd9Sstevel@tonic-gate REF_DYN_NEED, /* a .so symbol satisfies a .o symbol */ 1007c478bd9Sstevel@tonic-gate REF_REL_NEED, /* a .o symbol */ 1017c478bd9Sstevel@tonic-gate REF_NUM /* the number of symbol references */ 1027c478bd9Sstevel@tonic-gate } Symref; 1037c478bd9Sstevel@tonic-gate 1047c478bd9Sstevel@tonic-gate /* 1057c478bd9Sstevel@tonic-gate * GOT reference models 1067c478bd9Sstevel@tonic-gate */ 1077c478bd9Sstevel@tonic-gate typedef enum { 1087c478bd9Sstevel@tonic-gate GOT_REF_GENERIC, /* generic symbol reference */ 1097c478bd9Sstevel@tonic-gate GOT_REF_TLSIE, /* TLS initial exec (gnu) reference */ 1107c478bd9Sstevel@tonic-gate GOT_REF_TLSLD, /* TLS local dynamic reference */ 1117c478bd9Sstevel@tonic-gate GOT_REF_TLSGD /* TLS general dynamic reference */ 1127c478bd9Sstevel@tonic-gate } Gotref; 1137c478bd9Sstevel@tonic-gate 1147c478bd9Sstevel@tonic-gate typedef struct { 1157c478bd9Sstevel@tonic-gate Xword gn_addend; /* addend associated with GOT entry */ 1167c478bd9Sstevel@tonic-gate Sword gn_gotndx; /* GOT table index */ 1177c478bd9Sstevel@tonic-gate Gotref gn_gotref; 1187c478bd9Sstevel@tonic-gate } Gotndx; 1197c478bd9Sstevel@tonic-gate 1207c478bd9Sstevel@tonic-gate /* 1217c478bd9Sstevel@tonic-gate * Got debugging structure. The got index is defined as a signed value as we 1227c478bd9Sstevel@tonic-gate * do so much mucking around with negative and positive gots on SPARC, and sign 1237c478bd9Sstevel@tonic-gate * extension is necessary when building 64-bit objects. On intel we explicitly 1247c478bd9Sstevel@tonic-gate * cast this variable to an unsigned value. 1257c478bd9Sstevel@tonic-gate */ 1267c478bd9Sstevel@tonic-gate typedef struct { 1277c478bd9Sstevel@tonic-gate Sym_desc *gt_sym; 1287c478bd9Sstevel@tonic-gate Gotndx gt_gndx; 1297c478bd9Sstevel@tonic-gate } Gottable; 1307c478bd9Sstevel@tonic-gate 1317c478bd9Sstevel@tonic-gate /* 1326b3ba5bdSAli Bahrami * The link-editor caches the results of sloppy relocation processing 13340e53e87SAli Bahrami * in a variable of type Rlxrel_cache. Symbols come for processing in sorted 13440e53e87SAli Bahrami * order, so a single item cache suffices to eliminate duplicate lookups. 13540e53e87SAli Bahrami * 13640e53e87SAli Bahrami * When sloppy relocation processing fails, the Rlxrel_rej enum reports 13740e53e87SAli Bahrami * the underlying reason. 1386b3ba5bdSAli Bahrami */ 13940e53e87SAli Bahrami typedef enum { 14040e53e87SAli Bahrami RLXREL_REJ_NONE = 0, /* Replacement symbol was found */ 14140e53e87SAli Bahrami RLXREL_REJ_TARGET, /* Target sec disallows relaxed relocations */ 14240e53e87SAli Bahrami RLXREL_REJ_SECTION, /* Either there is no replacement section, */ 14340e53e87SAli Bahrami /* or its attributes are incompatible */ 14440e53e87SAli Bahrami RLXREL_REJ_SYMBOL, /* Replacement symbol not found */ 14540e53e87SAli Bahrami } Rlxrel_rej; 14640e53e87SAli Bahrami 1476b3ba5bdSAli Bahrami typedef struct sreloc_cache { 1486b3ba5bdSAli Bahrami Sym_desc *sr_osdp; /* Original symbol */ 1496b3ba5bdSAli Bahrami Sym_desc *sr_rsdp; /* Replacement symbol */ 15040e53e87SAli Bahrami Rlxrel_rej sr_rej; /* Reason for failure if NULL sr_rsdp */ 15140e53e87SAli Bahrami } Rlxrel_cache; 1526b3ba5bdSAli Bahrami 1536b3ba5bdSAli Bahrami /* 154cdcc71c0SAli Bahrami * Nodes in an ofl_wrap AVL tree 155cdcc71c0SAli Bahrami * 156cdcc71c0SAli Bahrami * wsn_name is the name of the symbol to be wrapped. wsn_wrapname is used 157cdcc71c0SAli Bahrami * when we need to refer to the wrap symbol, and consists of the symbol 158cdcc71c0SAli Bahrami * name with a __wrap_ prefix. 159cdcc71c0SAli Bahrami */ 160cdcc71c0SAli Bahrami typedef struct wrap_sym_node { 161cdcc71c0SAli Bahrami avl_node_t wsn_avlnode; /* AVL book-keeping */ 162cdcc71c0SAli Bahrami const char *wsn_name; /* Symbol name: XXX */ 163cdcc71c0SAli Bahrami const char *wsn_wrapname; /* Wrap symbol name: __wrap_XXX */ 164cdcc71c0SAli Bahrami } WrapSymNode; 165cdcc71c0SAli Bahrami 16608278a5eSRod Evans /* 16708278a5eSRod Evans * Capabilities structures, used to maintain a capabilities set. 16808278a5eSRod Evans * 16908278a5eSRod Evans * Capabilities can be defined within input relocatable objects, and can be 17008278a5eSRod Evans * augmented or replaced by mapfile directives. In addition, mapfile directives 17108278a5eSRod Evans * can be used to exclude capabilities that would otherwise be carried over to 17208278a5eSRod Evans * the output object. 17308278a5eSRod Evans * 17408278a5eSRod Evans * CA_SUNW_HW_1, CA_SUNW_SF_1 and CA_SUNW_HW_2 values are bitmasks. A current 17508278a5eSRod Evans * value, and an exclude value are maintained for each capability. 17608278a5eSRod Evans * 17708278a5eSRod Evans * There can be multiple CA_SUNW_PLAT and CA_SUNW_MACH entries and thus Alists 17808278a5eSRod Evans * are used to collect these entries. A current list for each capability is 17908278a5eSRod Evans * maintained as Capstr entries, which provide for maintaining the strings 18008278a5eSRod Evans * eventual index into a string table. An exclude list is maintained as a 18108278a5eSRod Evans * list of string pointers. 18208278a5eSRod Evans */ 18308278a5eSRod Evans typedef struct { 18408278a5eSRod Evans elfcap_mask_t cm_val; /* bitmask value */ 18508278a5eSRod Evans elfcap_mask_t cm_exc; /* bits to exclude from final object */ 18608278a5eSRod Evans } Capmask; 18708278a5eSRod Evans 18808278a5eSRod Evans typedef struct { 18908278a5eSRod Evans Alist *cl_val; /* string (Capstr) value */ 19008278a5eSRod Evans APlist *cl_exc; /* strings to exclude from final */ 19108278a5eSRod Evans } Caplist; /* object */ 19208278a5eSRod Evans 19308278a5eSRod Evans typedef struct { 19408278a5eSRod Evans char *cs_str; /* platform or machine name */ 19508278a5eSRod Evans Word cs_ndx; /* the entries output Cap index */ 19608278a5eSRod Evans } Capstr; 19708278a5eSRod Evans 19808278a5eSRod Evans typedef uint_t oc_flag_t; 19908278a5eSRod Evans typedef struct { 20008278a5eSRod Evans Capmask oc_hw_1; /* CA_SUNW_HW_1 capabilities */ 20108278a5eSRod Evans Capmask oc_sf_1; /* CA_SUNW_SF_1 capabilities */ 20208278a5eSRod Evans Capmask oc_hw_2; /* CA_SUNW_HW_2 capabilities */ 20308278a5eSRod Evans Caplist oc_plat; /* CA_SUNW_PLAT capabilities */ 20408278a5eSRod Evans Caplist oc_mach; /* CA_SUNW_MACH capabilities */ 20508278a5eSRod Evans Capstr oc_id; /* CA_SUNW_ID capability */ 20608278a5eSRod Evans oc_flag_t oc_flags; 20708278a5eSRod Evans } Objcapset; 20808278a5eSRod Evans 20908278a5eSRod Evans #define FLG_OCS_USRDEFID 0x1 /* user defined CA_SUNW_ID */ 210cdcc71c0SAli Bahrami 211cdcc71c0SAli Bahrami /* 21269112eddSAli Bahrami * Bitmasks for a single capability. Capabilities come from input objects, 21369112eddSAli Bahrami * augmented or replaced by mapfile directives. In addition, mapfile directives 21469112eddSAli Bahrami * can be used to exclude bits that would otherwise be set in the output object. 21569112eddSAli Bahrami */ 21669112eddSAli Bahrami typedef struct { 21769112eddSAli Bahrami elfcap_mask_t cm_value; /* Bitmask value */ 21869112eddSAli Bahrami elfcap_mask_t cm_exclude; /* Bits to remove from final object */ 21969112eddSAli Bahrami } CapMask; 22069112eddSAli Bahrami 22169112eddSAli Bahrami /* 22269112eddSAli Bahrami * Combine the bitmask in a CapMask with the exclusion mask and 22369112eddSAli Bahrami * return the resulting final value. 22469112eddSAli Bahrami */ 22569112eddSAli Bahrami #define CAPMASK_VALUE(_cbmp) ((_cbmp)->cm_value & ~(_cbmp)->cm_exclude) 22669112eddSAli Bahrami 22769112eddSAli Bahrami typedef struct { 22869112eddSAli Bahrami CapMask c_hw_1; /* CA_SUNW_HW_1 capabilities */ 22969112eddSAli Bahrami CapMask c_sf_1; /* CA_SUNW_SF_1 capabilities */ 23069112eddSAli Bahrami CapMask c_hw_2; /* CA_SUNW_HW_2 capabilities */ 23169112eddSAli Bahrami } Outcapset; 23269112eddSAli Bahrami 23369112eddSAli Bahrami 23469112eddSAli Bahrami /* 2357c478bd9Sstevel@tonic-gate * Output file processing structure 2367c478bd9Sstevel@tonic-gate */ 2371d9df23bSab196087 typedef Lword ofl_flag_t; 2387c478bd9Sstevel@tonic-gate struct ofl_desc { 2397c478bd9Sstevel@tonic-gate char *ofl_sgsid; /* link-editor identification */ 2407c478bd9Sstevel@tonic-gate const char *ofl_name; /* full file name */ 2417c478bd9Sstevel@tonic-gate Elf *ofl_elf; /* elf_memory() elf descriptor */ 2427c478bd9Sstevel@tonic-gate Elf *ofl_welf; /* ELF_C_WRITE elf descriptor */ 2435aefb655Srie Ehdr *ofl_dehdr; /* default elf header, and new elf */ 2445aefb655Srie Ehdr *ofl_nehdr; /* header describing this file */ 2457c478bd9Sstevel@tonic-gate Phdr *ofl_phdr; /* program header descriptor */ 2467c478bd9Sstevel@tonic-gate Phdr *ofl_tlsphdr; /* TLS phdr */ 2477c478bd9Sstevel@tonic-gate int ofl_fd; /* file descriptor */ 2487c478bd9Sstevel@tonic-gate size_t ofl_size; /* image size */ 24957ef7aa9SRod Evans APlist *ofl_maps; /* list of input mapfiles */ 25057ef7aa9SRod Evans APlist *ofl_segs; /* list of segments */ 25169112eddSAli Bahrami APlist *ofl_segs_order; /* SEGMENT_ORDER segments */ 25269112eddSAli Bahrami avl_tree_t ofl_segs_avl; /* O(log N) access to named segments */ 25369112eddSAli Bahrami APlist *ofl_ents; /* list of entrance descriptors */ 25469112eddSAli Bahrami avl_tree_t ofl_ents_avl; /* O(log N) access to named ent. desc */ 25557ef7aa9SRod Evans APlist *ofl_objs; /* relocatable object file list */ 2567c478bd9Sstevel@tonic-gate Word ofl_objscnt; /* and count */ 25757ef7aa9SRod Evans APlist *ofl_ars; /* archive library list */ 2587c478bd9Sstevel@tonic-gate Word ofl_arscnt; /* and count */ 259551cffe3SAli Bahrami int ofl_ars_gsandx; /* archive group argv index. 0 means */ 260551cffe3SAli Bahrami /* no current group, < 0 means */ 261551cffe3SAli Bahrami /* error reported. >0 is cur ndx */ 262551cffe3SAli Bahrami Word ofl_ars_gsndx; /* current -zrescan-start ofl_ars ndx */ 26357ef7aa9SRod Evans APlist *ofl_sos; /* shared object list */ 2647c478bd9Sstevel@tonic-gate Word ofl_soscnt; /* and count */ 26557ef7aa9SRod Evans APlist *ofl_soneed; /* list of implicitly required .so's */ 26657ef7aa9SRod Evans APlist *ofl_socntl; /* list of .so control definitions */ 26757ef7aa9SRod Evans APlist *ofl_outrels; /* list of output relocations */ 2687c478bd9Sstevel@tonic-gate Word ofl_outrelscnt; /* and count */ 26957ef7aa9SRod Evans APlist *ofl_actrels; /* list of relocations to perform */ 2707c478bd9Sstevel@tonic-gate Word ofl_actrelscnt; /* and count */ 271c174926fSrie Word ofl_entrelscnt; /* no of relocations entered */ 27257ef7aa9SRod Evans Alist *ofl_copyrels; /* list of copy relocations */ 27357ef7aa9SRod Evans APlist *ofl_ordered; /* list of shf_ordered sections */ 274635216b6SRod Evans APlist *ofl_symdtent; /* list of syminfo symbols that need */ 275635216b6SRod Evans /* to reference .dynamic entries */ 27657ef7aa9SRod Evans APlist *ofl_ismove; /* list of .SUNW_move sections */ 27757ef7aa9SRod Evans APlist *ofl_ismoverel; /* list of relocation input section */ 2787c478bd9Sstevel@tonic-gate /* targeting to expanded area */ 27957ef7aa9SRod Evans APlist *ofl_parsyms; /* list of partially initialized */ 28057ef7aa9SRod Evans /* symbols (ie. move symbols) */ 28157ef7aa9SRod Evans APlist *ofl_extrarels; /* relocation sections which have */ 2827c478bd9Sstevel@tonic-gate /* a NULL sh_info */ 283cc7efc4fSrie avl_tree_t *ofl_groups; /* pointer to head of Groups AVL tree */ 28457ef7aa9SRod Evans APlist *ofl_initarray; /* list of init array func names */ 28557ef7aa9SRod Evans APlist *ofl_finiarray; /* list of fini array func names */ 28657ef7aa9SRod Evans APlist *ofl_preiarray; /* list of preinit array func names */ 28757ef7aa9SRod Evans APlist *ofl_rtldinfo; /* list of rtldinfo syms */ 28857ef7aa9SRod Evans APlist *ofl_osgroups; /* list of output GROUP sections */ 28957ef7aa9SRod Evans APlist *ofl_ostlsseg; /* pointer to sections in TLS segment */ 2907e16fca0SAli Bahrami APlist *ofl_unwind; /* list of unwind output sections */ 2917c478bd9Sstevel@tonic-gate Os_desc *ofl_unwindhdr; /* Unwind hdr */ 2927c478bd9Sstevel@tonic-gate avl_tree_t ofl_symavl; /* pointer to head of Syms AVL tree */ 2937c478bd9Sstevel@tonic-gate Sym_desc **ofl_regsyms; /* array of potential register */ 2947c478bd9Sstevel@tonic-gate Word ofl_regsymsno; /* symbols and array count */ 2957c478bd9Sstevel@tonic-gate Word ofl_regsymcnt; /* no. of output register symbols */ 2967c478bd9Sstevel@tonic-gate Word ofl_lregsymcnt; /* no. of local register symbols */ 2977c478bd9Sstevel@tonic-gate Sym_desc *ofl_dtracesym; /* ld -zdtrace= */ 2981d9df23bSab196087 ofl_flag_t ofl_flags; /* various state bits, args etc. */ 2991d9df23bSab196087 ofl_flag_t ofl_flags1; /* more flags */ 3007c478bd9Sstevel@tonic-gate void *ofl_entry; /* entry point (-e and Sym_desc *) */ 3017c478bd9Sstevel@tonic-gate char *ofl_filtees; /* shared objects we are a filter for */ 3027c478bd9Sstevel@tonic-gate const char *ofl_soname; /* (-h option) output file name for */ 3037c478bd9Sstevel@tonic-gate /* dynamic structure */ 3047c478bd9Sstevel@tonic-gate const char *ofl_interp; /* interpreter name used by exec() */ 3057c478bd9Sstevel@tonic-gate char *ofl_rpath; /* run path to store in .dynamic */ 3067c478bd9Sstevel@tonic-gate char *ofl_config; /* config path to store in .dynamic */ 30757ef7aa9SRod Evans APlist *ofl_ulibdirs; /* user supplied library search list */ 30857ef7aa9SRod Evans APlist *ofl_dlibdirs; /* default library search list */ 3097c478bd9Sstevel@tonic-gate Word ofl_vercnt; /* number of versions to generate */ 31057ef7aa9SRod Evans APlist *ofl_verdesc; /* list of version descriptors */ 3117c478bd9Sstevel@tonic-gate size_t ofl_verdefsz; /* size of version definition section */ 3127c478bd9Sstevel@tonic-gate size_t ofl_verneedsz; /* size of version needed section */ 3137c478bd9Sstevel@tonic-gate Word ofl_entercnt; /* no. of global symbols entered */ 3147c478bd9Sstevel@tonic-gate Word ofl_globcnt; /* no. of global symbols to output */ 3157c478bd9Sstevel@tonic-gate Word ofl_scopecnt; /* no. of scoped symbols to output */ 3169039eeafSab196087 Word ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */ 3177c478bd9Sstevel@tonic-gate Word ofl_elimcnt; /* no. of eliminated symbols */ 3189039eeafSab196087 Word ofl_locscnt; /* no. of local symbols in .symtab */ 3199039eeafSab196087 Word ofl_dynlocscnt; /* no. local symbols in .SUNW_ldynsym */ 320d579eb63Sab196087 Word ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */ 321d579eb63Sab196087 Word ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */ 3227c478bd9Sstevel@tonic-gate Word ofl_dynshdrcnt; /* no. of output section in .dynsym */ 3237c478bd9Sstevel@tonic-gate Word ofl_shdrcnt; /* no. of output sections */ 32408278a5eSRod Evans Word ofl_caploclcnt; /* no. of local capabilities symbols */ 32508278a5eSRod Evans Word ofl_capsymcnt; /* no. of symbol capabilities entries */ 32608278a5eSRod Evans /* required */ 32708278a5eSRod Evans Word ofl_capchaincnt; /* no. of Capchain symbols */ 32808278a5eSRod Evans APlist *ofl_capgroups; /* list of capabilities groups */ 32908278a5eSRod Evans avl_tree_t *ofl_capfamilies; /* capability family AVL tree */ 3307c478bd9Sstevel@tonic-gate Str_tbl *ofl_shdrsttab; /* Str_tbl for shdr strtab */ 3317c478bd9Sstevel@tonic-gate Str_tbl *ofl_strtab; /* Str_tbl for symtab strtab */ 3327c478bd9Sstevel@tonic-gate Str_tbl *ofl_dynstrtab; /* Str_tbl for dymsym strtab */ 3337c478bd9Sstevel@tonic-gate Gotndx *ofl_tlsldgotndx; /* index to LD TLS_index structure */ 3347c478bd9Sstevel@tonic-gate Xword ofl_relocsz; /* size of output relocations */ 3357c478bd9Sstevel@tonic-gate Xword ofl_relocgotsz; /* size of .got relocations */ 3367c478bd9Sstevel@tonic-gate Xword ofl_relocpltsz; /* size of .plt relocations */ 3377c478bd9Sstevel@tonic-gate Xword ofl_relocbsssz; /* size of .bss (copy) relocations */ 3387c478bd9Sstevel@tonic-gate Xword ofl_relocrelsz; /* size of .rel[a] relocations */ 3397c478bd9Sstevel@tonic-gate Word ofl_relocincnt; /* no. of input relocations */ 3407c478bd9Sstevel@tonic-gate Word ofl_reloccnt; /* tot number of output relocations */ 3417c478bd9Sstevel@tonic-gate Word ofl_reloccntsub; /* tot numb of output relocations to */ 3427c478bd9Sstevel@tonic-gate /* skip (-zignore) */ 3437c478bd9Sstevel@tonic-gate Word ofl_relocrelcnt; /* tot number of relative */ 3447c478bd9Sstevel@tonic-gate /* relocations */ 3457c478bd9Sstevel@tonic-gate Word ofl_gotcnt; /* no. of .got entries */ 3467c478bd9Sstevel@tonic-gate Word ofl_pltcnt; /* no. of .plt entries */ 3477c478bd9Sstevel@tonic-gate Word ofl_pltpad; /* no. of .plt padd entries */ 3487c478bd9Sstevel@tonic-gate Word ofl_hashbkts; /* no. of hash buckets required */ 3497c478bd9Sstevel@tonic-gate Is_desc *ofl_isbss; /* .bss input section (globals) */ 35054d82594Sseizo Is_desc *ofl_islbss; /* .lbss input section (globals) */ 3517c478bd9Sstevel@tonic-gate Is_desc *ofl_istlsbss; /* .tlsbss input section (globals) */ 35235450702SAli Bahrami Is_desc *ofl_isparexpn; /* -z nopartial .data input section */ 3537c478bd9Sstevel@tonic-gate Os_desc *ofl_osdynamic; /* .dynamic output section */ 3547c478bd9Sstevel@tonic-gate Os_desc *ofl_osdynsym; /* .dynsym output section */ 3559039eeafSab196087 Os_desc *ofl_osldynsym; /* .SUNW_ldynsym output section */ 3567c478bd9Sstevel@tonic-gate Os_desc *ofl_osdynstr; /* .dynstr output section */ 357d579eb63Sab196087 Os_desc *ofl_osdynsymsort; /* .SUNW_dynsymsort output section */ 358d579eb63Sab196087 Os_desc *ofl_osdyntlssort; /* .SUNW_dyntlssort output section */ 3597c478bd9Sstevel@tonic-gate Os_desc *ofl_osgot; /* .got output section */ 3607c478bd9Sstevel@tonic-gate Os_desc *ofl_oshash; /* .hash output section */ 3617c478bd9Sstevel@tonic-gate Os_desc *ofl_osinitarray; /* .initarray output section */ 3627c478bd9Sstevel@tonic-gate Os_desc *ofl_osfiniarray; /* .finiarray output section */ 3637c478bd9Sstevel@tonic-gate Os_desc *ofl_ospreinitarray; /* .preinitarray output section */ 3647c478bd9Sstevel@tonic-gate Os_desc *ofl_osinterp; /* .interp output section */ 3657c478bd9Sstevel@tonic-gate Os_desc *ofl_oscap; /* .SUNW_cap output section */ 36608278a5eSRod Evans Os_desc *ofl_oscapinfo; /* .SUNW_capinfo output section */ 36708278a5eSRod Evans Os_desc *ofl_oscapchain; /* .SUNW_capchain output section */ 3687c478bd9Sstevel@tonic-gate Os_desc *ofl_osplt; /* .plt output section */ 3697c478bd9Sstevel@tonic-gate Os_desc *ofl_osmove; /* .SUNW_move output section */ 3707c478bd9Sstevel@tonic-gate Os_desc *ofl_osrelhead; /* first relocation section */ 3717c478bd9Sstevel@tonic-gate Os_desc *ofl_osrel; /* .rel[a] relocation section */ 3727c478bd9Sstevel@tonic-gate Os_desc *ofl_osshstrtab; /* .shstrtab output section */ 3737c478bd9Sstevel@tonic-gate Os_desc *ofl_osstrtab; /* .strtab output section */ 3747c478bd9Sstevel@tonic-gate Os_desc *ofl_ossymtab; /* .symtab output section */ 3757c478bd9Sstevel@tonic-gate Os_desc *ofl_ossymshndx; /* .symtab_shndx output section */ 3767c478bd9Sstevel@tonic-gate Os_desc *ofl_osdynshndx; /* .dynsym_shndx output section */ 3779039eeafSab196087 Os_desc *ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */ 3787c478bd9Sstevel@tonic-gate Os_desc *ofl_osverdef; /* .version definition output section */ 3797c478bd9Sstevel@tonic-gate Os_desc *ofl_osverneed; /* .version needed output section */ 3807c478bd9Sstevel@tonic-gate Os_desc *ofl_osversym; /* .version symbol ndx output section */ 3817c478bd9Sstevel@tonic-gate Word ofl_dtflags_1; /* DT_FLAGS_1 entries */ 3827c478bd9Sstevel@tonic-gate Word ofl_dtflags; /* DT_FLAGS entries */ 3837c478bd9Sstevel@tonic-gate Os_desc *ofl_ossyminfo; /* .SUNW_syminfo output section */ 38435450702SAli Bahrami Half ofl_parexpnndx; /* -z nopartial section index */ 3857c478bd9Sstevel@tonic-gate /* Ref. at perform_outreloc() in */ 3867c478bd9Sstevel@tonic-gate /* libld/{mach}/machrel.c */ 3877c478bd9Sstevel@tonic-gate Xword *ofl_checksum; /* DT_CHECKSUM value address */ 3887c478bd9Sstevel@tonic-gate char *ofl_depaudit; /* dependency auditing required (-P) */ 3897c478bd9Sstevel@tonic-gate char *ofl_audit; /* object auditing required (-p) */ 3907c478bd9Sstevel@tonic-gate Alist *ofl_symfltrs; /* per-symbol filtees and their */ 3917c478bd9Sstevel@tonic-gate Alist *ofl_dtsfltrs; /* associated .dynamic/.dynstrs */ 39208278a5eSRod Evans Objcapset ofl_ocapset; /* object capabilities */ 3935aefb655Srie Lm_list *ofl_lml; /* runtime link-map list */ 394d326b23bSrie Gottable *ofl_gottable; /* debugging got information */ 39540e53e87SAli Bahrami Rlxrel_cache ofl_sr_cache; /* Cache last result from */ 3966b3ba5bdSAli Bahrami /* sloppy_comdat_reloc() */ 39757ef7aa9SRod Evans APlist *ofl_maptext; /* mapfile added text sections */ 39857ef7aa9SRod Evans APlist *ofl_mapdata; /* mapfile added data sections */ 399cdcc71c0SAli Bahrami avl_tree_t *ofl_wrap; /* -z wrap symbols */ 4007c478bd9Sstevel@tonic-gate }; 4017c478bd9Sstevel@tonic-gate 4027c478bd9Sstevel@tonic-gate #define FLG_OF_DYNAMIC 0x00000001 /* generate dynamic output module */ 4037c478bd9Sstevel@tonic-gate #define FLG_OF_STATIC 0x00000002 /* generate static output module */ 4047c478bd9Sstevel@tonic-gate #define FLG_OF_EXEC 0x00000004 /* generate an executable */ 4057c478bd9Sstevel@tonic-gate #define FLG_OF_RELOBJ 0x00000008 /* generate a relocatable object */ 4067c478bd9Sstevel@tonic-gate #define FLG_OF_SHAROBJ 0x00000010 /* generate a shared object */ 4077c478bd9Sstevel@tonic-gate #define FLG_OF_BFLAG 0x00000020 /* do no special plt building: -b */ 4087c478bd9Sstevel@tonic-gate #define FLG_OF_IGNENV 0x00000040 /* ignore LD_LIBRARY_PATH: -i */ 4097c478bd9Sstevel@tonic-gate #define FLG_OF_STRIP 0x00000080 /* strip output: -s */ 4107c478bd9Sstevel@tonic-gate #define FLG_OF_NOWARN 0x00000100 /* disable symbol warnings: -t */ 4117c478bd9Sstevel@tonic-gate #define FLG_OF_NOUNDEF 0x00000200 /* allow no undefined symbols: -zdefs */ 4127c478bd9Sstevel@tonic-gate #define FLG_OF_PURETXT 0x00000400 /* allow no text relocations: -ztext */ 4137c478bd9Sstevel@tonic-gate #define FLG_OF_GENMAP 0x00000800 /* generate a memory map: -m */ 4147c478bd9Sstevel@tonic-gate #define FLG_OF_DYNLIBS 0x00001000 /* dynamic input allowed: -Bdynamic */ 4157c478bd9Sstevel@tonic-gate #define FLG_OF_SYMBOLIC 0x00002000 /* bind global symbols: -Bsymbolic */ 4167c478bd9Sstevel@tonic-gate #define FLG_OF_ADDVERS 0x00004000 /* add version stamp: -Qy */ 4179039eeafSab196087 #define FLG_OF_NOLDYNSYM 0x00008000 /* -znoldynsym set */ 41869112eddSAli Bahrami #define FLG_OF_IS_ORDER 0x00010000 /* input section ordering within a */ 41969112eddSAli Bahrami /* segment is required */ 42069112eddSAli Bahrami #define FLG_OF_EC_FILES 0x00020000 /* Ent_desc exist w/non-NULL ec_files */ 4217c478bd9Sstevel@tonic-gate #define FLG_OF_TEXTREL 0x00040000 /* text relocations have been found */ 4227c478bd9Sstevel@tonic-gate #define FLG_OF_MULDEFS 0x00080000 /* multiple symbols are allowed */ 423dd94ecefSrie #define FLG_OF_TLSPHDR 0x00100000 /* a TLS program header is required */ 4247c478bd9Sstevel@tonic-gate #define FLG_OF_BLDGOT 0x00200000 /* build GOT table */ 4257c478bd9Sstevel@tonic-gate #define FLG_OF_VERDEF 0x00400000 /* record version definitions */ 4267c478bd9Sstevel@tonic-gate #define FLG_OF_VERNEED 0x00800000 /* record version dependencies */ 4277c478bd9Sstevel@tonic-gate #define FLG_OF_NOVERSEC 0x01000000 /* don't record version sections */ 4280e233487SRod Evans #define FLG_OF_KEY 0x02000000 /* file requires sort keys */ 4297c478bd9Sstevel@tonic-gate #define FLG_OF_PROCRED 0x04000000 /* process any symbol reductions by */ 4307c478bd9Sstevel@tonic-gate /* effecting the symbol table */ 4317c478bd9Sstevel@tonic-gate /* output and relocations */ 4327c478bd9Sstevel@tonic-gate #define FLG_OF_SYMINFO 0x08000000 /* create a syminfo section */ 4337c478bd9Sstevel@tonic-gate #define FLG_OF_AUX 0x10000000 /* ofl_filter is an auxiliary filter */ 4347c478bd9Sstevel@tonic-gate #define FLG_OF_FATAL 0x20000000 /* fatal error during input */ 4357c478bd9Sstevel@tonic-gate #define FLG_OF_WARN 0x40000000 /* warning during input processing. */ 4367c478bd9Sstevel@tonic-gate #define FLG_OF_VERBOSE 0x80000000 /* -z verbose flag set */ 4377c478bd9Sstevel@tonic-gate 4389a411307Srie #define FLG_OF_MAPSYMB 0x000100000000 /* symbolic scope definition seen */ 4399a411307Srie #define FLG_OF_MAPGLOB 0x000200000000 /* global scope definition seen */ 440e38a713aSrie #define FLG_OF_COMREL 0x000400000000 /* -z combreloc set, which enables */ 441e38a713aSrie /* DT_RELACNT tracking, */ 442e38a713aSrie #define FLG_OF_NOCOMREL 0x000800000000 /* -z nocombreloc set */ 44344bac77bSrie #define FLG_OF_AUTOLCL 0x001000000000 /* automatically reduce unspecified */ 44444bac77bSrie /* global symbols to locals */ 44544bac77bSrie #define FLG_OF_AUTOELM 0x002000000000 /* automatically eliminate */ 44644bac77bSrie /* unspecified global symbols */ 44744bac77bSrie #define FLG_OF_REDLSYM 0x004000000000 /* reduce local symbols */ 44869112eddSAli Bahrami #define FLG_OF_OS_ORDER 0x008000000000 /* output section ordering required */ 449635216b6SRod Evans #define FLG_OF_OSABI 0x010000000000 /* tag object as ELFOSABI_SOLARIS */ 45008278a5eSRod Evans #define FLG_OF_ADJOSCNT 0x020000000000 /* adjust ofl_shdrcnt to accommodate */ 451e64d0ff9SAli Bahrami /* discarded sections */ 45208278a5eSRod Evans #define FLG_OF_OTOSCAP 0x040000000000 /* convert object capabilities to */ 45308278a5eSRod Evans /* symbol capabilities */ 45408278a5eSRod Evans #define FLG_OF_PTCAP 0x080000000000 /* PT_SUNWCAP required */ 45508278a5eSRod Evans #define FLG_OF_CAPSTRS 0x100000000000 /* capability strings are required */ 456*d444b03eSAli Bahrami #define FLG_OF_EHFRAME 0x200000000000 /* output contains .eh_frame section */ 4579a411307Srie 4587c478bd9Sstevel@tonic-gate /* 4597c478bd9Sstevel@tonic-gate * In the flags1 arena, establish any options that are applicable to archive 4607c478bd9Sstevel@tonic-gate * extraction first, and associate a mask. These values are recorded with any 4617c478bd9Sstevel@tonic-gate * archive descriptor so that they may be reset should the archive require a 4627c478bd9Sstevel@tonic-gate * rescan to try and resolve undefined symbols. 4637c478bd9Sstevel@tonic-gate */ 46469112eddSAli Bahrami #define FLG_OF1_ALLEXRT 0x0000000001 /* extract all members from an */ 4657c478bd9Sstevel@tonic-gate /* archive file */ 46669112eddSAli Bahrami #define FLG_OF1_WEAKEXT 0x0000000002 /* allow archive extraction to */ 4677c478bd9Sstevel@tonic-gate /* resolve weak references */ 46869112eddSAli Bahrami #define MSK_OF1_ARCHIVE 0x0000000003 /* archive flags mask */ 4697c478bd9Sstevel@tonic-gate 47069112eddSAli Bahrami #define FLG_OF1_NOINTRP 0x0000000008 /* -z nointerp flag set */ 47169112eddSAli Bahrami #define FLG_OF1_ZDIRECT 0x0000000010 /* -z direct flag set */ 47269112eddSAli Bahrami #define FLG_OF1_NDIRECT 0x0000000020 /* no-direct bindings specified */ 473e38a713aSrie 47469112eddSAli Bahrami #define FLG_OF1_RELDYN 0x0000000100 /* process .dynamic in rel obj */ 47569112eddSAli Bahrami #define FLG_OF1_NRLXREL 0x0000000200 /* -z norelaxreloc flag set */ 47669112eddSAli Bahrami #define FLG_OF1_RLXREL 0x0000000400 /* -z relaxreloc flag set */ 47769112eddSAli Bahrami #define FLG_OF1_IGNORE 0x0000000800 /* ignore unused dependencies */ 47869112eddSAli Bahrami #define FLG_OF1_NOSGHND 0x0000001000 /* -z nosighandler flag set */ 47969112eddSAli Bahrami #define FLG_OF1_TEXTOFF 0x0000002000 /* text relocations are ok */ 48069112eddSAli Bahrami #define FLG_OF1_ABSEXEC 0x0000004000 /* -zabsexec set */ 48169112eddSAli Bahrami #define FLG_OF1_LAZYLD 0x0000008000 /* lazy loading of objects enabled */ 48269112eddSAli Bahrami #define FLG_OF1_GRPPRM 0x0000010000 /* dependencies are to have */ 4837c478bd9Sstevel@tonic-gate /* GROUPPERM enabled */ 48469112eddSAli Bahrami #define FLG_OF1_OVRFLW 0x0000020000 /* size exceeds 32-bit limitation */ 4857c478bd9Sstevel@tonic-gate /* of 32-bit libld */ 48669112eddSAli Bahrami #define FLG_OF1_NOPARTI 0x0000040000 /* -znopartial set */ 48769112eddSAli Bahrami #define FLG_OF1_BSSOREL 0x0000080000 /* output relocation against bss */ 4887c478bd9Sstevel@tonic-gate /* section */ 48969112eddSAli Bahrami #define FLG_OF1_TLSOREL 0x0000100000 /* output relocation against .tlsbss */ 4907c478bd9Sstevel@tonic-gate /* section */ 49169112eddSAli Bahrami #define FLG_OF1_MEMORY 0x0000200000 /* produce a memory model */ 49269112eddSAli Bahrami #define FLG_OF1_NGLBDIR 0x0000400000 /* no DT_1_DIRECT flag allowed */ 49308278a5eSRod Evans #define FLG_OF1_ENCDIFF 0x0000800000 /* host running linker has different */ 494f3324781Sab196087 /* byte order than output object */ 49569112eddSAli Bahrami #define FLG_OF1_VADDR 0x0001000000 /* a segment defines explicit vaddr */ 49669112eddSAli Bahrami #define FLG_OF1_EXTRACT 0x0002000000 /* archive member has been extracted */ 49769112eddSAli Bahrami #define FLG_OF1_RESCAN 0x0004000000 /* any archives should be rescanned */ 49869112eddSAli Bahrami #define FLG_OF1_IGNPRC 0x0008000000 /* ignore processing required */ 49969112eddSAli Bahrami #define FLG_OF1_NCSTTAB 0x0010000000 /* -znocompstrtab set */ 50069112eddSAli Bahrami #define FLG_OF1_DONE 0x0020000000 /* link-editor processing complete */ 50169112eddSAli Bahrami #define FLG_OF1_NONREG 0x0040000000 /* non-regular file specified as */ 5027c478bd9Sstevel@tonic-gate /* the output file */ 50369112eddSAli Bahrami #define FLG_OF1_ALNODIR 0x0080000000 /* establish NODIRECT for all */ 5047c478bd9Sstevel@tonic-gate /* exported interfaces. */ 50569112eddSAli Bahrami #define FLG_OF1_OVHWCAP1 0x0100000000 /* override CA_SUNW_HW_1 capabilities */ 50669112eddSAli Bahrami #define FLG_OF1_OVSFCAP1 0x0200000000 /* override CA_SUNW_SF_1 capabilities */ 50769112eddSAli Bahrami #define FLG_OF1_OVHWCAP2 0x0400000000 /* override CA_SUNW_HW_2 capabilities */ 50808278a5eSRod Evans #define FLG_OF1_OVMACHCAP 0x0800000000 /* override CA_SUNW_MACH capability */ 50908278a5eSRod Evans #define FLG_OF1_OVPLATCAP 0x1000000000 /* override CA_SUNW_PLAT capability */ 51008278a5eSRod Evans #define FLG_OF1_OVIDCAP 0x2000000000 /* override CA_SUNW_ID capability */ 5117c478bd9Sstevel@tonic-gate 5127c478bd9Sstevel@tonic-gate /* 5139039eeafSab196087 * Test to see if the output file would allow the presence of 5149039eeafSab196087 * a .dynsym section. 5159039eeafSab196087 */ 516f3324781Sab196087 #define OFL_ALLOW_DYNSYM(_ofl) (((_ofl)->ofl_flags & \ 5179039eeafSab196087 (FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC) 5189039eeafSab196087 5199039eeafSab196087 /* 5209039eeafSab196087 * Test to see if the output file would allow the presence of 5219039eeafSab196087 * a .SUNW_ldynsym section. The requirements are that a .dynsym 5229039eeafSab196087 * is allowed, and -znoldynsym has not been specified. Note that 5239039eeafSab196087 * even if the answer is True (1), we will only generate one if there 5249039eeafSab196087 * are local symbols that require it. 5259039eeafSab196087 */ 526f3324781Sab196087 #define OFL_ALLOW_LDYNSYM(_ofl) (((_ofl)->ofl_flags & \ 5279039eeafSab196087 (FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC) 5289039eeafSab196087 5299039eeafSab196087 /* 530f3324781Sab196087 * Test to see if relocation processing should be done. This is normally 531f3324781Sab196087 * true, but can be disabled via the '-z noreloc' option. Note that 532f3324781Sab196087 * relocatable objects are still relocated even if '-z noreloc' is present. 533f3324781Sab196087 */ 534f3324781Sab196087 #define OFL_DO_RELOC(_ofl) (((_ofl)->ofl_flags & FLG_OF_RELOBJ) || \ 535f3324781Sab196087 !((_ofl)->ofl_dtflags_1 & DF_1_NORELOC)) 536f3324781Sab196087 537f3324781Sab196087 /* 538635216b6SRod Evans * Determine whether a static executable is being built. 539635216b6SRod Evans */ 540635216b6SRod Evans #define OFL_IS_STATIC_EXEC(_ofl) (((_ofl)->ofl_flags & \ 541635216b6SRod Evans (FLG_OF_STATIC | FLG_OF_EXEC)) == (FLG_OF_STATIC | FLG_OF_EXEC)) 542635216b6SRod Evans 543635216b6SRod Evans /* 544635216b6SRod Evans * Determine whether a static object is being built. This macro is used 545635216b6SRod Evans * to select the appropriate string table, and symbol table that other 546635216b6SRod Evans * sections need to reference. 547635216b6SRod Evans */ 548635216b6SRod Evans #define OFL_IS_STATIC_OBJ(_ofl) ((_ofl)->ofl_flags & \ 549635216b6SRod Evans (FLG_OF_RELOBJ | FLG_OF_STATIC)) 550635216b6SRod Evans 551635216b6SRod Evans /* 552635216b6SRod Evans * Macros for counting symbol table entries. These are used to size symbol 553635216b6SRod Evans * tables and associated sections (.syminfo, SUNW_capinfo, .hash, etc.) and 554635216b6SRod Evans * set required sh_info entries (the offset to the first global symbol). 555635216b6SRod Evans */ 556635216b6SRod Evans #define SYMTAB_LOC_CNT(_ofl) /* local .symtab entries */ \ 557635216b6SRod Evans (2 + /* NULL and STT_FILE */ \ 558635216b6SRod Evans (_ofl)->ofl_shdrcnt + /* section symbol */ \ 55908278a5eSRod Evans (_ofl)->ofl_caploclcnt + /* local capabilities */ \ 560635216b6SRod Evans (_ofl)->ofl_scopecnt + /* scoped symbols */ \ 561635216b6SRod Evans (_ofl)->ofl_locscnt) /* standard locals */ 562635216b6SRod Evans #define SYMTAB_ALL_CNT(_ofl) /* all .symtab entries */ \ 563635216b6SRod Evans (SYMTAB_LOC_CNT(_ofl) + /* .symtab locals */ \ 564635216b6SRod Evans (_ofl)->ofl_globcnt) /* standard globals */ 565635216b6SRod Evans 566635216b6SRod Evans #define DYNSYM_LOC_CNT(_ofl) /* local .dynsym entries */ \ 567635216b6SRod Evans (1 + /* NULL */ \ 568635216b6SRod Evans (_ofl)->ofl_dynshdrcnt + /* section symbols */ \ 56908278a5eSRod Evans (_ofl)->ofl_caploclcnt + /* local capabilities */ \ 570635216b6SRod Evans (_ofl)->ofl_lregsymcnt) /* local register symbols */ 571635216b6SRod Evans #define DYNSYM_ALL_CNT(_ofl) /* all .dynsym entries */ \ 572635216b6SRod Evans (DYNSYM_LOC_CNT(_ofl) + /* .dynsym locals */ \ 573635216b6SRod Evans (_ofl)->ofl_globcnt) /* standard globals */ 574635216b6SRod Evans 575635216b6SRod Evans /* 57657ef7aa9SRod Evans * Define a move descriptor used within relocation structures. 57757ef7aa9SRod Evans */ 57857ef7aa9SRod Evans typedef struct { 57957ef7aa9SRod Evans Move *mr_move; 58057ef7aa9SRod Evans Sym_desc *mr_sym; 58157ef7aa9SRod Evans } Mv_reloc; 58257ef7aa9SRod Evans 58357ef7aa9SRod Evans /* 5847c478bd9Sstevel@tonic-gate * Relocation (active & output) processing structure - transparent to common 5857c478bd9Sstevel@tonic-gate * code. 586cce0e03bSab196087 * 587cce0e03bSab196087 * Note that rel_raddend is primarily only of interest to RELA relocations, 588cce0e03bSab196087 * and is set to 0 for REL. However, there is an exception: If FLG_REL_NADDEND 589cce0e03bSab196087 * is set, then rel_raddend contains a replacement value for the implicit 590cce0e03bSab196087 * addend found in the relocation target. 5917c478bd9Sstevel@tonic-gate */ 5927c478bd9Sstevel@tonic-gate struct rel_desc { 5937c478bd9Sstevel@tonic-gate Os_desc *rel_osdesc; /* output section reloc is against */ 5947c478bd9Sstevel@tonic-gate Is_desc *rel_isdesc; /* input section reloc is against */ 5957c478bd9Sstevel@tonic-gate const char *rel_sname; /* symbol name (may be "unknown") */ 5967c478bd9Sstevel@tonic-gate Sym_desc *rel_sym; /* sym relocation is against */ 5977c478bd9Sstevel@tonic-gate Sym_desc *rel_usym; /* strong sym if this is a weak pair */ 59857ef7aa9SRod Evans Mv_reloc *rel_move; /* move table information */ 5997c478bd9Sstevel@tonic-gate Word rel_flags; /* misc. flags for relocations */ 6007c478bd9Sstevel@tonic-gate Word rel_rtype; /* relocation type */ 6017c478bd9Sstevel@tonic-gate Xword rel_roffset; /* relocation offset */ 6027c478bd9Sstevel@tonic-gate Sxword rel_raddend; /* addend from input relocation */ 6037c478bd9Sstevel@tonic-gate Word rel_typedata; /* ELF_R_TYPE_DATA(info) */ 6047c478bd9Sstevel@tonic-gate }; 6057c478bd9Sstevel@tonic-gate 6067c478bd9Sstevel@tonic-gate /* 6077c478bd9Sstevel@tonic-gate * common flags used on the Rel_desc structure (defined in machrel.h). 6087c478bd9Sstevel@tonic-gate */ 6097c478bd9Sstevel@tonic-gate #define FLG_REL_GOT 0x00000001 /* relocation against GOT */ 6107c478bd9Sstevel@tonic-gate #define FLG_REL_PLT 0x00000002 /* relocation against PLT */ 6117c478bd9Sstevel@tonic-gate #define FLG_REL_BSS 0x00000004 /* relocation against BSS */ 6127c478bd9Sstevel@tonic-gate #define FLG_REL_LOAD 0x00000008 /* section loadable */ 6137c478bd9Sstevel@tonic-gate #define FLG_REL_SCNNDX 0x00000010 /* use section index for symbol ndx */ 6147c478bd9Sstevel@tonic-gate #define FLG_REL_CLVAL 0x00000020 /* clear VALUE for active relocation */ 6157c478bd9Sstevel@tonic-gate #define FLG_REL_ADVAL 0x00000040 /* add VALUE for output relocation, */ 61663360950Smp204432 /* only relevant to SPARC and */ 6177c478bd9Sstevel@tonic-gate /* R_SPARC_RELATIVE */ 6187c478bd9Sstevel@tonic-gate #define FLG_REL_GOTCL 0x00000080 /* clear the GOT entry. This is */ 6197c478bd9Sstevel@tonic-gate /* relevant to RELA relocations, */ 6207c478bd9Sstevel@tonic-gate /* not REL (i386) relocations */ 6217c478bd9Sstevel@tonic-gate #define FLG_REL_MOVETAB 0x00000100 /* Relocation against .SUNW_move */ 6227c478bd9Sstevel@tonic-gate /* adjustments required before */ 6237c478bd9Sstevel@tonic-gate /* actual relocation */ 6247c478bd9Sstevel@tonic-gate #define FLG_REL_NOINFO 0x00000200 /* Relocation comes from a section */ 6257c478bd9Sstevel@tonic-gate /* with a null sh_info field */ 6267c478bd9Sstevel@tonic-gate #define FLG_REL_REG 0x00000400 /* Relocation target is reg sym */ 6277c478bd9Sstevel@tonic-gate #define FLG_REL_FPTR 0x00000800 /* relocation against func. desc. */ 6287c478bd9Sstevel@tonic-gate #define FLG_REL_RFPTR1 0x00001000 /* Relative relocation against */ 6297c478bd9Sstevel@tonic-gate /* 1st part of FD */ 6307c478bd9Sstevel@tonic-gate #define FLG_REL_RFPTR2 0x00002000 /* Relative relocation against */ 6317c478bd9Sstevel@tonic-gate /* 2nd part of FD */ 6327c478bd9Sstevel@tonic-gate #define FLG_REL_DISP 0x00004000 /* *disp* relocation */ 6337c478bd9Sstevel@tonic-gate #define FLG_REL_STLS 0x00008000 /* IE TLS reference to */ 6347c478bd9Sstevel@tonic-gate /* static TLS GOT index */ 6357c478bd9Sstevel@tonic-gate #define FLG_REL_DTLS 0x00010000 /* GD TLS reference relative to */ 6367c478bd9Sstevel@tonic-gate /* dynamic TLS GOT index */ 6377c478bd9Sstevel@tonic-gate #define FLG_REL_MTLS 0x00020000 /* LD TLS reference against GOT */ 6387c478bd9Sstevel@tonic-gate #define FLG_REL_STTLS 0x00040000 /* LE TLS reference directly */ 6397c478bd9Sstevel@tonic-gate /* to static tls index */ 6407c478bd9Sstevel@tonic-gate #define FLG_REL_TLSFIX 0x00080000 /* relocation points to TLS instr. */ 6417c478bd9Sstevel@tonic-gate /* which needs updating */ 64257ef7aa9SRod Evans #define FLG_REL_RELA 0x00100000 /* descriptor captures a Rela */ 6437c478bd9Sstevel@tonic-gate #define FLG_REL_GOTFIX 0x00200000 /* relocation points to GOTOP instr. */ 6447c478bd9Sstevel@tonic-gate /* which needs updating */ 645cce0e03bSab196087 #define FLG_REL_NADDEND 0x00400000 /* Replace implicit addend in dest */ 646cce0e03bSab196087 /* with value in rel_raddend */ 647cce0e03bSab196087 /* Relevant to REL (i386) */ 648cce0e03bSab196087 /* relocations, not to RELA. */ 6497c478bd9Sstevel@tonic-gate 6507c478bd9Sstevel@tonic-gate /* 6517c478bd9Sstevel@tonic-gate * Structure to hold a cache of Relocations. 6527c478bd9Sstevel@tonic-gate */ 6537c478bd9Sstevel@tonic-gate struct rel_cache { 6547c478bd9Sstevel@tonic-gate Rel_desc *rc_end; 6557c478bd9Sstevel@tonic-gate Rel_desc *rc_free; 6567c478bd9Sstevel@tonic-gate }; 6577c478bd9Sstevel@tonic-gate 6587c478bd9Sstevel@tonic-gate /* 6597c478bd9Sstevel@tonic-gate * Symbol value descriptor. For relocatable objects, each symbols value is 6607c478bd9Sstevel@tonic-gate * its offset within its associated section. Therefore, to uniquely define 6617c478bd9Sstevel@tonic-gate * each symbol within a reloctable object, record and sort the sh_offset and 66208278a5eSRod Evans * symbol value. This information is used to search for displacement 6637c478bd9Sstevel@tonic-gate * relocations as part of copy relocation validation. 6647c478bd9Sstevel@tonic-gate */ 6657c478bd9Sstevel@tonic-gate typedef struct { 6667c478bd9Sstevel@tonic-gate Addr ssv_value; 6677c478bd9Sstevel@tonic-gate Sym_desc *ssv_sdp; 6687c478bd9Sstevel@tonic-gate } Ssv_desc; 6697c478bd9Sstevel@tonic-gate 6707c478bd9Sstevel@tonic-gate /* 6717c478bd9Sstevel@tonic-gate * Input file processing structures. 6727c478bd9Sstevel@tonic-gate */ 6737c478bd9Sstevel@tonic-gate struct ifl_desc { /* input file descriptor */ 6747c478bd9Sstevel@tonic-gate const char *ifl_name; /* full file name */ 6757c478bd9Sstevel@tonic-gate const char *ifl_soname; /* shared object name */ 6767c478bd9Sstevel@tonic-gate dev_t ifl_stdev; /* device id and inode number for .so */ 6777c478bd9Sstevel@tonic-gate ino_t ifl_stino; /* multiple inclusion checks */ 6787c478bd9Sstevel@tonic-gate Ehdr *ifl_ehdr; /* elf header describing this file */ 6797c478bd9Sstevel@tonic-gate Elf *ifl_elf; /* elf descriptor for this file */ 6807c478bd9Sstevel@tonic-gate Sym_desc **ifl_oldndx; /* original symbol table indices */ 6817c478bd9Sstevel@tonic-gate Sym_desc *ifl_locs; /* symbol desc version of locals */ 6827c478bd9Sstevel@tonic-gate Ssv_desc *ifl_sortsyms; /* sorted list of symbols by value */ 6837c478bd9Sstevel@tonic-gate Word ifl_locscnt; /* no. of local symbols to process */ 6847c478bd9Sstevel@tonic-gate Word ifl_symscnt; /* total no. of symbols to process */ 6857c478bd9Sstevel@tonic-gate Word ifl_sortcnt; /* no. of sorted symbols to process */ 6867c478bd9Sstevel@tonic-gate Word ifl_shnum; /* number of sections in file */ 6877c478bd9Sstevel@tonic-gate Word ifl_shstrndx; /* index to .shstrtab */ 6887c478bd9Sstevel@tonic-gate Word ifl_vercnt; /* number of versions in file */ 68957ef7aa9SRod Evans Half ifl_neededndx; /* index to NEEDED in .dyn section */ 69028bda19cSRod Evans Word ifl_flags; /* explicit/implicit reference */ 6917c478bd9Sstevel@tonic-gate Is_desc **ifl_isdesc; /* isdesc[scn ndx] = Is_desc ptr */ 6927c478bd9Sstevel@tonic-gate Sdf_desc *ifl_sdfdesc; /* control definition */ 6937c478bd9Sstevel@tonic-gate Versym *ifl_versym; /* version symbol table array */ 6947c478bd9Sstevel@tonic-gate Ver_index *ifl_verndx; /* verndx[ver ndx] = Ver_index */ 69557ef7aa9SRod Evans APlist *ifl_verdesc; /* version descriptor list */ 69657ef7aa9SRod Evans APlist *ifl_relsect; /* relocation section list */ 697cc7efc4fSrie Alist *ifl_groups; /* SHT_GROUP section list */ 69808278a5eSRod Evans Cap_desc *ifl_caps; /* capabilities descriptor */ 6997c478bd9Sstevel@tonic-gate }; 7007c478bd9Sstevel@tonic-gate 701d840867fSab196087 #define FLG_IF_CMDLINE 0x00000001 /* full filename specified from the */ 7027c478bd9Sstevel@tonic-gate /* command line (no -l) */ 703d840867fSab196087 #define FLG_IF_NEEDED 0x00000002 /* shared object should be recorded */ 704d840867fSab196087 #define FLG_IF_DIRECT 0x00000004 /* establish direct bindings to this */ 7057c478bd9Sstevel@tonic-gate /* object */ 706d840867fSab196087 #define FLG_IF_EXTRACT 0x00000008 /* file extracted from an archive */ 707d840867fSab196087 #define FLG_IF_VERNEED 0x00000010 /* version dependency information is */ 7087c478bd9Sstevel@tonic-gate /* required */ 709d840867fSab196087 #define FLG_IF_DEPREQD 0x00000020 /* dependency is required to satisfy */ 7107c478bd9Sstevel@tonic-gate /* symbol references */ 711d840867fSab196087 #define FLG_IF_NEEDSTR 0x00000040 /* dependency specified by -Nn */ 7127c478bd9Sstevel@tonic-gate /* flag */ 713d840867fSab196087 #define FLG_IF_IGNORE 0x00000080 /* ignore unused dependencies */ 714d840867fSab196087 #define FLG_IF_NODIRECT 0x00000100 /* object contains symbols that */ 715635216b6SRod Evans /* cannot be directly bound to */ 716d840867fSab196087 #define FLG_IF_LAZYLD 0x00000200 /* bindings to this object should be */ 7177c478bd9Sstevel@tonic-gate /* lazy loaded */ 718d840867fSab196087 #define FLG_IF_GRPPRM 0x00000400 /* this dependency should have the */ 7197c478bd9Sstevel@tonic-gate /* DF_P1_GROUPPERM flag set */ 720d840867fSab196087 #define FLG_IF_DISPPEND 0x00000800 /* displacement relocation done */ 7217c478bd9Sstevel@tonic-gate /* in the ld time. */ 722d840867fSab196087 #define FLG_IF_DISPDONE 0x00001000 /* displacement relocation done */ 7237c478bd9Sstevel@tonic-gate /* at the run time */ 724d840867fSab196087 #define FLG_IF_MAPFILE 0x00002000 /* file is a mapfile */ 725d840867fSab196087 #define FLG_IF_HSTRTAB 0x00004000 /* file has a string section */ 726d840867fSab196087 #define FLG_IF_FILEREF 0x00008000 /* file contains a section which */ 7277c478bd9Sstevel@tonic-gate /* is included in the output */ 7287c478bd9Sstevel@tonic-gate /* allocatable image */ 729d840867fSab196087 #define FLG_IF_GNUVER 0x00010000 /* file used GNU-style versioning */ 7300e233487SRod Evans #define FLG_IF_ORDERED 0x00020000 /* ordered section processing */ 7310e233487SRod Evans /* required */ 73208278a5eSRod Evans #define FLG_IF_OTOSCAP 0x00040000 /* convert object capabilities to */ 73308278a5eSRod Evans /* symbol capabilities */ 7347c478bd9Sstevel@tonic-gate 7357c478bd9Sstevel@tonic-gate struct is_desc { /* input section descriptor */ 7360e233487SRod Evans const char *is_name; /* original section name */ 7377c478bd9Sstevel@tonic-gate Shdr *is_shdr; /* the elf section header */ 7387c478bd9Sstevel@tonic-gate Ifl_desc *is_file; /* infile desc for this section */ 7397c478bd9Sstevel@tonic-gate Os_desc *is_osdesc; /* new output section for this */ 7407c478bd9Sstevel@tonic-gate /* input section */ 7417c478bd9Sstevel@tonic-gate Elf_Data *is_indata; /* input sections raw data */ 7427c478bd9Sstevel@tonic-gate Is_desc *is_symshndx; /* related SHT_SYM_SHNDX section */ 7436b3ba5bdSAli Bahrami Is_desc *is_comdatkeep; /* If COMDAT section is discarded, */ 7446b3ba5bdSAli Bahrami /* this is section that was kept */ 7457c478bd9Sstevel@tonic-gate Word is_scnndx; /* original section index in file */ 74608278a5eSRod Evans Word is_ordndx; /* index for section. Used to decide */ 7477c478bd9Sstevel@tonic-gate /* where to insert section when */ 7487c478bd9Sstevel@tonic-gate /* reordering sections */ 7491dd9d86fSAli Bahrami Word is_keyident; /* key for SHF_{ORDERED|LINK_ORDER} */ 7501dd9d86fSAli Bahrami /* processing and ident used for */ 7510e233487SRod Evans /* placing/ordering sections */ 7520e233487SRod Evans Word is_flags; /* Various flags */ 7537c478bd9Sstevel@tonic-gate }; 7547c478bd9Sstevel@tonic-gate 7550e233487SRod Evans #define FLG_IS_ORDERED 0x0001 /* this is a SHF_ORDERED section */ 7560e233487SRod Evans #define FLG_IS_KEY 0x0002 /* section requires sort keys */ 7577c478bd9Sstevel@tonic-gate #define FLG_IS_DISCARD 0x0004 /* section is to be discarded */ 7587c478bd9Sstevel@tonic-gate #define FLG_IS_RELUPD 0x0008 /* symbol defined here may have moved */ 7597c478bd9Sstevel@tonic-gate #define FLG_IS_SECTREF 0x0010 /* section has been referenced */ 7607c478bd9Sstevel@tonic-gate #define FLG_IS_GDATADEF 0x0020 /* section contains global data sym */ 76169112eddSAli Bahrami #define FLG_IS_EXTERNAL 0x0040 /* isp from a user file */ 762cce0e03bSab196087 #define FLG_IS_INSTRMRG 0x0080 /* Usable SHF_MERGE|SHF_STRINGS sec */ 763cce0e03bSab196087 #define FLG_IS_GNSTRMRG 0x0100 /* Generated mergeable string section */ 7640e233487SRod Evans #define FLG_IS_GROUPS 0x0200 /* section has groups to process */ 7650e233487SRod Evans #define FLG_IS_PLACE 0x0400 /* section requires to be placed */ 7660e233487SRod Evans #define FLG_IS_COMDAT 0x0800 /* section is COMDAT */ 7677e16fca0SAli Bahrami #define FLG_IS_EHFRAME 0x1000 /* section is .eh_frame */ 7687c478bd9Sstevel@tonic-gate 7697c478bd9Sstevel@tonic-gate /* 7701dd9d86fSAli Bahrami * Output sections contain lists of input sections that are assigned to them. 7711dd9d86fSAli Bahrami * These items fall into 4 categories: 7721dd9d86fSAli Bahrami * BEFORE - Ordered sections that specify SHN_BEFORE, in input order. 7731dd9d86fSAli Bahrami * ORDERED - Ordered sections that are sorted using unsorted sections 7741dd9d86fSAli Bahrami * as the sort key. 7751dd9d86fSAli Bahrami * DEFAULT - Sections that are placed into the output section 7761dd9d86fSAli Bahrami * in input order. 7771dd9d86fSAli Bahrami * AFTER - Ordered sections that specify SHN_AFTER, in input order. 7781dd9d86fSAli Bahrami */ 7791dd9d86fSAli Bahrami #define OS_ISD_BEFORE 0 7801dd9d86fSAli Bahrami #define OS_ISD_ORDERED 1 7811dd9d86fSAli Bahrami #define OS_ISD_DEFAULT 2 7821dd9d86fSAli Bahrami #define OS_ISD_AFTER 3 7831dd9d86fSAli Bahrami #define OS_ISD_NUM 4 7841dd9d86fSAli Bahrami typedef APlist *os_isdecs_arr[OS_ISD_NUM]; 7851dd9d86fSAli Bahrami 7861dd9d86fSAli Bahrami /* 7871dd9d86fSAli Bahrami * Convenience macro for traversing every input section associated 7881dd9d86fSAli Bahrami * with a given output section. The primary benefit of this macro 7891dd9d86fSAli Bahrami * is that it preserves a precious level of code indentation in the 7901dd9d86fSAli Bahrami * code that uses it. 7911dd9d86fSAli Bahrami */ 7921dd9d86fSAli Bahrami #define OS_ISDESCS_TRAVERSE(_list_idx, _osp, _idx, _isp) \ 7931dd9d86fSAli Bahrami for (_list_idx = 0; _list_idx < OS_ISD_NUM; _list_idx++) \ 7941dd9d86fSAli Bahrami for (APLIST_TRAVERSE(_osp->os_isdescs[_list_idx], _idx, _isp)) 7951dd9d86fSAli Bahrami 7961dd9d86fSAli Bahrami 7971dd9d86fSAli Bahrami /* 7987c478bd9Sstevel@tonic-gate * Map file and output file processing structures 7997c478bd9Sstevel@tonic-gate */ 8007c478bd9Sstevel@tonic-gate struct os_desc { /* Output section descriptor */ 8017c478bd9Sstevel@tonic-gate const char *os_name; /* the section name */ 8027c478bd9Sstevel@tonic-gate Elf_Scn *os_scn; /* the elf section descriptor */ 8037c478bd9Sstevel@tonic-gate Shdr *os_shdr; /* the elf section header */ 8047c478bd9Sstevel@tonic-gate Os_desc *os_relosdesc; /* the output relocation section */ 8056b3ba5bdSAli Bahrami APlist *os_relisdescs; /* reloc input section descriptors */ 8067c478bd9Sstevel@tonic-gate /* for this output section */ 8071dd9d86fSAli Bahrami os_isdecs_arr os_isdescs; /* lists of input sections in output */ 808cce0e03bSab196087 APlist *os_mstrisdescs; /* FLG_IS_INSTRMRG input sections */ 8097c478bd9Sstevel@tonic-gate Sg_desc *os_sgdesc; /* segment os_desc is placed on */ 8107c478bd9Sstevel@tonic-gate Elf_Data *os_outdata; /* output sections raw data */ 8116b3ba5bdSAli Bahrami avl_tree_t *os_comdats; /* AVL tree of COMDAT input sections */ 8126b3ba5bdSAli Bahrami /* associated to output section */ 81357ef7aa9SRod Evans Word os_identndx; /* section identifier for input */ 81457ef7aa9SRod Evans /* section processing, followed */ 81557ef7aa9SRod Evans /* by section symbol index */ 81657ef7aa9SRod Evans Word os_ordndx; /* index for section. Used to decide */ 8177c478bd9Sstevel@tonic-gate /* where to insert section when */ 8187c478bd9Sstevel@tonic-gate /* reordering sections */ 8197c478bd9Sstevel@tonic-gate Xword os_szoutrels; /* size of output relocation section */ 8207c478bd9Sstevel@tonic-gate uint_t os_namehash; /* hash on section name */ 8217c478bd9Sstevel@tonic-gate uchar_t os_flags; /* various flags */ 8227c478bd9Sstevel@tonic-gate }; 8237c478bd9Sstevel@tonic-gate 8240e233487SRod Evans #define FLG_OS_KEY 0x01 /* section requires sort keys */ 8257c478bd9Sstevel@tonic-gate #define FLG_OS_OUTREL 0x02 /* output rel against this section */ 826dd94ecefSrie #define FLG_OS_SECTREF 0x04 /* isps are not affected by -zignore */ 827*d444b03eSAli Bahrami #define FLG_OS_EHFRAME 0x08 /* section is .eh_frame */ 8287c478bd9Sstevel@tonic-gate 8297c478bd9Sstevel@tonic-gate /* 83069112eddSAli Bahrami * The sg_id field of the segment descriptor is used to establish the default 83169112eddSAli Bahrami * order for program headers and segments in the output object. Segments are 83269112eddSAli Bahrami * ordered according to the following SGID values that classify them based on 83369112eddSAli Bahrami * their attributes. The initial set of built in segments are in this order, 83469112eddSAli Bahrami * and new mapfile defined segments are inserted into these groups. Within a 83569112eddSAli Bahrami * given SGID group, the position of new segments depends on the syntax 83669112eddSAli Bahrami * version of the mapfile that creates them. Version 1 (original sysv) 83769112eddSAli Bahrami * mapfiles place the new segment at the head of their group (reverse creation 83869112eddSAli Bahrami * order). The newer syntax places them at the end, following the others 83969112eddSAli Bahrami * (creation order). 84069112eddSAli Bahrami * 84169112eddSAli Bahrami * Note that any new segments must always be added after PT_PHDR and 84269112eddSAli Bahrami * PT_INTERP (refer Generic ABI, Page 5-4). 84357ef7aa9SRod Evans */ 84469112eddSAli Bahrami #define SGID_PHDR 0 /* PT_PHDR */ 84569112eddSAli Bahrami #define SGID_INTERP 1 /* PT_INTERP */ 84669112eddSAli Bahrami #define SGID_SUNWCAP 2 /* PT_SUNWCAP */ 84769112eddSAli Bahrami #define SGID_TEXT 3 /* PT_LOAD */ 84869112eddSAli Bahrami #define SGID_DATA 4 /* PT_LOAD */ 84969112eddSAli Bahrami #define SGID_BSS 5 /* PT_LOAD */ 85057ef7aa9SRod Evans #if defined(_ELF64) 85169112eddSAli Bahrami #define SGID_LRODATA 6 /* PT_LOAD (amd64-only) */ 85269112eddSAli Bahrami #define SGID_LDATA 7 /* PT_LOAD (amd64-only) */ 85357ef7aa9SRod Evans #endif 85469112eddSAli Bahrami #define SGID_TEXT_EMPTY 8 /* PT_LOAD, reserved (?E in version 1 syntax) */ 85569112eddSAli Bahrami #define SGID_NULL_EMPTY 9 /* PT_NULL, reserved (?E in version 1 syntax) */ 85669112eddSAli Bahrami #define SGID_DYN 10 /* PT_DYNAMIC */ 85769112eddSAli Bahrami #define SGID_DTRACE 11 /* PT_SUNWDTRACE */ 85869112eddSAli Bahrami #define SGID_TLS 12 /* PT_TLS */ 85969112eddSAli Bahrami #define SGID_UNWIND 13 /* PT_SUNW_UNWIND */ 86069112eddSAli Bahrami #define SGID_SUNWSTACK 14 /* PT_SUNWSTACK */ 86169112eddSAli Bahrami #define SGID_NOTE 15 /* PT_NOTE */ 86269112eddSAli Bahrami #define SGID_NULL 16 /* PT_NULL, mapfile defined empty phdr slots */ 86369112eddSAli Bahrami /* for use by post processors */ 86469112eddSAli Bahrami #define SGID_EXTRA 17 /* PT_NULL (final catchall) */ 86557ef7aa9SRod Evans 86669112eddSAli Bahrami typedef Half sg_flags_t; 8677c478bd9Sstevel@tonic-gate struct sg_desc { /* output segment descriptor */ 86869112eddSAli Bahrami Word sg_id; /* segment identifier (for sorting) */ 8697c478bd9Sstevel@tonic-gate Phdr sg_phdr; /* segment header for output file */ 87069112eddSAli Bahrami const char *sg_name; /* segment name for PT_LOAD, PT_NOTE, */ 87169112eddSAli Bahrami /* and PT_NULL, otherwise NULL */ 8727c478bd9Sstevel@tonic-gate Xword sg_round; /* data rounding required (mapfile) */ 8737c478bd9Sstevel@tonic-gate Xword sg_length; /* maximum segment length; if 0 */ 8747c478bd9Sstevel@tonic-gate /* segment is not specified */ 875cce0e03bSab196087 APlist *sg_osdescs; /* list of output section descriptors */ 87669112eddSAli Bahrami APlist *sg_is_order; /* list of entry criteria */ 87769112eddSAli Bahrami /* giving input section order */ 87869112eddSAli Bahrami Alist *sg_os_order; /* list specifying output section */ 87969112eddSAli Bahrami /* ordering for the segment */ 88069112eddSAli Bahrami sg_flags_t sg_flags; 88169112eddSAli Bahrami APlist *sg_sizesym; /* size symbols for this segment */ 88269112eddSAli Bahrami Xword sg_align; /* LCM of sh_addralign */ 8837c478bd9Sstevel@tonic-gate Elf_Scn *sg_fscn; /* the SCN of the first section. */ 88469112eddSAli Bahrami avl_node_t sg_avlnode; /* AVL book-keeping */ 8857c478bd9Sstevel@tonic-gate }; 8867c478bd9Sstevel@tonic-gate 88769112eddSAli Bahrami #define FLG_SG_P_VADDR 0x0001 /* p_vaddr segment attribute set */ 88869112eddSAli Bahrami #define FLG_SG_P_PADDR 0x0002 /* p_paddr segment attribute set */ 8897c478bd9Sstevel@tonic-gate #define FLG_SG_LENGTH 0x0004 /* length segment attribute set */ 89069112eddSAli Bahrami #define FLG_SG_P_ALIGN 0x0008 /* p_align segment attribute set */ 8917c478bd9Sstevel@tonic-gate #define FLG_SG_ROUND 0x0010 /* round segment attribute set */ 89269112eddSAli Bahrami #define FLG_SG_P_FLAGS 0x0020 /* p_flags segment attribute set */ 89369112eddSAli Bahrami #define FLG_SG_P_TYPE 0x0040 /* p_type segment attribute set */ 89469112eddSAli Bahrami #define FLG_SG_IS_ORDER 0x0080 /* input section ordering is required */ 89569112eddSAli Bahrami /* for this segment. */ 8967c478bd9Sstevel@tonic-gate #define FLG_SG_NOHDR 0x0100 /* don't map ELF or phdrs into */ 8977c478bd9Sstevel@tonic-gate /* this segment */ 8987c478bd9Sstevel@tonic-gate #define FLG_SG_EMPTY 0x0200 /* an empty segment specification */ 8997c478bd9Sstevel@tonic-gate /* no input sections will be */ 9007c478bd9Sstevel@tonic-gate /* associated to this section */ 9010e233487SRod Evans #define FLG_SG_KEY 0x0400 /* segment requires sort keys */ 90269112eddSAli Bahrami #define FLG_SG_NODISABLE 0x0800 /* FLG_SG_DISABLED is not allowed on */ 90369112eddSAli Bahrami /* this segment */ 90469112eddSAli Bahrami #define FLG_SG_DISABLED 0x1000 /* this segment is disabled */ 90569112eddSAli Bahrami #define FLG_SG_PHREQ 0x2000 /* this segment requires a program */ 90654d82594Sseizo /* header */ 90769112eddSAli Bahrami #define FLG_SG_ORDERED 0x4000 /* SEGMENT_ORDER segment */ 9087c478bd9Sstevel@tonic-gate 9097c478bd9Sstevel@tonic-gate struct sec_order { 9107c478bd9Sstevel@tonic-gate const char *sco_secname; /* section name to be ordered */ 9117c478bd9Sstevel@tonic-gate Half sco_flags; 9127c478bd9Sstevel@tonic-gate }; 9137c478bd9Sstevel@tonic-gate 9147c478bd9Sstevel@tonic-gate #define FLG_SGO_USED 0x0001 /* was ordering used? */ 9157c478bd9Sstevel@tonic-gate 91669112eddSAli Bahrami typedef Half ec_flags_t; 9177c478bd9Sstevel@tonic-gate struct ent_desc { /* input section entrance criteria */ 91869112eddSAli Bahrami const char *ec_name; /* entrace criteria name, or NULL */ 91969112eddSAli Bahrami Alist *ec_files; /* files from which to accept */ 9207c478bd9Sstevel@tonic-gate /* sections */ 92169112eddSAli Bahrami const char *ec_is_name; /* input section name to match */ 92269112eddSAli Bahrami /* (NULL if none) */ 9237c478bd9Sstevel@tonic-gate Word ec_type; /* section type */ 92454d82594Sseizo Word ec_attrmask; /* section attribute mask (AWX) */ 92554d82594Sseizo Word ec_attrbits; /* sections attribute bits */ 9267c478bd9Sstevel@tonic-gate Sg_desc *ec_segment; /* output segment to enter if matched */ 92757ef7aa9SRod Evans Word ec_ordndx; /* index to determine where section */ 9287c478bd9Sstevel@tonic-gate /* meeting this criteria should */ 9297c478bd9Sstevel@tonic-gate /* inserted. Used for reordering */ 9307c478bd9Sstevel@tonic-gate /* of sections. */ 93169112eddSAli Bahrami ec_flags_t ec_flags; 93269112eddSAli Bahrami avl_node_t ec_avlnode; /* AVL book-keeping */ 9337c478bd9Sstevel@tonic-gate }; 9347c478bd9Sstevel@tonic-gate 935e23c41c9SAli Bahrami #define FLG_EC_BUILTIN 0x0001 /* built in descriptor */ 936e23c41c9SAli Bahrami #define FLG_EC_USED 0x0002 /* entrance criteria met? */ 93769112eddSAli Bahrami #define FLG_EC_CATCHALL 0x0004 /* Catches any section */ 93869112eddSAli Bahrami 93969112eddSAli Bahrami /* 94069112eddSAli Bahrami * Ent_desc_file is the type of element maintained in the ec_files Alist 94169112eddSAli Bahrami * of an entrance criteria descriptor. Each item maintains one file 94269112eddSAli Bahrami * path, and a set of flags that specify the type of comparison it implies, 94369112eddSAli Bahrami * and other information about it. The comparison type is maintained in 94469112eddSAli Bahrami * the bottom byte of the flags. 94569112eddSAli Bahrami */ 94669112eddSAli Bahrami #define TYP_ECF_MASK 0x00ff /* Comparison type mask */ 94769112eddSAli Bahrami #define TYP_ECF_PATH 0 /* Compare to file path */ 94869112eddSAli Bahrami #define TYP_ECF_BASENAME 1 /* Compare to file basename */ 94969112eddSAli Bahrami #define TYP_ECF_OBJNAME 2 /* Compare to regular file basename, */ 95069112eddSAli Bahrami /* or to archive member name */ 95169112eddSAli Bahrami #define TYP_ECF_NUM 3 95269112eddSAli Bahrami 95369112eddSAli Bahrami #define FLG_ECF_ARMEMBER 0x0100 /* name includes archive member */ 95469112eddSAli Bahrami 95569112eddSAli Bahrami typedef struct { 95669112eddSAli Bahrami Word edf_flags; /* Type of comparison */ 95769112eddSAli Bahrami const char *edf_name; /* String to compare to */ 95869112eddSAli Bahrami size_t edf_name_len; /* strlen(edf_name) */ 95969112eddSAli Bahrami } Ent_desc_file; 9607c478bd9Sstevel@tonic-gate 9617c478bd9Sstevel@tonic-gate /* 96257ef7aa9SRod Evans * One structure is allocated for a move entry, and associated to the symbol 96357ef7aa9SRod Evans * against which a move is targeted. 9647c478bd9Sstevel@tonic-gate */ 96557ef7aa9SRod Evans typedef struct { 96657ef7aa9SRod Evans Move *md_move; /* original Move entry */ 96757ef7aa9SRod Evans Xword md_start; /* start position */ 96857ef7aa9SRod Evans Xword md_len; /* length of initialization */ 96957ef7aa9SRod Evans Word md_oidx; /* output Move entry index */ 97057ef7aa9SRod Evans } Mv_desc; 9717c478bd9Sstevel@tonic-gate 9727c478bd9Sstevel@tonic-gate /* 97357ef7aa9SRod Evans * Symbol descriptor. 9747c478bd9Sstevel@tonic-gate */ 975635216b6SRod Evans typedef Lword sd_flag_t; 9767c478bd9Sstevel@tonic-gate struct sym_desc { 97757ef7aa9SRod Evans Alist *sd_GOTndxs; /* list of associated GOT entries */ 9787c478bd9Sstevel@tonic-gate Sym *sd_sym; /* pointer to symbol table entry */ 9797c478bd9Sstevel@tonic-gate Sym *sd_osym; /* copy of the original symbol entry */ 980d326b23bSrie /* used only for local partial */ 98157ef7aa9SRod Evans Alist *sd_move; /* move information associated with a */ 98257ef7aa9SRod Evans /* partially initialized symbol */ 9837c478bd9Sstevel@tonic-gate const char *sd_name; /* symbols name */ 9847c478bd9Sstevel@tonic-gate Ifl_desc *sd_file; /* file where symbol is taken */ 9857c478bd9Sstevel@tonic-gate Is_desc *sd_isc; /* input section of symbol definition */ 9867c478bd9Sstevel@tonic-gate Sym_aux *sd_aux; /* auxiliary global symbol info. */ 9877c478bd9Sstevel@tonic-gate Word sd_symndx; /* index in output symbol table */ 9887c478bd9Sstevel@tonic-gate Word sd_shndx; /* sect. index sym is associated w/ */ 989635216b6SRod Evans sd_flag_t sd_flags; /* state flags */ 9907c478bd9Sstevel@tonic-gate Half sd_ref; /* reference definition of symbol */ 9917c478bd9Sstevel@tonic-gate }; 9927c478bd9Sstevel@tonic-gate 9937c478bd9Sstevel@tonic-gate /* 9947c478bd9Sstevel@tonic-gate * The auxiliary symbol descriptor contains the additional information (beyond 9957c478bd9Sstevel@tonic-gate * the symbol descriptor) required to process global symbols. These symbols are 9967c478bd9Sstevel@tonic-gate * accessed via an internal symbol hash table where locality of reference is 9977c478bd9Sstevel@tonic-gate * important for performance. 9987c478bd9Sstevel@tonic-gate */ 9997c478bd9Sstevel@tonic-gate struct sym_aux { 100057ef7aa9SRod Evans APlist *sa_dfiles; /* files where symbol is defined */ 10017c478bd9Sstevel@tonic-gate Sym sa_sym; /* copy of symtab entry */ 10027c478bd9Sstevel@tonic-gate const char *sa_vfile; /* first unavailable definition */ 10037c478bd9Sstevel@tonic-gate const char *sa_rfile; /* file with first symbol referenced */ 10047c478bd9Sstevel@tonic-gate Word sa_hash; /* the pure hash value of symbol */ 10057c478bd9Sstevel@tonic-gate Word sa_PLTndx; /* index into PLT for symbol */ 10067c478bd9Sstevel@tonic-gate Word sa_PLTGOTndx; /* GOT entry indx for PLT indirection */ 1007d579eb63Sab196087 Word sa_linkndx; /* index of associated symbol from */ 1008d579eb63Sab196087 /* ET_DYN file */ 10097c478bd9Sstevel@tonic-gate Half sa_symspec; /* special symbol ids */ 10107c478bd9Sstevel@tonic-gate Half sa_overndx; /* output file versioning index */ 10117c478bd9Sstevel@tonic-gate Half sa_dverndx; /* dependency versioning index */ 10127c478bd9Sstevel@tonic-gate }; 10137c478bd9Sstevel@tonic-gate 10147c478bd9Sstevel@tonic-gate /* 10157c478bd9Sstevel@tonic-gate * Nodes used to track symbols in the global AVL symbol dictionary. 10167c478bd9Sstevel@tonic-gate */ 10177c478bd9Sstevel@tonic-gate struct sym_avlnode { 10187c478bd9Sstevel@tonic-gate avl_node_t sav_node; /* AVL node */ 10197c478bd9Sstevel@tonic-gate Word sav_hash; /* symbol hash value */ 10207c478bd9Sstevel@tonic-gate const char *sav_name; /* symbol name */ 1021635216b6SRod Evans Sym_desc *sav_sdp; /* symbol descriptor */ 10227c478bd9Sstevel@tonic-gate }; 10237c478bd9Sstevel@tonic-gate 10247c478bd9Sstevel@tonic-gate /* 10257c478bd9Sstevel@tonic-gate * These are the ids for processing of `Special symbols'. They are used 10267c478bd9Sstevel@tonic-gate * to set the sym->sd_aux->sa_symspec field. 10277c478bd9Sstevel@tonic-gate */ 10287c478bd9Sstevel@tonic-gate #define SDAUX_ID_ETEXT 1 /* etext && _etext symbol */ 10297c478bd9Sstevel@tonic-gate #define SDAUX_ID_EDATA 2 /* edata && _edata symbol */ 10307c478bd9Sstevel@tonic-gate #define SDAUX_ID_END 3 /* end, _end, && _END_ symbol */ 10317c478bd9Sstevel@tonic-gate #define SDAUX_ID_DYN 4 /* DYNAMIC && _DYNAMIC symbol */ 10327c478bd9Sstevel@tonic-gate #define SDAUX_ID_PLT 5 /* _PROCEDURE_LINKAGE_TABLE_ symbol */ 10337c478bd9Sstevel@tonic-gate #define SDAUX_ID_GOT 6 /* _GLOBAL_OFFSET_TABLE_ symbol */ 10347c478bd9Sstevel@tonic-gate #define SDAUX_ID_START 7 /* START_ && _START_ symbol */ 10357c478bd9Sstevel@tonic-gate 10367c478bd9Sstevel@tonic-gate /* 10377c478bd9Sstevel@tonic-gate * Flags for sym_desc.sd_flags 10387c478bd9Sstevel@tonic-gate */ 10397c478bd9Sstevel@tonic-gate #define FLG_SY_MVTOCOMM 0x00000001 /* assign symbol to common (.bss) */ 10407c478bd9Sstevel@tonic-gate /* this is a result of a */ 10417c478bd9Sstevel@tonic-gate /* copy reloc against sym */ 10427c478bd9Sstevel@tonic-gate #define FLG_SY_GLOBREF 0x00000002 /* a global reference has been seen */ 10437c478bd9Sstevel@tonic-gate #define FLG_SY_WEAKDEF 0x00000004 /* a weak definition has been used */ 10447c478bd9Sstevel@tonic-gate #define FLG_SY_CLEAN 0x00000008 /* `Sym' entry points to original */ 10457c478bd9Sstevel@tonic-gate /* input file (read-only). */ 10467c478bd9Sstevel@tonic-gate #define FLG_SY_UPREQD 0x00000010 /* symbol value update is required, */ 10477c478bd9Sstevel@tonic-gate /* either it's used as an entry */ 10487c478bd9Sstevel@tonic-gate /* point or for relocation, but */ 10497c478bd9Sstevel@tonic-gate /* it must be updated even if */ 10507c478bd9Sstevel@tonic-gate /* the -s flag is in effect */ 10517c478bd9Sstevel@tonic-gate #define FLG_SY_NOTAVAIL 0x00000020 /* symbol is not available to the */ 10527c478bd9Sstevel@tonic-gate /* application either because it */ 10537c478bd9Sstevel@tonic-gate /* originates from an implicitly */ 10547c478bd9Sstevel@tonic-gate /* referenced shared object, or */ 10557c478bd9Sstevel@tonic-gate /* because it is not part of a */ 10567c478bd9Sstevel@tonic-gate /* specified version. */ 10577c478bd9Sstevel@tonic-gate #define FLG_SY_REDUCED 0x00000040 /* a global is reduced to local */ 10587c478bd9Sstevel@tonic-gate #define FLG_SY_VERSPROM 0x00000080 /* version definition has been */ 10597c478bd9Sstevel@tonic-gate /* promoted to output file */ 10607c478bd9Sstevel@tonic-gate #define FLG_SY_PROT 0x00000100 /* stv_protected visibility seen */ 10617c478bd9Sstevel@tonic-gate #define FLG_SY_MAPREF 0x00000200 /* symbol reference generated by user */ 10627c478bd9Sstevel@tonic-gate /* from mapfile */ 10637c478bd9Sstevel@tonic-gate #define FLG_SY_REFRSD 0x00000400 /* symbols sd_ref has been raised */ 10647c478bd9Sstevel@tonic-gate /* due to a copy-relocs */ 10657c478bd9Sstevel@tonic-gate /* weak-strong pairing */ 10669a411307Srie #define FLG_SY_INTPOSE 0x00000800 /* symbol defines an interposer */ 10677c478bd9Sstevel@tonic-gate #define FLG_SY_INVALID 0x00001000 /* unwanted/erroneous symbol */ 10687c478bd9Sstevel@tonic-gate #define FLG_SY_SMGOT 0x00002000 /* small got index assigned to symbol */ 10697c478bd9Sstevel@tonic-gate /* sparc only */ 10707c478bd9Sstevel@tonic-gate #define FLG_SY_PARENT 0x00004000 /* symbol to be found in parent */ 10717c478bd9Sstevel@tonic-gate /* only used with direct bindings */ 10727c478bd9Sstevel@tonic-gate #define FLG_SY_LAZYLD 0x00008000 /* symbol to cause lazyloading of */ 10737c478bd9Sstevel@tonic-gate /* parent object */ 10747c478bd9Sstevel@tonic-gate #define FLG_SY_ISDISC 0x00010000 /* symbol is a member of a DISCARDED */ 10757c478bd9Sstevel@tonic-gate /* section (COMDAT) */ 10767c478bd9Sstevel@tonic-gate #define FLG_SY_PAREXPN 0x00020000 /* partially init. symbol to be */ 10777c478bd9Sstevel@tonic-gate /* expanded */ 10787c478bd9Sstevel@tonic-gate #define FLG_SY_PLTPAD 0x00040000 /* pltpadding has been allocated for */ 10797c478bd9Sstevel@tonic-gate /* this symbol */ 10807c478bd9Sstevel@tonic-gate #define FLG_SY_REGSYM 0x00080000 /* REGISTER symbol (sparc only) */ 10817c478bd9Sstevel@tonic-gate #define FLG_SY_SOFOUND 0x00100000 /* compared against an SO definition */ 10827c478bd9Sstevel@tonic-gate #define FLG_SY_EXTERN 0x00200000 /* symbol is external, allows -zdefs */ 10837c478bd9Sstevel@tonic-gate /* error suppression */ 10847c478bd9Sstevel@tonic-gate #define FLG_SY_MAPUSED 0x00400000 /* mapfile symbol used (occurred */ 10857c478bd9Sstevel@tonic-gate /* within a relocatable object) */ 10867c478bd9Sstevel@tonic-gate #define FLG_SY_COMMEXP 0x00800000 /* COMMON symbol which has been */ 10877c478bd9Sstevel@tonic-gate /* allocated */ 10887c478bd9Sstevel@tonic-gate #define FLG_SY_CMDREF 0x01000000 /* symbol was referenced from the */ 10897c478bd9Sstevel@tonic-gate /* command line. (ld -u <>, */ 10907c478bd9Sstevel@tonic-gate /* ld -zrtldinfo=<>, ...) */ 10917c478bd9Sstevel@tonic-gate #define FLG_SY_SPECSEC 0x02000000 /* section index is reserved value */ 10927c478bd9Sstevel@tonic-gate /* ABS, COMMON, ... */ 10937c478bd9Sstevel@tonic-gate #define FLG_SY_TENTSYM 0x04000000 /* tentative symbol */ 10947c478bd9Sstevel@tonic-gate #define FLG_SY_VISIBLE 0x08000000 /* symbols visibility determined */ 10957c478bd9Sstevel@tonic-gate #define FLG_SY_STDFLTR 0x10000000 /* symbol is a standard filter */ 10967c478bd9Sstevel@tonic-gate #define FLG_SY_AUXFLTR 0x20000000 /* symbol is an auxiliary filter */ 1097d579eb63Sab196087 #define FLG_SY_DYNSORT 0x40000000 /* req. in dyn[sym|tls]sort section */ 1098d579eb63Sab196087 #define FLG_SY_NODYNSORT 0x80000000 /* excluded from dyn[sym_tls]sort sec */ 10997c478bd9Sstevel@tonic-gate 1100635216b6SRod Evans #define FLG_SY_DEFAULT 0x0000100000000 /* global symbol, default */ 1101635216b6SRod Evans #define FLG_SY_SINGLE 0x0000200000000 /* global symbol, singleton defined */ 1102635216b6SRod Evans #define FLG_SY_PROTECT 0x0000400000000 /* global symbol, protected defined */ 1103635216b6SRod Evans #define FLG_SY_EXPORT 0x0000800000000 /* global symbol, exported defined */ 11047c478bd9Sstevel@tonic-gate 1105635216b6SRod Evans #define MSK_SY_GLOBAL \ 1106635216b6SRod Evans (FLG_SY_DEFAULT | FLG_SY_SINGLE | FLG_SY_PROTECT | FLG_SY_EXPORT) 110760758829Srie /* this mask indicates that the */ 110860758829Srie /* symbol has been explicitly */ 110960758829Srie /* defined within a mapfile */ 111060758829Srie /* definition, and is a candidate */ 111160758829Srie /* for versioning */ 111260758829Srie 1113635216b6SRod Evans #define FLG_SY_HIDDEN 0x0001000000000 /* global symbol, reduce to local */ 1114635216b6SRod Evans #define FLG_SY_ELIM 0x0002000000000 /* global symbol, eliminate */ 1115635216b6SRod Evans #define FLG_SY_IGNORE 0x0004000000000 /* global symbol, ignored */ 111660758829Srie 1117635216b6SRod Evans #define MSK_SY_LOCAL (FLG_SY_HIDDEN | FLG_SY_ELIM | FLG_SY_IGNORE) 111860758829Srie /* this mask allows all local state */ 111960758829Srie /* flags to be removed when the */ 112060758829Srie /* symbol is copy relocated */ 112160758829Srie 1122635216b6SRod Evans #define FLG_SY_EXPDEF 0x0008000000000 /* symbol visibility defined */ 112360758829Srie /* explicitly */ 112460758829Srie 1125635216b6SRod Evans #define MSK_SY_NOAUTO (FLG_SY_SINGLE | FLG_SY_EXPORT | FLG_SY_EXPDEF) 112660758829Srie /* this mask indicates that the */ 112760758829Srie /* symbol is not a candidate for */ 112860758829Srie /* auto-reduction/elimination */ 112960758829Srie 1130635216b6SRod Evans #define FLG_SY_MAPFILE 0x0010000000000 /* symbol attribute defined in a */ 113160758829Srie /* mapfile */ 1132635216b6SRod Evans #define FLG_SY_DIR 0x0020000000000 /* global symbol, direct bindings */ 1133635216b6SRod Evans #define FLG_SY_NDIR 0x0040000000000 /* global symbol, nondirect bindings */ 1134635216b6SRod Evans #define FLG_SY_OVERLAP 0x0080000000000 /* move entry overlap detected */ 113508278a5eSRod Evans #define FLG_SY_CAP 0x0100000000000 /* symbol is associated with */ 113608278a5eSRod Evans /* capabilities */ 113708278a5eSRod Evans 113808278a5eSRod Evans /* 113908278a5eSRod Evans * A symbol can only be truly hidden if it is not a capabilities symbol. 114008278a5eSRod Evans */ 114108278a5eSRod Evans #define SYM_IS_HIDDEN(_sdp) \ 114208278a5eSRod Evans (((_sdp)->sd_flags & (FLG_SY_HIDDEN | FLG_SY_CAP)) == FLG_SY_HIDDEN) 11437c478bd9Sstevel@tonic-gate 11447c478bd9Sstevel@tonic-gate /* 114560758829Srie * Create a mask for (sym.st_other & visibility) since the gABI does not yet 114660758829Srie * define a ELF*_ST_OTHER macro. 11477c478bd9Sstevel@tonic-gate */ 114860758829Srie #define MSK_SYM_VISIBILITY 0x7 11497c478bd9Sstevel@tonic-gate 11507c478bd9Sstevel@tonic-gate /* 11517c478bd9Sstevel@tonic-gate * Structure to manage the shared object definition lists. There are two lists 11527c478bd9Sstevel@tonic-gate * that use this structure: 11537c478bd9Sstevel@tonic-gate * 115428bda19cSRod Evans * - ofl_soneed; maintain the list of implicitly required dependencies 11557c478bd9Sstevel@tonic-gate * (ie. shared objects needed by other shared objects). These definitions 11567c478bd9Sstevel@tonic-gate * may include RPATH's required to locate the dependencies, and any 11577c478bd9Sstevel@tonic-gate * version requirements. 11587c478bd9Sstevel@tonic-gate * 115928bda19cSRod Evans * - ofl_socntl; maintains the shared object control definitions. These are 11607c478bd9Sstevel@tonic-gate * provided by the user (via a mapfile) and are used to indicate any 116128bda19cSRod Evans * version control requirements. 11627c478bd9Sstevel@tonic-gate */ 11637c478bd9Sstevel@tonic-gate struct sdf_desc { 11647c478bd9Sstevel@tonic-gate const char *sdf_name; /* the shared objects file name */ 11657c478bd9Sstevel@tonic-gate char *sdf_rpath; /* library search path DT_RPATH */ 11667c478bd9Sstevel@tonic-gate const char *sdf_rfile; /* referencing file for diagnostics */ 11677c478bd9Sstevel@tonic-gate Ifl_desc *sdf_file; /* the final input file descriptor */ 116857ef7aa9SRod Evans Alist *sdf_vers; /* list of versions that are required */ 11697c478bd9Sstevel@tonic-gate /* from this object */ 117057ef7aa9SRod Evans Alist *sdf_verneed; /* list of VERNEEDS to create for */ 11714a8d0ea7SAli Bahrami /* object via mapfile ADDVERS */ 11727c478bd9Sstevel@tonic-gate Word sdf_flags; 11737c478bd9Sstevel@tonic-gate }; 11747c478bd9Sstevel@tonic-gate 11754a8d0ea7SAli Bahrami #define FLG_SDF_SELECT 0x01 /* version control selection required */ 11764a8d0ea7SAli Bahrami #define FLG_SDF_VERIFY 0x02 /* version definition verification */ 11777c478bd9Sstevel@tonic-gate /* required */ 11784a8d0ea7SAli Bahrami #define FLG_SDF_ADDVER 0x04 /* add VERNEED references */ 11797c478bd9Sstevel@tonic-gate 11807c478bd9Sstevel@tonic-gate /* 11817c478bd9Sstevel@tonic-gate * Structure to manage shared object version usage requirements. 11827c478bd9Sstevel@tonic-gate */ 11837c478bd9Sstevel@tonic-gate struct sdv_desc { 11847c478bd9Sstevel@tonic-gate const char *sdv_name; /* version name */ 11857c478bd9Sstevel@tonic-gate const char *sdv_ref; /* versions reference */ 11867c478bd9Sstevel@tonic-gate Word sdv_flags; /* flags */ 11877c478bd9Sstevel@tonic-gate }; 11887c478bd9Sstevel@tonic-gate 11897c478bd9Sstevel@tonic-gate #define FLG_SDV_MATCHED 0x01 /* VERDEF found and matched */ 11907c478bd9Sstevel@tonic-gate 11917c478bd9Sstevel@tonic-gate /* 11927c478bd9Sstevel@tonic-gate * Structures to manage versioning information. Two versioning structures are 11937c478bd9Sstevel@tonic-gate * defined: 11947c478bd9Sstevel@tonic-gate * 119528bda19cSRod Evans * - a version descriptor maintains a linked list of versions and their 11967c478bd9Sstevel@tonic-gate * associated dependencies. This is used to build the version definitions 11977c478bd9Sstevel@tonic-gate * for an image being created (see map_symbol), and to determine the 11987c478bd9Sstevel@tonic-gate * version dependency graph for any input files that are versioned. 11997c478bd9Sstevel@tonic-gate * 120028bda19cSRod Evans * - a version index array contains each version of an input file that is 12017c478bd9Sstevel@tonic-gate * being processed. It informs us which versions are available for 12027c478bd9Sstevel@tonic-gate * binding, and is used to generate any version dependency information. 12037c478bd9Sstevel@tonic-gate */ 12047c478bd9Sstevel@tonic-gate struct ver_desc { 12057c478bd9Sstevel@tonic-gate const char *vd_name; /* version name */ 12067c478bd9Sstevel@tonic-gate Ifl_desc *vd_file; /* file that defined version */ 120757ef7aa9SRod Evans Word vd_hash; /* hash value of name */ 12087c478bd9Sstevel@tonic-gate Half vd_ndx; /* coordinates with symbol index */ 12097c478bd9Sstevel@tonic-gate Half vd_flags; /* version information */ 121057ef7aa9SRod Evans APlist *vd_deps; /* version dependencies */ 12117c478bd9Sstevel@tonic-gate Ver_desc *vd_ref; /* dependency's first reference */ 12127c478bd9Sstevel@tonic-gate }; 12137c478bd9Sstevel@tonic-gate 12147c478bd9Sstevel@tonic-gate struct ver_index { 12157c478bd9Sstevel@tonic-gate const char *vi_name; /* dependency version name */ 12167c478bd9Sstevel@tonic-gate Half vi_flags; /* communicates availability */ 121708278a5eSRod Evans Half vi_overndx; /* index assigned to this version in */ 1218090a8d9eSAli Bahrami /* output object Verneed section */ 12197c478bd9Sstevel@tonic-gate Ver_desc *vi_desc; /* cross reference to descriptor */ 12207c478bd9Sstevel@tonic-gate }; 12217c478bd9Sstevel@tonic-gate 12227c478bd9Sstevel@tonic-gate /* 12237c478bd9Sstevel@tonic-gate * Define any internal version descriptor flags ([vd|vi]_flags). Note that the 12247c478bd9Sstevel@tonic-gate * first byte is reserved for user visible flags (refer VER_FLG's in link.h). 12257c478bd9Sstevel@tonic-gate */ 12267c478bd9Sstevel@tonic-gate #define MSK_VER_USER 0x0f /* mask for user visible flags */ 12277c478bd9Sstevel@tonic-gate 12287c478bd9Sstevel@tonic-gate #define FLG_VER_AVAIL 0x10 /* version is available for binding */ 12297c478bd9Sstevel@tonic-gate #define FLG_VER_REFER 0x20 /* version has been referenced */ 12304a8d0ea7SAli Bahrami #define FLG_VER_CYCLIC 0x40 /* a member of cyclic dependency */ 12317c478bd9Sstevel@tonic-gate 12327c478bd9Sstevel@tonic-gate /* 12337c478bd9Sstevel@tonic-gate * isalist(1) descriptor - used to break an isalist string into its component 12347c478bd9Sstevel@tonic-gate * options. 12357c478bd9Sstevel@tonic-gate */ 12367c478bd9Sstevel@tonic-gate struct isa_opt { 12377c478bd9Sstevel@tonic-gate char *isa_name; /* individual isa option name */ 12387c478bd9Sstevel@tonic-gate size_t isa_namesz; /* and associated size */ 12397c478bd9Sstevel@tonic-gate }; 12407c478bd9Sstevel@tonic-gate 12417c478bd9Sstevel@tonic-gate struct isa_desc { 12427c478bd9Sstevel@tonic-gate char *isa_list; /* sysinfo(SI_ISALIST) list */ 12437c478bd9Sstevel@tonic-gate size_t isa_listsz; /* and associated size */ 12447c478bd9Sstevel@tonic-gate Isa_opt *isa_opt; /* table of individual isa options */ 12457c478bd9Sstevel@tonic-gate size_t isa_optno; /* and associated number */ 12467c478bd9Sstevel@tonic-gate }; 12477c478bd9Sstevel@tonic-gate 12487c478bd9Sstevel@tonic-gate /* 12497c478bd9Sstevel@tonic-gate * uname(2) descriptor - used to break a utsname structure into its component 12507c478bd9Sstevel@tonic-gate * options (at least those that we're interested in). 12517c478bd9Sstevel@tonic-gate */ 12527c478bd9Sstevel@tonic-gate struct uts_desc { 12537c478bd9Sstevel@tonic-gate char *uts_osname; /* operating system name */ 12547c478bd9Sstevel@tonic-gate size_t uts_osnamesz; /* and associated size */ 12557c478bd9Sstevel@tonic-gate char *uts_osrel; /* operating system release */ 12567c478bd9Sstevel@tonic-gate size_t uts_osrelsz; /* and associated size */ 12577c478bd9Sstevel@tonic-gate }; 12587c478bd9Sstevel@tonic-gate 12597c478bd9Sstevel@tonic-gate /* 12607c478bd9Sstevel@tonic-gate * SHT_GROUP descriptor - used to track group sections at the global 12610e233487SRod Evans * level to resolve conflicts and determine which to keep. 12627c478bd9Sstevel@tonic-gate */ 12637c478bd9Sstevel@tonic-gate struct group_desc { 12640e233487SRod Evans Is_desc *gd_isc; /* input section descriptor */ 12650e233487SRod Evans Is_desc *gd_oisc; /* overriding input section */ 12660e233487SRod Evans /* descriptor when discarded */ 12670e233487SRod Evans const char *gd_name; /* group name (signature symbol) */ 1268cc7efc4fSrie Word *gd_data; /* data for group section */ 1269cc7efc4fSrie size_t gd_cnt; /* number of entries in group data */ 12707c478bd9Sstevel@tonic-gate }; 12717c478bd9Sstevel@tonic-gate 12727c478bd9Sstevel@tonic-gate /* 12737c478bd9Sstevel@tonic-gate * Indexes into the ld_support_funcs[] table. 12747c478bd9Sstevel@tonic-gate */ 12757c478bd9Sstevel@tonic-gate typedef enum { 1276d2d5cf7cSAli Bahrami LDS_VERSION = 0, /* Must be first and have value 0 */ 12777c478bd9Sstevel@tonic-gate LDS_INPUT_DONE, 12787c478bd9Sstevel@tonic-gate LDS_START, 12797c478bd9Sstevel@tonic-gate LDS_ATEXIT, 12803906e0c2Srie LDS_OPEN, 12817c478bd9Sstevel@tonic-gate LDS_FILE, 12822926dd2eSrie LDS_INSEC, 12832926dd2eSrie LDS_SEC, 12847c478bd9Sstevel@tonic-gate LDS_NUM 12857c478bd9Sstevel@tonic-gate } Support_ndx; 12867c478bd9Sstevel@tonic-gate 12877c478bd9Sstevel@tonic-gate /* 12887c478bd9Sstevel@tonic-gate * Structure to manage archive member caching. Each archive has an archive 12897c478bd9Sstevel@tonic-gate * descriptor (Ar_desc) associated with it. This contains pointers to the 12907c478bd9Sstevel@tonic-gate * archive symbol table (obtained by elf_getarsyms(3e)) and an auxiliary 12917c478bd9Sstevel@tonic-gate * structure (Ar_uax[]) that parallels this symbol table. The member element 12927c478bd9Sstevel@tonic-gate * of this auxiliary table indicates whether the archive member associated with 12937c478bd9Sstevel@tonic-gate * the symbol offset has already been extracted (AREXTRACTED) or partially 12947c478bd9Sstevel@tonic-gate * processed (refer process_member()). 12957c478bd9Sstevel@tonic-gate */ 12967c478bd9Sstevel@tonic-gate typedef struct ar_mem { 12977c478bd9Sstevel@tonic-gate Elf *am_elf; /* elf descriptor for this member */ 12987c478bd9Sstevel@tonic-gate char *am_name; /* members name */ 12997c478bd9Sstevel@tonic-gate char *am_path; /* path (ie. lib(foo.o)) */ 13007c478bd9Sstevel@tonic-gate Sym *am_syms; /* start of global symbols */ 13017c478bd9Sstevel@tonic-gate char *am_strs; /* associated string table start */ 13027c478bd9Sstevel@tonic-gate Xword am_symn; /* no. of global symbols */ 13037c478bd9Sstevel@tonic-gate } Ar_mem; 13047c478bd9Sstevel@tonic-gate 13057c478bd9Sstevel@tonic-gate typedef struct ar_aux { 13067c478bd9Sstevel@tonic-gate Sym_desc *au_syms; /* internal symbol descriptor */ 13077c478bd9Sstevel@tonic-gate Ar_mem *au_mem; /* associated member */ 13087c478bd9Sstevel@tonic-gate } Ar_aux; 13097c478bd9Sstevel@tonic-gate 13107c478bd9Sstevel@tonic-gate #define FLG_ARMEM_PROC (Ar_mem *)-1 13117c478bd9Sstevel@tonic-gate 13127c478bd9Sstevel@tonic-gate typedef struct ar_desc { 13137c478bd9Sstevel@tonic-gate const char *ad_name; /* archive file name */ 13147c478bd9Sstevel@tonic-gate Elf *ad_elf; /* elf descriptor for the archive */ 13157c478bd9Sstevel@tonic-gate Elf_Arsym *ad_start; /* archive symbol table start */ 13167c478bd9Sstevel@tonic-gate Ar_aux *ad_aux; /* auxiliary symbol information */ 13177c478bd9Sstevel@tonic-gate dev_t ad_stdev; /* device id and inode number for */ 13187c478bd9Sstevel@tonic-gate ino_t ad_stino; /* multiple inclusion checks */ 13191d9df23bSab196087 ofl_flag_t ad_flags; /* archive specific cmd line flags */ 13207c478bd9Sstevel@tonic-gate } Ar_desc; 13217c478bd9Sstevel@tonic-gate 13227c478bd9Sstevel@tonic-gate /* 13237c478bd9Sstevel@tonic-gate * Define any archive descriptor flags. NOTE, make sure they do not clash with 13247c478bd9Sstevel@tonic-gate * any output file descriptor archive extraction flags, as these are saved in 13257c478bd9Sstevel@tonic-gate * the same entry (see MSK_OF1_ARCHIVE). 13267c478bd9Sstevel@tonic-gate */ 13277c478bd9Sstevel@tonic-gate #define FLG_ARD_EXTRACT 0x00010000 /* archive member has been extracted */ 13287c478bd9Sstevel@tonic-gate 132969112eddSAli Bahrami /* Mapfile versions supported by libld */ 133069112eddSAli Bahrami #define MFV_NONE 0 /* Not a valid version */ 133169112eddSAli Bahrami #define MFV_SYSV 1 /* Original System V syntax */ 133269112eddSAli Bahrami #define MFV_SOLARIS 2 /* Solaris mapfile syntax */ 133369112eddSAli Bahrami #define MFV_NUM 3 /* # of mapfile versions */ 133469112eddSAli Bahrami 133569112eddSAli Bahrami 13367c478bd9Sstevel@tonic-gate /* 13375aefb655Srie * Function Declarations. 13387c478bd9Sstevel@tonic-gate */ 13395aefb655Srie #if defined(_ELF64) 13405aefb655Srie 13415aefb655Srie #define ld_create_outfile ld64_create_outfile 13425aefb655Srie #define ld_ent_setup ld64_ent_setup 1343c1c6f601Srie #define ld_init_strings ld64_init_strings 1344ba2be530Sab196087 #define ld_init_target ld64_init_target 13455aefb655Srie #define ld_make_sections ld64_make_sections 13465aefb655Srie #define ld_main ld64_main 13472926dd2eSrie #define ld_ofl_cleanup ld64_ofl_cleanup 134856deab07SRod Evans #define ld_process_mem ld64_process_mem 13495aefb655Srie #define ld_reloc_init ld64_reloc_init 13505aefb655Srie #define ld_reloc_process ld64_reloc_process 13515aefb655Srie #define ld_sym_validate ld64_sym_validate 13525aefb655Srie #define ld_update_outfile ld64_update_outfile 13535aefb655Srie 13545aefb655Srie #else 13555aefb655Srie 13565aefb655Srie #define ld_create_outfile ld32_create_outfile 13575aefb655Srie #define ld_ent_setup ld32_ent_setup 1358c1c6f601Srie #define ld_init_strings ld32_init_strings 1359ba2be530Sab196087 #define ld_init_target ld32_init_target 13605aefb655Srie #define ld_make_sections ld32_make_sections 13615aefb655Srie #define ld_main ld32_main 13622926dd2eSrie #define ld_ofl_cleanup ld32_ofl_cleanup 136356deab07SRod Evans #define ld_process_mem ld32_process_mem 13645aefb655Srie #define ld_reloc_init ld32_reloc_init 13655aefb655Srie #define ld_reloc_process ld32_reloc_process 13665aefb655Srie #define ld_sym_validate ld32_sym_validate 13675aefb655Srie #define ld_update_outfile ld32_update_outfile 13685aefb655Srie 13695aefb655Srie #endif 13705aefb655Srie 137192a02081SRod Evans extern int ld_getopt(Lm_list *, int, int, char **); 137292a02081SRod Evans 1373ba2be530Sab196087 extern int ld32_main(int, char **, Half); 1374ba2be530Sab196087 extern int ld64_main(int, char **, Half); 13755aefb655Srie 13765aefb655Srie extern uintptr_t ld_create_outfile(Ofl_desc *); 13775aefb655Srie extern uintptr_t ld_ent_setup(Ofl_desc *, Xword); 1378c1c6f601Srie extern uintptr_t ld_init_strings(Ofl_desc *); 1379ba2be530Sab196087 extern int ld_init_target(Lm_list *, Half mach); 13805aefb655Srie extern uintptr_t ld_make_sections(Ofl_desc *); 13812926dd2eSrie extern void ld_ofl_cleanup(Ofl_desc *); 138256deab07SRod Evans extern Ifl_desc *ld_process_mem(const char *, const char *, char *, 138356deab07SRod Evans size_t, Ofl_desc *, Rej_desc *); 13845aefb655Srie extern uintptr_t ld_reloc_init(Ofl_desc *); 13855aefb655Srie extern uintptr_t ld_reloc_process(Ofl_desc *); 13865aefb655Srie extern uintptr_t ld_sym_validate(Ofl_desc *); 13875aefb655Srie extern uintptr_t ld_update_outfile(Ofl_desc *); 13885aefb655Srie 13897c478bd9Sstevel@tonic-gate #ifdef __cplusplus 13907c478bd9Sstevel@tonic-gate } 13917c478bd9Sstevel@tonic-gate #endif 13927c478bd9Sstevel@tonic-gate 13937c478bd9Sstevel@tonic-gate #endif /* _LIBLD_H */ 1394