Skip to content

Commit 33d0f96

Browse files
nivedita76torvalds
authored andcommitted
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. Signed-off-by: Arvind Sankar <[email protected]> Link: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56888 Signed-off-by: Linus Torvalds <[email protected]>
1 parent 394b19d commit 33d0f96

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

lib/Makefile

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,16 @@ KCOV_INSTRUMENT_debugobjects.o := n
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.

0 commit comments

Comments
 (0)