Bug 950856 - Fail the build if you attempt to use NS_StackWalk on Windows where it won't work; r=froydnj,BenWa
authorEhsan Akhgari <ehsan@mozilla.com>
Wed, 18 Dec 2013 15:03:11 -0500
changeset 177311 57eb08af0794e358e38fc4acbee428870d877f7c
parent 177310 3d0de9cfddcb37b6c80ae8dd66ff021b446e7805
child 177312 7294b1ba5056b8bf049662bb0d91fe9e070281ce
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersfroydnj, BenWa
bugs950856
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 950856 - Fail the build if you attempt to use NS_StackWalk on Windows where it won't work; r=froydnj,BenWa
xpcom/base/moz.build
xpcom/base/nsTraceRefcntImpl.cpp
xpcom/build/LateWriteChecks.cpp
xpcom/build/moz.build
--- a/xpcom/base/moz.build
+++ b/xpcom/base/moz.build
@@ -105,24 +105,35 @@ UNIFIED_SOURCES += [
     'nsErrorService.cpp',
     'nsGZFileWriter.cpp',
     'nsInterfaceRequestorAgg.cpp',
     'nsMemoryImpl.cpp',
     'nsMemoryInfoDumper.cpp',
     'nsMemoryReporterManager.cpp',
     'nsMessageLoop.cpp',
     'nsSecurityConsoleMessage.cpp',
-    'nsStackWalk.cpp',
     'nsSystemInfo.cpp',
     'nsTraceRefcntImpl.cpp',
     'nsUUIDGenerator.cpp',
     'nsVersionComparatorImpl.cpp',
     'VisualEventTracer.cpp',
 ]
 
+# On Windows, NS_StackWalk will only work correctly if we have frame pointers available.
+# That will only be true for non-optimized builds, and for optimized builds with
+# --enable-profiling in the .mozconfig (which is turned on in Nightly by default.)
+# We exclude this file from other build configurations so that if somebody adds a
+# new usage of NS_StackWalk it will cause a link error, which is better than having
+# NS_StackWalk silently return garbage at runtime.
+if CONFIG['OS_TARGET'] != 'WINNT' or \
+   (not CONFIG['MOZ_OPTIMIZE'] or CONFIG['MOZ_PROFILING'] or CONFIG['MOZ_DEBUG']):
+    UNIFIED_SOURCES += [
+        'nsStackWalk.cpp',
+    ]
+
 if CONFIG['OS_ARCH'] == 'Linux':
     SOURCES += [
         'SystemMemoryReporter.cpp',
     ]
 
 if CONFIG['MOZ_WIDGET_TOOLKIT'] == 'cocoa':
     SOURCES += [
         'nsMacUtilsImpl.cpp',
@@ -136,8 +147,11 @@ UNIFIED_SOURCES += [
     'nsErrorAssertsC.c',
 ]
 
 MSVC_ENABLE_PGO = True
 
 include('/ipc/chromium/chromium-config.mozbuild')
 
 FINAL_LIBRARY = 'xpcom_core'
+
+if CONFIG['MOZ_OPTIMIZE']:
+    DEFINES['MOZ_OPTIMIZE'] = True
--- a/xpcom/base/nsTraceRefcntImpl.cpp
+++ b/xpcom/base/nsTraceRefcntImpl.cpp
@@ -55,16 +55,20 @@ NS_MeanAndStdDev(double n, double sumOfV
     stdDev = var != 0.0 ? sqrt(var) : 0.0;
   }
   *meanResult = mean;
   *stdDevResult = stdDev;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
 
+#if !defined(XP_WIN) || (!defined(MOZ_OPTIMIZE) || defined(MOZ_PROFILING) || defined(DEBUG))
+#define STACKWALKING_AVAILABLE
+#endif
+
 #define NS_IMPL_REFCNT_LOGGING
 
 #ifdef NS_IMPL_REFCNT_LOGGING
 #include "plhash.h"
 #include "prmem.h"
 
 #include "prlock.h"
 
@@ -831,34 +835,38 @@ static void InitTraceLog(void)
 
   gTraceLock = PR_NewLock();
 }
 
 #endif
 
 extern "C" {
 
+#ifdef STACKWALKING_AVAILABLE
 static void PrintStackFrame(void *aPC, void *aSP, void *aClosure)
 {
   FILE *stream = (FILE*)aClosure;
   nsCodeAddressDetails details;
   char buf[1024];
 
   NS_DescribeCodeAddress(aPC, &details);
   NS_FormatCodeAddressDetails(aPC, &details, buf, sizeof(buf));
   fputs(buf, stream);
 }
+#endif
 
 }
 
 void
 nsTraceRefcntImpl::WalkTheStack(FILE* aStream)
 {
+#ifdef STACKWALKING_AVAILABLE
   NS_StackWalk(PrintStackFrame, /* skipFrames */ 2, /* maxFrames */ 0, aStream,
                0, nullptr);
+#endif
 }
 
 //----------------------------------------------------------------------
 
 // This thing is exported by libstdc++
 // Yes, this is a gcc only hack
 #if defined(MOZ_DEMANGLE_SYMBOLS)
 #include <cxxabi.h>
