Home | History | Annotate | Line # | Download | only in ld.elf_so
      1 /*	$NetBSD: rtld.h,v 1.157 2026/07/18 04:26:42 riastradh Exp $	 */
      2 
      3 /*
      4  * Copyright 1996 John D. Polstra.
      5  * Copyright 1996 Matt Thomas <matt (at) 3am-software.com>
      6  * All rights reserved.
      7  *
      8  * Redistribution and use in source and binary forms, with or without
      9  * modification, are permitted provided that the following conditions
     10  * are met:
     11  * 1. Redistributions of source code must retain the above copyright
     12  *    notice, this list of conditions and the following disclaimer.
     13  * 2. Redistributions in binary form must reproduce the above copyright
     14  *    notice, this list of conditions and the following disclaimer in the
     15  *    documentation and/or other materials provided with the distribution.
     16  * 3. All advertising materials mentioning features or use of this software
     17  *    must display the following acknowledgement:
     18  *      This product includes software developed by John Polstra.
     19  * 4. The name of the author may not be used to endorse or promote products
     20  *    derived from this software without specific prior written permission.
     21  *
     22  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     25  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     26  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
     27  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
     28  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     29  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
     30  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
     31  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
     32  */
     33 
     34 #ifndef RTLD_H
     35 #define RTLD_H
     36 
     37 #include <dlfcn.h>
     38 #include <signal.h>
     39 #include <stdbool.h>
     40 #include <stddef.h>
     41 #include <sys/param.h>
     42 #include <sys/endian.h>
     43 #include <sys/types.h>
     44 #include <sys/queue.h>
     45 #include <sys/exec_elf.h>
     46 #include <sys/tls.h>
     47 #include "rtldenv.h"
     48 #include "link.h"
     49 
     50 #if defined(_RTLD_SOURCE)
     51 
     52 #if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
     53 #include "unwind.h"
     54 #endif
     55 
     56 #ifndef	RTLD_DEFAULT_LIBRARY_PATH
     57 #define	RTLD_DEFAULT_LIBRARY_PATH	"/usr/lib"
     58 #endif
     59 #define _PATH_LD_HINTS			"/etc/ld.so.conf"
     60 
     61 extern size_t _rtld_pagesz;
     62 
     63 #define round_down(x)	((x) & ~(_rtld_pagesz - 1))
     64 #define round_up(x)	round_down((x) + _rtld_pagesz - 1)
     65 
     66 #define NEW(type)	((type *) xmalloc(sizeof(type)))
     67 #define CNEW(type)	((type *) xcalloc(sizeof(type)))
     68 
     69 /*
     70  * Fill in a DoneList with an allocation large enough to hold all of
     71  * the currently-loaded objects. Keep this in a macro since it calls
     72  * alloca and we want that to occur within the scope of the caller.
     73  * Callers must be built with -Wno-stack-protector.
     74  */
     75 #define _rtld_donelist_init(dlp)					\
     76     ((dlp)->num_alloc = _rtld_objcount,					\
     77     (dlp)->objs = alloca((dlp)->num_alloc * sizeof((dlp)->objs[0])),	\
     78     assert((dlp)->objs != NULL),					\
     79     (dlp)->num_used = 0)
     80 
     81 
     82 typedef struct Struct_Elf_Hash {
     83 	unsigned long sysv;
     84 	unsigned long gnu;
     85 } Elf_Hash;
     86 #endif /* _RTLD_SOURCE */
     87 
     88 /*
     89  * C++ has mandated the use of the following keywords for its new boolean
     90  * type.  We might as well follow their lead.
     91  */
     92 struct Struct_Obj_Entry;
     93 
     94 typedef struct Struct_Objlist_Entry {
     95 	SIMPLEQ_ENTRY(Struct_Objlist_Entry) link;
     96 	struct Struct_Obj_Entry *obj;
     97 } Objlist_Entry;
     98 
     99 typedef SIMPLEQ_HEAD(Struct_Objlist, Struct_Objlist_Entry) Objlist;
    100 
    101 typedef struct Struct_Name_Entry {
    102 	SIMPLEQ_ENTRY(Struct_Name_Entry) link;
    103 	char	name[1];
    104 } Name_Entry;
    105 
    106 typedef struct Struct_Needed_Entry {
    107 	struct Struct_Needed_Entry *next;
    108 	struct Struct_Obj_Entry *obj;
    109 	unsigned long   name;	/* Offset of name in string table */
    110 } Needed_Entry;
    111 
    112 typedef struct _rtld_search_path_t {
    113 	struct _rtld_search_path_t *sp_next;
    114 	const char     *sp_path;
    115 	size_t          sp_pathlen;
    116 } Search_Path;
    117 
    118 typedef struct Struct_Ver_Entry {
    119 	Elf_Word        hash;
    120 	u_int           flags;
    121 	const char     *name;
    122 	const char     *file;
    123 } Ver_Entry;
    124 
    125 /* Ver_Entry.flags */
    126 #define VER_INFO_HIDDEN	0x01
    127 
    128 #define RTLD_MAX_ENTRY 10
    129 #define RTLD_MAX_LIBRARY 4
    130 #define RTLD_MAX_CTL 2
    131 typedef struct _rtld_library_xform_t {
    132 	struct _rtld_library_xform_t *next;
    133 	char *name;
    134 	const char *ctlname;
    135 	struct {
    136 		char *value;
    137 		char *library[RTLD_MAX_LIBRARY];
    138 	} entry[RTLD_MAX_ENTRY];
    139 } Library_Xform;
    140 
    141 /*
    142  * Shared object descriptor.
    143  *
    144  * Items marked with "(%)" are dynamically allocated, and must be freed
    145  * when the structure is destroyed.
    146  */
    147 
    148 typedef void (*fptr_t)(void);
    149 
    150 typedef struct Struct_Obj_Entry {
    151 	struct Struct_Obj_Entry *next;
    152 	char           *path;		/* Pathname of underlying file (%) */
    153 	int             refcount;
    154 	int             dl_refcount;	/* Number of times loaded by dlopen */
    155 
    156 	/* These items are computed by map_object() or by digest_phdr(). */
    157 	caddr_t         mapbase;	/* Base address of mapped region */
    158 	size_t          mapsize;	/* Size of mapped region in bytes */
    159 	size_t          textsize;	/* Size of text segment in bytes */
    160 	Elf_Addr        vaddrbase;	/* Base address in shared object file */
    161 	caddr_t         relocbase;	/* Reloc const = mapbase - *vaddrbase */
    162 	Elf_Dyn        *dynamic;	/* Dynamic section */
    163 	caddr_t         entry;		/* Entry point */
    164 	const Elf_Phdr *phdr;		/* Program header (may be xmalloc'ed) */
    165 	size_t		phsize;		/* Size of program header in bytes */
    166 
    167 	/* Items from the dynamic section. */
    168 	Elf_Addr       *pltgot;		/* PLTGOT table */
    169 	const Elf_Rel  *rel;		/* Relocation entries */
    170 	const Elf_Rel  *rellim;		/* Limit of Relocation entries */
    171 	const Elf_Rela *rela;		/* Relocation entries */
    172 	const Elf_Rela *relalim;	/* Limit of Relocation entries */
    173 	const Elf_Relr *relr;		/* Relative relocations */
    174 	const Elf_Relr *relrlim;	/* Limit of relative relocations */
    175 	const Elf_Rel  *pltrel;		/* PLT relocation entries */
    176 	const Elf_Rel  *pltrellim;	/* Limit of PLT relocation entries */
    177 	const Elf_Rela *pltrela;	/* PLT relocation entries */
    178 	const Elf_Rela *pltrelalim;	/* Limit of PLT relocation entries */
    179 	const Elf_Sym  *symtab;		/* Symbol table */
    180 	const char     *strtab;		/* String table */
    181 	unsigned long   strsize;	/* Size in bytes of string table */
    182 #if defined(__mips__) || defined(__riscv__)
    183 	Elf_Word        local_gotno;	/* Number of local GOT entries */
    184 	Elf_Word        symtabno;	/* Number of dynamic symbols */
    185 	Elf_Word        gotsym;		/* First dynamic symbol in GOT */
    186 #endif
    187 
    188 	/* SysV Hash fields */
    189 	const Elf_Symindx *buckets;	/* Hash table buckets array */
    190 	unsigned long	unused1;	/* Used to be nbuckets */
    191 	const Elf_Symindx *chains;	/* Hash table chain array */
    192 	unsigned long   nchains;	/* Number of chains */
    193 
    194 	Search_Path    *rpaths;		/* Search path specified in object */
    195 	Needed_Entry   *needed;		/* Shared objects needed by this (%) */
    196 
    197 	fptr_t		init;		/* Initialization function to call */
    198 	fptr_t		fini;		/* Termination function to call */
    199 
    200 	u_int32_t	mainprog:1,	/* True if this is the main program */
    201 	        	rtld:1,		/* True if this is the dynamic linker */
    202 			textrel:1,	/* True if there are relocations to
    203 					 * text seg */
    204 			symbolic:1,	/* True if generated with
    205 					 * "-Bsymbolic" */
    206 			printed:1,	/* True if ldd has printed it */
    207 			isdynamic:1,	/* True if this is a pure PIC object */
    208 			mainref:1,	/* True if on _rtld_list_main */
    209 			globalref:1,	/* True if on _rtld_list_global */
    210 			init_done:1,	/* True if .init has been added */
    211 			init_blocked:1,	/* True if blocked in recursive dl* */
    212 			init_called:1,	/* True if .init function has been
    213 					 * called */
    214 			fini_called:1,	/* True if .fini function has been
    215 					 * called */
    216 			z_now:1,	/* True if object's symbols should be
    217 					   bound immediately */
    218 			z_nodelete:1,	/* True if object should never be
    219 					   unloaded */
    220 			z_initfirst:1,	/* True if object's .init/.fini take
    221 					 * priority over others */
    222 			z_noopen:1,	/* True if object should never be
    223 					   dlopen'ed */
    224 			phdr_loaded:1,	/* Phdr is loaded and doesn't need to
    225 					 * be freed. */
    226 #ifdef __alpha__
    227 			secureplt:1,	/* True if PLT is read-only format */
    228 #endif
    229 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
    230 			tls_static:1,	/* True if static TLS offset
    231 					 * has been allocated */
    232 			tls_dynamic:1,	/* True if any non-static DTV entry
    233 					 * has been allocated */
    234 #endif
    235 			ref_nodel:1,	/* Refcount increased to prevent dlclose */
    236 			sysv_hash:1,	/* SysV Hash available */
    237 			gnu_hash:1;	/* GNU Hash available */
    238 
    239 	struct link_map linkmap;	/* for the debugger */
    240 
    241 	/* These items are computed by map_object() or by digest_phdr(). */
    242 	const char     *interp;	/* Pathname of the interpreter, if any */
    243 	Objlist         dldags;	/* Object belongs to these dlopened DAGs (%) */
    244 	Objlist         dagmembers;	/* DAG has these members (%) */
    245 	dev_t           dev;		/* Object's filesystem's device */
    246 	ino_t           ino;		/* Object's inode number */
    247 
    248 	void		*ehdr;
    249 
    250 	/* SysV Hash fields */
    251 	uint32_t        nbuckets;	/* Number of buckets */
    252 	uint32_t        nbuckets_m;	/* Precomputed for fast remainder */
    253 	uint8_t         nbuckets_s1;
    254 	uint8_t         nbuckets_s2;
    255 
    256 	/* GNU Hash fields */
    257 	const uint32_t *buckets_gnu;	/* Hash table buckets array */
    258 	uint32_t	nbuckets_gnu;	/* Number of GNU hash buckets */
    259 	uint32_t	nbuckets_m_gnu;	/* Precomputed for fast remainder */
    260 	uint8_t		nbuckets_s1_gnu;
    261 	uint8_t		nbuckets_s2_gnu;
    262 	const uint32_t *chains_gnu;	/* Hash table chain array */
    263 #define nchains_gnu	nchains		/* Number of symbols, shared with SysV Hash */
    264 	const Elf_Addr *bloom_gnu;
    265 	uint32_t	symndx_gnu;	/* First accessible symbol on dynsym table */
    266 	uint32_t	mask_bm_gnu;	/* Bloom filter words - 1 (bitmask) */
    267 	uint32_t	shift2_gnu;	/* Bloom filter shift count */
    268 
    269 	size_t		pathlen;	/* Pathname length */
    270 	SIMPLEQ_HEAD(, Struct_Name_Entry) names; /* List of names for this
    271 						  * object we know about. */
    272 
    273 #ifdef __powerpc__
    274 #ifdef _LP64
    275 	Elf_Addr	glink;		/* global linkage */
    276 #else
    277 	Elf_Addr       *gotptr;		/* GOT table (secure-plt only) */
    278 #endif
    279 #endif
    280 
    281 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
    282 	/* Thread Local Storage support for this module */
    283 	size_t		tlsindex;	/* Index in DTV */
    284 	void		*tlsinit;	/* Base address of TLS init block */
    285 	size_t		tlsinitsize;	/* Size of TLS init block */
    286 	size_t		tlssize;	/* Size of TLS block */
    287 	size_t		tlsoffset;	/* Offset in the static TLS block */
    288 	size_t		tlsalign;	/* Needed alignment for static TLS */
    289 #endif
    290 
    291 #ifdef GNU_RELRO
    292 	/* relocation readonly */
    293 	void		*relro_page;
    294 	size_t		relro_size;
    295 #endif
    296 
    297 	/* symbol versioning */
    298 	const Elf_Verneed *verneed;	/* Required versions. */
    299 	Elf_Word	verneednum;	/* Number of entries in verneed table */
    300 	const Elf_Verdef  *verdef;	/* Provided versions. */
    301 	Elf_Word	verdefnum;	/* Number of entries in verdef table */
    302 	const Elf_Versym *versyms;	/* Symbol versions table */
    303 
    304 	Ver_Entry	*vertab;	/* Versions required/defined by this
    305 					 * object */
    306 	int		vertabnum;	/* Number of entries in vertab */
    307 
    308 	/* init_array/fini_array */
    309 	fptr_t		*init_array;	/* start of init array */
    310 	size_t		init_arraysz;	/* # of entries in it */
    311 	fptr_t		*fini_array;	/* start of fini array */
    312 	size_t		fini_arraysz;	/* # of entries in it */
    313 	fptr_t		*preinit_array;	/* start of preinit array */
    314 	size_t		preinit_arraysz;/* # of entries in it */
    315 	/* IRELATIVE relocations */
    316 	size_t		ifunc_remaining;
    317 #if \
    318     defined(__aarch64__) || \
    319     defined(__arm__) || \
    320     defined(__i386__) || \
    321     defined(__powerpc__) || \
    322     defined(__sparc__) || \
    323     defined(__x86_64__)
    324 #define IFUNC_NONPLT
    325 	/* On SPARC, the PLT variant is called JMP_IREL and counted above. */
    326 	size_t		ifunc_remaining_nonplt;
    327 #endif
    328 	size_t		cxa_refcount;	/* For TLS destructors. */
    329 #ifdef __ARM_EABI__
    330 	void		*exidx_start;
    331 	size_t		exidx_sz;
    332 #endif
    333 	int		finiwaiter;	/* dlopen thread waiting for dlclose */
    334 	int		initfinilock;	/* thread running init/fini */
    335 	int		initfinilockwaiter; /* thread waiting to init/fini */
    336 	int		neededrefcount;	/* #threads loading obj's deps */
    337 	int		neededwaiter;	/* thread waiting for neededrefcount */
    338 	enum {
    339 		OBJRELOC_NOTYET = 0,	/* object created, NEEDED not loaded */
    340 		OBJRELOC_READY,		/* NEEDED loaded, dldags inited */
    341 		OBJRELOC_DONE,		/* relocation successful */
    342 		OBJRELOC_FAILED,	/* relocation failed */
    343 	}		relocstate;
    344 	unsigned	dlclosing;	/* true if being dlclosed now */
    345 } Obj_Entry;
    346 
    347 typedef struct Struct_DoneList {
    348 	const Obj_Entry **objs;		/* Array of object pointers */
    349 	unsigned int num_alloc;		/* Allocated size of the array */
    350 	unsigned int num_used;		/* Number of array slots used */
    351 } DoneList;
    352 
    353 
    354 #if defined(_RTLD_SOURCE)
    355 
    356 extern struct r_debug _rtld_debug;
    357 extern Search_Path *_rtld_default_paths;
    358 extern Obj_Entry *_rtld_objlist;
    359 extern Obj_Entry **_rtld_objtail;
    360 extern u_int _rtld_objrelocpending;
    361 extern u_int _rtld_objcount;
    362 extern u_int _rtld_objloads;
    363 extern const uintptr_t _rtld_compat_obj[];
    364 extern Obj_Entry *_rtld_objmain;
    365 extern Obj_Entry _rtld_objself;
    366 extern Search_Path *_rtld_paths;
    367 extern Library_Xform *_rtld_xforms;
    368 extern bool _rtld_trust;
    369 extern Objlist _rtld_list_global;
    370 extern Objlist _rtld_list_main;
    371 extern Elf_Sym _rtld_sym_zero;
    372 extern u_int _rtld_objgen;
    373 
    374 #define	RTLD_MODEMASK 0x3
    375 
    376 /* Flags to be passed into _rtld_symlook_ family of functions. */
    377 #define SYMLOOK_IN_PLT	0x01	/* Lookup for PLT symbol */
    378 #define SYMLOOK_DLSYM	0x02	/* Return newest versioned symbol.
    379 				   Used by dlsym. */
    380 
    381 /* Flags for _rtld_load_object() and friends. */
    382 #define	_RTLD_GLOBAL	0x01	/* Add object to global DAG. */
    383 #define	_RTLD_MAIN	0x02
    384 #define	_RTLD_NOLOAD	0x04	/* dlopen() specified RTLD_NOLOAD. */
    385 #define	_RTLD_DLOPEN	0x08	/* Load_object() called from dlopen(). */
    386 
    387 /* Preallocation for static TLS model */
    388 #define	RTLD_STATIC_TLS_RESERVATION	64
    389 
    390 /* rtld.c */
    391 __dso_public char *dlerror(void);
    392 __dso_public void *dlopen(const char *, int);
    393 __dso_public void *dlsym(void *, const char *);
    394 __dso_public int dlclose(void *);
    395 __dso_public int dladdr(const void *, Dl_info *);
    396 __dso_public int dlinfo(void *, int, void *);
    397 __dso_public int dl_iterate_phdr(int (*)(struct dl_phdr_info *, size_t, void *),
    398     void *);
    399 
    400 __dso_public void *_dlauxinfo(void) __pure;
    401 __dso_public void __dl_cxa_refcount(void *addr, ssize_t delta);
    402 
    403 __dso_public pid_t __locked_fork(int *);
    404 
    405 #if defined(__ARM_EABI__) && !defined(__ARM_DWARF_EH__)
    406 /*
    407  * This is used by libgcc to find the start and length of the exception table
    408  * associated with a PC.
    409  */
    410 __dso_public _Unwind_Ptr __gnu_Unwind_Find_exidx(_Unwind_Ptr, int *);
    411 #endif
    412 
    413 /* These aren't exported */
    414 void _rtld_error(const char *, ...) __printflike(1,2);
    415 void _rtld_die(void) __dead;
    416 void *_rtld_objmain_sym(const char *);
    417 __dso_public void _rtld_debug_state(void) __noinline;
    418 void _rtld_linkmap_add(Obj_Entry *);
    419 void _rtld_linkmap_delete(Obj_Entry *);
    420 void _rtld_objlist_push_head(Objlist *, Obj_Entry *);
    421 void _rtld_objlist_push_tail(Objlist *, Obj_Entry *);
    422 Objlist_Entry *_rtld_objlist_find(Objlist *, const Obj_Entry *);
    423 void _rtld_ref_dag(Obj_Entry *);
    424 
    425 #ifdef RTLD_LOADER
    426 void _rtld_load_needed_enter(Obj_Entry *);
    427 void _rtld_load_needed_exit(Obj_Entry *);
    428 bool _rtld_wait_for_fini(Obj_Entry **, sigset_t *);
    429 #else
    430 static inline void
    431 _rtld_load_needed_enter(Obj_Entry *obj)
    432 {
    433 	obj->neededrefcount++;
    434 }
    435 static inline void
    436 _rtld_load_needed_exit(Obj_Entry *obj)
    437 {
    438 	obj->neededrefcount--;
    439 }
    440 static inline bool
    441 _rtld_wait_for_fini(Obj_Entry **objp, sigset_t *mask)
    442 {
    443 	assert((*objp)->refcount);
    444 	return false;
    445 }
    446 #endif
    447 
    448 void _rtld_shared_enter(void);
    449 void _rtld_shared_exit(void);
    450 void _rtld_exclusive_enter(sigset_t *);
    451 void _rtld_exclusive_exit(sigset_t *);
    452 
    453 int _rtld_relro(const Obj_Entry *, bool);
    454 
    455 /* expand.c */
    456 size_t _rtld_expand_path(char *, size_t, const char *, const char *,\
    457     const char *);
    458 
    459 /* headers.c */
    460 void _rtld_digest_dynamic(const char *, Obj_Entry *);
    461 Obj_Entry *_rtld_digest_phdr(const Elf_Phdr *, int, caddr_t);
    462 
    463 /* load.c */
    464 Obj_Entry *_rtld_load_object(const char *, int, sigset_t *);
    465 int _rtld_load_needed_objects(Obj_Entry *, int, sigset_t *);
    466 int _rtld_preload(const char *, sigset_t *);
    467 
    468 /* arch/<arch>/fixup.c */
    469 int _rtld_map_segment_fixup(const char *, int, Elf_Ehdr *, Elf_Phdr *,
    470     caddr_t, size_t, int);
    471 
    472 #define	OBJ_ERR	(Obj_Entry *)(-1)
    473 /* path.c */
    474 void _rtld_add_paths(const char *, Search_Path **, const char *);
    475 void _rtld_process_hints(const char *, Search_Path **, Library_Xform **,
    476     const char *);
    477 int _rtld_sysctl(const char *, void *, size_t *);
    478 
    479 /* reloc.c */
    480 int _rtld_do_copy_relocations(const Obj_Entry *);
    481 int _rtld_relocate_objects(Obj_Entry *, bool);
    482 int _rtld_relocate_nonplt_objects(Obj_Entry *);
    483 int _rtld_relocate_plt_lazy(Obj_Entry *);
    484 int _rtld_relocate_plt_objects(const Obj_Entry *);
    485 void _rtld_setup_pltgot(const Obj_Entry *);
    486 Elf_Addr _rtld_resolve_ifunc(const Obj_Entry *, const Elf_Sym *);
    487 Elf_Addr _rtld_resolve_ifunc2(const Obj_Entry *, Elf_Addr);
    488 
    489 void _rtld_call_ifunc(Obj_Entry *, sigset_t *, u_int);
    490 
    491 /* search.c */
    492 Obj_Entry *_rtld_load_library(const char *, const Obj_Entry *, int,
    493     sigset_t *);
    494 
    495 /* symbol.c */
    496 const Elf_Sym *_rtld_symlook_obj(const char *, Elf_Hash *,
    497     const Obj_Entry *, u_int, const Ver_Entry *);
    498 const Elf_Sym *_rtld_find_symdef(unsigned long, const Obj_Entry *,
    499     const Obj_Entry **, u_int);
    500 const Elf_Sym *_rtld_find_plt_symdef(unsigned long, const Obj_Entry *,
    501     const Obj_Entry **, bool);
    502 
    503 const Elf_Sym *_rtld_symlook_list(const char *, Elf_Hash *,
    504     const Objlist *, const Obj_Entry **, u_int, const Ver_Entry *, DoneList *);
    505 const Elf_Sym *_rtld_symlook_default(const char *, Elf_Hash *,
    506     const Obj_Entry *, const Obj_Entry **, u_int, const Ver_Entry *);
    507 const Elf_Sym *_rtld_symlook_needed(const char *, Elf_Hash *,
    508     const Needed_Entry *, const Obj_Entry **, u_int, const Ver_Entry *,
    509     DoneList *, DoneList *);
    510 
    511 /* symver.c */
    512 void _rtld_object_add_name(Obj_Entry *, const char *);
    513 int _rtld_object_match_name(const Obj_Entry *, const char *);
    514 int _rtld_verify_object_versions(Obj_Entry *);
    515 
    516 static __inline const Ver_Entry *
    517 _rtld_fetch_ventry(const Obj_Entry *obj, unsigned long symnum)
    518 {
    519 	Elf_Half vernum;
    520 
    521 	if (obj->vertab) {
    522 		vernum = VER_NDX(obj->versyms[symnum]);
    523 		if (vernum >= obj->vertabnum) {
    524 			_rtld_error("%s: symbol %s has wrong verneed value %d",
    525 			    obj->path, &obj->strtab[symnum], vernum);
    526 		} else if (obj->vertab[vernum].hash) {
    527 			return &obj->vertab[vernum];
    528 		}
    529 	}
    530 	return NULL;
    531 }
    532 
    533 #if defined(__HAVE_TLS_VARIANT_I) || defined(__HAVE_TLS_VARIANT_II)
    534 /* tls.c */
    535 void *_rtld_tls_get_addr(void *, size_t, size_t);
    536 void _rtld_tls_initial_allocation(void);
    537 int _rtld_tls_offset_allocate(Obj_Entry *);
    538 void _rtld_tls_offset_free(Obj_Entry *);
    539 
    540 extern size_t _rtld_tls_dtv_generation;
    541 extern size_t _rtld_tls_max_index;
    542 
    543 __dso_public extern void *__tls_get_addr(void *);
    544 #ifdef __i386__
    545 __dso_public extern void *___tls_get_addr(void *)
    546     __attribute__((__regparm__(1)));
    547 #endif
    548 #endif
    549 
    550 /* map_object.c */
    551 struct stat;
    552 Obj_Entry *_rtld_map_object(const char *, int, const struct stat *);
    553 void _rtld_obj_free(Obj_Entry *);
    554 Obj_Entry *_rtld_obj_new(void);
    555 
    556 #ifdef RTLD_LOADER
    557 /* function descriptors */
    558 #ifdef __HAVE_FUNCTION_DESCRIPTORS
    559 Elf_Addr _rtld_function_descriptor_alloc(const Obj_Entry *,
    560     const Elf_Sym *, Elf_Addr);
    561 const void *_rtld_function_descriptor_function(const void *);
    562 
    563 Elf_Addr _rtld_call_function_addr(const Obj_Entry *, Elf_Addr);
    564 #else
    565 static inline Elf_Addr
    566 _rtld_call_function_addr(const Obj_Entry *obj, Elf_Addr addr)
    567 {
    568 	return ((Elf_Addr(*)(void))addr)();
    569 }
    570 #endif /* __HAVE_FUNCTION_DESCRIPTORS */
    571 #endif /* RTLD_LOADER */
    572 
    573 #endif /* _RTLD_SOURCE */
    574 
    575 #endif /* RTLD_H */
    576