Skip to content

Commit 3f301dc

Browse files
xen0nchenhuacai
authored andcommitted
LoongArch: Replace -ffreestanding with finer-grained -fno-builtin's
As explained by Nick in the original issue: the kernel usually does a good job of providing library helpers that have similar semantics as their ordinary userspace libc equivalents, but -ffreestanding disables such libcall optimization and other related features in the compiler, which can lead to unexpected things such as CONFIG_FORTIFY_SOURCE not working (!). However, due to the desire for better control over unaligned accesses with respect to CONFIG_ARCH_STRICT_ALIGN, and also for avoiding the GCC bug https://gcc.gnu.org/PR109465, we do want to still disable optimizations for the memory libcalls (memcpy, memmove and memset for now). Use finer-grained -fno-builtin-* toggles to achieve this without losing source fortification and other libcall optimizations. Closes: ClangBuiltLinux#1897 Reported-by: Nathan Chancellor <nathan@kernel.org> Suggested-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: WANG Xuerui <git@xen0n.name> Signed-off-by: Huacai Chen <chenhuacai@loongson.cn>
1 parent b8e2771 commit 3f301dc

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

arch/loongarch/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,8 @@ KBUILD_CFLAGS_KERNEL += -fPIE
8383
LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext
8484
endif
8585

86-
cflags-y += -ffreestanding
8786
cflags-y += $(call cc-option, -mno-check-zero-division)
87+
cflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset
8888

8989
load-y = 0x9000000000200000
9090
bootvars-y = VMLINUX_LOAD_ADDRESS=$(load-y)

0 commit comments

Comments
 (0)