ldsodefs.h 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173
  1. /* Run-time dynamic linker data structures for loaded ELF shared objects.
  2. Copyright (C) 1995-2019 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <http://www.gnu.org/licenses/>. */
  15. #ifndef _LDSODEFS_H
  16. #define _LDSODEFS_H 1
  17. #include <features.h>
  18. #include <stdbool.h>
  19. #define __need_size_t
  20. #define __need_NULL
  21. #include <stddef.h>
  22. #include <string.h>
  23. #include <stdint.h>
  24. #include <elf.h>
  25. #include <dlfcn.h>
  26. #include <fpu_control.h>
  27. #include <sys/mman.h>
  28. #include <link.h>
  29. #include <dl-lookupcfg.h>
  30. #include <dl-sysdep.h>
  31. #include <libc-lock.h>
  32. #include <hp-timing.h>
  33. #include <tls.h>
  34. __BEGIN_DECLS
  35. #define VERSYMIDX(sym) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGIDX (sym))
  36. #define VALIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
  37. + DT_EXTRANUM + DT_VALTAGIDX (tag))
  38. #define ADDRIDX(tag) (DT_NUM + DT_THISPROCNUM + DT_VERSIONTAGNUM \
  39. + DT_EXTRANUM + DT_VALNUM + DT_ADDRTAGIDX (tag))
  40. /* We use this macro to refer to ELF types independent of the native wordsize.
  41. `ElfW(TYPE)' is used in place of `Elf32_TYPE' or `Elf64_TYPE'. */
  42. #define ELFW(type) _ElfW (ELF, __ELF_NATIVE_CLASS, type)
  43. /* All references to the value of l_info[DT_PLTGOT],
  44. l_info[DT_STRTAB], l_info[DT_SYMTAB], l_info[DT_RELA],
  45. l_info[DT_REL], l_info[DT_JMPREL], and l_info[VERSYMIDX (DT_VERSYM)]
  46. have to be accessed via the D_PTR macro. The macro is needed since for
  47. most architectures the entry is already relocated - but for some not
  48. and we need to relocate at access time. */
  49. #ifdef DL_RO_DYN_SECTION
  50. # define D_PTR(map, i) ((map)->i->d_un.d_ptr + (map)->l_addr)
  51. #else
  52. # define D_PTR(map, i) (map)->i->d_un.d_ptr
  53. #endif
  54. /* Result of the lookup functions and how to retrieve the base address. */
  55. typedef struct link_map *lookup_t;
  56. #define LOOKUP_VALUE(map) map
  57. #define LOOKUP_VALUE_ADDRESS(map, set) ((set) || (map) ? (map)->l_addr : 0)
  58. /* Calculate the address of symbol REF using the base address from map MAP,
  59. if non-NULL. Don't check for NULL map if MAP_SET is TRUE. */
  60. #define SYMBOL_ADDRESS(map, ref, map_set) \
  61. ((ref) == NULL ? 0 \
  62. : (__glibc_unlikely ((ref)->st_shndx == SHN_ABS) ? 0 \
  63. : LOOKUP_VALUE_ADDRESS (map, map_set)) + (ref)->st_value)
  64. /* On some architectures a pointer to a function is not just a pointer
  65. to the actual code of the function but rather an architecture
  66. specific descriptor. */
  67. #ifndef ELF_FUNCTION_PTR_IS_SPECIAL
  68. # define DL_SYMBOL_ADDRESS(map, ref) \
  69. (void *) SYMBOL_ADDRESS (map, ref, false)
  70. # define DL_LOOKUP_ADDRESS(addr) ((ElfW(Addr)) (addr))
  71. # define DL_CALL_DT_INIT(map, start, argc, argv, env) \
  72. ((init_t) (start)) (argc, argv, env)
  73. # define DL_CALL_DT_FINI(map, start) ((fini_t) (start)) ()
  74. #endif
  75. /* On some architectures dladdr can't use st_size of all symbols this way. */
  76. #define DL_ADDR_SYM_MATCH(L, SYM, MATCHSYM, ADDR) \
  77. ((ADDR) >= (L)->l_addr + (SYM)->st_value \
  78. && ((((SYM)->st_shndx == SHN_UNDEF || (SYM)->st_size == 0) \
  79. && (ADDR) == (L)->l_addr + (SYM)->st_value) \
  80. || (ADDR) < (L)->l_addr + (SYM)->st_value + (SYM)->st_size) \
  81. && ((MATCHSYM) == NULL || (MATCHSYM)->st_value < (SYM)->st_value))
  82. /* According to the ELF gABI no STV_HIDDEN or STV_INTERNAL symbols are
  83. expected to be present in dynamic symbol tables as they should have
  84. been either removed or converted to STB_LOCAL binding by the static
  85. linker. However some GNU binutils versions produce such symbols in
  86. some cases. To prevent such symbols present in a buggy binary from
  87. preempting global symbols we filter them out with this predicate. */
  88. static __always_inline bool
  89. dl_symbol_visibility_binds_local_p (const ElfW(Sym) *sym)
  90. {
  91. return (ELFW(ST_VISIBILITY) (sym->st_other) == STV_HIDDEN
  92. || ELFW(ST_VISIBILITY) (sym->st_other) == STV_INTERNAL);
  93. }
  94. /* Unmap a loaded object, called by _dl_close (). */
  95. #ifndef DL_UNMAP_IS_SPECIAL
  96. # define DL_UNMAP(map) _dl_unmap_segments (map)
  97. #endif
  98. /* By default we do not need special support to initialize DSOs loaded
  99. by statically linked binaries. */
  100. #ifndef DL_STATIC_INIT
  101. # define DL_STATIC_INIT(map)
  102. #endif
  103. /* Reloc type classes as returned by elf_machine_type_class().
  104. ELF_RTYPE_CLASS_PLT means this reloc should not be satisfied by
  105. some PLT symbol, ELF_RTYPE_CLASS_COPY means this reloc should not be
  106. satisfied by any symbol in the executable. Some architectures do
  107. not support copy relocations. In this case we define the macro to
  108. zero so that the code for handling them gets automatically optimized
  109. out. ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA means address of protected
  110. data defined in the shared library may be external, i.e., due to copy
  111. relocation. */
  112. #define ELF_RTYPE_CLASS_PLT 1
  113. #ifndef DL_NO_COPY_RELOCS
  114. # define ELF_RTYPE_CLASS_COPY 2
  115. #else
  116. # define ELF_RTYPE_CLASS_COPY 0
  117. #endif
  118. /* If DL_EXTERN_PROTECTED_DATA is defined, address of protected data
  119. defined in the shared library may be external, i.e., due to copy
  120. relocation. */
  121. #ifdef DL_EXTERN_PROTECTED_DATA
  122. # define ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA 4
  123. #else
  124. # define ELF_RTYPE_CLASS_EXTERN_PROTECTED_DATA 0
  125. #endif
  126. /* ELF uses the PF_x macros to specify the segment permissions, mmap
  127. uses PROT_xxx. In most cases the three macros have the values 1, 2,
  128. and 3 but not in a matching order. The following macros allows
  129. converting from the PF_x values to PROT_xxx values. */
  130. #define PF_TO_PROT \
  131. ((PROT_READ << (PF_R * 4)) \
  132. | (PROT_WRITE << (PF_W * 4)) \
  133. | (PROT_EXEC << (PF_X * 4)) \
  134. | ((PROT_READ | PROT_WRITE) << ((PF_R | PF_W) * 4)) \
  135. | ((PROT_READ | PROT_EXEC) << ((PF_R | PF_X) * 4)) \
  136. | ((PROT_WRITE | PROT_EXEC) << (PF_W | PF_X) * 4) \
  137. | ((PROT_READ | PROT_WRITE | PROT_EXEC) << ((PF_R | PF_W | PF_X) * 4)))
  138. /* The filename itself, or the main program name, if available. */
  139. #define DSO_FILENAME(name) ((name)[0] ? (name) \
  140. : (rtld_progname ?: "<main program>"))
  141. #define RTLD_PROGNAME (rtld_progname ?: "<program name unknown>")
  142. /* For the version handling we need an array with only names and their
  143. hash values. */
  144. struct r_found_version
  145. {
  146. const char *name;
  147. ElfW(Word) hash;
  148. int hidden;
  149. const char *filename;
  150. };
  151. /* We want to cache information about the searches for shared objects. */
  152. enum r_dir_status { unknown, nonexisting, existing };
  153. struct r_search_path_elem
  154. {
  155. /* This link is only used in the `all_dirs' member of `r_search_path'. */
  156. struct r_search_path_elem *next;
  157. /* Strings saying where the definition came from. */
  158. const char *what;
  159. const char *where;
  160. /* Basename for this search path element. The string must end with
  161. a slash character. */
  162. const char *dirname;
  163. size_t dirnamelen;
  164. enum r_dir_status status[0];
  165. };
  166. struct r_strlenpair
  167. {
  168. const char *str;
  169. size_t len;
  170. };
  171. /* A data structure for a simple single linked list of strings. */
  172. struct libname_list
  173. {
  174. const char *name; /* Name requested (before search). */
  175. struct libname_list *next; /* Link to next name for this object. */
  176. int dont_free; /* Flag whether this element should be freed
  177. if the object is not entirely unloaded. */
  178. };
  179. /* Bit masks for the objects which valid callers can come from to
  180. functions with restricted interface. */
  181. enum allowmask
  182. {
  183. allow_libc = 1,
  184. allow_libdl = 2,
  185. allow_libpthread = 4,
  186. allow_ldso = 8
  187. };
  188. struct audit_ifaces
  189. {
  190. void (*activity) (uintptr_t *, unsigned int);
  191. char *(*objsearch) (const char *, uintptr_t *, unsigned int);
  192. unsigned int (*objopen) (struct link_map *, Lmid_t, uintptr_t *);
  193. void (*preinit) (uintptr_t *);
  194. union
  195. {
  196. uintptr_t (*symbind32) (Elf32_Sym *, unsigned int, uintptr_t *,
  197. uintptr_t *, unsigned int *, const char *);
  198. uintptr_t (*symbind64) (Elf64_Sym *, unsigned int, uintptr_t *,
  199. uintptr_t *, unsigned int *, const char *);
  200. };
  201. union
  202. {
  203. #ifdef ARCH_PLTENTER_MEMBERS
  204. ARCH_PLTENTER_MEMBERS;
  205. #endif
  206. };
  207. union
  208. {
  209. #ifdef ARCH_PLTEXIT_MEMBERS
  210. ARCH_PLTEXIT_MEMBERS;
  211. #endif
  212. };
  213. unsigned int (*objclose) (uintptr_t *);
  214. struct audit_ifaces *next;
  215. };
  216. /* Test whether given NAME matches any of the names of the given object. */
  217. extern int _dl_name_match_p (const char *__name, const struct link_map *__map)
  218. attribute_hidden;
  219. /* Compute next higher prime number. */
  220. extern unsigned long int _dl_higher_prime_number (unsigned long int n)
  221. attribute_hidden;
  222. /* A stripped down strtoul-like implementation. */
  223. uint64_t _dl_strtoul (const char *, char **) attribute_hidden;
  224. /* Function used as argument for `_dl_receive_error' function. The
  225. arguments are the error code, error string, and the objname the
  226. error occurred in. */
  227. typedef void (*receiver_fct) (int, const char *, const char *);
  228. /* Internal functions of the run-time dynamic linker.
  229. These can be accessed if you link again the dynamic linker
  230. as a shared library, as in `-lld' or `/lib/ld.so' explicitly;
  231. but are not normally of interest to user programs.
  232. The `-ldl' library functions in <dlfcn.h> provide a simple
  233. user interface to run-time dynamic linking. */
  234. #ifndef SHARED
  235. # define EXTERN extern
  236. # define GL(name) _##name
  237. #else
  238. # define EXTERN
  239. # if IS_IN (rtld)
  240. # define GL(name) _rtld_local._##name
  241. # else
  242. # define GL(name) _rtld_global._##name
  243. # endif
  244. struct rtld_global
  245. {
  246. #endif
  247. /* Don't change the order of the following elements. 'dl_loaded'
  248. must remain the first element. Forever. */
  249. /* Non-shared code has no support for multiple namespaces. */
  250. #ifdef SHARED
  251. # define DL_NNS 16
  252. #else
  253. # define DL_NNS 1
  254. #endif
  255. EXTERN struct link_namespaces
  256. {
  257. /* A pointer to the map for the main map. */
  258. struct link_map *_ns_loaded;
  259. /* Number of object in the _dl_loaded list. */
  260. unsigned int _ns_nloaded;
  261. /* Direct pointer to the searchlist of the main object. */
  262. struct r_scope_elem *_ns_main_searchlist;
  263. /* This is zero at program start to signal that the global scope map is
  264. allocated by rtld. Later it keeps the size of the map. It might be
  265. reset if in _dl_close if the last global object is removed. */
  266. size_t _ns_global_scope_alloc;
  267. /* Search table for unique objects. */
  268. struct unique_sym_table
  269. {
  270. __rtld_lock_define_recursive (, lock)
  271. struct unique_sym
  272. {
  273. uint32_t hashval;
  274. const char *name;
  275. const ElfW(Sym) *sym;
  276. const struct link_map *map;
  277. } *entries;
  278. size_t size;
  279. size_t n_elements;
  280. void (*free) (void *);
  281. } _ns_unique_sym_table;
  282. /* Keep track of changes to each namespace' list. */
  283. struct r_debug _ns_debug;
  284. } _dl_ns[DL_NNS];
  285. /* One higher than index of last used namespace. */
  286. EXTERN size_t _dl_nns;
  287. /* During the program run we must not modify the global data of
  288. loaded shared object simultanously in two threads. Therefore we
  289. protect `_dl_open' and `_dl_close' in dl-close.c.
  290. This must be a recursive lock since the initializer function of
  291. the loaded object might as well require a call to this function.
  292. At this time it is not anymore a problem to modify the tables. */
  293. __rtld_lock_define_recursive (EXTERN, _dl_load_lock)
  294. /* This lock is used to keep __dl_iterate_phdr from inspecting the
  295. list of loaded objects while an object is added to or removed
  296. from that list. */
  297. __rtld_lock_define_recursive (EXTERN, _dl_load_write_lock)
  298. /* Incremented whenever something may have been added to dl_loaded. */
  299. EXTERN unsigned long long _dl_load_adds;
  300. /* The object to be initialized first. */
  301. EXTERN struct link_map *_dl_initfirst;
  302. #if HP_SMALL_TIMING_AVAIL
  303. /* Start time on CPU clock. */
  304. EXTERN hp_timing_t _dl_cpuclock_offset;
  305. #endif
  306. /* Map of shared object to be profiled. */
  307. EXTERN struct link_map *_dl_profile_map;
  308. /* Counters for the number of relocations performed. */
  309. EXTERN unsigned long int _dl_num_relocations;
  310. EXTERN unsigned long int _dl_num_cache_relocations;
  311. /* List of search directories. */
  312. EXTERN struct r_search_path_elem *_dl_all_dirs;
  313. /* Structure describing the dynamic linker itself. We need to
  314. reserve memory for the data the audit libraries need. */
  315. EXTERN struct link_map _dl_rtld_map;
  316. #ifdef SHARED
  317. struct auditstate audit_data[DL_NNS];
  318. #endif
  319. #if defined SHARED && defined _LIBC_REENTRANT \
  320. && defined __rtld_lock_default_lock_recursive
  321. EXTERN void (*_dl_rtld_lock_recursive) (void *);
  322. EXTERN void (*_dl_rtld_unlock_recursive) (void *);
  323. #endif
  324. /* Get architecture specific definitions. */
  325. #define PROCINFO_DECL
  326. #ifndef PROCINFO_CLASS
  327. # define PROCINFO_CLASS EXTERN
  328. #endif
  329. #include <dl-procruntime.c>
  330. /* If loading a shared object requires that we make the stack executable
  331. when it was not, we do it by calling this function.
  332. It returns an errno code or zero on success. */
  333. EXTERN int (*_dl_make_stack_executable_hook) (void **);
  334. /* Prevailing state of the stack, PF_X indicating it's executable. */
  335. EXTERN ElfW(Word) _dl_stack_flags;
  336. /* Flag signalling whether there are gaps in the module ID allocation. */
  337. EXTERN bool _dl_tls_dtv_gaps;
  338. /* Highest dtv index currently needed. */
  339. EXTERN size_t _dl_tls_max_dtv_idx;
  340. /* Information about the dtv slots. */
  341. EXTERN struct dtv_slotinfo_list
  342. {
  343. size_t len;
  344. struct dtv_slotinfo_list *next;
  345. struct dtv_slotinfo
  346. {
  347. size_t gen;
  348. struct link_map *map;
  349. } slotinfo[0];
  350. } *_dl_tls_dtv_slotinfo_list;
  351. /* Number of modules in the static TLS block. */
  352. EXTERN size_t _dl_tls_static_nelem;
  353. /* Size of the static TLS block. */
  354. EXTERN size_t _dl_tls_static_size;
  355. /* Size actually allocated in the static TLS block. */
  356. EXTERN size_t _dl_tls_static_used;
  357. /* Alignment requirement of the static TLS block. */
  358. EXTERN size_t _dl_tls_static_align;
  359. /* Number of additional entries in the slotinfo array of each slotinfo
  360. list element. A large number makes it almost certain take we never
  361. have to iterate beyond the first element in the slotinfo list. */
  362. #define TLS_SLOTINFO_SURPLUS (62)
  363. /* Number of additional slots in the dtv allocated. */
  364. #define DTV_SURPLUS (14)
  365. /* Initial dtv of the main thread, not allocated with normal malloc. */
  366. EXTERN void *_dl_initial_dtv;
  367. /* Generation counter for the dtv. */
  368. EXTERN size_t _dl_tls_generation;
  369. EXTERN void (*_dl_init_static_tls) (struct link_map *);
  370. EXTERN void (*_dl_wait_lookup_done) (void);
  371. /* Scopes to free after next THREAD_GSCOPE_WAIT (). */
  372. EXTERN struct dl_scope_free_list
  373. {
  374. size_t count;
  375. void *list[50];
  376. } *_dl_scope_free_list;
  377. #if !THREAD_GSCOPE_IN_TCB
  378. EXTERN int _dl_thread_gscope_count;
  379. #endif
  380. #ifdef SHARED
  381. };
  382. # define __rtld_global_attribute__
  383. # if IS_IN (rtld)
  384. # ifdef HAVE_SDATA_SECTION
  385. # define __rtld_local_attribute__ \
  386. __attribute__ ((visibility ("hidden"), section (".sdata")))
  387. # undef __rtld_global_attribute__
  388. # define __rtld_global_attribute__ __attribute__ ((section (".sdata")))
  389. # else
  390. # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
  391. # endif
  392. extern struct rtld_global _rtld_local __rtld_local_attribute__;
  393. # undef __rtld_local_attribute__
  394. # endif
  395. extern struct rtld_global _rtld_global __rtld_global_attribute__;
  396. # undef __rtld_global_attribute__
  397. #endif
  398. #ifndef SHARED
  399. # define GLRO(name) _##name
  400. #else
  401. # if IS_IN (rtld)
  402. # define GLRO(name) _rtld_local_ro._##name
  403. # else
  404. # define GLRO(name) _rtld_global_ro._##name
  405. # endif
  406. struct rtld_global_ro
  407. {
  408. #endif
  409. /* If nonzero the appropriate debug information is printed. */
  410. EXTERN int _dl_debug_mask;
  411. #define DL_DEBUG_LIBS (1 << 0)
  412. #define DL_DEBUG_IMPCALLS (1 << 1)
  413. #define DL_DEBUG_BINDINGS (1 << 2)
  414. #define DL_DEBUG_SYMBOLS (1 << 3)
  415. #define DL_DEBUG_VERSIONS (1 << 4)
  416. #define DL_DEBUG_RELOC (1 << 5)
  417. #define DL_DEBUG_FILES (1 << 6)
  418. #define DL_DEBUG_STATISTICS (1 << 7)
  419. #define DL_DEBUG_UNUSED (1 << 8)
  420. #define DL_DEBUG_SCOPES (1 << 9)
  421. /* These two are used only internally. */
  422. #define DL_DEBUG_HELP (1 << 10)
  423. #define DL_DEBUG_PRELINK (1 << 11)
  424. /* OS version. */
  425. EXTERN unsigned int _dl_osversion;
  426. /* Platform name. */
  427. EXTERN const char *_dl_platform;
  428. EXTERN size_t _dl_platformlen;
  429. /* Cached value of `getpagesize ()'. */
  430. EXTERN size_t _dl_pagesize;
  431. /* Do we read from ld.so.cache? */
  432. EXTERN int _dl_inhibit_cache;
  433. /* Copy of the content of `_dl_main_searchlist' at startup time. */
  434. EXTERN struct r_scope_elem _dl_initial_searchlist;
  435. /* CLK_TCK as reported by the kernel. */
  436. EXTERN int _dl_clktck;
  437. /* If nonzero print warnings messages. */
  438. EXTERN int _dl_verbose;
  439. /* File descriptor to write debug messages to. */
  440. EXTERN int _dl_debug_fd;
  441. /* Do we do lazy relocations? */
  442. EXTERN int _dl_lazy;
  443. /* Nonzero if runtime lookups should not update the .got/.plt. */
  444. EXTERN int _dl_bind_not;
  445. /* Nonzero if references should be treated as weak during runtime
  446. linking. */
  447. EXTERN int _dl_dynamic_weak;
  448. /* Default floating-point control word. */
  449. EXTERN fpu_control_t _dl_fpu_control;
  450. /* Expected cache ID. */
  451. EXTERN int _dl_correct_cache_id;
  452. /* Mask for hardware capabilities that are available. */
  453. EXTERN uint64_t _dl_hwcap;
  454. #if !HAVE_TUNABLES
  455. /* Mask for important hardware capabilities we honour. */
  456. EXTERN uint64_t _dl_hwcap_mask;
  457. #endif
  458. #ifdef HAVE_AUX_VECTOR
  459. /* Pointer to the auxv list supplied to the program at startup. */
  460. EXTERN ElfW(auxv_t) *_dl_auxv;
  461. #endif
  462. /* Get architecture specific definitions. */
  463. #include <dl-procinfo.c>
  464. /* Names of shared object for which the RPATH should be ignored. */
  465. EXTERN const char *_dl_inhibit_rpath;
  466. /* Location of the binary. */
  467. EXTERN const char *_dl_origin_path;
  468. /* -1 if the dynamic linker should honor library load bias,
  469. 0 if not, -2 use the default (honor biases for normal
  470. binaries, don't honor for PIEs). */
  471. EXTERN ElfW(Addr) _dl_use_load_bias;
  472. /* Name of the shared object to be profiled (if any). */
  473. EXTERN const char *_dl_profile;
  474. /* Filename of the output file. */
  475. EXTERN const char *_dl_profile_output;
  476. /* Name of the object we want to trace the prelinking. */
  477. EXTERN const char *_dl_trace_prelink;
  478. /* Map of shared object to be prelink traced. */
  479. EXTERN struct link_map *_dl_trace_prelink_map;
  480. /* All search directories defined at startup. This is assigned a
  481. non-NULL pointer by the ld.so startup code (after initialization
  482. to NULL), so this can also serve as an indicator whether a copy
  483. of ld.so is initialized and active. See the rtld_active function
  484. below. */
  485. EXTERN struct r_search_path_elem *_dl_init_all_dirs;
  486. #ifdef NEED_DL_SYSINFO
  487. /* Syscall handling improvements. This is very specific to x86. */
  488. EXTERN uintptr_t _dl_sysinfo;
  489. #endif
  490. #ifdef NEED_DL_SYSINFO_DSO
  491. /* The vsyscall page is a virtual DSO pre-mapped by the kernel.
  492. This points to its ELF header. */
  493. EXTERN const ElfW(Ehdr) *_dl_sysinfo_dso;
  494. /* At startup time we set up the normal DSO data structure for it,
  495. and this points to it. */
  496. EXTERN struct link_map *_dl_sysinfo_map;
  497. #endif
  498. /* Mask for more hardware capabilities that are available on some
  499. platforms. */
  500. EXTERN uint64_t _dl_hwcap2;
  501. #ifdef SHARED
  502. /* We add a function table to _rtld_global which is then used to
  503. call the function instead of going through the PLT. The result
  504. is that we can avoid exporting the functions and we do not jump
  505. PLT relocations in libc.so. */
  506. void (*_dl_debug_printf) (const char *, ...)
  507. __attribute__ ((__format__ (__printf__, 1, 2)));
  508. void (*_dl_mcount) (ElfW(Addr) frompc, ElfW(Addr) selfpc);
  509. lookup_t (*_dl_lookup_symbol_x) (const char *, struct link_map *,
  510. const ElfW(Sym) **, struct r_scope_elem *[],
  511. const struct r_found_version *, int, int,
  512. struct link_map *);
  513. void *(*_dl_open) (const char *file, int mode, const void *caller_dlopen,
  514. Lmid_t nsid, int argc, char *argv[], char *env[]);
  515. void (*_dl_close) (void *map);
  516. void *(*_dl_tls_get_addr_soft) (struct link_map *);
  517. #ifdef HAVE_DL_DISCOVER_OSVERSION
  518. int (*_dl_discover_osversion) (void);
  519. #endif
  520. /* List of auditing interfaces. */
  521. struct audit_ifaces *_dl_audit;
  522. unsigned int _dl_naudit;
  523. };
  524. # define __rtld_global_attribute__
  525. # if IS_IN (rtld)
  526. # define __rtld_local_attribute__ __attribute__ ((visibility ("hidden")))
  527. extern struct rtld_global_ro _rtld_local_ro
  528. attribute_relro __rtld_local_attribute__;
  529. extern struct rtld_global_ro _rtld_global_ro
  530. attribute_relro __rtld_global_attribute__;
  531. # undef __rtld_local_attribute__
  532. # else
  533. /* We cheat a bit here. We declare the variable as as const even
  534. though it is at startup. */
  535. extern const struct rtld_global_ro _rtld_global_ro
  536. attribute_relro __rtld_global_attribute__;
  537. # endif
  538. # undef __rtld_global_attribute__
  539. #endif
  540. #undef EXTERN
  541. #ifndef SHARED
  542. /* dl-support.c defines these and initializes them early on. */
  543. extern const ElfW(Phdr) *_dl_phdr;
  544. extern size_t _dl_phnum;
  545. #endif
  546. /* This is the initial value of GL(dl_make_stack_executable_hook).
  547. A threads library can change it. */
  548. extern int _dl_make_stack_executable (void **stack_endp);
  549. rtld_hidden_proto (_dl_make_stack_executable)
  550. /* Variable pointing to the end of the stack (or close to it). This value
  551. must be constant over the runtime of the application. Some programs
  552. might use the variable which results in copy relocations on some
  553. platforms. But this does not matter, ld.so can always use the local
  554. copy. */
  555. extern void *__libc_stack_end
  556. #ifndef LIBC_STACK_END_NOT_RELRO
  557. attribute_relro
  558. #endif
  559. ;
  560. rtld_hidden_proto (__libc_stack_end)
  561. /* Parameters passed to the dynamic linker. */
  562. extern int _dl_argc attribute_hidden attribute_relro;
  563. extern char **_dl_argv
  564. #ifndef DL_ARGV_NOT_RELRO
  565. attribute_relro
  566. #endif
  567. ;
  568. rtld_hidden_proto (_dl_argv)
  569. #if IS_IN (rtld)
  570. extern unsigned int _dl_skip_args attribute_hidden
  571. # ifndef DL_ARGV_NOT_RELRO
  572. attribute_relro
  573. # endif
  574. ;
  575. extern unsigned int _dl_skip_args_internal attribute_hidden
  576. # ifndef DL_ARGV_NOT_RELRO
  577. attribute_relro
  578. # endif
  579. ;
  580. #endif
  581. #define rtld_progname _dl_argv[0]
  582. /* Flag set at startup and cleared when the last initializer has run. */
  583. extern int _dl_starting_up;
  584. weak_extern (_dl_starting_up)
  585. rtld_hidden_proto (_dl_starting_up)
  586. /* Random data provided by the kernel. */
  587. extern void *_dl_random attribute_hidden attribute_relro;
  588. /* OS-dependent function to open the zero-fill device. */
  589. extern int _dl_sysdep_open_zero_fill (void); /* dl-sysdep.c */
  590. /* Write message on the debug file descriptor. The parameters are
  591. interpreted as for a `printf' call. All the lines start with a
  592. tag showing the PID. */
  593. extern void _dl_debug_printf (const char *fmt, ...)
  594. __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
  595. /* Write message on the debug file descriptor. The parameters are
  596. interpreted as for a `printf' call. All the lines buf the first
  597. start with a tag showing the PID. */
  598. extern void _dl_debug_printf_c (const char *fmt, ...)
  599. __attribute__ ((__format__ (__printf__, 1, 2))) attribute_hidden;
  600. /* Write a message on the specified descriptor FD. The parameters are
  601. interpreted as for a `printf' call. */
  602. #if IS_IN (rtld) || !defined (SHARED)
  603. extern void _dl_dprintf (int fd, const char *fmt, ...)
  604. __attribute__ ((__format__ (__printf__, 2, 3)))
  605. attribute_hidden;
  606. #else
  607. __attribute__ ((always_inline, __format__ (__printf__, 2, 3)))
  608. static inline void
  609. _dl_dprintf (int fd, const char *fmt, ...)
  610. {
  611. /* Use local declaration to avoid includign <stdio.h>. */
  612. extern int __dprintf(int fd, const char *format, ...) attribute_hidden;
  613. __dprintf (fd, fmt, __builtin_va_arg_pack ());
  614. }
  615. #endif
  616. /* Write a message on the specified descriptor standard output. The
  617. parameters are interpreted as for a `printf' call. */
  618. #define _dl_printf(fmt, args...) \
  619. _dl_dprintf (STDOUT_FILENO, fmt, ##args)
  620. /* Write a message on the specified descriptor standard error. The
  621. parameters are interpreted as for a `printf' call. */
  622. #define _dl_error_printf(fmt, args...) \
  623. _dl_dprintf (STDERR_FILENO, fmt, ##args)
  624. /* Write a message on the specified descriptor standard error and exit
  625. the program. The parameters are interpreted as for a `printf' call. */
  626. #define _dl_fatal_printf(fmt, args...) \
  627. do \
  628. { \
  629. _dl_dprintf (STDERR_FILENO, fmt, ##args); \
  630. _exit (127); \
  631. } \
  632. while (1)
  633. /* An exception raised by the _dl_signal_error function family and
  634. caught by _dl_catch_error function family. Exceptions themselves
  635. are copied as part of the raise operation, but the strings are
  636. not. */
  637. struct dl_exception
  638. {
  639. const char *objname;
  640. const char *errstring;
  641. /* This buffer typically stores both objname and errstring
  642. above. */
  643. char *message_buffer;
  644. };
  645. /* Creates a new exception. This calls malloc; if allocation fails,
  646. dummy values are inserted. OBJECT is the name of the problematical
  647. shared object, or null if its a general problem. ERRSTRING is a
  648. string describing the specific problem. */
  649. void _dl_exception_create (struct dl_exception *, const char *object,
  650. const char *errstring)
  651. __attribute__ ((nonnull (1, 3)));
  652. rtld_hidden_proto (_dl_exception_create)
  653. /* Like _dl_exception_create, but create errstring from a format
  654. string FMT. Currently, only "%s" and "%%" are supported as format
  655. directives. */
  656. void _dl_exception_create_format (struct dl_exception *, const char *objname,
  657. const char *fmt, ...)
  658. __attribute__ ((nonnull (1, 3), format (printf, 3, 4)));
  659. rtld_hidden_proto (_dl_exception_create_format)
  660. /* Deallocate the exception, freeing allocated buffers (if
  661. possible). */
  662. void _dl_exception_free (struct dl_exception *)
  663. __attribute__ ((nonnull (1)));
  664. rtld_hidden_proto (_dl_exception_free)
  665. /* This function is called by all the internal dynamic linker
  666. functions when they encounter an error. ERRCODE is either an
  667. `errno' code or zero; it specifies the return value of
  668. _dl_catch_error. OCCASION is included in the error message if the
  669. process is terminated immediately. */
  670. void _dl_signal_exception (int errcode, struct dl_exception *,
  671. const char *occasion)
  672. __attribute__ ((__noreturn__));
  673. libc_hidden_proto (_dl_signal_exception)
  674. /* Like _dl_signal_exception, but creates the exception first. */
  675. extern void _dl_signal_error (int errcode, const char *object,
  676. const char *occasion, const char *errstring)
  677. __attribute__ ((__noreturn__));
  678. libc_hidden_proto (_dl_signal_error)
  679. /* Like _dl_signal_exception, but may return when called in the
  680. context of _dl_receive_error. This is only used during ld.so
  681. bootstrap. In static and profiled builds, this is equivalent to
  682. _dl_signal_exception. */
  683. #if IS_IN (rtld)
  684. extern void _dl_signal_cexception (int errcode, struct dl_exception *,
  685. const char *occasion) attribute_hidden;
  686. #else
  687. __attribute__ ((always_inline))
  688. static inline void
  689. _dl_signal_cexception (int errcode, struct dl_exception *exception,
  690. const char *occasion)
  691. {
  692. _dl_signal_exception (errcode, exception, occasion);
  693. }
  694. #endif
  695. /* See _dl_signal_cexception above. */
  696. #if IS_IN (rtld)
  697. extern void _dl_signal_cerror (int errcode, const char *object,
  698. const char *occasion, const char *errstring)
  699. attribute_hidden;
  700. #else
  701. __attribute__ ((always_inline))
  702. static inline void
  703. _dl_signal_cerror (int errcode, const char *object,
  704. const char *occasion, const char *errstring)
  705. {
  706. _dl_signal_error (errcode, object, occasion, errstring);
  707. }
  708. #endif
  709. /* Call OPERATE, receiving errors from `dl_signal_cerror'. Unlike
  710. `_dl_catch_error' the operation is resumed after the OPERATE
  711. function returns.
  712. ARGS is passed as argument to OPERATE. */
  713. extern void _dl_receive_error (receiver_fct fct, void (*operate) (void *),
  714. void *args) attribute_hidden;
  715. /* Call OPERATE, catching errors from `_dl_signal_error' and related
  716. functions. If there is no error, *ERRSTRING is set to null. If
  717. there is an error, *ERRSTRING is set to a string constructed from
  718. the strings passed to _dl_signal_error, and the error code passed
  719. is the return value and *OBJNAME is set to the object name which
  720. experienced the problems. ERRSTRING if nonzero points to a
  721. malloc'ed string which the caller has to free after use. ARGS is
  722. passed as argument to OPERATE. MALLOCEDP is set to true only if
  723. the returned string is allocated using the libc's malloc. */
  724. extern int _dl_catch_error (const char **objname, const char **errstring,
  725. bool *mallocedp, void (*operate) (void *),
  726. void *args);
  727. libc_hidden_proto (_dl_catch_error)
  728. /* Call OPERATE (ARGS). If no error occurs, set *EXCEPTION to zero.
  729. Otherwise, store a copy of the raised exception in *EXCEPTION,
  730. which has to be freed by _dl_exception_free. */
  731. int _dl_catch_exception (struct dl_exception *exception,
  732. void (*operate) (void *), void *args);
  733. libc_hidden_proto (_dl_catch_exception)
  734. /* Open the shared object NAME and map in its segments.
  735. LOADER's DT_RPATH is used in searching for NAME.
  736. If the object is already opened, returns its existing map. */
  737. extern struct link_map *_dl_map_object (struct link_map *loader,
  738. const char *name,
  739. int type, int trace_mode, int mode,
  740. Lmid_t nsid) attribute_hidden;
  741. /* Call _dl_map_object on the dependencies of MAP, and set up
  742. MAP->l_searchlist. PRELOADS points to a vector of NPRELOADS previously
  743. loaded objects that will be inserted into MAP->l_searchlist after MAP
  744. but before its dependencies. */
  745. extern void _dl_map_object_deps (struct link_map *map,
  746. struct link_map **preloads,
  747. unsigned int npreloads, int trace_mode,
  748. int open_mode)
  749. attribute_hidden;
  750. /* Cache the locations of MAP's hash table. */
  751. extern void _dl_setup_hash (struct link_map *map) attribute_hidden;
  752. /* Collect the directories in the search path for LOADER's dependencies.
  753. The data structure is defined in <dlfcn.h>. If COUNTING is true,
  754. SI->dls_cnt and SI->dls_size are set; if false, those must be as set
  755. by a previous call with COUNTING set, and SI must point to SI->dls_size
  756. bytes to be used in filling in the result. */
  757. extern void _dl_rtld_di_serinfo (struct link_map *loader,
  758. Dl_serinfo *si, bool counting);
  759. /* Search loaded objects' symbol tables for a definition of the symbol
  760. referred to by UNDEF. *SYM is the symbol table entry containing the
  761. reference; it is replaced with the defining symbol, and the base load
  762. address of the defining object is returned. SYMBOL_SCOPE is a
  763. null-terminated list of object scopes to search; each object's
  764. l_searchlist (i.e. the segment of the dependency tree starting at that
  765. object) is searched in turn. REFERENCE_NAME should name the object
  766. containing the reference; it is used in error messages.
  767. TYPE_CLASS describes the type of symbol we are looking for. */
  768. enum
  769. {
  770. /* If necessary add dependency between user and provider object. */
  771. DL_LOOKUP_ADD_DEPENDENCY = 1,
  772. /* Return most recent version instead of default version for
  773. unversioned lookup. */
  774. DL_LOOKUP_RETURN_NEWEST = 2,
  775. /* Set if dl_lookup* called with GSCOPE lock held. */
  776. DL_LOOKUP_GSCOPE_LOCK = 4,
  777. };
  778. /* Lookup versioned symbol. */
  779. extern lookup_t _dl_lookup_symbol_x (const char *undef,
  780. struct link_map *undef_map,
  781. const ElfW(Sym) **sym,
  782. struct r_scope_elem *symbol_scope[],
  783. const struct r_found_version *version,
  784. int type_class, int flags,
  785. struct link_map *skip_map)
  786. attribute_hidden;
  787. /* Add the new link_map NEW to the end of the namespace list. */
  788. extern void _dl_add_to_namespace_list (struct link_map *new, Lmid_t nsid)
  789. attribute_hidden;
  790. /* Allocate a `struct link_map' for a new object being loaded. */
  791. extern struct link_map *_dl_new_object (char *realname, const char *libname,
  792. int type, struct link_map *loader,
  793. int mode, Lmid_t nsid)
  794. attribute_hidden;
  795. /* Relocate the given object (if it hasn't already been).
  796. SCOPE is passed to _dl_lookup_symbol in symbol lookups.
  797. If RTLD_LAZY is set in RELOC-MODE, don't relocate its PLT. */
  798. extern void _dl_relocate_object (struct link_map *map,
  799. struct r_scope_elem *scope[],
  800. int reloc_mode, int consider_profiling)
  801. attribute_hidden;
  802. /* Protect PT_GNU_RELRO area. */
  803. extern void _dl_protect_relro (struct link_map *map) attribute_hidden;
  804. /* Call _dl_signal_error with a message about an unhandled reloc type.
  805. TYPE is the result of ELFW(R_TYPE) (r_info), i.e. an R_<CPU>_* value.
  806. PLT is nonzero if this was a PLT reloc; it just affects the message. */
  807. extern void _dl_reloc_bad_type (struct link_map *map,
  808. unsigned int type, int plt)
  809. attribute_hidden __attribute__ ((__noreturn__));
  810. /* Resolve conflicts if prelinking. */
  811. extern void _dl_resolve_conflicts (struct link_map *l,
  812. ElfW(Rela) *conflict,
  813. ElfW(Rela) *conflictend)
  814. attribute_hidden;
  815. /* Check the version dependencies of all objects available through
  816. MAP. If VERBOSE print some more diagnostics. */
  817. extern int _dl_check_all_versions (struct link_map *map, int verbose,
  818. int trace_mode) attribute_hidden;
  819. /* Check the version dependencies for MAP. If VERBOSE print some more
  820. diagnostics. */
  821. extern int _dl_check_map_versions (struct link_map *map, int verbose,
  822. int trace_mode) attribute_hidden;
  823. /* Initialize the object in SCOPE by calling the constructors with
  824. ARGC, ARGV, and ENV as the parameters. */
  825. extern void _dl_init (struct link_map *main_map, int argc, char **argv,
  826. char **env) attribute_hidden;
  827. /* Call the finalizer functions of all shared objects whose
  828. initializer functions have completed. */
  829. extern void _dl_fini (void) attribute_hidden;
  830. /* Sort array MAPS according to dependencies of the contained objects. */
  831. extern void _dl_sort_maps (struct link_map **maps, unsigned int nmaps,
  832. char *used, bool for_fini) attribute_hidden;
  833. /* The dynamic linker calls this function before and having changing
  834. any shared object mappings. The `r_state' member of `struct r_debug'
  835. says what change is taking place. This function's address is
  836. the value of the `r_brk' member. */
  837. extern void _dl_debug_state (void);
  838. rtld_hidden_proto (_dl_debug_state)
  839. /* Initialize `struct r_debug' if it has not already been done. The
  840. argument is the run-time load address of the dynamic linker, to be put
  841. in the `r_ldbase' member. Returns the address of the structure. */
  842. extern struct r_debug *_dl_debug_initialize (ElfW(Addr) ldbase, Lmid_t ns)
  843. attribute_hidden;
  844. /* Initialize the basic data structure for the search paths. */
  845. extern void _dl_init_paths (const char *library_path) attribute_hidden;
  846. /* Gather the information needed to install the profiling tables and start
  847. the timers. */
  848. extern void _dl_start_profile (void) attribute_hidden;
  849. /* The actual functions used to keep book on the calls. */
  850. extern void _dl_mcount (ElfW(Addr) frompc, ElfW(Addr) selfpc);
  851. rtld_hidden_proto (_dl_mcount)
  852. /* This function is simply a wrapper around the _dl_mcount function
  853. which does not require a FROMPC parameter since this is the
  854. calling function. */
  855. extern void _dl_mcount_wrapper (void *selfpc);
  856. /* Show the members of the auxiliary array passed up from the kernel. */
  857. extern void _dl_show_auxv (void) attribute_hidden;
  858. /* Return all environment variables starting with `LD_', one after the
  859. other. */
  860. extern char *_dl_next_ld_env_entry (char ***position) attribute_hidden;
  861. /* Return an array with the names of the important hardware capabilities. */
  862. extern const struct r_strlenpair *_dl_important_hwcaps (const char *platform,
  863. size_t paltform_len,
  864. size_t *sz,
  865. size_t *max_capstrlen)
  866. attribute_hidden;
  867. /* Look up NAME in ld.so.cache and return the file name stored there,
  868. or null if none is found. Caller must free returned string. */
  869. extern char *_dl_load_cache_lookup (const char *name) attribute_hidden;
  870. /* If the system does not support MAP_COPY we cannot leave the file open
  871. all the time since this would create problems when the file is replaced.
  872. Therefore we provide this function to close the file and open it again
  873. once needed. */
  874. extern void _dl_unload_cache (void) attribute_hidden;
  875. /* System-dependent function to read a file's whole contents in the
  876. most convenient manner available. *SIZEP gets the size of the
  877. file. On error MAP_FAILED is returned. */
  878. extern void *_dl_sysdep_read_whole_file (const char *file, size_t *sizep,
  879. int prot) attribute_hidden;
  880. /* System-specific function to do initial startup for the dynamic linker.
  881. After this, file access calls and getenv must work. This is responsible
  882. for setting __libc_enable_secure if we need to be secure (e.g. setuid),
  883. and for setting _dl_argc and _dl_argv, and then calling _dl_main. */
  884. extern ElfW(Addr) _dl_sysdep_start (void **start_argptr,
  885. void (*dl_main) (const ElfW(Phdr) *phdr,
  886. ElfW(Word) phnum,
  887. ElfW(Addr) *user_entry,
  888. ElfW(auxv_t) *auxv))
  889. attribute_hidden;
  890. extern void _dl_sysdep_start_cleanup (void) attribute_hidden;
  891. /* Determine next available module ID. */
  892. extern size_t _dl_next_tls_modid (void) attribute_hidden;
  893. /* Count the modules with TLS segments. */
  894. extern size_t _dl_count_modids (void) attribute_hidden;
  895. /* Calculate offset of the TLS blocks in the static TLS block. */
  896. extern void _dl_determine_tlsoffset (void) attribute_hidden;
  897. #ifndef SHARED
  898. /* Set up the TCB for statically linked applications. This is called
  899. early during startup because we always use TLS (for errno and the
  900. stack protector, among other things). */
  901. void __libc_setup_tls (void);
  902. # if ENABLE_STATIC_PIE
  903. /* Relocate static executable with PIE. */
  904. extern void _dl_relocate_static_pie (void) attribute_hidden;
  905. /* Get a pointer to _dl_main_map. */
  906. extern struct link_map * _dl_get_dl_main_map (void)
  907. __attribute__ ((visibility ("hidden")));
  908. # else
  909. # define _dl_relocate_static_pie()
  910. # endif
  911. #endif
  912. /* Initialization of libpthread for statically linked applications.
  913. If libpthread is not linked in, this is an empty function. */
  914. void __pthread_initialize_minimal (void) weak_function;
  915. /* Allocate memory for static TLS block (unless MEM is nonzero) and dtv. */
  916. extern void *_dl_allocate_tls (void *mem);
  917. rtld_hidden_proto (_dl_allocate_tls)
  918. /* Get size and alignment requirements of the static TLS block. */
  919. extern void _dl_get_tls_static_info (size_t *sizep, size_t *alignp);
  920. extern void _dl_allocate_static_tls (struct link_map *map) attribute_hidden;
  921. /* These are internal entry points to the two halves of _dl_allocate_tls,
  922. only used within rtld.c itself at startup time. */
  923. extern void *_dl_allocate_tls_storage (void) attribute_hidden;
  924. extern void *_dl_allocate_tls_init (void *);
  925. rtld_hidden_proto (_dl_allocate_tls_init)
  926. /* Deallocate memory allocated with _dl_allocate_tls. */
  927. extern void _dl_deallocate_tls (void *tcb, bool dealloc_tcb);
  928. rtld_hidden_proto (_dl_deallocate_tls)
  929. extern void _dl_nothread_init_static_tls (struct link_map *) attribute_hidden;
  930. /* Find origin of the executable. */
  931. extern const char *_dl_get_origin (void) attribute_hidden;
  932. /* Count DSTs. */
  933. extern size_t _dl_dst_count (const char *name) attribute_hidden;
  934. /* Substitute DST values. */
  935. extern char *_dl_dst_substitute (struct link_map *l, const char *name,
  936. char *result) attribute_hidden;
  937. /* Open the shared object NAME, relocate it, and run its initializer if it
  938. hasn't already been run. MODE is as for `dlopen' (see <dlfcn.h>). If
  939. the object is already opened, returns its existing map. */
  940. extern void *_dl_open (const char *name, int mode, const void *caller,
  941. Lmid_t nsid, int argc, char *argv[], char *env[])
  942. attribute_hidden;
  943. /* Free or queue for freeing scope OLD. If other threads might be
  944. in the middle of _dl_fixup, _dl_profile_fixup or dl*sym using the
  945. old scope, OLD can't be freed until no thread is using it. */
  946. extern int _dl_scope_free (void *) attribute_hidden;
  947. /* Add module to slot information data. */
  948. extern void _dl_add_to_slotinfo (struct link_map *l) attribute_hidden;
  949. /* Update slot information data for at least the generation of the
  950. module with the given index. */
  951. extern struct link_map *_dl_update_slotinfo (unsigned long int req_modid)
  952. attribute_hidden;
  953. /* Look up the module's TLS block as for __tls_get_addr,
  954. but never touch anything. Return null if it's not allocated yet. */
  955. extern void *_dl_tls_get_addr_soft (struct link_map *l) attribute_hidden;
  956. extern int _dl_addr_inside_object (struct link_map *l, const ElfW(Addr) addr)
  957. attribute_hidden;
  958. /* Show show of an object. */
  959. extern void _dl_show_scope (struct link_map *new, int from)
  960. attribute_hidden;
  961. extern struct link_map *_dl_find_dso_for_object (const ElfW(Addr) addr);
  962. rtld_hidden_proto (_dl_find_dso_for_object)
  963. /* Initialization which is normally done by the dynamic linker. */
  964. extern void _dl_non_dynamic_init (void)
  965. attribute_hidden;
  966. /* Used by static binaries to check the auxiliary vector. */
  967. extern void _dl_aux_init (ElfW(auxv_t) *av)
  968. attribute_hidden;
  969. /* Return true if the ld.so copy in this namespace is actually active
  970. and working. If false, the dl_open/dlfcn hooks have to be used to
  971. call into the outer dynamic linker (which happens after static
  972. dlopen). */
  973. #ifdef SHARED
  974. static inline bool
  975. rtld_active (void)
  976. {
  977. /* The default-initialized variable does not have a non-zero
  978. dl_init_all_dirs member, so this allows us to recognize an
  979. initialized and active ld.so copy. */
  980. return GLRO(dl_init_all_dirs) != NULL;
  981. }
  982. #endif
  983. __END_DECLS
  984. #endif /* ldsodefs.h */