@@ -890,17 +898,19 @@ nsTraceRefcntImpl::DemangleSymbol(const 
 
 
 //----------------------------------------------------------------------
 
 EXPORT_XPCOM_API(void)
 NS_LogInit()
 {
   // FIXME: This is called multiple times, we should probably not allow that.
+#ifdef STACKWALKING_AVAILABLE
   StackWalkInitCriticalAddress();
+#endif
 #ifdef NS_IMPL_REFCNT_LOGGING
   if (++gInitCount)
     nsTraceRefcntImpl::SetActivityIsLegal(true);
 #endif
 
 #ifdef NS_TRACE_MALLOC
   // XXX we don't have to worry about shutting down trace-malloc; it
   // handles this itself, through an atexit() callback.
--- a/xpcom/build/LateWriteChecks.cpp
+++ b/xpcom/build/LateWriteChecks.cpp
@@ -29,16 +29,20 @@
 #include <sys/stat.h>
 #include <windows.h>
 #else
 #define NS_SLASH "/"
 #endif
 
 #include "LateWriteChecks.h"
 
+#if !defined(XP_WIN) || (!defined(MOZ_OPTIMIZE) || defined(MOZ_PROFILING) || defined(DEBUG))
+#define OBSERVE_LATE_WRITES
+#endif
+
 using namespace mozilla;
 
 /*************************** Auxiliary Declarations ***************************/
 
 // This a wrapper over a file descriptor that provides a Printf method and
 // computes the sha1 of the data that passes through it.
 class SHA1Stream
 {
@@ -101,16 +105,17 @@ public:
 
   void Observe(IOInterposeObserver::Observation& aObservation);
 private:
   char* mProfileDirectory;
 };
 
 void LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb)
 {
+#ifdef OBSERVE_LATE_WRITES
   // Crash if that is the shutdown check mode
   if (gShutdownChecks == SCM_CRASH) {
     MOZ_CRASH();
   }
 
   // If we have shutdown mode SCM_NOTHING or we can't record then abort
   if (gShutdownChecks == SCM_NOTHING || !Telemetry::CanRecord()) {
     return;
@@ -196,16 +201,17 @@ void LateWriteObserver::Observe(IOInterp
   // client side deduplication.
   nsPrintfCString finalName("%s%s", mProfileDirectory,
                             "/Telemetry.LateWriteFinal-");
   for (int i = 0; i < 20; ++i) {
     finalName.AppendPrintf("%02x", sha1[i]);
   }
   PR_Delete(finalName.get());
   PR_Rename(name, finalName.get());
+#endif
 }
 
 /******************************* Setup/Teardown *******************************/
 
 static StaticAutoPtr<LateWriteObserver> sLateWriteObserver;
 
 namespace mozilla{
 
--- a/xpcom/build/moz.build
+++ b/xpcom/build/moz.build
@@ -70,8 +70,11 @@ include('/ipc/chromium/chromium-config.m
 
 FINAL_LIBRARY = 'xul'
 
 DEFINES['_IMPL_NS_STRINGAPI'] = True
 DEFINES['OMNIJAR_NAME'] = CONFIG['OMNIJAR_NAME']
 
 if CONFIG['TARGET_XPCOM_ABI']:
     DEFINES['TARGET_XPCOM_ABI'] = '"%s"' % CONFIG['TARGET_XPCOM_ABI']
+
+if CONFIG['MOZ_OPTIMIZE']:
+    DEFINES['MOZ_OPTIMIZE'] = True