mirror of
http://git.haproxy.org/git/haproxy.git/
synced 2025-01-05 03:29:35 +00:00
MINOR: compiler: add a new DO_NOT_FOLD() macro to prevent code folding
Modern compilers sometimes perform function tail merging and identical code folding, which consist in merging identical occurrences of same code paths, generally final ones (e.g. before a return, a jump or an unreachable statement). In the case of ABORT_NOW(), it can happen that the compiler merges all of them into a single one in a function, defeating the purpose of the check which initially was to figure where the bug occurred. Here we're creating a DO_NO_FOLD() macro which makes use of the line number and passes it as an integer argument to an empty asm() statement. The effect is a code position dependency which prevents the compiler from merging the code till that point (though it may still merge the following code). In practice it's efficient at stopping the compilers from merging calls to ha_crash_now(), which was the initial purpose. It may also be used to force certain optimization constructs since it gives more control to the developer.
This commit is contained in:
parent
dfb1cea693
commit
e06e8a2390
@ -199,6 +199,20 @@
|
||||
#endif
|
||||
#endif
|
||||
|
||||
/* This prevents the compiler from folding multiple identical code paths into a
|
||||
* single one, by adding a dependency on the line number in the path. This may
|
||||
* typically happen on function tails, or purposely placed abort() before an
|
||||
* unreachable() statement, due to the compiler performing an Identical Code
|
||||
* Folding optimization. This macro is aimed at helping with code tracing in
|
||||
* crash dumps and may also be used for specific optimizations. One known case
|
||||
* is gcc-4.7 and 4.8 which aggressively fold multiple ABORT_NOW() exit points
|
||||
* and which causes wrong line numbers to be reported by the debugger (note
|
||||
* that even newer compilers do this when using abort()). Please keep in mind
|
||||
* that nothing prevents the compiler from folding the code after that point,
|
||||
* but at least it will not fold the code before.
|
||||
*/
|
||||
#define DO_NOT_FOLD() do { asm volatile("" :: "i"(__LINE__)); } while (0)
|
||||
|
||||
/* This macro may be used to block constant propagation that lets the compiler
|
||||
* detect a possible NULL dereference on a variable resulting from an explicit
|
||||
* assignment in an impossible check. Sometimes a function is called which does
|
||||
|
Loading…
Reference in New Issue
Block a user