Bug 666501: fix jprof to work in builds without run-mozilla.sh r=glandium
authorRandell Jesup <rjesup@wgate.com>
Fri, 24 Jun 2011 00:01:49 -0400
changeset 71622 0d5c92e9760e3800e6c85d90dcb576efd90e474d
parent 71621 c980dcde975498d0529112b4a2854e31d5212f16
child 71623 63ce1a21bbd0ac0806ea36e76e322b25cb38c435
push idunknown
push userunknown
push dateunknown
reviewersglandium
bugs666501
milestone7.0a1
Bug 666501: fix jprof to work in builds without run-mozilla.sh r=glandium
browser/app/Makefile.in
tools/jprof/stub/libmalloc.cpp
xpcom/stub/Makefile.in
xulrunner/app/Makefile.in
--- a/browser/app/Makefile.in
+++ b/browser/app/Makefile.in
@@ -102,20 +102,16 @@ LOCAL_INCLUDES += -I$(topsrcdir)/xpcom/b
 DEFINES += -DXPCOM_GLUE
 STL_FLAGS=
 
 LIBS += \
 	$(EXTRA_DSO_LIBS) \
 	$(XPCOM_STANDALONE_GLUE_LDOPTS) \
 	$(NULL)
 
-ifdef MOZ_JPROF
-LIBS += -ljprof
-endif
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 
--- a/tools/jprof/stub/libmalloc.cpp
+++ b/tools/jprof/stub/libmalloc.cpp
@@ -87,16 +87,33 @@ extern r_debug _r_debug;
 static int gLogFD = -1;
 static pthread_t main_thread;
 
 static void startSignalCounter(unsigned long millisec);
 static int enableRTCSignals(bool enable);
 
 
 //----------------------------------------------------------------------
+// replace use of atexit()
+
+static void DumpAddressMap();
+
+struct JprofShutdown {
+    JprofShutdown() {}
+    ~JprofShutdown() {
+        DumpAddressMap();
+    }
+};
+
+static void RegisterJprofShutdown() {
+    // This instanciates the dummy class above, and will trigger the class
+    // destructor when libxul is unloaded. This is equivalent to atexit(),
+    // but gracefully handles dlclose().
+    static JprofShutdown t;
+}
 
 #if defined(i386) || defined(_i386) || defined(__x86_64__)
 JPROF_STATIC void CrawlStack(malloc_log_entry* me,
                              void* stack_top, void* top_instr_ptr)
 {
 #if USE_GLIBC_BACKTRACE
     // This probably works on more than x86!  But we need a way to get the
     // top instruction pointer, which is kindof arch-specific
@@ -453,17 +470,17 @@ NS_EXPORT_(void) setupProfilingStuff(voi
 		if(gLogFD<0) {
 		    fprintf(stderr, "Unable to create " M_LOGFILE);
 		    perror(":");
 		} else {
 		    struct sigaction action;
 		    sigset_t mset;
 
 		    // Dump out the address map when we terminate
-		    atexit(DumpAddressMap);
+		    RegisterJprofShutdown();
 
 		    main_thread = pthread_self();
                     //fprintf(stderr,"jprof: main_thread = %u\n",
                     //        (unsigned int)main_thread);
 
 		    sigemptyset(&mset);
 		    action.sa_handler = NULL;
 		    action.sa_sigaction = StackHook;
--- a/xpcom/stub/Makefile.in
+++ b/xpcom/stub/Makefile.in
@@ -96,16 +96,20 @@ DEPENDENT_LIBS_LIST += \
 	$(DLL_PREFIX)ssl3$(DLL_SUFFIX) \
 	$(DLL_PREFIX)smime3$(DLL_SUFFIX) \
 	$(NULL)
 
 ifdef JS_SHARED_LIBRARY
 DEPENDENT_LIBS_LIST += $(DLL_PREFIX)mozjs$(DLL_SUFFIX)
 endif
 
+ifdef MOZ_JPROF
+DEPENDENT_LIBS_LIST += $(DLL_PREFIX)jprof$(DLL_SUFFIX)
+endif
+
 ifeq (bundle,$(MOZ_FS_LAYOUT))
 EXTRA_DSO_LDOPTS += $(DIST)/bin/XUL
 DEPENDENT_LIBS_LIST += XUL
 else
 EXTRA_DSO_LIBS = xul
 DEPENDENT_LIBS_LIST += $(DLL_PREFIX)xul$(DLL_SUFFIX)
 endif
 
--- a/xulrunner/app/Makefile.in
+++ b/xulrunner/app/Makefile.in
@@ -81,20 +81,16 @@ endif
 
 LIBS += \
   $(EXTRA_DSO_LIBS) \
   $(DIST)/lib/$(LIB_PREFIX)xpcomglue_s.$(LIB_SUFFIX) \
   $(XPCOM_LIBS) \
   $(NSPR_LIBS) \
   $(NULL)
 
-ifdef MOZ_JPROF
-LIBS += -ljprof
-endif
-
 ifndef MOZ_WINCONSOLE
 ifdef MOZ_DEBUG
 MOZ_WINCONSOLE = 1
 else
 MOZ_WINCONSOLE = 0
 endif
 endif
 DEFINES += -DMOZ_WINCONSOLE=$(MOZ_WINCONSOLE)