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 2007 Sun Microsystems, Inc. All rights reserved. 24 * Use is subject to license terms. 25 */ 26 27 #ifndef _RTLD_H 28 #define _RTLD_H 29 30 #pragma ident "%Z%%M% %I% %E% SMI" 31 32 /* 33 * Global include file for the runtime linker. 34 */ 35 #include <time.h> 36 #include <sgs.h> 37 #include <thread.h> 38 #include <synch.h> 39 #include <machdep.h> 40 #include <sys/avl.h> 41 #include <alist.h> 42 #include <libc_int.h> 43 44 #ifdef _SYSCALL32 45 #include <inttypes.h> 46 #endif 47 48 #ifdef __cplusplus 49 extern "C" { 50 #endif 51 52 53 /* 54 * Linked list of directories or filenames (built from colon separated string). 55 */ 56 typedef struct pnode { 57 const char *p_name; 58 const char *p_oname; 59 size_t p_len; 60 uint_t p_orig; 61 void *p_info; 62 struct pnode *p_next; 63 } Pnode; 64 65 typedef struct rt_map Rt_map; 66 67 /* 68 * A binding descriptor. Establishes the binding relationship between two 69 * objects, the caller (originator) and the dependency (destination). 70 */ 71 typedef struct { 72 Rt_map *b_caller; /* caller (originator) of a binding */ 73 Rt_map *b_depend; /* dependency (destination) of a */ 74 /* binding */ 75 uint_t b_flags; /* relationship of caller to the */ 76 /* dependency */ 77 } Bnd_desc; 78 79 #define BND_NEEDED 0x0001 /* caller NEEDED the dependency */ 80 #define BND_REFER 0x0002 /* caller relocation references the */ 81 /* dependency */ 82 #define BND_FILTER 0x0004 /* pseudo binding to identify filter */ 83 84 /* 85 * Private structure for communication between rtld_db and rtld. 86 * 87 * We must bump the version number when ever an update in one of the 88 * structures/fields that rtld_db reads is updated. This hopefully permits 89 * rtld_db implementations of the future to recognize core files produced on 90 * older systems and deal with these core files accordingly. 91 * 92 * As of version 'RTLD_DB_VERSION <= 2' the following fields were valid for core 93 * file examination (basically the public Link_map): 94 * 95 * ADDR() 96 * NAME() 97 * DYN() 98 * NEXT() 99 * PREV() 100 * 101 * Valid fields for RTLD_DB_VERSION3 102 * 103 * PATHNAME() 104 * PADSTART() 105 * PADIMLEN() 106 * MSIZE() 107 * FLAGS() 108 * FLAGS1() 109 * 110 * Valid fields for RTLD_DB_VERSION4 111 * 112 * TLSMODID() 113 * 114 * Valid fields for RTLD_DB_VERSION5 115 * 116 * Added rtld_flags & FLG_RT_RELOCED to stable flags range 117 * 118 */ 119 #define R_RTLDDB_VERSION1 1 /* base version level - used for core */ 120 /* file examination */ 121 #define R_RTLDDB_VERSION2 2 /* minor revision - not relevant for */ 122 /* core files */ 123 #define R_RTLDDB_VERSION3 3 124 #define R_RTLDDB_VERSION4 4 125 #define R_RTLDDB_VERSION5 5 126 #define R_RTLDDB_VERSION R_RTLDDB_VERSION5 /* current version */ 127 128 typedef struct rtld_db_priv { 129 struct r_debug rtd_rdebug; /* original r_debug structure */ 130 Word rtd_version; /* version no. */ 131 size_t rtd_objpad; /* padding around mmap()ed objects */ 132 List * rtd_dynlmlst; /* pointer to Dynlm_list */ 133 } Rtld_db_priv; 134 135 #ifdef _SYSCALL32 136 typedef struct rtld_db_priv32 { 137 struct r_debug32 rtd_rdebug; /* original r_debug structure */ 138 Elf32_Word rtd_version; /* version no. */ 139 Elf32_Word rtd_objpad; /* padding around mmap()ed objects */ 140 Elf32_Addr rtd_dynlmlst; /* pointer to Dynlm_list */ 141 } Rtld_db_priv32; 142 #endif /* _SYSCALL32 */ 143 144 /* 145 * External function definitions. ld.so.1 must convey information to libc in 146 * regards to threading. libc also provides routines for atexit() and message 147 * localization. libc provides the necessary interfaces via its RTLDINFO 148 * structure and/or later _ld_libc() calls. 149 * 150 * These external functions are maintained for each link-map list, and used 151 * where appropriate. The functions are associated with the object that 152 * provided them, so that should the object be deleted (say, from an alternative 153 * link-map), the functions can be removed. 154 */ 155 typedef struct { 156 Rt_map *lc_lmp; /* function provider */ 157 union { 158 int (*lc_func)(); /* external function pointer */ 159 uintptr_t lc_val; /* external value */ 160 char *lc_ptr; /* external character pointer */ 161 } lc_un; 162 } Lc_desc; 163 164 /* 165 * Link map list definition. Link-maps are used to describe each loaded object. 166 * Lists of these link-maps describe the various namespaces within a process. 167 * The process executable and its dependencies are maintained on the lml_main 168 * list. The runtime linker, and its dependencies are maintained on the 169 * lml_rtld list. Additional lists can be created (see dlmopen()) for such 170 * things as auditors and their dependencies. 171 * 172 * Each link-map list maintains an Alist of one, or more, linked lists of 173 * link-maps. For backward compatibility, the lm_head/lm_tail elements are 174 * initialized to the first linked-list of link-maps: 175 * 176 * Lm_list 177 * ---------- 178 * | lm_tail | ------------------------------------ 179 * | lm_head | -------------------- | 180 * | | | Rt_map | Rt_map 181 * | | | ------ | ------ 182 * | | Alist --> | | |--> | | 183 * | | --------- | | | -- | | 184 * | lm_lists | ----> | | | | | --> | | 185 * | | |---------| | | | | | | 186 * | | | lc_head | -- ------ | ------ 187 * | | | lc_tail | ------------------ 188 * | | |---------| 189 * | lc_head | 190 * | lc_tail | 191 * |---------| 192 * 193 * Multiple link-map lists exist to support the addition of lazy loaded 194 * families, filtee families, and dlopen() families. The intent of these 195 * lists is to insure that a family of objects that are to be loaded are 196 * fully relocatable, and hence usable, before they become part of the main 197 * (al_data[0]) link-map control list. This main link-map control list is 198 * the only list in existence when control is transferred to user code. 199 * 200 * During process initialization, the dynamic executable and its non-lazy 201 * dependencies are maintained on al_data[0]. If a new object is loaded, then 202 * this object is added to the next available control list [1], typically 203 * al_data[1]. Any dependencies of this object that have not already been 204 * loaded are added to the same control list. Once all of the objects on the 205 * new control list have been successfully relocated, the objects are moved from 206 * the new control list to the highest control list to which objects of the new 207 * control list bound to, typically al_data[1] to al_data[0]. 208 * 209 * Each loading scenario can be broken down as follows: 210 * 211 * setup() - only the initial link-map control list is used: 212 * i. create al_data[0] 213 * ii. add new link-map for main on al_data[0] 214 * iii. analyze al_data[0] to add all non-lazy dependencies 215 * iv. relocate al_data[0] dependencies. 216 * 217 * dlopen() - the initiator can only be the initial link-map control list: 218 * i. create al_data[1] from caller al_data[0] 219 * ii. add new link-map for the dlopen'ed object on al_data[1] 220 * iii. analyze al_data[1] to add all non-lazy dependencies 221 * iv. relocate al_data[1] dependencies, and move to al_data[0]. 222 * 223 * filtee and lazy loading processing - the initiator can be any link-map 224 * control list that is being relocated: 225 * i. create al_data[y] from caller al_data[x] 226 * ii. add new link-map for the new object on al_data[y] 227 * iii. analyze al_data[y] to add all non-lazy dependencies 228 * iv. relocate al_data[y] dependencies, and move to al_data[x]. 229 * 230 * This Alist therefore maintains a stack of link-map control lists. The newest 231 * link-map control list can locate symbols within any of the former lists, 232 * however, control is not passed to a former list until the newest lists 233 * processing is complete. Thus, objects can't bind to new objects until they 234 * have been fully analyzed and relocated. 235 * 236 * [1] Note, additional link-map control list creation occurs after the head 237 * link-map object (typically the dynamic executable) has been relocated. This 238 * staging is required to satisfy the binding requirements of copy relocations. 239 * Copy relocations, effectively, transfer the bindings of the copied data 240 * (say _iob in libc.so.1) to the copy location (_iob in the application). 241 * Thus an object that might bind to the original copy data must be redirected 242 * to the copy reference. As the knowledge of a copy relocation having taken 243 * place is only known after relocating the application, link-map control list 244 * additions are suspended until after this relocation has completed. 245 */ 246 typedef struct { 247 Rt_map *lc_head; 248 Rt_map *lc_tail; 249 Alist *lc_now; /* pending promoted bind-now objects */ 250 uint_t lc_flags; 251 } Lm_cntl; 252 253 #define LMC_FLG_ANALYZING 0x01 /* control list is being analyzed */ 254 #define LMC_FLG_RELOCATING 0x02 /* control list is being relocated */ 255 #define LMC_FLG_REANALYZE 0x04 /* repeat analysis (established when */ 256 /* interposers are added */ 257 258 struct lm_list { 259 /* 260 * BEGIN: Exposed to rtld_db - don't move, don't delete 261 */ 262 Rt_map *lm_head; /* linked list pointers to active */ 263 Rt_map *lm_tail; /* link-map list */ 264 Alist *lm_handle; /* not used by rtld_db - but spacing */ 265 /* is required for flags */ 266 Word lm_flags; 267 /* 268 * END: Exposed to rtld_db - don't move, don't delete 269 */ 270 Alist *lm_rti; /* list of RTLDINFO tables */ 271 Audit_list *lm_alp; /* audit list descriptor */ 272 avl_tree_t *lm_fpavl; /* avl tree of objects loaded */ 273 Alist *lm_lists; /* active and pending link-map lists */ 274 char ***lm_environ; /* pointer to environment array */ 275 Word lm_tflags; /* transferable flags */ 276 uint_t lm_obj; /* total number of objs on link-map */ 277 uint_t lm_init; /* new obj since last init processing */ 278 uint_t lm_lazy; /* obj with pending lazy dependencies */ 279 uint_t lm_tls; /* new obj that require TLS */ 280 uint_t lm_lmid; /* unique link-map list identifier, */ 281 char *lm_lmidstr; /* and associated diagnostic string */ 282 Alist *lm_actaudit; /* list of pending audit activity */ 283 Lc_desc lm_lcs[CI_MAX]; /* external libc functions */ 284 }; 285 286 #ifdef _SYSCALL32 287 struct lm_list32 { 288 /* 289 * BEGIN: Exposed to rtld_db - don't move, don't delete 290 */ 291 Elf32_Addr lm_head; 292 Elf32_Addr lm_tail; 293 Elf32_Addr lm_handle; 294 Elf32_Word lm_flags; 295 /* 296 * END: Exposed to rtld_db - don't move, don't delete 297 */ 298 Elf32_Addr lm_rti; 299 Elf32_Addr lm_fpavl; 300 Elf32_Addr lm_lists; 301 Elf32_Addr lm_environ; 302 Elf32_Word lm_tflags; 303 uint_t lm_obj; 304 uint_t lm_init; 305 uint_t lm_lazy; 306 uint_t lm_tls; 307 uint_t lm_lmid; 308 Elf32_Addr lm_lmidstr; 309 Elf32_Addr lm_actaudit; 310 Elf32_Addr lm_lcs[CI_MAX]; 311 }; 312 #endif /* _SYSCALL32 */ 313 314 /* 315 * Possible Link_map list flags (Lm_list.lm_flags) 316 */ 317 /* 318 * BEGIN: Exposed to rtld_db - don't move, don't delete 319 */ 320 #define LML_FLG_BASELM 0x00000001 /* primary link-map */ 321 #define LML_FLG_RTLDLM 0x00000002 /* rtld link-map */ 322 /* 323 * END: Exposed to rtld_db - don't move, don't delete 324 */ 325 #define LML_FLG_NOAUDIT 0x00000004 /* symbol auditing disabled */ 326 #define LML_FLG_PLTREL 0x00000008 /* deferred plt relocation */ 327 /* initialization */ 328 /* (ld.so.1 only) */ 329 #define LML_FLG_HOLDLOCK 0x00000010 /* hold the rtld mutex lock */ 330 #define LML_FLG_ENVIRON 0x00000020 /* environ var initialized */ 331 #define LML_FLG_INTRPOSE 0x00000040 /* interposing objs on list */ 332 #define LML_FLG_LOCAUDIT 0x00000080 /* local auditors exists for */ 333 /* this link-map list */ 334 #define LML_FLG_LOADAVAIL 0x00000100 /* load anything available */ 335 #define LML_FLG_IGNRELERR 0x00000200 /* ignore relocation errors - */ 336 /* internal for crle(1) */ 337 #define LML_FLG_DBNOTIF 0x00000400 /* binding activity going on */ 338 #define LML_FLG_STARTREL 0x00000800 /* relocation started */ 339 #define LML_FLG_ATEXIT 0x00001000 /* atexit processing */ 340 #define LML_FLG_OBJADDED 0x00002000 /* object(s) added */ 341 #define LML_FLG_OBJDELETED 0x00004000 /* object(s) deleted */ 342 #define LML_FLG_OBJREEVAL 0x00008000 /* existing object(s) needs */ 343 /* tsort reevaluation */ 344 #define LML_FLG_NOPENDGLBLAZY 0x00010000 /* no pending, global, lazy */ 345 /* dependencies remain */ 346 #define LML_FLG_INTRPOSETSORT 0x00020000 /* interpose tsorting done */ 347 #define LML_FLG_AUDITNOTIFY 0x00040000 /* audit consistent required */ 348 #define LML_FLG_GROUPSEXIST 0x00080000 /* local groups exist */ 349 350 #define LML_FLG_TRC_LDDSTUB 0x00100000 /* identify lddstub */ 351 #define LML_FLG_TRC_ENABLE 0x00200000 /* tracing enabled (ldd) */ 352 #define LML_FLG_TRC_WARN 0x00400000 /* print warnings for undefs */ 353 #define LML_FLG_TRC_VERBOSE 0x00800000 /* verbose (versioning) trace */ 354 #define LML_FLG_TRC_SEARCH 0x01000000 /* trace search paths */ 355 #define LML_FLG_TRC_UNREF 0x02000000 /* trace unreferenced */ 356 /* dependencies */ 357 #define LML_FLG_TRC_UNUSED 0x04000000 /* trace unused dependencies */ 358 #define LML_FLG_TRC_INIT 0x08000000 /* print .init order */ 359 #define LML_FLG_TRC_NOUNRESWEAK 0x10000000 /* unresolved weak references */ 360 /* are not allowed */ 361 #define LML_MSK_TRC 0xfff00000 /* tracing mask */ 362 363 /* 364 * Possible Link_map transferable flags (Lm_list.lm_tflags), i.e., link-map 365 * list flags that can be propagated to any new link-map list created. 366 */ 367 #define LML_TFLG_NOLAZYLD 0x00000001 /* lazy loading disabled */ 368 #define LML_TFLG_NODIRECT 0x00000002 /* direct bindings disabled */ 369 370 #define LML_TFLG_LOADFLTR 0x00000008 /* trigger filtee loading */ 371 372 #define LML_TFLG_AUD_PREINIT 0x00100000 /* preinit (audit) exists */ 373 #define LML_TFLG_AUD_OBJSEARCH 0x00200000 /* objsearch (audit) exists */ 374 #define LML_TFLG_AUD_OBJOPEN 0x00400000 /* objopen (audit) exists */ 375 #define LML_TFLG_AUD_OBJFILTER 0x00800000 /* objfilter (audit) exists */ 376 #define LML_TFLG_AUD_OBJCLOSE 0x01000000 /* objclose (audit) exists */ 377 #define LML_TFLG_AUD_SYMBIND 0x02000000 /* symbind (audit) exists */ 378 #define LML_TFLG_AUD_PLTENTER 0x04000000 /* pltenter (audit) exists */ 379 #define LML_TFLG_AUD_PLTEXIT 0x08000000 /* pltexit (audit) exists */ 380 #define LML_TFLG_AUD_ACTIVITY 0x10000000 /* activity (audit) exists */ 381 382 /* 383 * NOTE: Audit flags have duplicated FLAGS1() values. If more audit flags are 384 * added, update the FLAGS1() reservation FL1_AUD_RS_STR to FL1_AUD_RS_END 385 * defined later. 386 */ 387 #define LML_TFLG_AUD_MASK 0xfff00000 /* audit interfaces mask */ 388 389 /* 390 * Define a Group Handle. 391 * 392 * The capability of ld.so.1 to associate a group of objects, look for symbols 393 * within that group, ensure that groups are isolated from one another (with 394 * regard to relocations), and to unload a group, centers around a handle. This 395 * data structure is tracked from the link-map HANDLE(), and is the structure 396 * returned from dlopen(), and similar object loading capabilities such as 397 * filter/filtee processing. 398 * 399 * A handle keeps track of all the dependencies of the associated object. 400 * These dependencies may be added as objects are lazily loaded. The core 401 * dependencies on the handle are the ldd(1) list of the associated object. 402 * The object assigned the handle, and the parent (or caller) who requested the 403 * handle are also maintained as dependencies on the handle. 404 * 405 * Presently, an object may have two handles, one requested with RTLD_FIRST 406 * and one without. 407 * 408 * A handle may be referenced by any number of parents (callers). A reference 409 * count tracks the number. A dlclose() operation drops the reference count, 410 * and when the count is zero, the handle is used to determine the family of 411 * objects to unload. As bindings may occur to objects on the handle from 412 * other handles, it may not be possible to remove a complete family of 413 * objects or that handle itself. Handles in this state are moved to an orphan 414 * list. A handle on the orphan list is taken off the orphan list if the 415 * associated object is reopened. Otherwise, the handle remains on the orphan 416 * list for the duration of the process. The orphan list is inspected any time 417 * objects are unloaded, to determine if the orphaned objects can also be 418 * unloaded. 419 * 420 * Objects can be dlopened using RTLD_NOW. This attribute requires that all 421 * relocations of the object, and its dependencies are processed immediately, 422 * before return to the caller. Typically, an object is loaded without 423 * RTLD_NOW, and procedure linkage relocations are satisfied when their 424 * associated function is first called. If an object is already loaded, and an 425 * RTLD_NOW request is made, then the object, and its dependencies, most undergo 426 * additional relocation processing. This promotion from lazy binding to 427 * immediate binding is carried out using handles, as the handle defines the 428 * dependencies that must be processed. A temporary handle is created for this 429 * purpose, and is discarded immediately after the promotion operation has been 430 * completed. 431 */ 432 typedef struct { 433 Alist *gh_depends; /* handle dependency list */ 434 Rt_map *gh_ownlmp; /* handle owners link-map */ 435 Lm_list *gh_ownlml; /* handle owners link-map list */ 436 uint_t gh_refcnt; /* handle reference count */ 437 uint_t gh_flags; /* handle flags (GPH_ values) */ 438 } Grp_hdl; 439 440 #define GPH_ZERO 0x0001 /* special handle for dlopen(0) */ 441 #define GPH_LDSO 0x0002 /* special handle for ld.so.1 */ 442 #define GPH_FIRST 0x0004 /* dlsym() can only use originating */ 443 /* dependency */ 444 #define GPH_FILTEE 0x0008 /* handle used to specify a filtee */ 445 #define GPH_INITIAL 0x0010 /* handle is initialized */ 446 #define GPH_NOPENDLAZY 0x0020 /* no pending lazy dependencies */ 447 /* remain for this handle */ 448 449 /* 450 * Define a Group Descriptor. 451 * 452 * Each dependency associated with a group handle is maintained by a group 453 * descriptor. The descriptor defines the associated dependency together with 454 * flags that indicate how the dependency can be used. 455 */ 456 typedef struct { 457 Rt_map * gd_depend; /* dependency */ 458 uint_t gd_flags; /* dependency flags (GPD_ values) */ 459 } Grp_desc; 460 461 #define GPD_DLSYM 0x0001 /* dependency available to dlsym() */ 462 #define GPD_RELOC 0x0002 /* dependency available to satisfy */ 463 /* relocation binding */ 464 #define GPD_ADDEPS 0x0004 /* dependencies of this dependency */ 465 /* should be added to handle */ 466 #define GPD_PARENT 0x0008 /* dependency is a parent */ 467 #define GPD_FILTER 0x0010 /* dependency is our filter */ 468 #define GPD_PROMOTE 0x0020 /* dependency is our RTLD_NOW */ 469 /* promoter */ 470 #define GPD_REMOVE 0x1000 /* descriptor is a candidate for */ 471 /* removal from the group */ 472 473 /* 474 * Define threading structures. For compatibility with libthread (T1_VERSION 1 475 * and TI_VERSION 2) our locking structure is sufficient to hold a mutex or a 476 * readers/writers lock. 477 */ 478 typedef struct { 479 union { 480 mutex_t l_mutex; 481 rwlock_t l_rwlock; 482 } u; 483 } Rt_lock; 484 485 typedef cond_t Rt_cond; 486 487 /* 488 * Define a dynamic section information descriptor. This parallels the entries 489 * in the .dynamic section and holds auxiliary information to implement lazy 490 * loading and filtee processing. 491 */ 492 typedef struct { 493 uint_t di_flags; 494 void *di_info; 495 } Dyninfo; 496 497 #define FLG_DI_STDFLTR 0x00001 /* .dynamic entry for DT_FILTER */ 498 #define FLG_DI_AUXFLTR 0x00002 /* .dynamic entry for DT_AUXILIARY */ 499 #define FLG_DI_SYMFLTR 0x00004 /* .dynamic entry for DT_SYMFILTER */ 500 /* and DT_SYMAUXILIARY */ 501 #define MSK_DI_FILTER 0x0000f /* mask for all filter possibilities */ 502 503 #define FLG_DI_NEEDED 0x00010 /* entry represents a dependency */ 504 #define FLG_DI_GROUP 0x00020 /* open dependency as a group */ 505 #define FLG_DI_PROCESSD 0x00040 /* entry has been processed */ 506 507 /* 508 * Data Structure to track AVL tree for pathnames of objects 509 * loaded into memory 510 */ 511 typedef struct { 512 const char *fpn_name; /* object name */ 513 Rt_map *fpn_lmp; /* object link-map */ 514 avl_node_t fpn_avl; /* avl book-keeping (see SGSOFFSETOF) */ 515 uint_t fpn_hash; /* object name hash value */ 516 } FullpathNode; 517 518 /* 519 * Define a mapping structure, which is maintained to describe each mapping 520 * of an object, ie. the text segment, data segment, bss segment, etc. 521 */ 522 typedef struct { 523 caddr_t m_vaddr; /* mapping address */ 524 size_t m_fsize; /* backing file size */ 525 size_t m_msize; /* mapping size */ 526 int m_perm; /* mapping permissions */ 527 } Mmap; 528 529 /* 530 * Link-map definition. 531 */ 532 struct rt_map { 533 /* 534 * BEGIN: Exposed to rtld_db - don't move, don't delete 535 */ 536 Link_map rt_public; /* public data */ 537 char *rt_pathname; /* full pathname of loaded object */ 538 ulong_t rt_padstart; /* start of image (including padding) */ 539 ulong_t rt_padimlen; /* size of image (including padding */ 540 ulong_t rt_msize; /* total memory mapped */ 541 uint_t rt_flags; /* state flags, see FLG below */ 542 uint_t rt_flags1; /* state flags1, see FL1 below */ 543 ulong_t rt_tlsmodid; /* TLS module id */ 544 /* 545 * END: Exposed to rtld_db - don't move, don't delete 546 */ 547 Alist *rt_alias; /* list of linked file names */ 548 Alist *rt_fpnode; /* list of FullpathNode AVL nodes */ 549 void (*rt_init)(); /* address of _init */ 550 void (*rt_fini)(); /* address of _fini */ 551 char *rt_runpath; /* LD_RUN_PATH and its equivalent */ 552 Pnode *rt_runlist; /* Pnode structures */ 553 Alist *rt_depends; /* list of dependencies */ 554 Alist *rt_callers; /* list of callers */ 555 Alist *rt_handles; /* dlopen handles */ 556 Alist *rt_groups; /* groups we're a member of */ 557 ulong_t rt_etext; /* etext address */ 558 struct fct *rt_fct; /* file class table for this object */ 559 Sym *(*rt_symintp)(); /* link map symbol interpreter */ 560 void *rt_priv; /* private data, object type specific */ 561 Lm_list *rt_list; /* link map list we belong to */ 562 uint_t rt_objfltrndx; /* object filtees .dynamic index */ 563 uint_t rt_symsfltrcnt; /* number of standard symbol filtees */ 564 uint_t rt_symafltrcnt; /* number of auxiliary symbol filtees */ 565 int rt_mode; /* usage mode, see RTLD mode flags */ 566 int rt_sortval; /* temporary buffer to traverse graph */ 567 uint_t rt_cycgroup; /* cyclic group */ 568 dev_t rt_stdev; /* device id and inode number for .so */ 569 ino_t rt_stino; /* multiple inclusion checks */ 570 char *rt_origname; /* original pathname of loaded object */ 571 size_t rt_dirsz; /* and its size */ 572 Alist *rt_copy; /* list of copy relocations */ 573 Audit_desc *rt_auditors; /* audit descriptor array */ 574 Audit_info *rt_audinfo; /* audit information descriptor */ 575 Syminfo *rt_syminfo; /* elf .syminfo section - here */ 576 /* because it is checked in */ 577 /* common code */ 578 Addr *rt_initarray; /* .initarray table */ 579 Addr *rt_finiarray; /* .finiarray table */ 580 Addr *rt_preinitarray; /* .preinitarray table */ 581 Mmap *rt_mmaps; /* array of mapping information */ 582 uint_t rt_mmapcnt; /* and associated number */ 583 uint_t rt_initarraysz; /* size of .initarray table */ 584 uint_t rt_finiarraysz; /* size of .finiarray table */ 585 uint_t rt_preinitarraysz; /* size of .preinitarray table */ 586 Dyninfo *rt_dyninfo; /* .dynamic information descriptors */ 587 uint_t rt_dyninfocnt; /* count of dyninfo entries */ 588 uint_t rt_relacount; /* no. of RELATIVE relocations */ 589 uint_t rt_idx; /* hold index within linkmap list */ 590 uint_t rt_lazy; /* lazy dependencies pending */ 591 Rt_cond *rt_condvar; /* variables */ 592 Xword rt_hwcap; /* hardware capabilities */ 593 Xword rt_sfcap; /* software capabilities */ 594 thread_t rt_threadid; /* thread init/fini synchronization */ 595 uint_t rt_cntl; /* link-map control list we belong to */ 596 }; 597 598 599 #ifdef _SYSCALL32 600 /* 601 * Structure to allow 64-bit rtld_db to read 32-bit processes out of procfs. 602 */ 603 typedef struct rt_map32 { 604 /* 605 * BEGIN: Exposed to rtld_db - don't move, don't delete 606 */ 607 Link_map32 rt_public; 608 uint32_t rt_pathname; 609 uint32_t rt_padstart; 610 uint32_t rt_padimlen; 611 uint32_t rt_msize; 612 uint32_t rt_flags; 613 uint32_t rt_flags1; 614 uint32_t rt_tlsmodid; 615 /* 616 * END: Exposed to rtld_db - don't move, don't delete 617 */ 618 uint32_t rt_alias; 619 uint32_t rt_fpnode; 620 uint32_t rt_init; 621 uint32_t rt_fini; 622 uint32_t rt_runpath; 623 uint32_t rt_runlist; 624 uint32_t rt_depends; 625 uint32_t rt_callers; 626 uint32_t rt_handles; 627 uint32_t rt_groups; 628 uint32_t rt_etext; 629 uint32_t rt_fct; 630 uint32_t rt_symintp; 631 uint32_t rt_priv; 632 uint32_t rt_list; 633 uint32_t rt_objfltrndx; 634 uint32_t rt_symsfltrcnt; 635 uint32_t rt_symafltrcnt; 636 int32_t rt_mode; 637 int32_t rt_sortval; 638 uint32_t rt_cycgroup; 639 uint32_t rt_stdev; 640 uint32_t rt_stino; 641 uint32_t rt_origname; 642 uint32_t rt_dirsz; 643 uint32_t rt_copy; 644 uint32_t rt_auditors; 645 uint32_t rt_audinfo; 646 uint32_t rt_syminfo; 647 uint32_t rt_initarray; 648 uint32_t rt_finiarray; 649 uint32_t rt_preinitarray; 650 uint32_t rt_mmaps; 651 uint32_t rt_mmapcnt; 652 uint32_t rt_initarraysz; 653 uint32_t rt_finiarraysz; 654 uint32_t rt_preinitarraysz; 655 uint32_t rt_dyninfo; 656 uint32_t rt_dyninfocnt; 657 uint32_t rt_relacount; 658 uint32_t rt_idx; 659 uint32_t rt_lazy; 660 uint32_t rt_condvar; 661 uint32_t rt_hwcap; 662 uint32_t rt_sfcap; 663 uint32_t rt_threadid; 664 uint32_t rt_cntl; 665 } Rt_map32; 666 667 #endif /* _SYSCALL32 */ 668 669 /* 670 * Link map state flags. 671 */ 672 /* 673 * BEGIN: Exposed to rtld_db - don't move, don't delete 674 */ 675 #define FLG_RT_ISMAIN 0x00000001 /* object represents main executable */ 676 #define FLG_RT_IMGALLOC 0x00000002 /* image is allocated (not mmap'ed) */ 677 /* 678 * Available for r_debug version >= RTLD_DB_VERSION5 679 */ 680 #define FLG_RT_RELOCED 0x00000004 /* object has been relocated */ 681 /* 682 * END: Exposed to rtld_db - don't move, don't delete 683 */ 684 #define FLG_RT_SETGROUP 0x00000008 /* group establishment required */ 685 #define FLG_RT_HWCAP 0x00000010 /* process $HWCAP expansion */ 686 #define FLG_RT_OBJECT 0x00000020 /* object processing (ie. .o's) */ 687 #define FLG_RT_NEWLOAD 0x00000040 /* object is newly loaded */ 688 #define FLG_RT_NODUMP 0x00000080 /* object can't be dldump(3x)'ed */ 689 #define FLG_RT_DELETE 0x00000100 /* object can be deleted */ 690 #define FLG_RT_ANALYZED 0x00000200 /* object has been analyzed */ 691 #define FLG_RT_INITDONE 0x00000400 /* objects .init has been completed */ 692 #define FLG_RT_TRANS 0x00000800 /* object is acting as a translator */ 693 #define FLG_RT_FIXED 0x00001000 /* image location is fixed */ 694 #define FLG_RT_PRELOAD 0x00002000 /* object was preloaded */ 695 #define FLG_RT_ALTER 0x00004000 /* alternative object used */ 696 #define FLG_RT_LOADFLTR 0x00008000 /* trigger filtee loading */ 697 #define FLG_RT_AUDIT 0x00010000 /* object is an auditor */ 698 #define FLG_RT_MODESET 0x00020000 /* MODE() has been initialized */ 699 #define FLG_RT_ANALZING 0x00040000 /* object is being analyzed */ 700 #define FLG_RT_INITFRST 0x00080000 /* execute .init first */ 701 #define FLG_RT_NOOPEN 0x00100000 /* dlopen() not allowed */ 702 #define FLG_RT_FINICLCT 0x00200000 /* fini has been collected (tsort) */ 703 #define FLG_RT_INITCALL 0x00400000 /* objects .init has been called */ 704 #define FLG_RT_SUNWBSS 0x00800000 /* object with PT_SUNWBSS, not mapped */ 705 #define FLG_RT_OBJINTPO 0x01000000 /* object is a global interposer */ 706 #define FLG_RT_SYMINTPO 0x02000000 /* object contains symbol interposer */ 707 #define MSK_RT_INTPOSE 0x03000000 /* mask for all interposer */ 708 /* possibilities */ 709 #define FLG_RT_MOVE 0x04000000 /* object needs move operation */ 710 #define FLG_RT_DLSYM 0x08000000 /* dlsym in progress on object */ 711 #define FLG_RT_REGSYMS 0x10000000 /* object has DT_REGISTER entries */ 712 #define FLG_RT_INITCLCT 0x20000000 /* init has been collected (tsort) */ 713 #define FLG_RT_HANDLE 0x40000000 /* generate a handle for this object */ 714 #define FLG_RT_RELOCING 0x80000000 /* object is being relocated */ 715 716 #define FL1_RT_COPYTOOK 0x00000001 /* copy relocation taken */ 717 #define FL1_RT_RELATIVE 0x00000002 /* relative path expansion required */ 718 #define FL1_RT_CONFSET 0x00000004 /* object was loaded by crle(1) */ 719 #define FL1_RT_NODEFLIB 0x00000008 /* ignore default library search */ 720 #define FL1_RT_ENDFILTE 0x00000010 /* filtee terminates filters search */ 721 #define FL1_RT_DISPREL 0x00000020 /* object has *disp* relocation */ 722 #define FL1_RT_TEXTREL 0x00000040 /* DT_TEXTREL set in object */ 723 #define FL1_RT_INITWAIT 0x00000080 /* threads are waiting on .init */ 724 #define FL1_RT_LDDSTUB 0x00000100 /* identify lddstub */ 725 #define FL1_RT_NOINIFIN 0x00000200 /* no .init or .fini exists */ 726 #define FL1_RT_USED 0x00000400 /* symbol referenced from this object */ 727 #define FL1_RT_SYMBOLIC 0x00000800 /* DF_SYMBOLIC was set - use */ 728 /* symbolic sym resolution */ 729 #define FL1_RT_OBJSFLTR 0x00001000 /* object is acting as a standard */ 730 #define FL1_RT_OBJAFLTR 0x00002000 /* or auxiliary filter */ 731 #define FL1_RT_SYMSFLTR 0x00004000 /* symbol is acting as a standard */ 732 #define FL1_RT_SYMAFLTR 0x00008000 /* or auxiliary filter */ 733 #define MSK_RT_FILTER 0x0000f000 /* mask for all filter possibilities */ 734 735 #define FL1_RT_TLSADD 0x00010000 /* objects TLS has been registered */ 736 #define FL1_RT_TLSSTAT 0x00020000 /* object requires static TLS */ 737 #define FL1_RT_DIRECT 0x00040000 /* object has DIRECT bindings enabled */ 738 #define FL1_RT_GLOBAUD 0x00080000 /* establish global auditing */ 739 740 /* 741 * The following range of bits are reserved to hold LML_TFLG_AUD_ values 742 * (although the definitions themselves aren't used anywhere). 743 */ 744 #define FL1_AUD_RS_STR 0x00100000 /* RESERVATION start for AU flags */ 745 #define FL1_AUD_RS_END 0x80000000 /* RESERVATION end for AU flags */ 746 747 748 /* 749 * Flags for the tls_modactivity() routine 750 */ 751 #define TM_FLG_MODADD 0x01 /* call tls_modadd() interface */ 752 #define TM_FLG_MODREM 0x02 /* call tls_modrem() interface */ 753 754 /* 755 * Macros for getting to link_map data. 756 */ 757 #define ADDR(X) ((X)->rt_public.l_addr) 758 #define NAME(X) ((X)->rt_public.l_name) 759 #define DYN(X) ((X)->rt_public.l_ld) 760 #define NEXT(X) ((X)->rt_public.l_next) 761 #define PREV(X) ((X)->rt_public.l_prev) 762 #define REFNAME(X) ((X)->rt_public.l_refname) 763 764 /* 765 * Macros for getting to linker private data. 766 */ 767 #define PATHNAME(X) ((X)->rt_pathname) 768 #define PADSTART(X) ((X)->rt_padstart) 769 #define PADIMLEN(X) ((X)->rt_padimlen) 770 #define MSIZE(X) ((X)->rt_msize) 771 #define FLAGS(X) ((X)->rt_flags) 772 #define FLAGS1(X) ((X)->rt_flags1) 773 #define TLSMODID(X) ((X)->rt_tlsmodid) 774 775 #define ALIAS(X) ((X)->rt_alias) 776 #define FPNODE(X) ((X)->rt_fpnode) 777 #define INIT(X) ((X)->rt_init) 778 #define FINI(X) ((X)->rt_fini) 779 #define RPATH(X) ((X)->rt_runpath) 780 #define RLIST(X) ((X)->rt_runlist) 781 #define DEPENDS(X) ((X)->rt_depends) 782 #define CALLERS(X) ((X)->rt_callers) 783 #define HANDLES(X) ((X)->rt_handles) 784 #define GROUPS(X) ((X)->rt_groups) 785 #define ETEXT(X) ((X)->rt_etext) 786 #define FCT(X) ((X)->rt_fct) 787 #define SYMINTP(X) ((X)->rt_symintp) 788 #define LIST(X) ((X)->rt_list) 789 #define OBJFLTRNDX(X) ((X)->rt_objfltrndx) 790 #define SYMSFLTRCNT(X) ((X)->rt_symsfltrcnt) 791 #define SYMAFLTRCNT(X) ((X)->rt_symafltrcnt) 792 #define MODE(X) ((X)->rt_mode) 793 #define SORTVAL(X) ((X)->rt_sortval) 794 #define CYCGROUP(X) ((X)->rt_cycgroup) 795 #define STDEV(X) ((X)->rt_stdev) 796 #define STINO(X) ((X)->rt_stino) 797 #define ORIGNAME(X) ((X)->rt_origname) 798 #define DIRSZ(X) ((X)->rt_dirsz) 799 #define COPY(X) ((X)->rt_copy) 800 #define AUDITORS(X) ((X)->rt_auditors) 801 #define AUDINFO(X) ((X)->rt_audinfo) 802 #define SYMINFO(X) ((X)->rt_syminfo) 803 #define INITARRAY(X) ((X)->rt_initarray) 804 #define FINIARRAY(X) ((X)->rt_finiarray) 805 #define PREINITARRAY(X) ((X)->rt_preinitarray) 806 #define MMAPS(X) ((X)->rt_mmaps) 807 #define MMAPCNT(X) ((X)->rt_mmapcnt) 808 #define INITARRAYSZ(X) ((X)->rt_initarraysz) 809 #define FINIARRAYSZ(X) ((X)->rt_finiarraysz) 810 #define PREINITARRAYSZ(X) ((X)->rt_preinitarraysz) 811 #define DYNINFO(X) ((X)->rt_dyninfo) 812 #define DYNINFOCNT(X) ((X)->rt_dyninfocnt) 813 #define RELACOUNT(X) ((X)->rt_relacount) 814 #define IDX(X) ((X)->rt_idx) 815 #define LAZY(X) ((X)->rt_lazy) 816 #define CONDVAR(X) ((X)->rt_condvar) 817 #define CNTL(X) ((X)->rt_cntl) 818 #define HWCAP(X) ((X)->rt_hwcap) 819 #define SFCAP(X) ((X)->rt_sfcap) 820 #define THREADID(X) ((X)->rt_threadid) 821 822 /* 823 * Flags for tsorting. 824 */ 825 #define RT_SORT_FWD 0x01 /* topological sort (.fini) */ 826 #define RT_SORT_REV 0x02 /* reverse topological sort (.init) */ 827 #define RT_SORT_DELETE 0x10 /* process FLG_RT_DELNEED objects */ 828 /* only (called via dlclose()) */ 829 #define RT_SORT_INTPOSE 0x20 /* process interposer objects */ 830 831 /* 832 * Flags for lookup_sym (and hence find_sym) routines. 833 */ 834 #define LKUP_DEFT 0x0000 /* simple lookup request */ 835 #define LKUP_SPEC 0x0001 /* special ELF lookup (allows address */ 836 /* resolutions to plt[] entries) */ 837 #define LKUP_LDOT 0x0002 /* indicates the original A_OUT */ 838 /* symbol had a leading `.' */ 839 #define LKUP_FIRST 0x0004 /* lookup symbol in first link map */ 840 /* only */ 841 #define LKUP_COPY 0x0008 /* lookup symbol for a COPY reloc, do */ 842 /* not bind to symbol at head */ 843 #define LKUP_STDRELOC 0x0010 /* lookup originates from a standard */ 844 /* relocation (elf_reloc()) */ 845 #define LKUP_SELF 0x0020 /* lookup symbol in ourself - undef */ 846 /* is valid */ 847 #define LKUP_WEAK 0x0040 /* relocation reference is weak */ 848 #define LKUP_NEXT 0x0080 /* request originates from RTLD_NEXT */ 849 #define LKUP_NODESCENT 0x0100 /* don't descend through dependencies */ 850 #define LKUP_NOFALBACK 0x0200 /* don't fall back to loading */ 851 /* pending lazy dependencies */ 852 #define LKUP_DIRECT 0x0400 /* direct binding request */ 853 #define LKUP_SYMNDX 0x0800 /* establish symbol index */ 854 #define LKUP_SINGLETON 0x1000 /* search for a singleton symbol */ 855 #define LKUP_STANDARD 0x2000 /* standard lookup - originated from */ 856 /* head link-map element */ 857 858 /* 859 * Data structure for calling lookup_sym() 860 */ 861 typedef struct { 862 const char *sl_name; /* symbol name */ 863 Rt_map *sl_cmap; /* callers link-map */ 864 Rt_map *sl_imap; /* initial link-map to search */ 865 ulong_t sl_hash; /* symbol hash value */ 866 ulong_t sl_rsymndx; /* referencing reloc symndx */ 867 Sym *sl_rsym; /* referencing symbol */ 868 uchar_t sl_rtype; /* relocation type associate with */ 869 /* symbol */ 870 uchar_t sl_bind; /* symbols binding (returned) */ 871 uint_t sl_flags; /* lookup flags */ 872 } Slookup; 873 874 875 typedef enum { 876 PLT_T_NONE = 0, 877 PLT_T_21D, 878 PLT_T_24D, 879 PLT_T_U32, 880 PLT_T_U44, 881 PLT_T_FULL, 882 PLT_T_FAR, 883 PLT_T_NUM /* Must be last */ 884 } Pltbindtype; 885 886 /* 887 * Prototypes. 888 */ 889 extern Lm_list lml_main; /* main's link map list */ 890 extern Lm_list lml_rtld; /* rtld's link map list */ 891 extern Lm_list *lml_list[]; 892 893 extern Pltbindtype elf_plt_write(uintptr_t, uintptr_t, void *, uintptr_t, 894 Xword); 895 extern Rt_map *is_so_loaded(Lm_list *, const char *); 896 extern Sym *lookup_sym(Slookup *, Rt_map **, uint_t *); 897 extern int rt_dldump(Rt_map *, const char *, int, Addr); 898 899 #ifdef __cplusplus 900 } 901 #endif 902 903 #endif /* _RTLD_H */ 904