Add rtld private interface for dso to detect dynamic loading

vs. static linking.

Tested by:	pho, antoine (exp-run)
Sponsored by:	The FreeBSD Foundation
MFC after:	1 week
This commit is contained in:
Konstantin Belousov 2015-01-03 18:09:53 +00:00
parent 04a8159ddf
commit 0e521992a4
6 changed files with 33 additions and 0 deletions

View File

@ -487,6 +487,7 @@ FBSDprivate_1.0 {
_rtld_atfork_post;
_rtld_error; /* for private use */
_rtld_get_stack_prot;
_rtld_is_dlopened;
_rtld_thread_init; /* for private use */
__elf_phdr_match_addr;
_err;

View File

@ -233,3 +233,10 @@ _rtld_get_stack_prot(void)
return (PROT_EXEC | PROT_READ | PROT_WRITE);
}
#pragma weak _rtld_is_dlopened
int
_rtld_is_dlopened(void *arg)
{
return (0);
}

View File

@ -30,5 +30,6 @@ FBSDprivate_1.0 {
_rtld_atfork_post;
_rtld_addr_phdr;
_rtld_get_stack_prot;
_rtld_is_dlopened;
_r_debug_postinit;
};

View File

@ -2222,6 +2222,7 @@ do_load_object(int fd, const char *name, char *path, struct stat *sbp,
return (NULL);
}
obj->dlopened = (flags & RTLD_LO_DLOPEN) != 0;
*obj_tail = obj;
obj_tail = &obj->next;
obj_count++;
@ -4884,6 +4885,27 @@ _rtld_get_stack_prot(void)
return (stack_prot);
}
int
_rtld_is_dlopened(void *arg)
{
Obj_Entry *obj;
RtldLockState lockstate;
int res;
rlock_acquire(rtld_bind_lock, &lockstate);
obj = dlcheck(arg);
if (obj == NULL)
obj = obj_from_addr(arg);
if (obj == NULL) {
_rtld_error("No shared object contains address");
lock_release(rtld_bind_lock, &lockstate);
return (-1);
}
res = obj->dlopened ? 1 : 0;
lock_release(rtld_bind_lock, &lockstate);
return (res);
}
static void
map_stacks_exec(RtldLockState *lockstate)
{

View File

@ -275,6 +275,7 @@ typedef struct Struct_Obj_Entry {
bool crt_no_init : 1; /* Object' crt does not call _init/_fini */
bool valid_hash_sysv : 1; /* A valid System V hash hash tag is available */
bool valid_hash_gnu : 1; /* A valid GNU hash tag is available */
bool dlopened : 1; /* dlopen()-ed (vs. load statically) */
struct link_map linkmap; /* For GDB and dlinfo() */
Objlist dldags; /* Object belongs to these dlopened DAGs (%) */

View File

@ -94,6 +94,7 @@ typedef int (*__dl_iterate_hdr_callback)(struct dl_phdr_info *, size_t, void *);
extern int dl_iterate_phdr(__dl_iterate_hdr_callback, void *);
int _rtld_addr_phdr(const void *, struct dl_phdr_info *);
int _rtld_get_stack_prot(void);
int _rtld_is_dlopened(void *);
#ifdef __ARM_EABI__
void * dl_unwind_find_exidx(const void *, int *);