I want to speed up integer overflow checking for hardening purposes by keeping a sticky overflow flag and only trapping when necessary. I want to keep it super simple while hopefully giving the optimizers room to do their thing.
In the codegen part of clang:
- each function gets an i1 for storing overflow information, initialized to 0
- each integer overflow check ORs its result into the overflow flag
- before each function call, return instruction, or other side-effecting operation, execude ud2 if overflow is set
Reasonable?
@nadavrot You can easily avoid register dependencies. But you're still going to be burning registers extracting and or-ing these things together.
@regehr Yes, branches do interfere with some things, but very minimally when they are perfectly predicted branches to ud2. The worst impacts I'm aware of are mild pressure on the branch prediction tables (but very mild) and blowing out the number of branches supported by the loop stream detector. These will hurt, but they will hurt much less than the alternatives.