1 /* 2 * CDDL HEADER START 3 * 4 * The contents of this file are subject to the terms of the 5 * Common Development and Distribution License (the "License"). 6 * You may not use this file except in compliance with the License. 7 * 8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9 * or http://www.opensolaris.org/os/licensing. 10 * See the License for the specific language governing permissions 11 * and limitations under the License. 12 * 13 * When distributing Covered Code, include this CDDL HEADER in each 14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15 * If applicable, add the following below this CDDL HEADER, with the 16 * fields enclosed by brackets "[]" replaced with your own identifying 17 * information: Portions Copyright [yyyy] [name of copyright owner] 18 * 19 * CDDL HEADER END 20 */ 21 22 /* 23 * Copyright (c) 1988 AT&T 24 * All Rights Reserved 25 * 26 * Copyright (c) 1992, 2010, Oracle and/or its affiliates. All rights reserved. 27 * Copyright 2024 Oxide Computer Company 28 */ 29 30 #ifndef _LIBLD_H 31 #define _LIBLD_H 32 33 #include <stdlib.h> 34 #include <libelf.h> 35 #include <sgs.h> 36 #include <_machelf.h> 37 #include <string_table.h> 38 #include <sys/avl.h> 39 #include <alist.h> 40 #include <elfcap.h> 41 42 #ifdef __cplusplus 43 extern "C" { 44 #endif 45 46 /* 47 * Default directory search path manipulation for the link-editor. YLDIR 48 * indicates which directory in LIBPATH is replaced by the -YL option to cc 49 * and ld. YUDIR indicates which directory is replaced by -YU. 50 */ 51 #define YLDIR 1 52 #define YUDIR 2 53 54 /* 55 * Define a hash value that can never be returned from elf_hash(). 56 */ 57 #define SYM_NOHASH (~(Word)0) 58 59 /* 60 * Macro that can be used to represent both ORDER flags 61 * in a section header. 62 */ 63 #define ALL_SHF_ORDER (SHF_ORDERED | SHF_LINK_ORDER) 64 65 /* 66 * The linker merges (concatenates) sections with the same name and 67 * compatible section header flags. When comparing these flags, 68 * there are some that should not be included in the decision. 69 * The ALL_SHF_IGNORE constant defines these flags. 70 * 71 * NOTE: SHF_MERGE|SHF_STRINGS: 72 * The compiler is allowed to set the SHF_MERGE|SHF_STRINGS flags in 73 * order to tell the linker that: 74 * 75 * 1) There is nothing in the section except null terminated strings. 76 * 2) Those strings do not contain NULL bytes, except as termination. 77 * 3) All references to these strings occur via standard relocation 78 * records. 79 * 80 * As a result, if two compatible sections both have these flags set, it is 81 * OK to combine the strings they contain into a single merged string table 82 * with duplicates removed and tail strings merged. 83 * 84 * This is a different meaning than the simple concatenating of sections 85 * that the linker always does. It is a hint that an additional optimization 86 * is possible, but not required. This means that sections that do not 87 * share the same SHF_MERGE|SHF_STRINGS values can be concatenated, 88 * but cannot have their duplicate strings combined. Hence, the 89 * SHF_MERGE|SHF_STRINGS flags should be ignored when deciding whether 90 * two sections can be concatenated. 91 */ 92 #define ALL_SHF_IGNORE (ALL_SHF_ORDER | SHF_GROUP | SHF_MERGE | SHF_STRINGS) 93 94 /* 95 * Define symbol reference types for use in symbol resolution. 96 */ 97 typedef enum { 98 REF_DYN_SEEN, /* a .so symbol has been seen */ 99 REF_DYN_NEED, /* a .so symbol satisfies a .o symbol */ 100 REF_REL_NEED, /* a .o symbol */ 101 REF_NUM /* the number of symbol references */ 102 } Symref; 103 104 /* 105 * Relocation descriptor cache 106 */ 107 struct rel_cache { 108 APlist *rc_list; /* list of Rel_cachebuf */ 109 Word rc_cnt; /* and count */ 110 }; 111 112 /* 113 * GOT reference models 114 */ 115 typedef enum { 116 GOT_REF_GENERIC, /* generic symbol reference */ 117 GOT_REF_TLSIE, /* TLS initial exec (gnu) reference */ 118 GOT_REF_TLSLD, /* TLS local dynamic reference */ 119 GOT_REF_TLSGD /* TLS general dynamic reference */ 120 } Gotref; 121 122 typedef struct { 123 Xword gn_addend; /* addend associated with GOT entry */ 124 Sword gn_gotndx; /* GOT table index */ 125 Gotref gn_gotref; 126 } Gotndx; 127 128 /* 129 * Got debugging structure. The got index is defined as a signed value as we 130 * do so much mucking around with negative and positive gots on SPARC, and sign 131 * extension is necessary when building 64-bit objects. On intel we explicitly 132 * cast this variable to an unsigned value. 133 */ 134 typedef struct { 135 Sym_desc *gt_sym; 136 Gotndx gt_gndx; 137 } Gottable; 138 139 /* 140 * The link-editor caches the results of sloppy relocation processing 141 * in a variable of type Rlxrel_cache. Symbols come for processing in sorted 142 * order, so a single item cache suffices to eliminate duplicate lookups. 143 * 144 * When sloppy relocation processing fails, the Rlxrel_rej enum reports 145 * the underlying reason. 146 */ 147 typedef enum { 148 RLXREL_REJ_NONE = 0, /* Replacement symbol was found */ 149 RLXREL_REJ_TARGET, /* Target sec disallows relaxed relocations */ 150 RLXREL_REJ_SECTION, /* Either there is no replacement section, */ 151 /* or its attributes are incompatible */ 152 RLXREL_REJ_SYMBOL, /* Replacement symbol not found */ 153 } Rlxrel_rej; 154 155 typedef struct sreloc_cache { 156 Sym_desc *sr_osdp; /* Original symbol */ 157 Sym_desc *sr_rsdp; /* Replacement symbol */ 158 Rlxrel_rej sr_rej; /* Reason for failure if NULL sr_rsdp */ 159 } Rlxrel_cache; 160 161 /* 162 * Nodes in an ofl_wrap AVL tree 163 * 164 * wsn_name is the name of the symbol to be wrapped. wsn_wrapname is used 165 * when we need to refer to the wrap symbol, and consists of the symbol 166 * name with a __wrap_ prefix. 167 */ 168 typedef struct wrap_sym_node { 169 avl_node_t wsn_avlnode; /* AVL book-keeping */ 170 const char *wsn_name; /* Symbol name: XXX */ 171 const char *wsn_wrapname; /* Wrap symbol name: __wrap_XXX */ 172 } WrapSymNode; 173 174 /* 175 * Capabilities structures, used to maintain a capabilities set. 176 * 177 * Capabilities can be defined within input relocatable objects, and can be 178 * augmented or replaced by mapfile directives. In addition, mapfile directives 179 * can be used to exclude capabilities that would otherwise be carried over to 180 * the output object. 181 * 182 * CA_SUNW_HW_1, CA_SUNW_SF_1 and CA_SUNW_HW_2 values are bitmasks. A current 183 * value, and an exclude value are maintained for each capability. 184 * 185 * There can be multiple CA_SUNW_PLAT and CA_SUNW_MACH entries and thus Alists 186 * are used to collect these entries. A current list for each capability is 187 * maintained as Capstr entries, which provide for maintaining the strings 188 * eventual index into a string table. An exclude list is maintained as a 189 * list of string pointers. 190 */ 191 typedef struct { 192 elfcap_mask_t cm_val; /* bitmask value */ 193 elfcap_mask_t cm_exc; /* bits to exclude from final object */ 194 } Capmask; 195 196 typedef struct { 197 Alist *cl_val; /* string (Capstr) value */ 198 APlist *cl_exc; /* strings to exclude from final */ 199 } Caplist; /* object */ 200 201 typedef struct { 202 char *cs_str; /* platform or machine name */ 203 Word cs_ndx; /* the entries output Cap index */ 204 } Capstr; 205 206 typedef uint_t oc_flag_t; 207 typedef struct { 208 Capmask oc_hw_1; /* CA_SUNW_HW_1 capabilities */ 209 Capmask oc_sf_1; /* CA_SUNW_SF_1 capabilities */ 210 Capmask oc_hw_2; /* CA_SUNW_HW_2 capabilities */ 211 Caplist oc_plat; /* CA_SUNW_PLAT capabilities */ 212 Caplist oc_mach; /* CA_SUNW_MACH capabilities */ 213 Capstr oc_id; /* CA_SUNW_ID capability */ 214 Capmask oc_hw_3; /* CA_SUNW_HW_3 capabilities */ 215 oc_flag_t oc_flags; 216 } Objcapset; 217 218 #define FLG_OCS_USRDEFID 0x1 /* user defined CA_SUNW_ID */ 219 220 /* 221 * Bitmasks for a single capability. Capabilities come from input objects, 222 * augmented or replaced by mapfile directives. In addition, mapfile directives 223 * can be used to exclude bits that would otherwise be set in the output object. 224 */ 225 typedef struct { 226 elfcap_mask_t cm_value; /* Bitmask value */ 227 elfcap_mask_t cm_exclude; /* Bits to remove from final object */ 228 } CapMask; 229 230 /* 231 * Combine the bitmask in a CapMask with the exclusion mask and 232 * return the resulting final value. 233 */ 234 #define CAPMASK_VALUE(_cbmp) ((_cbmp)->cm_value & ~(_cbmp)->cm_exclude) 235 236 typedef struct { 237 CapMask c_hw_1; /* CA_SUNW_HW_1 capabilities */ 238 CapMask c_sf_1; /* CA_SUNW_SF_1 capabilities */ 239 CapMask c_hw_2; /* CA_SUNW_HW_2 capabilities */ 240 } Outcapset; 241 242 243 /* 244 * Output file processing structure 245 */ 246 typedef Lword ofl_flag_t; 247 typedef Word ofl_guideflag_t; 248 struct ofl_desc { 249 char *ofl_sgsid; /* link-editor identification */ 250 const char *ofl_name; /* full file name */ 251 Elf *ofl_elf; /* elf_memory() elf descriptor */ 252 Elf *ofl_welf; /* ELF_C_WRITE elf descriptor */ 253 Ehdr *ofl_dehdr; /* default elf header, and new elf */ 254 Ehdr *ofl_nehdr; /* header describing this file */ 255 Phdr *ofl_phdr; /* program header descriptor */ 256 Phdr *ofl_tlsphdr; /* TLS phdr */ 257 int ofl_fd; /* file descriptor */ 258 size_t ofl_size; /* image size */ 259 APlist *ofl_maps; /* list of input mapfiles */ 260 APlist *ofl_segs; /* list of segments */ 261 APlist *ofl_segs_order; /* SEGMENT_ORDER segments */ 262 avl_tree_t ofl_segs_avl; /* O(log N) access to named segments */ 263 APlist *ofl_ents; /* list of entrance descriptors */ 264 avl_tree_t ofl_ents_avl; /* O(log N) access to named ent. desc */ 265 APlist *ofl_objs; /* relocatable object file list */ 266 Word ofl_objscnt; /* and count */ 267 APlist *ofl_ars; /* archive library list */ 268 Word ofl_arscnt; /* and count */ 269 int ofl_ars_gsandx; /* archive group argv index. 0 means */ 270 /* no current group, < 0 means */ 271 /* error reported. >0 is cur ndx */ 272 Word ofl_ars_gsndx; /* current -zrescan-start ofl_ars ndx */ 273 APlist *ofl_sos; /* shared object list */ 274 Word ofl_soscnt; /* and count */ 275 APlist *ofl_soneed; /* list of implicitly required .so's */ 276 APlist *ofl_socntl; /* list of .so control definitions */ 277 Rel_cache ofl_outrels; /* list of output relocations */ 278 Rel_cache ofl_actrels; /* list of relocations to perform */ 279 APlist *ofl_relaux; /* Rel_aux cache for outrels/actrels */ 280 Word ofl_entrelscnt; /* no of relocations entered */ 281 Alist *ofl_copyrels; /* list of copy relocations */ 282 APlist *ofl_ordered; /* list of shf_ordered sections */ 283 APlist *ofl_symdtent; /* list of syminfo symbols that need */ 284 /* to reference .dynamic entries */ 285 APlist *ofl_ismove; /* list of .SUNW_move sections */ 286 APlist *ofl_ismoverel; /* list of relocation input section */ 287 /* targeting to expanded area */ 288 APlist *ofl_parsyms; /* list of partially initialized */ 289 /* symbols (ie. move symbols) */ 290 APlist *ofl_extrarels; /* relocation sections which have */ 291 /* a NULL sh_info */ 292 avl_tree_t *ofl_groups; /* pointer to head of Groups AVL tree */ 293 APlist *ofl_initarray; /* list of init array func names */ 294 APlist *ofl_finiarray; /* list of fini array func names */ 295 APlist *ofl_preiarray; /* list of preinit array func names */ 296 APlist *ofl_rtldinfo; /* list of rtldinfo syms */ 297 APlist *ofl_osgroups; /* list of output GROUP sections */ 298 APlist *ofl_ostlsseg; /* pointer to sections in TLS segment */ 299 APlist *ofl_unwind; /* list of unwind output sections */ 300 Os_desc *ofl_unwindhdr; /* Unwind hdr */ 301 avl_tree_t ofl_symavl; /* pointer to head of Syms AVL tree */ 302 Sym_desc **ofl_regsyms; /* array of potential register */ 303 Word ofl_regsymsno; /* symbols and array count */ 304 Word ofl_regsymcnt; /* no. of output register symbols */ 305 Word ofl_lregsymcnt; /* no. of local register symbols */ 306 Sym_desc *ofl_dtracesym; /* ld -zdtrace= */ 307 ofl_flag_t ofl_flags; /* various state bits, args etc. */ 308 ofl_flag_t ofl_flags1; /* more flags */ 309 void *ofl_entry; /* entry point (-e and Sym_desc *) */ 310 char *ofl_filtees; /* shared objects we are a filter for */ 311 const char *ofl_soname; /* (-h option) output file name for */ 312 /* dynamic structure */ 313 const char *ofl_interp; /* interpreter name used by exec() */ 314 char *ofl_rpath; /* run path to store in .dynamic */ 315 char *ofl_config; /* config path to store in .dynamic */ 316 APlist *ofl_ulibdirs; /* user supplied library search list */ 317 APlist *ofl_dlibdirs; /* default library search list */ 318 Word ofl_vercnt; /* number of versions to generate */ 319 APlist *ofl_verdesc; /* list of version descriptors */ 320 size_t ofl_verdefsz; /* size of version definition section */ 321 size_t ofl_verneedsz; /* size of version needed section */ 322 Word ofl_entercnt; /* no. of global symbols entered */ 323 Word ofl_globcnt; /* no. of global symbols to output */ 324 Word ofl_scopecnt; /* no. of scoped symbols to output */ 325 Word ofl_dynscopecnt; /* no. scoped syms in .SUNW_ldynsym */ 326 Word ofl_elimcnt; /* no. of eliminated symbols */ 327 Word ofl_locscnt; /* no. of local symbols in .symtab */ 328 Word ofl_dynlocscnt; /* no. local symbols in .SUNW_ldynsym */ 329 Word ofl_dynsymsortcnt; /* no. ndx in .SUNW_dynsymsort */ 330 Word ofl_dyntlssortcnt; /* no. ndx in .SUNW_dyntlssort */ 331 Word ofl_dynshdrcnt; /* no. of output section in .dynsym */ 332 Word ofl_shdrcnt; /* no. of output sections */ 333 Word ofl_caploclcnt; /* no. of local capabilities symbols */ 334 Word ofl_capsymcnt; /* no. of symbol capabilities entries */ 335 /* required */ 336 Word ofl_capchaincnt; /* no. of Capchain symbols */ 337 APlist *ofl_capgroups; /* list of capabilities groups */ 338 avl_tree_t *ofl_capfamilies; /* capability family AVL tree */ 339 Str_tbl *ofl_shdrsttab; /* Str_tbl for shdr strtab */ 340 Str_tbl *ofl_strtab; /* Str_tbl for symtab strtab */ 341 Str_tbl *ofl_dynstrtab; /* Str_tbl for dymsym strtab */ 342 Gotndx *ofl_tlsldgotndx; /* index to LD TLS_index structure */ 343 Xword ofl_relocsz; /* size of output relocations */ 344 Xword ofl_relocgotsz; /* size of .got relocations */ 345 Xword ofl_relocpltsz; /* size of .plt relocations */ 346 Xword ofl_relocbsssz; /* size of .bss (copy) relocations */ 347 Xword ofl_relocrelsz; /* size of .rel[a] relocations */ 348 Word ofl_relocincnt; /* no. of input relocations */ 349 Word ofl_reloccnt; /* tot number of output relocations */ 350 Word ofl_reloccntsub; /* tot numb of output relocations to */ 351 /* skip (-zignore) */ 352 Word ofl_relocrelcnt; /* tot number of relative */ 353 /* relocations */ 354 Word ofl_gotcnt; /* no. of .got entries */ 355 Word ofl_pltcnt; /* no. of .plt entries */ 356 Word ofl_pltpad; /* no. of .plt padd entries */ 357 Word ofl_hashbkts; /* no. of hash buckets required */ 358 Is_desc *ofl_isbss; /* .bss input section (globals) */ 359 Is_desc *ofl_islbss; /* .lbss input section (globals) */ 360 Is_desc *ofl_istlsbss; /* .tlsbss input section (globals) */ 361 Is_desc *ofl_isparexpn; /* -z nopartial .data input section */ 362 Os_desc *ofl_osdynamic; /* .dynamic output section */ 363 Os_desc *ofl_osdynsym; /* .dynsym output section */ 364 Os_desc *ofl_osldynsym; /* .SUNW_ldynsym output section */ 365 Os_desc *ofl_osdynstr; /* .dynstr output section */ 366 Os_desc *ofl_osdynsymsort; /* .SUNW_dynsymsort output section */ 367 Os_desc *ofl_osdyntlssort; /* .SUNW_dyntlssort output section */ 368 Os_desc *ofl_osgot; /* .got output section */ 369 Os_desc *ofl_oshash; /* .hash output section */ 370 Os_desc *ofl_osinitarray; /* .init_array output section */ 371 Os_desc *ofl_osfiniarray; /* .fini_array output section */ 372 Os_desc *ofl_ospreinitarray; /* .preinit_array output section */ 373 Os_desc *ofl_osinterp; /* .interp output section */ 374 Os_desc *ofl_oscap; /* .SUNW_cap output section */ 375 Os_desc *ofl_oscapinfo; /* .SUNW_capinfo output section */ 376 Os_desc *ofl_oscapchain; /* .SUNW_capchain output section */ 377 Os_desc *ofl_osplt; /* .plt output section */ 378 Os_desc *ofl_osmove; /* .SUNW_move output section */ 379 Os_desc *ofl_osrelhead; /* first relocation section */ 380 Os_desc *ofl_osrel; /* .rel[a] relocation section */ 381 Os_desc *ofl_osshstrtab; /* .shstrtab output section */ 382 Os_desc *ofl_osstrtab; /* .strtab output section */ 383 Os_desc *ofl_ossymtab; /* .symtab output section */ 384 Os_desc *ofl_ossymshndx; /* .symtab_shndx output section */ 385 Os_desc *ofl_osdynshndx; /* .dynsym_shndx output section */ 386 Os_desc *ofl_osldynshndx; /* .SUNW_ldynsym_shndx output sec */ 387 Os_desc *ofl_osverdef; /* .version definition output section */ 388 Os_desc *ofl_osverneed; /* .version needed output section */ 389 Os_desc *ofl_osversym; /* .version symbol ndx output section */ 390 Word ofl_dtflags_1; /* DT_FLAGS_1 entries */ 391 Word ofl_dtflags; /* DT_FLAGS entries */ 392 Os_desc *ofl_ossyminfo; /* .SUNW_syminfo output section */ 393 Half ofl_parexpnndx; /* -z nopartial section index */ 394 /* Ref. at perform_outreloc() in */ 395 /* libld/{mach}/machrel.c */ 396 Xword *ofl_checksum; /* DT_CHECKSUM value address */ 397 char *ofl_depaudit; /* dependency auditing required (-P) */ 398 char *ofl_audit; /* object auditing required (-p) */ 399 Alist *ofl_symfltrs; /* per-symbol filtees and their */ 400 Alist *ofl_dtsfltrs; /* associated .dynamic/.dynstrs */ 401 Objcapset ofl_ocapset; /* object capabilities */ 402 Lm_list *ofl_lml; /* runtime link-map list */ 403 Gottable *ofl_gottable; /* debugging got information */ 404 Rlxrel_cache ofl_sr_cache; /* Cache last result from */ 405 /* sloppy_comdat_reloc() */ 406 APlist *ofl_maptext; /* mapfile added text sections */ 407 APlist *ofl_mapdata; /* mapfile added data sections */ 408 avl_tree_t *ofl_wrap; /* -z wrap symbols */ 409 ofl_guideflag_t ofl_guideflags; /* -z guide flags */ 410 APlist *ofl_assdeflib; /* -z assert-deflib exceptions */ 411 int ofl_aslr; /* -z aslr, -1 disable, 1 enable */ 412 APlist *ofl_symasserts; /* assertions about symbols */ 413 /* from mapfiles */ 414 }; 415 416 #define FLG_OF_DYNAMIC 0x00000001 /* generate dynamic output module */ 417 #define FLG_OF_STATIC 0x00000002 /* generate static output module */ 418 #define FLG_OF_EXEC 0x00000004 /* generate an executable */ 419 #define FLG_OF_RELOBJ 0x00000008 /* generate a relocatable object */ 420 #define FLG_OF_SHAROBJ 0x00000010 /* generate a shared object */ 421 #define FLG_OF_BFLAG 0x00000020 /* do no special plt building: -b */ 422 #define FLG_OF_IGNENV 0x00000040 /* ignore LD_LIBRARY_PATH: -i */ 423 #define FLG_OF_STRIP 0x00000080 /* strip output: -s */ 424 #define FLG_OF_NOWARN 0x00000100 /* disable symbol warnings: -t */ 425 #define FLG_OF_NOUNDEF 0x00000200 /* allow no undefined symbols: -zdefs */ 426 #define FLG_OF_PURETXT 0x00000400 /* allow no text relocations: -ztext */ 427 #define FLG_OF_GENMAP 0x00000800 /* generate a memory map: -m */ 428 #define FLG_OF_DYNLIBS 0x00001000 /* dynamic input allowed: -Bdynamic */ 429 #define FLG_OF_SYMBOLIC 0x00002000 /* bind global symbols: -Bsymbolic */ 430 #define FLG_OF_ADDVERS 0x00004000 /* add version stamp: -Qy */ 431 #define FLG_OF_NOLDYNSYM 0x00008000 /* -znoldynsym set */ 432 #define FLG_OF_IS_ORDER 0x00010000 /* input section ordering within a */ 433 /* segment is required */ 434 #define FLG_OF_EC_FILES 0x00020000 /* Ent_desc exist w/non-NULL ec_files */ 435 #define FLG_OF_TEXTREL 0x00040000 /* text relocations have been found */ 436 #define FLG_OF_MULDEFS 0x00080000 /* multiple symbols are allowed */ 437 #define FLG_OF_TLSPHDR 0x00100000 /* a TLS program header is required */ 438 #define FLG_OF_BLDGOT 0x00200000 /* build GOT table */ 439 #define FLG_OF_VERDEF 0x00400000 /* record version definitions */ 440 #define FLG_OF_VERNEED 0x00800000 /* record version dependencies */ 441 #define FLG_OF_NOVERSEC 0x01000000 /* don't record version sections */ 442 #define FLG_OF_KEY 0x02000000 /* file requires sort keys */ 443 #define FLG_OF_PROCRED 0x04000000 /* process any symbol reductions by */ 444 /* effecting the symbol table */ 445 /* output and relocations */ 446 #define FLG_OF_SYMINFO 0x08000000 /* create a syminfo section */ 447 #define FLG_OF_AUX 0x10000000 /* ofl_filter is an auxiliary filter */ 448 #define FLG_OF_FATAL 0x20000000 /* fatal error during input */ 449 #define FLG_OF_WARN 0x40000000 /* warning during input processing. */ 450 #define FLG_OF_VERBOSE 0x80000000 /* -z verbose flag set */ 451 452 #define FLG_OF_MAPSYMB 0x000100000000 /* symbolic scope definition seen */ 453 #define FLG_OF_MAPGLOB 0x000200000000 /* global scope definition seen */ 454 #define FLG_OF_COMREL 0x000400000000 /* -z combreloc set, which enables */ 455 /* DT_RELACNT tracking, */ 456 #define FLG_OF_NOCOMREL 0x000800000000 /* -z nocombreloc set */ 457 #define FLG_OF_AUTOLCL 0x001000000000 /* automatically reduce unspecified */ 458 /* global symbols to locals */ 459 #define FLG_OF_AUTOELM 0x002000000000 /* automatically eliminate */ 460 /* unspecified global symbols */ 461 #define FLG_OF_REDLSYM 0x004000000000 /* reduce local symbols */ 462 #define FLG_OF_OS_ORDER 0x008000000000 /* output section ordering required */ 463 #define FLG_OF_OSABI 0x010000000000 /* tag object as ELFOSABI_SOLARIS */ 464 #define FLG_OF_ADJOSCNT 0x020000000000 /* adjust ofl_shdrcnt to accommodate */ 465 /* discarded sections */ 466 #define FLG_OF_OTOSCAP 0x040000000000 /* convert object capabilities to */ 467 /* symbol capabilities */ 468 #define FLG_OF_PTCAP 0x080000000000 /* PT_SUNWCAP required */ 469 #define FLG_OF_CAPSTRS 0x100000000000 /* capability strings are required */ 470 #define FLG_OF_EHFRAME 0x200000000000 /* output contains .eh_frame section */ 471 #define FLG_OF_FATWARN 0x400000000000 /* make warnings fatal */ 472 #define FLG_OF_ADEFLIB 0x800000000000 /* no libraries in default path */ 473 474 #define FLG_OF_KMOD 0x1000000000000 /* output is a kernel module */ 475 476 /* 477 * In the flags1 arena, establish any options that are applicable to archive 478 * extraction first, and associate a mask. These values are recorded with any 479 * archive descriptor so that they may be reset should the archive require a 480 * rescan to try and resolve undefined symbols. 481 */ 482 #define FLG_OF1_ALLEXRT 0x0000000001 /* extract all members from an */ 483 /* archive file */ 484 #define FLG_OF1_WEAKEXT 0x0000000002 /* allow archive extraction to */ 485 /* resolve weak references */ 486 #define MSK_OF1_ARCHIVE 0x0000000003 /* archive flags mask */ 487 488 #define FLG_OF1_NOINTRP 0x0000000008 /* -z nointerp flag set */ 489 #define FLG_OF1_ZDIRECT 0x0000000010 /* -z direct flag set */ 490 #define FLG_OF1_NDIRECT 0x0000000020 /* no-direct bindings specified */ 491 #define FLG_OF1_DEFERRED 0x0000000040 /* deferred dependency recording */ 492 493 #define FLG_OF1_RELDYN 0x0000000100 /* process .dynamic in rel obj */ 494 #define FLG_OF1_NRLXREL 0x0000000200 /* -z norelaxreloc flag set */ 495 #define FLG_OF1_RLXREL 0x0000000400 /* -z relaxreloc flag set */ 496 #define FLG_OF1_IGNORE 0x0000000800 /* ignore unused dependencies */ 497 #define FLG_OF1_NOSGHND 0x0000001000 /* -z nosighandler flag set */ 498 #define FLG_OF1_TEXTOFF 0x0000002000 /* text relocations are ok */ 499 #define FLG_OF1_ABSEXEC 0x0000004000 /* -zabsexec set */ 500 #define FLG_OF1_LAZYLD 0x0000008000 /* lazy loading of objects enabled */ 501 #define FLG_OF1_GRPPRM 0x0000010000 /* dependencies are to have */ 502 /* GROUPPERM enabled */ 503 504 #define FLG_OF1_NOPARTI 0x0000040000 /* -znopartial set */ 505 #define FLG_OF1_BSSOREL 0x0000080000 /* output relocation against bss */ 506 /* section */ 507 #define FLG_OF1_TLSOREL 0x0000100000 /* output relocation against .tlsbss */ 508 /* section */ 509 #define FLG_OF1_MEMORY 0x0000200000 /* produce a memory model */ 510 #define FLG_OF1_NGLBDIR 0x0000400000 /* no DT_1_DIRECT flag allowed */ 511 #define FLG_OF1_ENCDIFF 0x0000800000 /* host running linker has different */ 512 /* byte order than output object */ 513 #define FLG_OF1_VADDR 0x0001000000 /* a segment defines explicit vaddr */ 514 #define FLG_OF1_EXTRACT 0x0002000000 /* archive member has been extracted */ 515 #define FLG_OF1_RESCAN 0x0004000000 /* any archives should be rescanned */ 516 #define FLG_OF1_IGNPRC 0x0008000000 /* ignore processing required */ 517 #define FLG_OF1_NCSTTAB 0x0010000000 /* -znocompstrtab set */ 518 #define FLG_OF1_DONE 0x0020000000 /* link-editor processing complete */ 519 #define FLG_OF1_NONREG 0x0040000000 /* non-regular file specified as */ 520 /* the output file */ 521 #define FLG_OF1_ALNODIR 0x0080000000 /* establish NODIRECT for all */ 522 /* exported interfaces. */ 523 #define FLG_OF1_OVHWCAP1 0x0100000000 /* override CA_SUNW_HW_1 capabilities */ 524 #define FLG_OF1_OVSFCAP1 0x0200000000 /* override CA_SUNW_SF_1 capabilities */ 525 #define FLG_OF1_OVHWCAP2 0x0400000000 /* override CA_SUNW_HW_2 capabilities */ 526 #define FLG_OF1_OVMACHCAP 0x0800000000 /* override CA_SUNW_MACH capability */ 527 #define FLG_OF1_OVPLATCAP 0x1000000000 /* override CA_SUNW_PLAT capability */ 528 #define FLG_OF1_OVIDCAP 0x2000000000 /* override CA_SUNW_ID capability */ 529 #define FLG_OF1_OVHWCAP3 0x4000000000 /* override CA_SUNW_HW_3 capabilities */ 530 531 /* 532 * Guidance flags. The flags with the FLG_OFG_NO_ prefix are used to suppress 533 * messages for a given category, and use the lower 28 bits of the word, 534 * The upper nibble is reserved for other guidance status. 535 */ 536 #define FLG_OFG_ENABLE 0x10000000 /* -z guidance option active */ 537 #define FLG_OFG_ISSUED 0x20000000 /* -z guidance message issued */ 538 539 #define FLG_OFG_NO_ALL 0x0fffffff /* disable all guidance */ 540 #define FLG_OFG_NO_DEFS 0x00000001 /* specify all dependencies */ 541 #define FLG_OFG_NO_DB 0x00000002 /* use direct bindings */ 542 #define FLG_OFG_NO_LAZY 0x00000004 /* be explicit about lazyload */ 543 #define FLG_OFG_NO_MF 0x00000008 /* use v2 mapfile syntax */ 544 #define FLG_OFG_NO_TEXT 0x00000010 /* verify pure text segment */ 545 #define FLG_OFG_NO_UNUSED 0x00000020 /* remove unused dependency */ 546 #define FLG_OFG_NO_ASSERTS 0x00000040 /* suggest mapfile assertions */ 547 548 /* 549 * Test to see if a guidance should be given for a given category 550 * or not. _no_flag is one of the FLG_OFG_NO_xxx flags. Returns TRUE 551 * if the guidance should be issued, and FALSE to remain silent. 552 */ 553 #define OFL_GUIDANCE(_ofl, _no_flag) (((_ofl)->ofl_guideflags & \ 554 (FLG_OFG_ENABLE | (_no_flag))) == FLG_OFG_ENABLE) 555 556 /* 557 * Test to see if the output file would allow the presence of 558 * a .dynsym section. 559 */ 560 #define OFL_ALLOW_DYNSYM(_ofl) (((_ofl)->ofl_flags & \ 561 (FLG_OF_DYNAMIC | FLG_OF_RELOBJ)) == FLG_OF_DYNAMIC) 562 563 /* 564 * Test to see if the output file would allow the presence of 565 * a .SUNW_ldynsym section. The requirements are that a .dynsym 566 * is allowed, and -znoldynsym has not been specified. Note that 567 * even if the answer is True (1), we will only generate one if there 568 * are local symbols that require it. 569 */ 570 #define OFL_ALLOW_LDYNSYM(_ofl) (((_ofl)->ofl_flags & \ 571 (FLG_OF_DYNAMIC | FLG_OF_RELOBJ | FLG_OF_NOLDYNSYM)) == FLG_OF_DYNAMIC) 572 573 /* 574 * Test to see if relocation processing should be done. This is normally 575 * true, but can be disabled via the '-z noreloc' option. Note that 576 * relocatable objects are still relocated even if '-z noreloc' is present. 577 */ 578 #define OFL_DO_RELOC(_ofl) (((_ofl)->ofl_flags & FLG_OF_RELOBJ) || \ 579 !((_ofl)->ofl_dtflags_1 & DF_1_NORELOC)) 580 581 /* 582 * Determine whether a static executable is being built. 583 */ 584 #define OFL_IS_STATIC_EXEC(_ofl) (((_ofl)->ofl_flags & \ 585 (FLG_OF_STATIC | FLG_OF_EXEC)) == (FLG_OF_STATIC | FLG_OF_EXEC)) 586 587 /* 588 * Determine whether a static object is being built. This macro is used 589 * to select the appropriate string table, and symbol table that other 590 * sections need to reference. 591 */ 592 #define OFL_IS_STATIC_OBJ(_ofl) ((_ofl)->ofl_flags & \ 593 (FLG_OF_RELOBJ | FLG_OF_STATIC)) 594 595 /* 596 * Macros for counting symbol table entries. These are used to size symbol 597 * tables and associated sections (.syminfo, SUNW_capinfo, .hash, etc.) and 598 * set required sh_info entries (the offset to the first global symbol). 599 */ 600 #define SYMTAB_LOC_CNT(_ofl) /* local .symtab entries */ \ 601 (2 + /* NULL and STT_FILE */ \ 602 (_ofl)->ofl_shdrcnt + /* section symbol */ \ 603 (_ofl)->ofl_caploclcnt + /* local capabilities */ \ 604 (_ofl)->ofl_scopecnt + /* scoped symbols */ \ 605 (_ofl)->ofl_locscnt) /* standard locals */ 606 #define SYMTAB_ALL_CNT(_ofl) /* all .symtab entries */ \ 607 (SYMTAB_LOC_CNT(_ofl) + /* .symtab locals */ \ 608 (_ofl)->ofl_globcnt) /* standard globals */ 609 610 #define DYNSYM_LOC_CNT(_ofl) /* local .dynsym entries */ \ 611 (1 + /* NULL */ \ 612 (_ofl)->ofl_dynshdrcnt + /* section symbols */ \ 613 (_ofl)->ofl_caploclcnt + /* local capabilities */ \ 614 (_ofl)->ofl_lregsymcnt) /* local register symbols */ 615 #define DYNSYM_ALL_CNT(_ofl) /* all .dynsym entries */ \ 616 (DYNSYM_LOC_CNT(_ofl) + /* .dynsym locals */ \ 617 (_ofl)->ofl_globcnt) /* standard globals */ 618 619 /* 620 * Define a move descriptor used within relocation structures. 621 */ 622 typedef struct { 623 Move *mr_move; 624 Sym_desc *mr_sym; 625 } Mv_reloc; 626 627 /* 628 * Relocation (active & output) processing structure - transparent to common 629 * code. There can be millions of these structures in a large link, so it 630 * is important to keep it small. You should only add new items to Rel_desc 631 * if they are critical, apply to most relocations, and cannot be easily 632 * computed from the other information. 633 * 634 * Items that can be derived should be implemented as a function that accepts 635 * a Rel_desc argument, and returns the desired data. ld_reloc_sym_name() is 636 * an example of this. 637 * 638 * Lesser used relocation data is kept in an auxiliary block, Rel_aux, 639 * that is only allocated as necessary. In exchange for adding one pointer 640 * of overhead to Rel_desc (rel_aux), most relocations are reduced in size 641 * by the size of Rel_aux. This strategy relies on the data in Rel_aux 642 * being rarely needed --- otherwise it will backfire badly. 643 * 644 * Note that rel_raddend is primarily only of interest to RELA relocations, 645 * and is set to 0 for REL. However, there is an exception: If FLG_REL_NADDEND 646 * is set, then rel_raddend contains a replacement value for the implicit 647 * addend found in the relocation target. 648 * 649 * Fields should be ordered from largest to smallest, to minimize packing 650 * holes in the struct layout. 651 */ 652 struct rel_desc { 653 Is_desc *rel_isdesc; /* input section reloc is against */ 654 Sym_desc *rel_sym; /* sym relocation is against */ 655 Rel_aux *rel_aux; /* NULL, or auxiliary data */ 656 Xword rel_roffset; /* relocation offset */ 657 Sxword rel_raddend; /* addend from input relocation */ 658 Word rel_flags; /* misc. flags for relocations */ 659 Word rel_rtype; /* relocation type */ 660 }; 661 662 /* 663 * Data that would be kept in Rel_desc if the size of that structure was 664 * not an issue. This auxiliary block is only allocated as needed, 665 * and must only contain rarely needed items. The goal is for the vast 666 * majority of Rel_desc structs to not have an auxiliary block. 667 * 668 * When a Rel_desc does not have an auxiliary block, a default value 669 * is assumed for each auxiliary item: 670 * 671 * - ra_osdesc: 672 * Output section to which relocation applies. The default 673 * value for this is the output section associated with the 674 * input section (rel_isdesc->is_osdesc), or NULL if there 675 * is no associated input section. 676 * 677 * - ra_usym: 678 * If the symbol associated with a relocation is part of a weak/strong 679 * pair, then ra_usym contains the strong symbol and rel_sym the weak. 680 * Otherwise, the default value is the same value as rel_sym. 681 * 682 * - ra_move: 683 * Move table data. The default value is NULL. 684 * 685 * - ra_typedata: 686 * ELF_R_TYPE_DATA(info). This value applies only to a small 687 * subset of 64-bit sparc relocations, and is otherwise 0. The 688 * default value is 0. 689 * 690 * If any value in Rel_aux is non-default, then an auxiliary block is 691 * necessary, and each field contains its actual value. If all the auxiliary 692 * values are default, no Rel_aux is needed, and the RELAUX_GET_xxx() 693 * macros below are able to supply the proper default. 694 * 695 * To set a Rel_aux value, use the ld_reloc_set_aux_XXX() functions. 696 * These functions are written to avoid unnecessary auxiliary allocations, 697 * and know the rules for each item. 698 */ 699 struct rel_aux { 700 Os_desc *ra_osdesc; /* output section reloc is against */ 701 Sym_desc *ra_usym; /* strong sym if this is a weak pair */ 702 Mv_reloc *ra_move; /* move table information */ 703 Word ra_typedata; /* ELF_R_TYPE_DATA(info) */ 704 }; 705 706 /* 707 * Test a given auxiliary value to determine if it has the default value 708 * for that item, as described above. If all the auxiliary items have 709 * their default values, no auxiliary place is necessary to represent them. 710 * If any one of them is non-default, the auxiliary block is needed. 711 */ 712 #define RELAUX_ISDEFAULT_MOVE(_rdesc, _mv) (_mv == NULL) 713 #define RELAUX_ISDEFAULT_USYM(_rdesc, _usym) ((_rdesc)->rel_sym == _usym) 714 #define RELAUX_ISDEFAULT_OSDESC(_rdesc, _osdesc) \ 715 ((((_rdesc)->rel_isdesc == NULL) && (_osdesc == NULL)) || \ 716 ((_rdesc)->rel_isdesc && ((_rdesc)->rel_isdesc->is_osdesc == _osdesc))) 717 #define RELAUX_ISDEFAULT_TYPEDATA(_rdesc, _typedata) (_typedata == 0) 718 719 /* 720 * Retrieve the value of an auxiliary relocation item, preserving the illusion 721 * that every relocation descriptor has an auxiliary block attached. The 722 * real implementation is that an auxiliary block is only present if one or 723 * more auxiliary items have non-default values. These macros return the true 724 * value if an auxiliary block is present, and the default value for the 725 * item otherwise. 726 */ 727 #define RELAUX_GET_MOVE(_rdesc) \ 728 ((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_move : NULL) 729 #define RELAUX_GET_USYM(_rdesc) \ 730 ((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_usym : (_rdesc)->rel_sym) 731 #define RELAUX_GET_OSDESC(_rdesc) \ 732 ((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_osdesc : \ 733 ((_rdesc)->rel_isdesc ? (_rdesc)->rel_isdesc->is_osdesc : NULL)) 734 #define RELAUX_GET_TYPEDATA(_rdesc) \ 735 ((_rdesc)->rel_aux ? (_rdesc)->rel_aux->ra_typedata : 0) 736 737 /* 738 * common flags used on the Rel_desc structure (defined in machrel.h). 739 */ 740 #define FLG_REL_GOT 0x00000001 /* relocation against GOT */ 741 #define FLG_REL_PLT 0x00000002 /* relocation against PLT */ 742 #define FLG_REL_BSS 0x00000004 /* relocation against BSS */ 743 #define FLG_REL_LOAD 0x00000008 /* section loadable */ 744 #define FLG_REL_SCNNDX 0x00000010 /* use section index for symbol ndx */ 745 #define FLG_REL_CLVAL 0x00000020 /* clear VALUE for active relocation */ 746 #define FLG_REL_ADVAL 0x00000040 /* add VALUE for output relocation, */ 747 /* only relevant to SPARC and */ 748 /* R_SPARC_RELATIVE */ 749 #define FLG_REL_GOTCL 0x00000080 /* clear the GOT entry. This is */ 750 /* relevant to RELA relocations, */ 751 /* not REL (i386) relocations */ 752 #define FLG_REL_MOVETAB 0x00000100 /* Relocation against .SUNW_move */ 753 /* adjustments required before */ 754 /* actual relocation */ 755 #define FLG_REL_NOINFO 0x00000200 /* Relocation comes from a section */ 756 /* with a null sh_info field */ 757 #define FLG_REL_REG 0x00000400 /* Relocation target is reg sym */ 758 #define FLG_REL_FPTR 0x00000800 /* relocation against func. desc. */ 759 #define FLG_REL_RFPTR1 0x00001000 /* Relative relocation against */ 760 /* 1st part of FD */ 761 #define FLG_REL_RFPTR2 0x00002000 /* Relative relocation against */ 762 /* 2nd part of FD */ 763 #define FLG_REL_DISP 0x00004000 /* *disp* relocation */ 764 #define FLG_REL_STLS 0x00008000 /* IE TLS reference to */ 765 /* static TLS GOT index */ 766 #define FLG_REL_DTLS 0x00010000 /* GD TLS reference relative to */ 767 /* dynamic TLS GOT index */ 768 #define FLG_REL_MTLS 0x00020000 /* LD TLS reference against GOT */ 769 #define FLG_REL_STTLS 0x00040000 /* LE TLS reference directly */ 770 /* to static tls index */ 771 #define FLG_REL_TLSFIX 0x00080000 /* relocation points to TLS instr. */ 772 /* which needs updating */ 773 #define FLG_REL_RELA 0x00100000 /* descriptor captures a Rela */ 774 #define FLG_REL_GOTFIX 0x00200000 /* relocation points to GOTOP instr. */ 775 /* which needs updating */ 776 #define FLG_REL_NADDEND 0x00400000 /* Replace implicit addend in dest */ 777 /* with value in rel_raddend */ 778 /* Relevant to REL (i386) */ 779 /* relocations, not to RELA. */ 780 781 /* 782 * We often need the name of the symbol contained in a relocation descriptor 783 * for diagnostic or error output. This is usually the symbol name, but 784 * we substitute a constructed name in some cases. Hence, the name is 785 * generated on the fly by a private function within libld. This is the 786 * prototype for that function. 787 */ 788 typedef const char *(* rel_desc_sname_func_t)(Rel_desc *); 789 790 /* 791 * Header for a relocation descriptor cache buffer. 792 */ 793 struct rel_cachebuf { 794 Rel_desc *rc_end; 795 Rel_desc *rc_free; 796 Rel_desc rc_arr[1]; 797 }; 798 799 /* 800 * Header for a relocation auxiliary descriptor cache buffer. 801 */ 802 struct rel_aux_cachebuf { 803 Rel_aux *rac_end; 804 Rel_aux *rac_free; 805 Rel_aux rac_arr[1]; 806 }; 807 808 /* 809 * Convenience macro for traversing every relocation descriptor found within 810 * a given relocation cache, transparently handling the cache buffers and 811 * skipping any unallocated descriptors within the buffers. 812 * 813 * entry: 814 * _rel_cache - Relocate descriptor cache (Rel_cache) to traverse 815 * _idx - Aliste index variable for use by the macro 816 * _rcbp - Cache buffer pointer, for use by the macro 817 * _orsp - Rel_desc pointer, which will take on the value of a different 818 * relocation descriptor in the cache in each iteration. 819 * 820 * The caller must not assign new values to _idx, _rcbp, or _orsp within 821 * the scope of REL_CACHE_TRAVERSE. 822 */ 823 #define REL_CACHE_TRAVERSE(_rel_cache, _idx, _rcbp, _orsp) \ 824 for (APLIST_TRAVERSE((_rel_cache)->rc_list, _idx, _rcbp)) \ 825 for (_orsp = _rcbp->rc_arr; _orsp < _rcbp->rc_free; _orsp++) 826 827 /* 828 * Symbol value descriptor. For relocatable objects, each symbols value is 829 * its offset within its associated section. Therefore, to uniquely define 830 * each symbol within a relocatable object, record and sort the sh_offset and 831 * symbol value. This information is used to search for displacement 832 * relocations as part of copy relocation validation. 833 */ 834 typedef struct { 835 Addr ssv_value; 836 Sym_desc *ssv_sdp; 837 } Ssv_desc; 838 839 /* 840 * Input file processing structures. 841 */ 842 struct ifl_desc { /* input file descriptor */ 843 const char *ifl_name; /* full file name */ 844 const char *ifl_soname; /* shared object name */ 845 dev_t ifl_stdev; /* device id and inode number for .so */ 846 ino_t ifl_stino; /* multiple inclusion checks */ 847 Ehdr *ifl_ehdr; /* elf header describing this file */ 848 Elf *ifl_elf; /* elf descriptor for this file */ 849 Sym_desc **ifl_oldndx; /* original symbol table indices */ 850 Sym_desc *ifl_locs; /* symbol desc version of locals */ 851 Ssv_desc *ifl_sortsyms; /* sorted list of symbols by value */ 852 Word ifl_locscnt; /* no. of local symbols to process */ 853 Word ifl_symscnt; /* total no. of symbols to process */ 854 Word ifl_sortcnt; /* no. of sorted symbols to process */ 855 Word ifl_shnum; /* number of sections in file */ 856 Word ifl_shstrndx; /* index to .shstrtab */ 857 Word ifl_vercnt; /* number of versions in file */ 858 Half ifl_neededndx; /* index to NEEDED in .dyn section */ 859 Word ifl_flags; /* explicit/implicit reference */ 860 Is_desc **ifl_isdesc; /* isdesc[scn ndx] = Is_desc ptr */ 861 Sdf_desc *ifl_sdfdesc; /* control definition */ 862 Versym *ifl_versym; /* version symbol table array */ 863 Ver_index *ifl_verndx; /* verndx[ver ndx] = Ver_index */ 864 APlist *ifl_verdesc; /* version descriptor list */ 865 APlist *ifl_relsect; /* relocation section list */ 866 Alist *ifl_groups; /* SHT_GROUP section list */ 867 Cap_desc *ifl_caps; /* capabilities descriptor */ 868 }; 869 870 #define FLG_IF_CMDLINE 0x00000001 /* full filename specified from the */ 871 /* command line (no -l) */ 872 #define FLG_IF_NEEDED 0x00000002 /* shared object should be recorded */ 873 #define FLG_IF_DIRECT 0x00000004 /* establish direct bindings to this */ 874 /* object */ 875 #define FLG_IF_EXTRACT 0x00000008 /* file extracted from an archive */ 876 #define FLG_IF_VERNEED 0x00000010 /* version dependency information is */ 877 /* required */ 878 #define FLG_IF_DEPREQD 0x00000020 /* dependency is required to satisfy */ 879 /* symbol references */ 880 #define FLG_IF_NEEDSTR 0x00000040 /* dependency specified by -Nn */ 881 /* flag */ 882 #define FLG_IF_IGNORE 0x00000080 /* ignore unused dependencies */ 883 #define FLG_IF_NODIRECT 0x00000100 /* object contains symbols that */ 884 /* cannot be directly bound to */ 885 #define FLG_IF_LAZYLD 0x00000200 /* dependency should be lazy loaded */ 886 #define FLG_IF_GRPPRM 0x00000400 /* dependency establishes a group */ 887 #define FLG_IF_DISPPEND 0x00000800 /* displacement relocation done */ 888 /* in the ld time. */ 889 #define FLG_IF_DISPDONE 0x00001000 /* displacement relocation done */ 890 /* at the run time */ 891 #define FLG_IF_MAPFILE 0x00002000 /* file is a mapfile */ 892 #define FLG_IF_HSTRTAB 0x00004000 /* file has a string section */ 893 #define FLG_IF_FILEREF 0x00008000 /* file contains a section which */ 894 /* is included in the output */ 895 /* allocatable image */ 896 #define FLG_IF_GNUVER 0x00010000 /* file used GNU-style versioning */ 897 #define FLG_IF_ORDERED 0x00020000 /* ordered section processing */ 898 /* required */ 899 #define FLG_IF_OTOSCAP 0x00040000 /* convert object capabilities to */ 900 /* symbol capabilities */ 901 #define FLG_IF_DEFERRED 0x00080000 /* dependency is deferred */ 902 #define FLG_IF_RTLDINF 0x00100000 /* dependency has DT_SUNW_RTLTINF set */ 903 #define FLG_IF_GROUPS 0x00200000 /* input file has groups to process */ 904 905 /* 906 * Symbol states that require the generation of a DT_POSFLAG_1 .dynamic entry. 907 */ 908 #define MSK_IF_POSFLAG1 (FLG_IF_LAZYLD | FLG_IF_GRPPRM | FLG_IF_DEFERRED) 909 910 /* 911 * Symbol states that require an associated Syminfo entry. 912 */ 913 #define MSK_IF_SYMINFO (FLG_IF_LAZYLD | FLG_IF_DIRECT | FLG_IF_DEFERRED) 914 915 916 struct is_desc { /* input section descriptor */ 917 const char *is_name; /* original section name */ 918 const char *is_sym_name; /* NULL, or name string to use for */ 919 /* related STT_SECTION symbols */ 920 Shdr *is_shdr; /* the elf section header */ 921 Ifl_desc *is_file; /* infile desc for this section */ 922 Os_desc *is_osdesc; /* new output section for this */ 923 /* input section */ 924 Elf_Data *is_indata; /* input sections raw data */ 925 Is_desc *is_symshndx; /* related SHT_SYM_SHNDX section */ 926 Is_desc *is_comdatkeep; /* If COMDAT section is discarded, */ 927 /* this is section that was kept */ 928 Word is_scnndx; /* original section index in file */ 929 Word is_ordndx; /* index for section. Used to decide */ 930 /* where to insert section when */ 931 /* reordering sections */ 932 Word is_keyident; /* key for SHF_{ORDERED|LINK_ORDER} */ 933 /* processing and ident used for */ 934 /* placing/ordering sections */ 935 Word is_flags; /* Various flags */ 936 }; 937 938 #define FLG_IS_ORDERED 0x0001 /* this is a SHF_ORDERED section */ 939 #define FLG_IS_KEY 0x0002 /* section requires sort keys */ 940 #define FLG_IS_DISCARD 0x0004 /* section is to be discarded */ 941 #define FLG_IS_RELUPD 0x0008 /* symbol defined here may have moved */ 942 #define FLG_IS_SECTREF 0x0010 /* section has been referenced */ 943 #define FLG_IS_GDATADEF 0x0020 /* section contains global data sym */ 944 #define FLG_IS_EXTERNAL 0x0040 /* isp from a user file */ 945 #define FLG_IS_INSTRMRG 0x0080 /* Usable SHF_MERGE|SHF_STRINGS sec */ 946 #define FLG_IS_GNSTRMRG 0x0100 /* Generated mergeable string section */ 947 948 #define FLG_IS_PLACE 0x0400 /* section requires to be placed */ 949 #define FLG_IS_COMDAT 0x0800 /* section is COMDAT */ 950 #define FLG_IS_EHFRAME 0x1000 /* section is .eh_frame */ 951 952 /* 953 * Output sections contain lists of input sections that are assigned to them. 954 * These items fall into 4 categories: 955 * BEFORE - Ordered sections that specify SHN_BEFORE, in input order. 956 * ORDERED - Ordered sections that are sorted using unsorted sections 957 * as the sort key. 958 * DEFAULT - Sections that are placed into the output section 959 * in input order. 960 * AFTER - Ordered sections that specify SHN_AFTER, in input order. 961 */ 962 #define OS_ISD_BEFORE 0 963 #define OS_ISD_ORDERED 1 964 #define OS_ISD_DEFAULT 2 965 #define OS_ISD_AFTER 3 966 #define OS_ISD_NUM 4 967 typedef APlist *os_isdecs_arr[OS_ISD_NUM]; 968 969 /* 970 * Convenience macro for traversing every input section associated 971 * with a given output section. The primary benefit of this macro 972 * is that it preserves a precious level of code indentation in the 973 * code that uses it. 974 */ 975 #define OS_ISDESCS_TRAVERSE(_list_idx, _osp, _idx, _isp) \ 976 for (_list_idx = 0; _list_idx < OS_ISD_NUM; _list_idx++) \ 977 for (APLIST_TRAVERSE(_osp->os_isdescs[_list_idx], _idx, _isp)) 978 979 980 /* 981 * Map file and output file processing structures 982 */ 983 struct os_desc { /* Output section descriptor */ 984 const char *os_name; /* the section name */ 985 Elf_Scn *os_scn; /* the elf section descriptor */ 986 Shdr *os_shdr; /* the elf section header */ 987 Os_desc *os_relosdesc; /* the output relocation section */ 988 APlist *os_relisdescs; /* reloc input section descriptors */ 989 /* for this output section */ 990 os_isdecs_arr os_isdescs; /* lists of input sections in output */ 991 APlist *os_mstrisdescs; /* FLG_IS_INSTRMRG input sections */ 992 Sg_desc *os_sgdesc; /* segment os_desc is placed on */ 993 Elf_Data *os_outdata; /* output sections raw data */ 994 avl_tree_t *os_comdats; /* AVL tree of COMDAT input sections */ 995 /* associated to output section */ 996 Word os_identndx; /* section identifier for input */ 997 /* section processing, followed */ 998 /* by section symbol index */ 999 Word os_ordndx; /* index for section. Used to decide */ 1000 /* where to insert section when */ 1001 /* reordering sections */ 1002 Xword os_szoutrels; /* size of output relocation section */ 1003 uint_t os_namehash; /* hash on section name */ 1004 uchar_t os_flags; /* various flags */ 1005 APlist *os_mstrsyms; /* symbols affected by string merge */ 1006 APlist *os_mstrrels; /* section relocs affected by... */ 1007 Str_tbl *os_mstrtab; /* merged string table */ 1008 Os_desc *os_hashnext; /* next hashed */ 1009 }; 1010 1011 /* 1012 * Hash of output section descriptors, by namehash. 1013 */ 1014 typedef struct os_desc_hash { 1015 Os_desc **osh_hashtab; /* hash table itself */ 1016 size_t osh_size; /* number of elements in hash table */ 1017 } os_desc_hash_t; 1018 1019 #define FLG_OS_KEY 0x01 /* section requires sort keys */ 1020 #define FLG_OS_OUTREL 0x02 /* output rel against this section */ 1021 #define FLG_OS_SECTREF 0x04 /* isps are not affected by -zignore */ 1022 #define FLG_OS_EHFRAME 0x08 /* section is .eh_frame */ 1023 1024 /* 1025 * The sg_id field of the segment descriptor is used to establish the default 1026 * order for program headers and segments in the output object. Segments are 1027 * ordered according to the following SGID values that classify them based on 1028 * their attributes. The initial set of built in segments are in this order, 1029 * and new mapfile defined segments are inserted into these groups. Within a 1030 * given SGID group, the position of new segments depends on the syntax 1031 * version of the mapfile that creates them. Version 1 (original sysv) 1032 * mapfiles place the new segment at the head of their group (reverse creation 1033 * order). The newer syntax places them at the end, following the others 1034 * (creation order). 1035 * 1036 * Note that any new segments must always be added after PT_PHDR and 1037 * PT_INTERP (refer Generic ABI, Page 5-4). 1038 */ 1039 #define SGID_PHDR 0 /* PT_PHDR */ 1040 #define SGID_INTERP 1 /* PT_INTERP */ 1041 #define SGID_SUNWCAP 2 /* PT_SUNWCAP */ 1042 #define SGID_TEXT 3 /* PT_LOAD */ 1043 #define SGID_DATA 4 /* PT_LOAD */ 1044 #define SGID_BSS 5 /* PT_LOAD */ 1045 #if defined(_ELF64) 1046 #define SGID_LRODATA 6 /* PT_LOAD (amd64-only) */ 1047 #define SGID_LDATA 7 /* PT_LOAD (amd64-only) */ 1048 #endif 1049 #define SGID_TEXT_EMPTY 8 /* PT_LOAD, reserved (?E in version 1 syntax) */ 1050 #define SGID_NULL_EMPTY 9 /* PT_NULL, reserved (?E in version 1 syntax) */ 1051 #define SGID_DYN 10 /* PT_DYNAMIC */ 1052 #define SGID_DTRACE 11 /* PT_SUNWDTRACE */ 1053 #define SGID_TLS 12 /* PT_TLS */ 1054 #define SGID_UNWIND 13 /* PT_SUNW_UNWIND */ 1055 #define SGID_SUNWSTACK 14 /* PT_SUNWSTACK */ 1056 #define SGID_NOTE 15 /* PT_NOTE */ 1057 #define SGID_NULL 16 /* PT_NULL, mapfile defined empty phdr slots */ 1058 /* for use by post processors */ 1059 #define SGID_EXTRA 17 /* PT_NULL (final catchall) */ 1060 1061 typedef Half sg_flags_t; 1062 struct sg_desc { /* output segment descriptor */ 1063 Word sg_id; /* segment identifier (for sorting) */ 1064 Phdr sg_phdr; /* segment header for output file */ 1065 const char *sg_name; /* segment name for PT_LOAD, PT_NOTE, */ 1066 /* and PT_NULL, otherwise NULL */ 1067 Xword sg_round; /* data rounding required (mapfile) */ 1068 Xword sg_length; /* maximum segment length; if 0 */ 1069 /* segment is not specified */ 1070 APlist *sg_osdescs; /* list of output section descriptors */ 1071 APlist *sg_is_order; /* list of entry criteria */ 1072 /* giving input section order */ 1073 Alist *sg_os_order; /* list specifying output section */ 1074 /* ordering for the segment */ 1075 sg_flags_t sg_flags; 1076 APlist *sg_sizesym; /* size symbols for this segment */ 1077 Xword sg_align; /* LCM of sh_addralign */ 1078 Elf_Scn *sg_fscn; /* the SCN of the first section. */ 1079 avl_node_t sg_avlnode; /* AVL book-keeping */ 1080 os_desc_hash_t *sg_hashtab; /* hash table of output descriptors */ 1081 }; 1082 1083 #define FLG_SG_P_VADDR 0x0001 /* p_vaddr segment attribute set */ 1084 #define FLG_SG_P_PADDR 0x0002 /* p_paddr segment attribute set */ 1085 #define FLG_SG_LENGTH 0x0004 /* length segment attribute set */ 1086 #define FLG_SG_P_ALIGN 0x0008 /* p_align segment attribute set */ 1087 #define FLG_SG_ROUND 0x0010 /* round segment attribute set */ 1088 #define FLG_SG_P_FLAGS 0x0020 /* p_flags segment attribute set */ 1089 #define FLG_SG_P_TYPE 0x0040 /* p_type segment attribute set */ 1090 #define FLG_SG_IS_ORDER 0x0080 /* input section ordering is required */ 1091 /* for this segment. */ 1092 #define FLG_SG_NOHDR 0x0100 /* don't map ELF or phdrs into */ 1093 /* this segment */ 1094 #define FLG_SG_EMPTY 0x0200 /* an empty segment specification */ 1095 /* no input sections will be */ 1096 /* associated to this section */ 1097 #define FLG_SG_KEY 0x0400 /* segment requires sort keys */ 1098 #define FLG_SG_NODISABLE 0x0800 /* FLG_SG_DISABLED is not allowed on */ 1099 /* this segment */ 1100 #define FLG_SG_DISABLED 0x1000 /* this segment is disabled */ 1101 #define FLG_SG_PHREQ 0x2000 /* this segment requires a program */ 1102 /* header */ 1103 #define FLG_SG_ORDERED 0x4000 /* SEGMENT_ORDER segment */ 1104 1105 struct sec_order { 1106 const char *sco_secname; /* section name to be ordered */ 1107 Half sco_flags; 1108 }; 1109 1110 #define FLG_SGO_USED 0x0001 /* was ordering used? */ 1111 1112 typedef Half ec_flags_t; 1113 struct ent_desc { /* input section entrance criteria */ 1114 const char *ec_name; /* entrace criteria name, or NULL */ 1115 Alist *ec_files; /* files from which to accept */ 1116 /* sections */ 1117 const char *ec_is_name; /* input section name to match */ 1118 /* (NULL if none) */ 1119 Word ec_type; /* section type */ 1120 Word ec_attrmask; /* section attribute mask (AWX) */ 1121 Word ec_attrbits; /* sections attribute bits */ 1122 Sg_desc *ec_segment; /* output segment to enter if matched */ 1123 Word ec_ordndx; /* index to determine where section */ 1124 /* meeting this criteria should */ 1125 /* inserted. Used for reordering */ 1126 /* of sections. */ 1127 ec_flags_t ec_flags; 1128 avl_node_t ec_avlnode; /* AVL book-keeping */ 1129 }; 1130 1131 #define FLG_EC_BUILTIN 0x0001 /* built in descriptor */ 1132 #define FLG_EC_USED 0x0002 /* entrance criteria met? */ 1133 #define FLG_EC_CATCHALL 0x0004 /* Catches any section */ 1134 1135 /* 1136 * Ent_desc_file is the type of element maintained in the ec_files Alist 1137 * of an entrance criteria descriptor. Each item maintains one file 1138 * path, and a set of flags that specify the type of comparison it implies, 1139 * and other information about it. The comparison type is maintained in 1140 * the bottom byte of the flags. 1141 */ 1142 #define TYP_ECF_MASK 0x00ff /* Comparison type mask */ 1143 #define TYP_ECF_PATH 0 /* Compare to file path */ 1144 #define TYP_ECF_BASENAME 1 /* Compare to file basename */ 1145 #define TYP_ECF_OBJNAME 2 /* Compare to regular file basename, */ 1146 /* or to archive member name */ 1147 #define TYP_ECF_NUM 3 1148 1149 #define FLG_ECF_ARMEMBER 0x0100 /* name includes archive member */ 1150 1151 typedef struct { 1152 Word edf_flags; /* Type of comparison */ 1153 const char *edf_name; /* String to compare to */ 1154 size_t edf_name_len; /* strlen(edf_name) */ 1155 } Ent_desc_file; 1156 1157 /* 1158 * One structure is allocated for a move entry, and associated to the symbol 1159 * against which a move is targeted. 1160 */ 1161 typedef struct { 1162 Move *md_move; /* original Move entry */ 1163 Xword md_start; /* start position */ 1164 Xword md_len; /* length of initialization */ 1165 Word md_oidx; /* output Move entry index */ 1166 } Mv_desc; 1167 1168 #define SYM_ASSERT_SIZE 0x01 1169 #define SYM_ASSERT_BIND 0x02 1170 #define SYM_ASSERT_TYPE 0x04 1171 #define SYM_ASSERT_BITS 0x08 1172 #define SYM_ASSERT_ALIAS 0x10 1173 1174 typedef struct { 1175 Sym_desc *ass_sdp; 1176 char *ass_file; 1177 Lineno ass_lineno; 1178 uchar_t ass_type; 1179 uchar_t ass_bind; 1180 Lword ass_size; 1181 Boolean ass_bits; 1182 const char *ass_alias; 1183 /* Assertions explicitly enabled by user */ 1184 uint_t ass_enabled; 1185 } Ass_desc; 1186 1187 /* 1188 * Symbol descriptor. 1189 */ 1190 typedef Lword sd_flag_t; 1191 struct sym_desc { 1192 Alist *sd_GOTndxs; /* list of associated GOT entries */ 1193 Sym *sd_sym; /* pointer to symbol table entry */ 1194 Sym *sd_osym; /* copy of the original symbol entry */ 1195 /* used only for local partial */ 1196 Alist *sd_move; /* move information associated with a */ 1197 /* partially initialized symbol */ 1198 const char *sd_name; /* symbols name */ 1199 Ifl_desc *sd_file; /* file where symbol is taken */ 1200 Is_desc *sd_isc; /* input section of symbol definition */ 1201 Sym_aux *sd_aux; /* auxiliary global symbol info. */ 1202 Word sd_symndx; /* index in output symbol table */ 1203 Word sd_shndx; /* sect. index sym is associated w/ */ 1204 sd_flag_t sd_flags; /* state flags */ 1205 Half sd_ref; /* reference definition of symbol */ 1206 Ass_desc *sd_ass; /* pointer back to symbol assertions */ 1207 }; 1208 1209 /* 1210 * The auxiliary symbol descriptor contains the additional information (beyond 1211 * the symbol descriptor) required to process global symbols. These symbols are 1212 * accessed via an internal symbol hash table where locality of reference is 1213 * important for performance. 1214 */ 1215 struct sym_aux { 1216 APlist *sa_dfiles; /* files where symbol is defined */ 1217 Sym sa_sym; /* copy of symtab entry */ 1218 const char *sa_vfile; /* first unavailable definition */ 1219 const char *sa_rfile; /* file with first symbol referenced */ 1220 Word sa_hash; /* the pure hash value of symbol */ 1221 Word sa_PLTndx; /* index into PLT for symbol */ 1222 Word sa_PLTGOTndx; /* GOT entry indx for PLT indirection */ 1223 Word sa_linkndx; /* index of associated symbol from */ 1224 /* ET_DYN file */ 1225 Half sa_symspec; /* special symbol ids */ 1226 Half sa_overndx; /* output file versioning index */ 1227 Half sa_dverndx; /* dependency versioning index */ 1228 Os_desc *sa_boundsec; /* output section of SECBOUND_ syms */ 1229 }; 1230 1231 /* 1232 * Nodes used to track symbols in the global AVL symbol dictionary. 1233 */ 1234 struct sym_avlnode { 1235 avl_node_t sav_node; /* AVL node */ 1236 Word sav_hash; /* symbol hash value */ 1237 const char *sav_name; /* symbol name */ 1238 Sym_desc *sav_sdp; /* symbol descriptor */ 1239 }; 1240 1241 /* 1242 * These are the ids for processing of `Special symbols'. They are used 1243 * to set the sym->sd_aux->sa_symspec field. 1244 */ 1245 #define SDAUX_ID_ETEXT 1 /* etext && _etext symbol */ 1246 #define SDAUX_ID_EDATA 2 /* edata && _edata symbol */ 1247 #define SDAUX_ID_END 3 /* end, _end, && _END_ symbol */ 1248 #define SDAUX_ID_DYN 4 /* DYNAMIC && _DYNAMIC symbol */ 1249 #define SDAUX_ID_PLT 5 /* _PROCEDURE_LINKAGE_TABLE_ symbol */ 1250 #define SDAUX_ID_GOT 6 /* _GLOBAL_OFFSET_TABLE_ symbol */ 1251 #define SDAUX_ID_START 7 /* START_ && _START_ symbol */ 1252 #define SDAUX_ID_SECBOUND_START 8 /* __start_<section> symbols */ 1253 #define SDAUX_ID_SECBOUND_STOP 9 /* __stop_<section> symbols */ 1254 1255 /* 1256 * Flags for sym_desc.sd_flags 1257 */ 1258 #define FLG_SY_MVTOCOMM 0x00000001 /* assign symbol to common (.bss) */ 1259 /* this is a result of a */ 1260 /* copy reloc against sym */ 1261 #define FLG_SY_GLOBREF 0x00000002 /* a global reference has been seen */ 1262 #define FLG_SY_WEAKDEF 0x00000004 /* a weak definition has been used */ 1263 #define FLG_SY_CLEAN 0x00000008 /* `Sym' entry points to original */ 1264 /* input file (read-only). */ 1265 #define FLG_SY_UPREQD 0x00000010 /* symbol value update is required, */ 1266 /* either it's used as an entry */ 1267 /* point or for relocation, but */ 1268 /* it must be updated even if */ 1269 /* the -s flag is in effect */ 1270 #define FLG_SY_NOTAVAIL 0x00000020 /* symbol is not available to the */ 1271 /* application either because it */ 1272 /* originates from an implicitly */ 1273 /* referenced shared object, or */ 1274 /* because it is not part of a */ 1275 /* specified version. */ 1276 #define FLG_SY_REDUCED 0x00000040 /* a global is reduced to local */ 1277 #define FLG_SY_VERSPROM 0x00000080 /* version definition has been */ 1278 /* promoted to output file */ 1279 #define FLG_SY_PROT 0x00000100 /* stv_protected visibility seen */ 1280 #define FLG_SY_MAPREF 0x00000200 /* symbol reference generated by user */ 1281 /* from mapfile */ 1282 #define FLG_SY_REFRSD 0x00000400 /* symbols sd_ref has been raised */ 1283 /* due to a copy-relocs */ 1284 /* weak-strong pairing */ 1285 #define FLG_SY_INTPOSE 0x00000800 /* symbol defines an interposer */ 1286 #define FLG_SY_INVALID 0x00001000 /* unwanted/erroneous symbol */ 1287 #define FLG_SY_SMGOT 0x00002000 /* small got index assigned to symbol */ 1288 /* sparc only */ 1289 #define FLG_SY_PARENT 0x00004000 /* symbol to be found in parent */ 1290 /* only used with direct bindings */ 1291 #define FLG_SY_LAZYLD 0x00008000 /* symbol to cause lazyloading of */ 1292 /* parent object */ 1293 #define FLG_SY_ISDISC 0x00010000 /* symbol is a member of a DISCARDED */ 1294 /* section (COMDAT) */ 1295 #define FLG_SY_PAREXPN 0x00020000 /* partially init. symbol to be */ 1296 /* expanded */ 1297 #define FLG_SY_PLTPAD 0x00040000 /* pltpadding has been allocated for */ 1298 /* this symbol */ 1299 #define FLG_SY_REGSYM 0x00080000 /* REGISTER symbol (sparc only) */ 1300 #define FLG_SY_SOFOUND 0x00100000 /* compared against an SO definition */ 1301 #define FLG_SY_EXTERN 0x00200000 /* symbol is external, allows -zdefs */ 1302 /* error suppression */ 1303 #define FLG_SY_MAPUSED 0x00400000 /* mapfile symbol used (occurred */ 1304 /* within a relocatable object) */ 1305 #define FLG_SY_COMMEXP 0x00800000 /* COMMON symbol which has been */ 1306 /* allocated */ 1307 #define FLG_SY_CMDREF 0x01000000 /* symbol was referenced from the */ 1308 /* command line. (ld -u <>, */ 1309 /* ld -zrtldinfo=<>, ...) */ 1310 #define FLG_SY_SPECSEC 0x02000000 /* section index is reserved value */ 1311 /* ABS, COMMON, ... */ 1312 #define FLG_SY_TENTSYM 0x04000000 /* tentative symbol */ 1313 #define FLG_SY_VISIBLE 0x08000000 /* symbols visibility determined */ 1314 #define FLG_SY_STDFLTR 0x10000000 /* symbol is a standard filter */ 1315 #define FLG_SY_AUXFLTR 0x20000000 /* symbol is an auxiliary filter */ 1316 #define FLG_SY_DYNSORT 0x40000000 /* req. in dyn[sym|tls]sort section */ 1317 #define FLG_SY_NODYNSORT 0x80000000 /* excluded from dyn[sym_tls]sort sec */ 1318 1319 #define FLG_SY_DEFAULT 0x0000100000000 /* global symbol, default */ 1320 #define FLG_SY_SINGLE 0x0000200000000 /* global symbol, singleton defined */ 1321 #define FLG_SY_PROTECT 0x0000400000000 /* global symbol, protected defined */ 1322 #define FLG_SY_EXPORT 0x0000800000000 /* global symbol, exported defined */ 1323 1324 #define MSK_SY_GLOBAL \ 1325 (FLG_SY_DEFAULT | FLG_SY_SINGLE | FLG_SY_PROTECT | FLG_SY_EXPORT) 1326 /* this mask indicates that the */ 1327 /* symbol has been explicitly */ 1328 /* defined within a mapfile */ 1329 /* definition, and is a candidate */ 1330 /* for versioning */ 1331 1332 #define FLG_SY_HIDDEN 0x0001000000000 /* global symbol, reduce to local */ 1333 #define FLG_SY_ELIM 0x0002000000000 /* global symbol, eliminate */ 1334 #define FLG_SY_IGNORE 0x0004000000000 /* global symbol, ignored */ 1335 1336 #define MSK_SY_LOCAL (FLG_SY_HIDDEN | FLG_SY_ELIM | FLG_SY_IGNORE) 1337 /* this mask allows all local state */ 1338 /* flags to be removed when the */ 1339 /* symbol is copy relocated */ 1340 1341 #define FLG_SY_EXPDEF 0x0008000000000 /* symbol visibility defined */ 1342 /* explicitly */ 1343 1344 #define MSK_SY_NOAUTO (FLG_SY_SINGLE | FLG_SY_EXPORT | FLG_SY_EXPDEF) 1345 /* this mask indicates that the */ 1346 /* symbol is not a candidate for */ 1347 /* auto-reduction/elimination */ 1348 1349 #define FLG_SY_MAPFILE 0x0010000000000 /* symbol attribute defined in a */ 1350 /* mapfile */ 1351 #define FLG_SY_DIR 0x0020000000000 /* global symbol, direct bindings */ 1352 #define FLG_SY_NDIR 0x0040000000000 /* global symbol, nondirect bindings */ 1353 #define FLG_SY_OVERLAP 0x0080000000000 /* move entry overlap detected */ 1354 #define FLG_SY_CAP 0x0100000000000 /* symbol is associated with */ 1355 /* capabilities */ 1356 #define FLG_SY_DEFERRED 0x0200000000000 /* symbol should not be bound to */ 1357 /* during BIND_NOW relocations */ 1358 1359 #define FLG_SY_MAPASSRT 0x0400000000000 /* Symbol has attribute assertions */ 1360 1361 /* 1362 * A symbol can only be truly hidden if it is not a capabilities symbol. 1363 */ 1364 #define SYM_IS_HIDDEN(_sdp) \ 1365 (((_sdp)->sd_flags & (FLG_SY_HIDDEN | FLG_SY_CAP)) == FLG_SY_HIDDEN) 1366 1367 /* 1368 * Create a mask for (sym.st_other & visibility) since the gABI does not yet 1369 * define a ELF*_ST_OTHER macro. 1370 */ 1371 #define MSK_SYM_VISIBILITY 0x7 1372 1373 /* 1374 * Structure to manage the shared object definition lists. There are two lists 1375 * that use this structure: 1376 * 1377 * - ofl_soneed; maintain the list of implicitly required dependencies 1378 * (ie. shared objects needed by other shared objects). These definitions 1379 * may include RPATH's required to locate the dependencies, and any 1380 * version requirements. 1381 * 1382 * - ofl_socntl; maintains the shared object control definitions. These are 1383 * provided by the user (via a mapfile) and are used to indicate any 1384 * version control requirements. 1385 */ 1386 struct sdf_desc { 1387 const char *sdf_name; /* the shared objects file name */ 1388 char *sdf_rpath; /* library search path DT_RPATH */ 1389 const char *sdf_rfile; /* referencing file for diagnostics */ 1390 Ifl_desc *sdf_file; /* the final input file descriptor */ 1391 Alist *sdf_vers; /* list of versions that are required */ 1392 /* from this object */ 1393 Alist *sdf_verneed; /* list of VERNEEDS to create for */ 1394 /* object via mapfile ADDVERS */ 1395 Word sdf_flags; 1396 }; 1397 1398 #define FLG_SDF_SELECT 0x01 /* version control selection required */ 1399 #define FLG_SDF_VERIFY 0x02 /* version definition verification */ 1400 /* required */ 1401 #define FLG_SDF_ADDVER 0x04 /* add VERNEED references */ 1402 1403 /* 1404 * Structure to manage shared object version usage requirements. 1405 */ 1406 struct sdv_desc { 1407 const char *sdv_name; /* version name */ 1408 const char *sdv_ref; /* versions reference */ 1409 Word sdv_flags; /* flags */ 1410 }; 1411 1412 #define FLG_SDV_MATCHED 0x01 /* VERDEF found and matched */ 1413 1414 /* 1415 * Structures to manage versioning information. Two versioning structures are 1416 * defined: 1417 * 1418 * - a version descriptor maintains a linked list of versions and their 1419 * associated dependencies. This is used to build the version definitions 1420 * for an image being created (see map_symbol), and to determine the 1421 * version dependency graph for any input files that are versioned. 1422 * 1423 * - a version index array contains each version of an input file that is 1424 * being processed. It informs us which versions are available for 1425 * binding, and is used to generate any version dependency information. 1426 */ 1427 struct ver_desc { 1428 const char *vd_name; /* version name */ 1429 Ifl_desc *vd_file; /* file that defined version */ 1430 Word vd_hash; /* hash value of name */ 1431 Half vd_ndx; /* coordinates with symbol index */ 1432 Half vd_flags; /* version information */ 1433 APlist *vd_deps; /* version dependencies */ 1434 Ver_desc *vd_ref; /* dependency's first reference */ 1435 }; 1436 1437 struct ver_index { 1438 const char *vi_name; /* dependency version name */ 1439 Half vi_flags; /* communicates availability */ 1440 Half vi_overndx; /* index assigned to this version in */ 1441 /* output object Verneed section */ 1442 Ver_desc *vi_desc; /* cross reference to descriptor */ 1443 }; 1444 1445 /* 1446 * Define any internal version descriptor flags ([vd|vi]_flags). Note that the 1447 * first byte is reserved for user visible flags (refer VER_FLG's in link.h). 1448 */ 1449 #define MSK_VER_USER 0x0f /* mask for user visible flags */ 1450 1451 #define FLG_VER_AVAIL 0x10 /* version is available for binding */ 1452 #define FLG_VER_REFER 0x20 /* version has been referenced */ 1453 #define FLG_VER_CYCLIC 0x40 /* a member of cyclic dependency */ 1454 1455 /* 1456 * isalist(1) descriptor - used to break an isalist string into its component 1457 * options. 1458 */ 1459 struct isa_opt { 1460 char *isa_name; /* individual isa option name */ 1461 size_t isa_namesz; /* and associated size */ 1462 }; 1463 1464 struct isa_desc { 1465 char *isa_list; /* sysinfo(SI_ISALIST) list */ 1466 size_t isa_listsz; /* and associated size */ 1467 Isa_opt *isa_opt; /* table of individual isa options */ 1468 size_t isa_optno; /* and associated number */ 1469 }; 1470 1471 /* 1472 * uname(2) descriptor - used to break a utsname structure into its component 1473 * options (at least those that we're interested in). 1474 */ 1475 struct uts_desc { 1476 char *uts_osname; /* operating system name */ 1477 size_t uts_osnamesz; /* and associated size */ 1478 char *uts_osrel; /* operating system release */ 1479 size_t uts_osrelsz; /* and associated size */ 1480 }; 1481 1482 /* 1483 * SHT_GROUP descriptor - used to track group sections at the global 1484 * level to resolve conflicts and determine which to keep. 1485 */ 1486 struct group_desc { 1487 Is_desc *gd_isc; /* input section descriptor */ 1488 Is_desc *gd_oisc; /* overriding input section */ 1489 /* descriptor when discarded */ 1490 const char *gd_name; /* group name (signature symbol) */ 1491 Word *gd_data; /* data for group section */ 1492 size_t gd_cnt; /* number of entries in group data */ 1493 }; 1494 1495 /* 1496 * Indexes into the ld_support_funcs[] table. 1497 */ 1498 typedef enum { 1499 LDS_VERSION = 0, /* Must be first and have value 0 */ 1500 LDS_INPUT_DONE, 1501 LDS_START, 1502 LDS_ATEXIT, 1503 LDS_OPEN, 1504 LDS_FILE, 1505 LDS_INSEC, 1506 LDS_SEC, 1507 LDS_NUM 1508 } Support_ndx; 1509 1510 /* 1511 * Structure to manage archive member caching. Each archive has an archive 1512 * descriptor (Ar_desc) associated with it. This contains pointers to the 1513 * archive symbol table (obtained by elf_getarsyms(3ELF)) and an auxiliary 1514 * structure (Ar_uax[]) that parallels this symbol table. The member element 1515 * of this auxiliary table indicates whether the archive member associated with 1516 * the symbol offset has already been extracted (AREXTRACTED) or partially 1517 * processed (refer process_member()). 1518 */ 1519 typedef struct ar_mem { 1520 Elf *am_elf; /* elf descriptor for this member */ 1521 const char *am_name; /* members name */ 1522 const char *am_path; /* path (ie. lib(foo.o)) */ 1523 Sym *am_syms; /* start of global symbols */ 1524 char *am_strs; /* associated string table start */ 1525 Xword am_symn; /* no. of global symbols */ 1526 } Ar_mem; 1527 1528 typedef struct ar_aux { 1529 Sym_desc *au_syms; /* internal symbol descriptor */ 1530 Ar_mem *au_mem; /* associated member */ 1531 } Ar_aux; 1532 1533 #define FLG_ARMEM_PROC (Ar_mem *)-1 1534 1535 typedef struct ar_desc { 1536 const char *ad_name; /* archive file name */ 1537 Elf *ad_elf; /* elf descriptor for the archive */ 1538 Elf_Arsym *ad_start; /* archive symbol table start */ 1539 Ar_aux *ad_aux; /* auxiliary symbol information */ 1540 dev_t ad_stdev; /* device id and inode number for */ 1541 ino_t ad_stino; /* multiple inclusion checks */ 1542 ofl_flag_t ad_flags; /* archive specific cmd line flags */ 1543 Boolean ad_allextract; /* archive has been allextract'ed */ 1544 } Ar_desc; 1545 1546 /* 1547 * Define any archive descriptor flags. NOTE, make sure they do not clash with 1548 * any output file descriptor archive extraction flags, as these are saved in 1549 * the same entry (see MSK_OF1_ARCHIVE). 1550 */ 1551 #define FLG_ARD_EXTRACT 0x00010000 /* archive member has been extracted */ 1552 1553 /* Mapfile versions supported by libld */ 1554 #define MFV_NONE 0 /* Not a valid version */ 1555 #define MFV_SYSV 1 /* Original System V syntax */ 1556 #define MFV_SOLARIS 2 /* Solaris mapfile syntax */ 1557 #define MFV_NUM 3 /* # of mapfile versions */ 1558 1559 1560 /* 1561 * Function Declarations. 1562 */ 1563 #if defined(_ELF64) 1564 1565 #define ld_create_outfile ld64_create_outfile 1566 #define ld_ent_setup ld64_ent_setup 1567 #define ld_init_strings ld64_init_strings 1568 #define ld_init_target ld64_init_target 1569 #define ld_make_sections ld64_make_sections 1570 #define ld_main ld64_main 1571 #define ld_ofl_cleanup ld64_ofl_cleanup 1572 #define ld_process_mem ld64_process_mem 1573 #define ld_reloc_init ld64_reloc_init 1574 #define ld_reloc_process ld64_reloc_process 1575 #define ld_sym_validate ld64_sym_validate 1576 #define ld_update_outfile ld64_update_outfile 1577 1578 #else 1579 1580 #define ld_create_outfile ld32_create_outfile 1581 #define ld_ent_setup ld32_ent_setup 1582 #define ld_init_strings ld32_init_strings 1583 #define ld_init_target ld32_init_target 1584 #define ld_make_sections ld32_make_sections 1585 #define ld_main ld32_main 1586 #define ld_ofl_cleanup ld32_ofl_cleanup 1587 #define ld_process_mem ld32_process_mem 1588 #define ld_reloc_init ld32_reloc_init 1589 #define ld_reloc_process ld32_reloc_process 1590 #define ld_sym_validate ld32_sym_validate 1591 #define ld_update_outfile ld32_update_outfile 1592 1593 #endif 1594 1595 extern int ld_getopt(Lm_list *, int, int, char **); 1596 1597 extern int ld32_main(int, char **, Half); 1598 extern int ld64_main(int, char **, Half); 1599 1600 extern uintptr_t ld_create_outfile(Ofl_desc *); 1601 extern uintptr_t ld_ent_setup(Ofl_desc *, Xword); 1602 extern uintptr_t ld_init_strings(Ofl_desc *); 1603 extern int ld_init_target(Lm_list *, Half mach); 1604 extern uintptr_t ld_make_sections(Ofl_desc *); 1605 extern void ld_ofl_cleanup(Ofl_desc *); 1606 extern Ifl_desc *ld_process_mem(const char *, const char *, char *, 1607 size_t, Ofl_desc *, Rej_desc *); 1608 extern uintptr_t ld_reloc_init(Ofl_desc *); 1609 extern uintptr_t ld_reloc_process(Ofl_desc *); 1610 extern uintptr_t ld_sym_validate(Ofl_desc *); 1611 extern uintptr_t ld_update_outfile(Ofl_desc *); 1612 1613 #ifdef __cplusplus 1614 } 1615 #endif 1616 1617 #endif /* _LIBLD_H */ 1618