From nobody Thu Sep 11 17:14:41 2025 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58D32C001DE for ; Sun, 6 Aug 2023 10:36:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230332AbjHFKg3 (ORCPT ); Sun, 6 Aug 2023 06:36:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48140 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229509AbjHFKg1 (ORCPT ); Sun, 6 Aug 2023 06:36:27 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2C1E1180 for ; Sun, 6 Aug 2023 03:36:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1691318184; bh=63Vj0WhE2taVV4Mgftn24397d24b8LwFSAcdGh/Tq2A=; h=From:To:Cc:Subject:Date:From; b=cVCQqZ22yRnPkiiMQqOPA3Bwbc4XpTdqP3rNvFckYb7TqUBBSlLFI99pIJXtvrTS5 xczYZjc382vW5ngo3YxwkcTb1clR+6kdcSjpG8+WeyafSl3Wqo2RJZzwpqalrvGc7C M7u0oBLi0oZ1pW380i49hO8BdJGq/1gkO98xKoQQ= Received: from ld50.lan (unknown [101.88.28.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mailbox.box.xen0n.name (Postfix) with ESMTPSA id 1B0956014B; Sun, 6 Aug 2023 18:36:23 +0800 (CST) From: WANG Xuerui To: Huacai Chen Cc: Nathan Chancellor , Xi Ruoyao , loongarch@lists.linux.dev, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui , Nick Desaulniers Subject: [PATCH v3] LoongArch: Replace -ffreestanding with finer-grained -fno-builtin's Date: Sun, 6 Aug 2023 18:36:20 +0800 Message-Id: <20230806103620.3118683-1-kernel@xen0n.name> X-Mailer: git-send-email 2.40.0 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: WANG Xuerui 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: https://github.com/ClangBuiltLinux/linux/issues/1897 Reported-by: Nathan Chancellor Suggested-by: Nick Desaulniers Signed-off-by: WANG Xuerui --- Changes in v3 (no functional changes): - Move explanatory words mentioning -ffreestanding from the comments into commit message. Changes in v2: - Keep the memory operation builtins disabled, add comments, and tweak the commit message along the way. arch/loongarch/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile index b1e5db51b61c..3a0a3b209fc1 100644 --- a/arch/loongarch/Makefile +++ b/arch/loongarch/Makefile @@ -83,7 +83,7 @@ KBUILD_CFLAGS_KERNEL +=3D -fPIE LDFLAGS_vmlinux +=3D -static -pie --no-dynamic-linker -z notext endif =20 -cflags-y +=3D -ffreestanding +cflags-y +=3D -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset cflags-y +=3D $(call cc-option, -mno-check-zero-division) =20 load-y =3D 0x9000000000200000 --=20 2.40.0