gcc can transform the loop in a naive implementation of memset/memcpy etc into a call to the function itself. This optimization is enabled by -ftree-loop-distribute-patterns. This has been the case for a while, but gcc-10.x enables this option at -O2 rather than -O3 as in previous versions. Add -ffreestanding, which implicitly disables this optimization with gcc. It is unclear whether clang performs such optimizations, but hopefully it will also not do so in a freestanding environment.
Unified · Split
| @@ -15,11 +15,16 @@ KCOV_INSTRUMENT_debugobjects.o := n · 14 unmodified lines | |||
| 15 | KCOV_INSTRUMENT_dynamic_debug.o := n | 15 | KCOV_INSTRUMENT_dynamic_debug.o := n |
| 16 | KCOV_INSTRUMENT_fault-inject.o := n | 16 | KCOV_INSTRUMENT_fault-inject.o := n |
| 17 | 17 | ||
| 18 | # string.o implements standard library functions like memset/memcpy etc. | ||
| 19 | # Use -ffreestanding to ensure that the compiler does not try to "optimize" | ||
| 20 | # them into calls to themselves. | ||
| 21 | CFLAGS_string.o := -ffreestanding | ||
| 22 | |||
| 18 | # Early boot use of cmdline, don't instrument it | 23 | # Early boot use of cmdline, don't instrument it |
| 19 | ifdef CONFIG_AMD_MEM_ENCRYPT | 24 | ifdef CONFIG_AMD_MEM_ENCRYPT |
| 20 | KASAN_SANITIZE_string.o := n | 25 | KASAN_SANITIZE_string.o := n |
| 21 | 26 | ||
| 22 | CFLAGS_string.o := -fno-stack-protector | 27 | CFLAGS_string.o += -fno-stack-protector |
| 23 | endif | 28 | endif |
| 24 | 29 | ||
| 25 | # Used by KCSAN while enabled, avoid recursion. | 30 | # Used by KCSAN while enabled, avoid recursion. |