Skip to content

Commit

Permalink
LoongArch: Replace -ffreestanding with finer-grained -fno-builtin's
Browse files Browse the repository at this point in the history
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.

Change-Id: I1ab73f976e878c13ea2a593137cd8533b3970846
Closes: ClangBuiltLinux/linux#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>
  • Loading branch information
xen0n authored and chenhuacai committed Nov 7, 2023
1 parent 4bd82c6 commit e88bebb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion arch/loongarch/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ ifeq ($(CONFIG_RELOCATABLE),y)
LDFLAGS_vmlinux += --emit-relocs
endif

cflags-y += -ffreestanding
cflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset

#
# Kernel compression
Expand Down

0 comments on commit e88bebb

Please sign in to comment.