summaryrefslogtreecommitdiff
path: root/src/fuzz
diff options
context:
space:
mode:
authorJan Janssen <medhefgo@web.de>2022-09-23 09:54:03 +0200
committerJan Janssen <medhefgo@web.de>2022-09-25 14:26:00 +0200
commit4b8eb86360b106afbc69cc014e8f1a15017c9d1f (patch)
tree7a485bb952d7da07c81318b567cb29b42c08b1d8 /src/fuzz
parente7508839afdd59619342a25c0c39c11fa934fd72 (diff)
downloadsystemd-4b8eb86360b106afbc69cc014e8f1a15017c9d1f.tar.gz
fuzz: Introduce DO_NOT_OPTIMIZE
The compiler may decide computations like these are not doing anything and decide to optimize them away. This would defeat the whole fuzzing exercise. This macro will force the compiler to materialize the value no matter what. It should be less prone to accidents compared to using log functions, which would either slow things down or still optimize the value away (or simply move it into the if branch the log macros create). The benefit over assert_se would be that no requirement is made on the value itself. If we are fine getting a string of any size (including zero), an assert_se would either create a noisy compiler warning about conditions that would alawys be met or yet again optimize the whole thing away.
Diffstat (limited to 'src/fuzz')
-rw-r--r--src/fuzz/fuzz.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/src/fuzz/fuzz.h b/src/fuzz/fuzz.h
index 04c438edaf..a7d3a89fe2 100644
--- a/src/fuzz/fuzz.h
+++ b/src/fuzz/fuzz.h
@@ -27,3 +27,6 @@ static inline bool outside_size_range(size_t size, size_t lower, size_t upper) {
return FUZZ_USE_SIZE_LIMIT;
return false;
}
+
+/* Force value to not be optimized away. */
+#define DO_NOT_OPTIMIZE(value) ({ asm volatile("" : : "g"(value) : "memory"); })