History

lib/string.c: Use freestanding environment

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.

Arvind Sankar committed 6 years ago

Commit 33d0f961 parent 394b19d1 file · +6 −1Browse files

Unified · Split

lib/Makefile+6−1
@@ -15,11 +15,16 @@ KCOV_INSTRUMENT_debugobjects.o := n · 14 unmodified lines
1515 KCOV_INSTRUMENT_dynamic_debug.o := n
1616 KCOV_INSTRUMENT_fault-inject.o := n
1717
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+
1823 # Early boot use of cmdline, don't instrument it
1924 ifdef CONFIG_AMD_MEM_ENCRYPT
2025 KASAN_SANITIZE_string.o := n
2126
22−CFLAGS_string.o := -fno-stack-protector
27+CFLAGS_string.o += -fno-stack-protector
2328 endif
2429
2530 # Used by KCSAN while enabled, avoid recursion.