From: Nicholas Nethercote Date: Sun, 19 Jun 2005 18:58:03 +0000 (+0000) Subject: Fix up the libc_freeres_wrapper code so that m_main depends on m_redir, X-Git-Tag: svn/VALGRIND_3_0_0~362 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=577e69aafdc51475aea4c24f192ab71cd1e77fb2;p=thirdparty%2Fvalgrind.git Fix up the libc_freeres_wrapper code so that m_main depends on m_redir, not the other way around. git-svn-id: svn://svn.valgrind.org/valgrind/trunk@3956 --- diff --git a/coregrind/m_main.c b/coregrind/m_main.c index bb43b62ff4..881e765f57 100644 --- a/coregrind/m_main.c +++ b/coregrind/m_main.c @@ -2759,26 +2759,19 @@ int main(int argc, char **argv, char **envp) } -/* The we need to know the address of it so it can be - called at program exit. */ -static Addr __libc_freeres_wrapper; - -void VG_(set_libc_freeres_wrapper_addr)(Addr addr) -{ - __libc_freeres_wrapper = addr; -} - /* Final clean-up before terminating the process. Clean up the client by calling __libc_freeres() (if requested) This is Linux-specific? */ static void final_tidyup(ThreadId tid) { + Addr __libc_freeres_wrapper; + vg_assert(VG_(is_running_thread)(tid)); - if (!VG_(needs).libc_freeres || - !VG_(clo_run_libc_freeres) || - __libc_freeres_wrapper == 0) + if ( !VG_(needs).libc_freeres || + !VG_(clo_run_libc_freeres) || + 0 == (__libc_freeres_wrapper = VG_(get_libc_freeres_wrapper)()) ) return; /* can't/won't do it */ if (VG_(clo_verbosity) > 2 || diff --git a/coregrind/m_redir.c b/coregrind/m_redir.c index b78350bed4..e7c7230470 100644 --- a/coregrind/m_redir.c +++ b/coregrind/m_redir.c @@ -36,7 +36,6 @@ #include "pub_core_libcbase.h" #include "pub_core_libcassert.h" #include "pub_core_libcprint.h" -#include "pub_core_main.h" // for VG_(set_libc_freeres_wrapper_addr) #include "pub_core_mallocfree.h" #include "pub_core_options.h" #include "pub_core_redir.h" @@ -512,6 +511,13 @@ static void handle_replacement_function( Char* symbol, Addr addr ) VG_(arena_free)(VG_AR_SYMTAB, lib); } +static Addr __libc_freeres_wrapper = 0; + +Addr VG_(get_libc_freeres_wrapper)(void) +{ + return __libc_freeres_wrapper; +} + // This is specifically for stringifying VG_(x) function names. We // need to do two macroexpansions to get the VG_ macro expanded before // stringifying. @@ -521,7 +527,7 @@ static void handle_replacement_function( Char* symbol, Addr addr ) static void handle_load_notifier( Char* symbol, Addr addr ) { if (VG_(strcmp)(symbol, STR(VG_NOTIFY_ON_LOAD(freeres))) == 0) - VG_(set_libc_freeres_wrapper_addr)(addr); + __libc_freeres_wrapper = addr; // else if (VG_(strcmp)(symbol, STR(VG_WRAPPER(pthread_startfunc_wrapper))) == 0) // VG_(pthread_startfunc_wrapper)((Addr)(si->offset + sym->st_value)); else diff --git a/coregrind/pub_core_main.h b/coregrind/pub_core_main.h index 0e1f59b424..c47e1f263a 100644 --- a/coregrind/pub_core_main.h +++ b/coregrind/pub_core_main.h @@ -48,9 +48,6 @@ Char* VG_(build_child_exename) ( void ); /* Something of a function looking for a home ... start up debugger. */ extern void VG_(start_debugger) ( ThreadId tid ); -// Set up the libc freeres wrapper -extern void VG_(set_libc_freeres_wrapper_addr)(Addr); - // Do everything which needs doing before the process finally ends, // like printing reports, etc extern void VG_(shutdown_actions_NORETURN) ( diff --git a/coregrind/pub_core_redir.h b/coregrind/pub_core_redir.h index d734d45062..59743e1f3c 100644 --- a/coregrind/pub_core_redir.h +++ b/coregrind/pub_core_redir.h @@ -89,6 +89,8 @@ extern void VG_(resolve_seg_redirs)(SegInfo *si); #define VG_NOTIFY_ON_LOAD_PREFIX "_vgw_" #define VG_NOTIFY_ON_LOAD_PREFIX_LEN 5 +// Called by m_main to get our __libc_freeres wrapper. +extern Addr VG_(get_libc_freeres_wrapper)(void); //-------------------------------------------------------------------- // Function wrapping