Skip to content

Commit cbd484a

Browse files
committedOct 24, 2023
Bug 1859964 - --enable-phc doesn't always imply --enable-frame-pointers r=glandium
Differential Revision: https://phabricator.services.mozilla.com/D191404
1 parent cdf77fd commit cbd484a

File tree

5 files changed

+43
-7
lines changed

5 files changed

+43
-7
lines changed
 

‎build/moz.configure/memory.configure

+24-3
Original file line numberDiff line numberDiff line change
@@ -90,13 +90,34 @@ option(
9090
default=phc_default,
9191
when="--enable-jemalloc",
9292
help="{Enable|Disable} PHC (Probabilistic Memory Checker). "
93-
"Also enables frame pointers",
93+
"Also enables frame pointers when needed",
9494
)
95-
imply_option("--enable-frame-pointers", True, when="--enable-phc")
96-
9795

9896
set_config("MOZ_PHC", True, when="--enable-phc")
9997

98+
99+
# PHC parses stacks using frame pointers on these systems.
100+
@depends("--enable-phc", target, have_unwind, when="--enable-jemalloc")
101+
def phc_implies_frame_pointers(phc, target, have_unwind):
102+
if not phc:
103+
return False
104+
105+
# This should be kept in sync with the ifdefs in memory/build/PHC.cpp
106+
# that control stack walking.
107+
# This is true for the first two options in PHC.cpp
108+
if (target.os == "WINNT" and target.cpu == "x86") or target.kernel == "Darwin":
109+
return True
110+
111+
# This should match the #defines in mozglue/misc/StackWalk.cpp
112+
if (target.cpu in ("x86", "ppc")) and (target.kernel in ("Darwin", "Linux")):
113+
return not have_unwind
114+
115+
return False
116+
117+
118+
imply_option("--enable-frame-pointers", True, when=phc_implies_frame_pointers)
119+
120+
100121
with only_when(depends(target.os)(lambda os: os != "WINNT")):
101122
set_define("HAVE_STRNDUP", check_symbol("strndup"))
102123
set_define("HAVE_POSIX_MEMALIGN", check_symbol("posix_memalign"))

‎build/moz.configure/toolchain.configure

+10
Original file line numberDiff line numberDiff line change
@@ -2335,6 +2335,7 @@ def ub_unsigned_overflow_san():
23352335

23362336
add_old_configure_assignment("MOZ_UNSIGNED_OVERFLOW_SANITIZE", ub_unsigned_overflow_san)
23372337

2338+
23382339
# Security Hardening
23392340
# ==============================================================
23402341

@@ -2538,6 +2539,15 @@ def frame_pointer_flags(enable, flags):
25382539
set_config("MOZ_FRAMEPTR_FLAGS", frame_pointer_flags)
25392540

25402541

2542+
# Stack unwinding without frame pointers
2543+
# ==============================================================
2544+
2545+
2546+
have_unwind = check_symbol(
2547+
"_Unwind_Backtrace", when=check_header("unwind.h", when=target_is_unix)
2548+
)
2549+
2550+
25412551
# Code Coverage
25422552
# ==============================================================
25432553

‎js/moz.configure

+1-4
Original file line numberDiff line numberDiff line change
@@ -1374,10 +1374,7 @@ with only_when(compile_environment & depends(target.os)(lambda os: os != "WINNT"
13741374

13751375
set_define("MOZ_DEMANGLE_SYMBOLS", demangle_symbols)
13761376

1377-
set_define(
1378-
"HAVE__UNWIND_BACKTRACE",
1379-
check_symbol("_Unwind_Backtrace", when=check_header("unwind.h")),
1380-
)
1377+
set_define("HAVE__UNWIND_BACKTRACE", True, when=have_unwind)
13811378

13821379
with only_when(compile_environment):
13831380
set_define("HAVE__GETC_NOLOCK", check_symbol("_getc_nolock"))

‎memory/build/PHC.cpp

+2
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,8 @@ class StackTrace : public phc::StackTrace {
207207
void StackTrace::Fill() {
208208
mLength = 0;
209209

210+
// These ifdefs should be kept in sync with the conditions in
211+
// phc_implies_frame_pointers in build/moz.configure/memory.configure
210212
#if defined(XP_WIN) && defined(_M_IX86)
211213
// This avoids MozStackWalk(), which causes unusably slow startup on Win32
212214
// when it is called during static initialization (see bug 1241684).

‎mozglue/misc/StackWalk.cpp

+6
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,9 @@ MFBT_API bool MozDescribeCodeAddress(void* aPC,
639639
}
640640

641641
// i386 or PPC Linux stackwalking code
642+
//
643+
// Changes to to OS/Architecture support here should be reflected in
644+
// build/moz.configure/memory.configure
642645
#elif HAVE_DLADDR && \
643646
(HAVE__UNWIND_BACKTRACE || MOZ_STACKWALK_SUPPORTS_LINUX || \
644647
MOZ_STACKWALK_SUPPORTS_MACOSX)
@@ -680,6 +683,9 @@ void DemangleSymbol(const char* aSymbol, char* aBuffer, int aBufLen) {
680683
} // namespace mozilla
681684

682685
// {x86, ppc} x {Linux, Mac} stackwalking code.
686+
//
687+
// Changes to to OS/Architecture support here should be reflected in
688+
// build/moz.configure/memory.configure
683689
# if ((defined(__i386) || defined(PPC) || defined(__ppc__)) && \
684690
(MOZ_STACKWALK_SUPPORTS_MACOSX || MOZ_STACKWALK_SUPPORTS_LINUX))
685691

0 commit comments

Comments
 (0)