2 #include <dlfcn/dlfcn.h>
4 #include <link.h> /* For ElfW. */
7 extern __typeof (_dl_find_object
) __dl_find_object
;
8 hidden_proto (__dl_find_object
)
10 /* Internally used flag. */
11 #define __RTLD_DLOPEN 0x80000000
12 #define __RTLD_SPROF 0x40000000
13 #define __RTLD_OPENEXEC 0x20000000
14 #define __RTLD_CALLMAP 0x10000000
15 #define __RTLD_AUDIT 0x08000000
16 #define __RTLD_SECURE 0x04000000 /* Apply additional security checks. */
17 #define __RTLD_NOIFUNC 0x02000000 /* Suppress calling ifunc functions. */
18 #define __RTLD_VDSO 0x01000000 /* Tell _dl_new_object the object is
21 #define __LM_ID_CALLER -2
23 /* These variables are defined and initialized in the startup code. */
24 extern int __libc_argc attribute_hidden
;
25 extern char **__libc_argv attribute_hidden
;
27 /* Now define the internal interfaces. */
29 /* Use RTLD_NOW here because:
30 1. In pthread_cancel_init we want to use RTLD_NOW to reduce the stack usage
31 of future cancellation operations, particularly when the target thread
32 is running with a small stack. Likewise for consistency we do the same
33 thing in __libgcc_s_init. RTLD_NOW will rarely make a difference for
34 __libgcc_s_init because unwinding is already in progress, so libgcc_s.so
35 has already been loaded if its unwinder is used (Bug 22636).
36 2. It allows us to provide robust fallback code at dlopen time for
37 incorrectly configured systems that mix old libnss_* modules
38 with newly installed libraries e.g. old libnss_dns.so.2 with new
39 libresolv.so.2. Using RTLD_LAZY here causes a failure at the
40 time the symbol is called and at that point it is much harder to
41 safely return an error (Bug 22766).
43 The use of RTLD_NOW also impacts gconv module loading, backtracing
44 (where the unwinder form libgcc_s.so is used), and IDNA functions
45 (which load libidn2), all of which load their respective DSOs on
46 demand, and so should not impact program startup. That is to say
47 that the DSOs are loaded as part of an API call and therefore we
48 will be calling that family of API functions shortly so RTLD_NOW or
49 RTLD_LAZY is not a big difference in performance, but RTLD_NOW has
50 better error handling semantics for the library. */
51 #define __libc_dlopen(name) \
52 __libc_dlopen_mode (name, RTLD_NOW | __RTLD_DLOPEN)
53 extern void *__libc_dlopen_mode (const char *__name
, int __mode
)
55 extern void *__libc_dlsym (void *__map
, const char *__name
)
57 extern void *__libc_dlvsym (void *map
, const char *name
, const char *version
)
59 extern int __libc_dlclose (void *__map
)
62 /* Locate shared object containing the given address. */
64 extern int _dl_addr (const void *address
, Dl_info
*info
,
65 struct link_map
**mapp
, const ElfW(Sym
) **symbolp
)
71 /* Close an object previously opened by _dl_open. */
72 extern void _dl_close (void *map
) attribute_hidden
;
73 /* Same as above, but without locking and safety checks for user
74 provided map arguments. */
75 extern void _dl_close_worker (struct link_map
*map
, bool force
)
78 /* Look up NAME in shared object HANDLE (which may be RTLD_DEFAULT or
79 RTLD_NEXT). WHO is the calling function, for RTLD_NEXT. Returns
80 the symbol value, which may be NULL. */
81 extern void *_dl_sym (void *handle
, const char *name
, void *who
)
84 /* Look up version VERSION of symbol NAME in shared object HANDLE
85 (which may be RTLD_DEFAULT or RTLD_NEXT). WHO is the calling
86 function, for RTLD_NEXT. Returns the symbol value, which may be
88 extern void *_dl_vsym (void *handle
, const char *name
, const char *version
,
89 void *who
) attribute_hidden
;
91 /* Helper function for <dlfcn.h> functions. Runs the OPERATE function via
92 _dl_catch_error. Returns zero for success, nonzero for failure; and
93 arranges for `dlerror' to return the error details.
94 ARGS is passed as argument to OPERATE. */
95 extern int _dlerror_run (void (*operate
) (void *), void *args
) attribute_hidden
;
97 /* This structure is used to make the outer (statically linked)
98 implementation of dlopen and related functions to the inner libc
99 after static dlopen, via the GLRO (dl_dlfcn_hook) pointer. */
102 /* Public interfaces. */
103 void *(*dlopen
) (const char *file
, int mode
, void *dl_caller
);
104 int (*dlclose
) (void *handle
);
105 void *(*dlsym
) (void *handle
, const char *name
, void *dl_caller
);
106 void *(*dlvsym
) (void *handle
, const char *name
, const char *version
,
108 char *(*dlerror
) (void);
109 int (*dladdr
) (const void *address
, Dl_info
*info
);
110 int (*dladdr1
) (const void *address
, Dl_info
*info
,
111 void **extra_info
, int flags
);
112 int (*dlinfo
) (void *handle
, int request
, void *arg
);
113 void *(*dlmopen
) (Lmid_t nsid
, const char *file
, int mode
, void *dl_caller
);
115 /* Internal interfaces. */
116 void* (*libc_dlopen_mode
) (const char *__name
, int __mode
);
117 void* (*libc_dlsym
) (void *map
, const char *name
);
118 void* (*libc_dlvsym
) (void *map
, const char *name
, const char *version
);
119 int (*libc_dlclose
) (void *map
);
122 /* Note: These prototypes are for initializing _dlfcn_hook in static
123 builds; see __rtld_static_init. Internal calls in glibc should use
124 the __libc_dl* functions defined in elf/dl-libc.c instead. */
126 extern void *__dlopen (const char *file
, int mode
, void *caller
);
127 extern void *__dlmopen (Lmid_t nsid
, const char *file
, int mode
,
129 extern int __dlclose (void *handle
);
130 extern void *__dlsym (void *handle
, const char *name
, void *dl_caller
);
131 extern void *__dlvsym (void *handle
, const char *name
, const char *version
,
133 extern int __dladdr (const void *address
, Dl_info
*info
);
134 extern int __dladdr1 (const void *address
, Dl_info
*info
,
135 void **extra_info
, int flags
);
136 extern int __dlinfo (void *handle
, int request
, void *arg
);
137 extern char *__dlerror (void);
141 # define DL_CALL_FCT(fctp, args) ((fctp) args)