From db89de647c8ef0760da4a13c83dea6305b748b53 Mon Sep 17 00:00:00 2001 From: markj Date: Thu, 7 Aug 2014 18:36:47 +0000 Subject: [PATCH] MFC r265456, r265578: Add a postinit debugger hook to rtld. This will be used by dtrace(1) to halt the victim process before its entry point is called, at which point probes and DOF data are registered with the kernel. The r_debug_state hook cannot be used for this purpose, as it is called before the program's init routines are invoked and in particular before DOF data is registered (via drti.o). git-svn-id: svn://svn.freebsd.org/base/stable/10@269680 ccf9f872-aa2e-dd11-9fc8-001c23d0bc1f --- libexec/rtld-elf/Symbol.map | 1 + libexec/rtld-elf/rtld.c | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/libexec/rtld-elf/Symbol.map b/libexec/rtld-elf/Symbol.map index 9ad625184..5ea7d7e17 100644 --- a/libexec/rtld-elf/Symbol.map +++ b/libexec/rtld-elf/Symbol.map @@ -30,4 +30,5 @@ FBSDprivate_1.0 { _rtld_atfork_post; _rtld_addr_phdr; _rtld_get_stack_prot; + _r_debug_postinit; }; diff --git a/libexec/rtld-elf/rtld.c b/libexec/rtld-elf/rtld.c index ad377450f..344a6d98a 100644 --- a/libexec/rtld-elf/rtld.c +++ b/libexec/rtld-elf/rtld.c @@ -161,6 +161,7 @@ static bool matched_symbol(SymLook *, const Obj_Entry *, Sym_Match_Result *, const unsigned long); void r_debug_state(struct r_debug *, struct link_map *) __noinline; +void _r_debug_postinit(struct link_map *) __noinline; /* * Data declarations. @@ -635,6 +636,7 @@ _rtld(Elf_Addr *sp, func_ptr_type *exit_proc, Obj_Entry **objp) if (obj_main->crt_no_init) preinit_main(); objlist_call_init(&initlist, &lockstate); + _r_debug_postinit(&obj_main->linkmap); objlist_clear(&initlist); dbg("loading filtees"); for (obj = obj_list->next; obj != NULL; obj = obj->next) { @@ -3497,7 +3499,20 @@ r_debug_state(struct r_debug* rd, struct link_map *m) * even when marked __noinline. However, gdb depends on those * calls being made. */ - __asm __volatile("" : : : "memory"); + __compiler_membar(); +} + +/* + * A function called after init routines have completed. This can be used to + * break before a program's entry routine is called, and can be used when + * main is not available in the symbol table. + */ +void +_r_debug_postinit(struct link_map *m) +{ + + /* See r_debug_state(). */ + __compiler_membar(); } /* -- 2.42.0