]> git.ipfire.org Git - thirdparty/haproxy.git/commit
MINOR: compiler: add a new DO_NOT_FOLD() macro to prevent code folding
authorWilly Tarreau <w@1wt.eu>
Fri, 2 Feb 2024 16:00:01 +0000 (17:00 +0100)
committerWilly Tarreau <w@1wt.eu>
Fri, 2 Feb 2024 16:12:06 +0000 (17:12 +0100)
commite06e8a2390c42260e2998c50887a09e1a78f7252
tree2e160641e027a8b17783a0528088737496b2b70c
parentdfb1cea693f18afd40193ff74288ee340ddf2116
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.
include/haproxy/compiler.h