Bug 1945507 - improve asm memory barrier in AnnotateMozCrashReason r=gsvelto
Adding explicit reference to gMozCrashReason as an input memory operand with r/w effect seems to prevent extra optimisation. The original snippet is inspired from google benchmark implementation of `DoNotOptimize`. Differential Revision: https://phabricator.services.mozilla.com/D236553
This commit is contained in:
@@ -53,9 +53,13 @@ MOZ_END_EXTERN_C
|
|||||||
#if defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API)
|
#if defined(MOZ_HAS_MOZGLUE) || defined(MOZILLA_INTERNAL_API)
|
||||||
static inline void AnnotateMozCrashReason(const char* reason) {
|
static inline void AnnotateMozCrashReason(const char* reason) {
|
||||||
gMozCrashReason = reason;
|
gMozCrashReason = reason;
|
||||||
// See bug 1681846, on 32-bit Android ARM the compiler removes the store to
|
// The following assembly fakes a memory read/write to the compiler, which
|
||||||
// gMozCrashReason if this barrier is not present.
|
// prevents the removal of gMozCrashReason store. See bug 1681846 and 1945507.
|
||||||
asm volatile("" ::: "memory");
|
# if defined(__clang__)
|
||||||
|
asm volatile("" : "+r,m"(gMozCrashReason) : : "memory");
|
||||||
|
# else
|
||||||
|
asm volatile("" : "+m,r"(gMozCrashReason) : : "memory");
|
||||||
|
# endif
|
||||||
}
|
}
|
||||||
# define MOZ_CRASH_ANNOTATE(...) AnnotateMozCrashReason(__VA_ARGS__)
|
# define MOZ_CRASH_ANNOTATE(...) AnnotateMozCrashReason(__VA_ARGS__)
|
||||||
#else
|
#else
|
||||||
|
|||||||
Reference in New Issue
Block a user