Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp1831027rwb; Sun, 6 Aug 2023 04:08:42 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEgMZbDW+ctI/6cR2Hr0GkUM2CZy8iuRfJxIDIgq7YkmYWAspqn7DEjQq0i/oTX0MSvzU+A X-Received: by 2002:a05:6a00:17aa:b0:687:2d90:acfc with SMTP id s42-20020a056a0017aa00b006872d90acfcmr7096028pfg.2.1691320122181; Sun, 06 Aug 2023 04:08:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691320122; cv=none; d=google.com; s=arc-20160816; b=l1JBNBs7Y8lkQgTu6w6BZBH1UPg03GmIuRA6DCvU6479QMPwerTb8HusTrf1VbzlZk 5HnR9RbWIQCJSgUrAeujAl5bVFTEX2yHBiJoyDCr4SxLyMuK+0CAeJlabi2sxwoqq5Zz +vjSwbKZnKg8z6U1bMvwPWy54Npc/eyAKiiTsMLKYmER8OAtSgBJ4FHFpM2+txvMiY4H nyZUe1ZxosYR5WiWJWY/BP0K/0rTD9xEyfm4RaJuQieJ/i9M0g1EBHCap1EG3wNcJOgP 8BN1akmu8LMAurPxQOhajH2SOuQvS1nd2vFGGinphfxKb+K0QyBqR2rE86C+BBBC7qiC qqVw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id:dkim-signature; bh=K3HNnohUhH4SUWu/C5phWopRyoPDvs2+WgUKf694mJA=; fh=Ithu3v20BVnvptaOo9bfZsOTTATPhw9jmojdMFmNAkc=; b=DbF2q6Bmy7kyTjoEkht/4EwB9zPGheywG4I2szQhZNEfYzJWzqR3qYCh4pAyBBPO4q fvXX6IWt3pW2sp7Vgq6gbmovN8WAzr5534HxKxc8j5dH1dHuRqFuyaldHStMarPQ2zrN gFpZwc3F+YMXMCnSGVCcIFkv4wM5Glu3JxsT9g6EU+t9o6cneOJnFb+VsxjaAa76EZfD b0534wuSA1JDSQwrGO4BenVmM8sQr/mgswABCmgAmzxdmAMzhdXHtFPDgvQJMOTLijC7 Z/aIkL2TVRVzXy4GdRVe92x8TqpLqnQ71XgpcFBSIDrp2HqtQtYaupHlkWk8jW+q2pQ/ fbSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xen0n.name header.s=mail header.b=XVMqvcmw; 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 fb34-20020a056a002da200b006786b7f4cc4si4384327pfb.240.2023.08.06.04.08.30; Sun, 06 Aug 2023 04:08:42 -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=XVMqvcmw; 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 S230326AbjHFKbR (ORCPT + 99 others); Sun, 6 Aug 2023 06:31:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47672 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230124AbjHFKbQ (ORCPT ); Sun, 6 Aug 2023 06:31:16 -0400 Received: from mailbox.box.xen0n.name (mail.xen0n.name [115.28.160.31]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC21C128 for ; Sun, 6 Aug 2023 03:31:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xen0n.name; s=mail; t=1691317869; bh=sqi/+CXZcnCn6zMHYik83KCgTz71fg+XcMCrPM7cGG4=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=XVMqvcmwcjHIKCiBjxUw0RfEjTcTZQLaFNwZGIp9VawMif1D6C58eMyRsq8hsygYN Y14Vs+JLbUeeuUeNLRbVO6uc/yjKHPGqBJrP3ew2xw5caurf6Ka88vW42zrdUDsWIZ E/0dTZc+nuAYvQ36ofDukS7eMnSRBizssYKFHQto= Received: from [192.168.9.172] (unknown [101.88.28.229]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 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 A9D5D600F8; Sun, 6 Aug 2023 18:31:09 +0800 (CST) Message-ID: Date: Sun, 6 Aug 2023 18:31:09 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.14.0 Subject: Re: [PATCH v2] LoongArch: Replace -ffreestanding with finer-grained -fno-builtin's 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 References: <20230806083021.2243574-1-kernel@xen0n.name> Content-Language: en-US From: WANG Xuerui In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-6.2 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,NICE_REPLY_A, 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 Hi, On 8/6/23 17:16, Huacai Chen wrote: > Hi, Xuerui, > > On Sun, Aug 6, 2023 at 4:30 PM WANG Xuerui wrote: >> 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 (!). >> >> As it turns out to be the case, only the memory operations really need >> to be prevented from expansion by the compiler, and this is doable with >> finer-grained -fno-builtin-* toggles. So only disable memcpy, memmove >> and memset, while leaving other builtins enabled, to fix source >> fortification among others. >> >> Closes: https://github.com/ClangBuiltLinux/linux/issues/1897 >> Reported-by: Nathan Chancellor >> Suggested-by: Nick Desaulniers >> Signed-off-by: WANG Xuerui >> --- >> >> Changes in v2: >> >> - Keep the memory operation builtins disabled, add comments, and tweak the >> commit message along the way. >> >> arch/loongarch/Makefile | 9 ++++++++- >> 1 file changed, 8 insertions(+), 1 deletion(-) >> >> diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile >> index b1e5db51b61c..34fc48df87f2 100644 >> --- a/arch/loongarch/Makefile >> +++ b/arch/loongarch/Makefile >> @@ -83,7 +83,14 @@ KBUILD_CFLAGS_KERNEL += -fPIE >> LDFLAGS_vmlinux += -static -pie --no-dynamic-linker -z notext >> endif >> >> -cflags-y += -ffreestanding >> +# Make sure the memory libcalls are not expanded by the compiler, for better >> +# control over unaligned accesses with respect to CONFIG_ARCH_STRICT_ALIGN, >> +# and also for avoiding https://gcc.gnu.org/PR109465. >> +# >> +# The overly broad -ffreestanding is undesirable as it disables *all* libcall >> +# handling, that unfortunately includes proper FORTIFY_SOURCE instrumentation. > I think these comments should go to commit message rather than here, > because after this patch there is no -ffreestanding in Makefile. Thanks for the advice, I'm fine either way and I'll send v3. > > Huacai > >> +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 >> >> -- WANG "xen0n" Xuerui Linux/LoongArch mailing list: https://lore.kernel.org/loongarch/