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

Showing the changes to lib (1 of 1 file). Show all

Unified · Split

lib/Makefile+6−1
@@ -15,11 +15,16 @@ KCOV_INSTRUMENT_debugobjects.o := n · 14 unmodified lines
15KCOV_INSTRUMENT_dynamic_debug.o := n15KCOV_INSTRUMENT_dynamic_debug.o := n
16KCOV_INSTRUMENT_fault-inject.o := n16KCOV_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.
21CFLAGS_string.o := -ffreestanding
22
18# Early boot use of cmdline, don't instrument it23# Early boot use of cmdline, don't instrument it
19ifdef CONFIG_AMD_MEM_ENCRYPT24ifdef CONFIG_AMD_MEM_ENCRYPT
20KASAN_SANITIZE_string.o := n25KASAN_SANITIZE_string.o := n
21 26
22CFLAGS_string.o := -fno-stack-protector27CFLAGS_string.o += -fno-stack-protector
23endif28endif
24 29
25# Used by KCSAN while enabled, avoid recursion.30# Used by KCSAN while enabled, avoid recursion.