Improve Socorro stacks for CheckedInt<T> in general and media::TimeUnit in particular
Categories
(Toolkit :: Crash Reporting, enhancement)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox121 | --- | fixed |
People
(Reporter: yannis, Assigned: padenot)
References
Details
Attachments
(2 files, 1 external file, 3 obsolete files)
In bug 1802624, a crash is triggered by an assert originating from inlined functions in AudioTrimmer::HandleDecodedResult. The memory address where we crash in libxul.so is shared by all the paths that can lead to an assert being triggered for that function: it belongs to a shared code block that calls abort. For this specific crash, there are at least 24 possible paths that can lead to this block for the specific assert that was triggered, which makes root causing the issue very difficult. Because the address belongs to a shared code block, it is not possible to identify which path led to the assert being triggered, and for the same reason, in Socorro no specific line in AudioTrimmer.cpp can be incriminated.
This is a consequence of inlining followed by other optimizations, e.g. inlining of mozilla::media::TimeUnit::ToMicroseconds() followed by inlining of mozilla::CheckedInt<T>::value() (that is not the only inlining in that example that leads to the assert being triggered). We could try to make CheckedInt<T>::value() non-inlinable and see if that is enough (maybe not) to get unique paths here and in the other functions that rely heavily on CheckedInt<T> computations. We probably want to do this only on Nightly channel, to still get the full benefits of inlining for the Release channel?
In bug 1810396, a null pointer is used in a comparison, but knowing which of the two operands was a null pointer required manual analysis because the calls to CheckedInt<T>::value() are on the same line. We could check operands on different lines to be able to guess the faulty operand directly from the stack in Socorro, i.e. change patterns like:
bool operator<=(const TimeUnit& aOther) const {
MOZ_ASSERT(IsValid() && aOther.IsValid());
return mValue.value() <= aOther.mValue.value();
}
To something like this, where the crashing line directly gives the faulty operand:
bool operator<=(const TimeUnit& aOther) const {
MOZ_ASSERT(IsValid());
MOZ_ASSERT(aOther.IsValid());
const auto& lhs = mValue.value();
const auto& rhs = aOther.mValue.value();
return lhs <= rhs;
}
We should do that for all similar code patterns in CheckedInt.h and TimeUnit.h.
| Assignee | ||
Comment 1•3 years ago
|
||
| Assignee | ||
Comment 2•3 years ago
|
||
Depends on D168672
| Reporter | ||
Comment 3•3 years ago
•
|
||
The first suggestion seems to have worked on [:padenot]'s local build: instead of 24 b (branch) instructions branching to a shared code block that calls abort, he obtained 24 bl (branch-and-link) instructions going to CheckedInt::value(). This should result in better crash analysis by Socorro when the crash from bug 1802624 happens.
We may also want to mark as noinline some other functions that may call MOZ_DIAGNOSTIC_ASSERT or MOZ_RELEASE_ASSERT. For example here are the other functions that could lead to an abort in AudioTrimmer::HandleDecodedResult and after inlining they were handled by branching to the shared code block:
constexpr T* Maybe<T>::operator->()(2 paths)Interval<T>::Interval(StartArg&& aStart, EndArg&& aEnd)(2 paths)detail::Nth<N, Ts...>::Type& Variant<... Ts>::as() &(1 path)
Because the number of paths is low, those functions are not as impacting as the 24 paths resulting from CheckedInt::value() though.
| Reporter | ||
Comment 4•3 years ago
•
|
||
Regarding the second part about splitting lines, [:gsvelto] pointed out that we should first consider if there could be a generic way to address this problem in Socorro, instead of modifying specific occurrences of the problem just because of Socorro limitations, although solving the generic problem could be difficult.
Comment 5•3 years ago
|
||
I filed an llvm bug about something like this a while ago: https://github.com/llvm/llvm-project/issues/42128
It seems like the nomerge attribute might be useful here. Here's some example uses from Chromium:
https://source.chromium.org/chromium/chromium/src/+/main:base/compiler_specific.h;l=350;drc=ddf1b22e9e98da473db3e0da86353fad71624bc2
| Reporter | ||
Comment 6•3 years ago
•
|
||
(In reply to Jeff Muizelaar [:jrmuizel] from comment #5)
I filed an llvm bug about something like this a while ago: https://github.com/llvm/llvm-project/issues/42128
It seems like the
nomergeattribute might be useful here. Here's some example uses from Chromium:
https://source.chromium.org/chromium/chromium/src/+/main:base/compiler_specific.h;l=350;drc=ddf1b22e9e98da473db3e0da86353fad71624bc2
Oh yes that makes a lot of sense, adding a nomerge + noinline attribute on our *_ASSERT functions definitely looks like the proper generic way to solve the first issue! (or maybe just marking their calls to abort as nomerge, since we have inline information showing in Socorro?) And if we do this then there is no need for noinline in caller functions like mozilla::CheckedInt<T>::value(). I believe Nightly crash report analysis would greatly benefit from this. We should double check the impact on code size, but it sounds worth it for Nightly at least for me. Thanks for the tip, I didn't know about this attribute, that's very helpful!
Edited: Actually I think trying to mark the calls to abort as nomerge is the best thing to try if the impact on binary size is reasonable. (Also, we don't have *_ASSERT functions at the moment, it's all macros. Also, )nomerge seems to be an attribute you can add on a specific call, not on the declaration of a function.
| Assignee | ||
Comment 7•3 years ago
|
||
| Assignee | ||
Comment 8•3 years ago
|
||
Documentation of nomerge: https://clang.llvm.org/docs/AttributeReference.html#nomerge
If a statement is marked nomerge and contains call expressions, those call expressions inside the statement will not be merged during optimization. This attribute can be used to prevent the optimizer from obscuring the source location of certain calls. For example, it will prevent tail merging otherwise identical code sequences that raise an exception or terminate the program. Tail merging normally reduces the precision of source location information, making stack traces less useful for debugging. This attribute gives the user control over the tradeoff between code size and debug information precision.
nomerge attribute can also be used as function attribute to prevent all calls to the specified function from merging. It has no effect on indirect calls.
An example in Chromium:
https://source.chromium.org/chromium/chromium/src/+/main:base/compiler_specific.h;l=348-353;bpv=1;bpt=1?q=NOMERGE&ss=chromium
:yannis told me on chat.m.o (translated from french):
[...] You can check that it worked on the generated binary by doing the same thing you did yesterday [i.e. disassembling] and checking that the generated code for HandleDecodedResult has 29
bl abortinstructions (if I'm counting correctly). On Windows this doesn't apply because we're not using a function call, but directly an instruction that raises a breakpoint, and LLVM doesn't perform merging on those.
Here's a patch that annotates the crashes as nomerge.
When building locally for android, in opt+debug, the media::TimeUnit operators and the CheckedInt don't seem to be inlined very aggresively, so I can't really verify that this works (attached are the disassembly of the function of interest, with and without this patch). I need to figure out how to disassemble what we're shipping to users.
Updated•3 years ago
|
Updated•3 years ago
|
| Assignee | ||
Comment 9•3 years ago
|
||
| Assignee | ||
Comment 10•3 years ago
|
||
| Assignee | ||
Comment 11•3 years ago
|
||
It turns out that the function we were looking at is widely different with and without PGO. jrmuizel has compared the code emitted without and without this nomerge attribute next to the abort() call, and when it's preset, there are a bunch of call sites (instead of just one), so nomerge works in this instance.
The number of instructions for this particular function is higher, but the final apk size is roughly similar. I'm wondering what's the best course of action is to land something like this, e.g., what perf tests to run.
| Assignee | ||
Comment 12•3 years ago
|
||
Serge tells me that this would pair well with __attribute__((cold)).
I've pushed a perf comparison here: https://treeherder.mozilla.org/perfherder/compare?originalProject=try&originalRevision=e2f814e02fcfcf908a4a1f0633e7657f90f304dc&newProject=try&newRevision=31aec519388a9c88d3e000c2ea2ad59b04a946e1&page=1 for the original patch (only [[nomerge]]), but we could try with __atribute__((cold)).
Updated•3 years ago
|
Comment 13•3 years ago
|
||
__attribute__((cold)) might be nice to use for the non-PGO builds. In PGO builds it won't make a difference.
| Assignee | ||
Comment 14•3 years ago
|
||
Updated•3 years ago
|
Comment 15•3 years ago
|
||
Comment 16•3 years ago
|
||
| bugherder | ||
Updated•3 years ago
|
Comment 17•2 years ago
|
||
It looks like this missed the Windows version of MOZ_REALLY_CRASH
Description
•