From a7d96f6225d5cfb8d76036a15ada4add1fad881c Mon Sep 17 00:00:00 2001 From: Ehsan Akhgari Date: Wed, 18 Dec 2013 15:03:11 -0500 Subject: [PATCH] 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 | 16 +++++++++++++++- xpcom/base/nsTraceRefcntImpl.cpp | 10 ++++++++++ xpcom/build/LateWriteChecks.cpp | 6 ++++++ xpcom/build/moz.build | 3 +++ 4 files changed, 34 insertions(+), 1 deletion(-) diff --git a/xpcom/base/moz.build b/xpcom/base/moz.build index fa05e8daa12..7768bc96dae 100644 --- a/xpcom/base/moz.build +++ b/xpcom/base/moz.build @@ -110,7 +110,6 @@ UNIFIED_SOURCES += [ 'nsMemoryReporterManager.cpp', 'nsMessageLoop.cpp', 'nsSecurityConsoleMessage.cpp', - 'nsStackWalk.cpp', 'nsSystemInfo.cpp', 'nsTraceRefcntImpl.cpp', 'nsUUIDGenerator.cpp', @@ -118,6 +117,18 @@ UNIFIED_SOURCES += [ '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', @@ -141,3 +152,6 @@ MSVC_ENABLE_PGO = True include('/ipc/chromium/chromium-config.mozbuild') FINAL_LIBRARY = 'xpcom_core' + +if CONFIG['MOZ_OPTIMIZE']: + DEFINES['MOZ_OPTIMIZE'] = True diff --git a/xpcom/base/nsTraceRefcntImpl.cpp b/xpcom/base/nsTraceRefcntImpl.cpp index 3ecfab2a79e..025bb7019d4 100644 --- a/xpcom/base/nsTraceRefcntImpl.cpp +++ b/xpcom/base/nsTraceRefcntImpl.cpp @@ -60,6 +60,10 @@ NS_MeanAndStdDev(double n, double sumOfValues, double sumOfSquaredValues, //////////////////////////////////////////////////////////////////////////////// +#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 @@ -836,6 +840,7 @@ static void InitTraceLog(void) extern "C" { +#ifdef STACKWALKING_AVAILABLE static void PrintStackFrame(void *aPC, void *aSP, void *aClosure) { FILE *stream = (FILE*)aClosure; @@ -846,14 +851,17 @@ static void PrintStackFrame(void *aPC, void *aSP, void *aClosure) 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 } //---------------------------------------------------------------------- @@ -895,7 +903,9 @@ 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); diff --git a/xpcom/build/LateWriteChecks.cpp b/xpcom/build/LateWriteChecks.cpp index 5d244772dbd..891998314c3 100644 --- a/xpcom/build/LateWriteChecks.cpp +++ b/xpcom/build/LateWriteChecks.cpp @@ -34,6 +34,10 @@ #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 ***************************/ @@ -106,6 +110,7 @@ private: void LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb) { +#ifdef OBSERVE_LATE_WRITES // Crash if that is the shutdown check mode if (gShutdownChecks == SCM_CRASH) { MOZ_CRASH(); @@ -201,6 +206,7 @@ void LateWriteObserver::Observe(IOInterposeObserver::Observation& aOb) } PR_Delete(finalName.get()); PR_Rename(name, finalName.get()); +#endif } /******************************* Setup/Teardown *******************************/ diff --git a/xpcom/build/moz.build b/xpcom/build/moz.build index c3885269a07..a268042be27 100644 --- a/xpcom/build/moz.build +++ b/xpcom/build/moz.build @@ -75,3 +75,6 @@ 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