Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp1845781rwb; Sun, 6 Aug 2023 04:30:38 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHEvNVCndnYMUnio/bAc57NZgYexrVdS+mGvsJSIM7sXY3hM+cvZugapi8LBxXdo9b2CfOc X-Received: by 2002:a05:6a00:1a12:b0:687:472f:5150 with SMTP id g18-20020a056a001a1200b00687472f5150mr6141559pfv.8.1691321437758; Sun, 06 Aug 2023 04:30:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691321437; cv=none; d=google.com; s=arc-20160816; b=d0mL3S0K4Rqi142ZyuKLz56Bao0uUj/sVeohTVSCguxF/kupB3Eg8Eo0yTEXn/tRmZ O3gPQj9xoOK0gEY9Pn/UZ3PbCgouNfKdSPuMJei9gxTQRw4w6biXho27tFlChJ6AmWJ7 yLXdyvqEO9WBl2QHj6YZZNBUKPtViGZoL4rADitp2h+12f0LOB2SiGNSccQs25laVtsX a7Y381gCynre+M7QxKRkgvOanorpyDpHlKOMAD3b32aNGmpAByA2p1OZC2WH86fzGmDl iE0NJyhUXeLnudRggbmdW4AXjrBTmwqEWXBCjdjMnOHC1Xqkn0JdnjNDqL4YR0ahMx01 a0kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=+86oQGHHYjLinU8gaBibonIOz9j0DR3WohVMF7VDZG4=; fh=gn9MSGgVMLLrYS41ELheX3gDILgoBnwaj5DSpUF/ufM=; b=kG2DpOtZvRtXBM5fvE6pkVhI2GFP6Kyokst7nRx792YD4qPRaLeiuAV8uoTXQf+9nd eI0f/fYymGcCwoP9wPZc8XVyzL9NYKrB680Jd3W5o92GQx8QOKzjjMBLwK4KVmxjI0PW 0VOnIrjLLWQ+8/QFX9+pYP23XFeeqeL27G9442JsOgWsFHSFue5GQBfiVsJJY6nDZN1A W3EEC203xy/eQIOXhvUgIDDeIMPNeb70Xsz6Il9MKKgH6yS57yi3UYj4QQ/wwkYNZMGg hIeysdWXpUYiLUNPoTB3LVR7iqhSdhrhXF92NRCAWbQ0BY8ScpnKtunksJuTZTNM1HNG kwww== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=cVCQqZ22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h20-20020a056a00219400b00686b8078e4asi4371289pfi.255.2023.08.06.04.30.25; Sun, 06 Aug 2023 04:30:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=cVCQqZ22; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230257AbjHFKg2 (ORCPT + 99 others); Sun, 6 Aug 2023 06:36:28 -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: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 += -fPIE LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext endif -cflags-y += -ffreestanding +cflags-y += -fno-builtin-memcpy -fno-builtin-memmove -fno-builtin-memset cflags-y += $(call cc-option, -mno-check-zero-division) load-y = 0x9000000000200000 -- 2.40.0