Have you measured the code size overhead from this extra flag? Did you
consider implementing this in the runtime library instead (by
suppressing duplicates based on return address or SourceLocation)?
Hmm, good point. I hadn't previously measured this, but I just did
now, see attached. Sizes are reported for text/data/bss/total as
reported by 'size', and ubsan calls are counted by occurrences of
calls in the actual resulting binary (grep'ing output from objdump
-d).
Summary: average increase across CINT2006 was 1.85% using
-fsanitize=integer with a neatly consistent ~5bytes per check
(including text).
For the ability to scale despite many sites triggering many times,
this does seem like a valid trade-off.
Previously IOC used a short linear scan table (~10-20 elements was
sweet spot IIRC) with fallback to a larger hashtable to manage
duplicates, but that was always a performance issue. As a useful data
point, a quick spot-check of 403.gcc shows 96 static locations
triggered a total of 3,476,066 times dynamically when just processing
one of the inputs used for the 'ref' input set (166.i). More on this
below.
+1. ThreadSanitizer has to solve the same problem - we want to report
each data race (pair of stack traces) exactly once. TSan runtime stores the
stacks of printed reports (as a sequence of PCs) to do this de-duplication.
Great, didn't realize TSan already solved this problem. That said,
the problem is somewhat different I think:
* TSan supports differentiating based on stack trace (apparently), but
that seems less interesting for ubsan/integer checks, especially since
we don't print that information :). The byte-per-check approach
doesn't work for stack traces, so that's not really an option for tsan
as-is.
* I would (perhaps erroneously) expect tsan to have many fewer dynamic
invocations than ubsan/integer checks, which might suggest difference
trade-offs in the size vs performance department. Checking a byte 1
million times vs scanning and managing a vector of ~100 items > 1
million times might make the size increase rather preferable, even if
that's not the right decision for tsan (I have no idea what's right
for tsan :)).
Given this, and in light of the attached data, do you buy that this is
indeed the appropriate approach for ubsan/integer checking?
Until I actually gathered this data I wasn't sure, but the 1-2% seems
very much worth it IMHO.
Thoughts, and thanks for helping ensure we do what's right!
~Will
size.pdf (45.7 KB)