Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp161679rwb; Fri, 4 Aug 2023 10:35:56 -0700 (PDT) X-Google-Smtp-Source: AGHT+IG2pRKY3bLbRKtUiVxS0IVLNsnQ02Kb9mKfCdAF+GtDy0L9qY6L51GBuzK8/mA2otn8K5pH X-Received: by 2002:a17:902:efd1:b0:1b9:ebe9:5f01 with SMTP id ja17-20020a170902efd100b001b9ebe95f01mr2517524plb.19.1691170556310; Fri, 04 Aug 2023 10:35:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691170556; cv=none; d=google.com; s=arc-20160816; b=Ik7wYFwUBmDLxLN3wLW1SsXhg/gvySunYKDrG3n/QFsBpMObfQkMU9oGZk2Ny9yImk 3EHuMZhC+lmEhUvZrbYMH4eqwqJecFindEei0fjwGbUWFMbyCMZD+qn/d8/n0WgsqLJp FpJ+iL2/KwEgXQqJHK1MgHmL+Dmj7XXOuFYNROh0G7R7dnaruKXMiPycrgzyEItppN3l NhB5CerN0JtDhw0pq3iO8NYZ9AebH66lYlDbSDV5ZpWb0CmagV/R3ovGqdJv4en+6eKG /3G9hYrPurxvi1rsiC21/+I3omT8sNRl7aK0KoiEAWC3msYqCL7bgbRW3e9CyvzdzOsw uU2w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=Lbb2VkUYpcvrjAbuA8UFz73QM1aapinYdQ8PfffEqdw=; fh=vKMJgY2PL1i6fsdVKDqLazRFXQ/xURBldTGTdZ0cHuM=; b=F4NHzfoxpD7DeI0Fpq0nr5bZt8H8vfZsPA+os+LD3QghYtpMMOiR9YIMm1HJ6FHbVf kxXPL3xG331gRVbo6HjAhNoi2tAqIq1/6miioEye0GWwEeg5iT5AVqw9x17jw1iQ6Pb3 EZ9Nm0nii6WhYRba/uUtP9+8gBOBqFzTb1294x7IMdPK/IIPC3zywZ415bQ5qyYJbdt7 +ODj27i8Q5xi+IofYASriE34sKN9oF9g8+NXns8mpRj2B45byyz5XZGMvIIRgcae83Hf yA05JbP2L8GA1+1l6QoFPneEuzdMAisGgnPbyc/ORZ8sfIbbGb2H24tCGrKpR9e0Fmsm bUHw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=uSw8srlv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id t7-20020a1709027fc700b001b9e31bda39si2008627plb.118.2023.08.04.10.35.41; Fri, 04 Aug 2023 10:35:56 -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=@google.com header.s=20221208 header.b=uSw8srlv; 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; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231862AbjHDPqd (ORCPT + 99 others); Fri, 4 Aug 2023 11:46:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44478 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230311AbjHDPqb (ORCPT ); Fri, 4 Aug 2023 11:46:31 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A56501734 for ; Fri, 4 Aug 2023 08:46:30 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id 6a1803df08f44-63d10da0f26so13755816d6.3 for ; Fri, 04 Aug 2023 08:46:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1691163990; x=1691768790; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=Lbb2VkUYpcvrjAbuA8UFz73QM1aapinYdQ8PfffEqdw=; b=uSw8srlvkdNUYJYtc5TNkofuuRG9NlvWsa9z1FxvyZgYol80KHdrxc49/RmliZ/fzc W62Zh23a8h9A5Q0U05CYcZlliurch5SLeO+NXbcUxc5Snxe44CHOT6pBpKqbjCQ5tJtu m9x21PVKgCsS8RkvCKOUgc2DDgcdAbsfSxqeCLcGA9Chi5toZU2Pq72NgECAMBtyTp0/ EvoBi8TVPPuKrA0RnO0NW6ui2xNhaT15TPafkWO048bdvP9IwJ2EdIlPNR0oKJfBKuZ+ 326P99bNO/E4ZNzmMhORxtwrEzvIcGTMMa/n/K+eISL7k3poBMBIMrfxtcQw793EssFM NbTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691163990; x=1691768790; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Lbb2VkUYpcvrjAbuA8UFz73QM1aapinYdQ8PfffEqdw=; b=WA9YwEdn714n6bHVnyUSEL9xsTnCO4QwI5VPm9zi6uTUV/3wUkf+6y9x+PVTRcy0L1 w0vvDTN3gxvedeDUV/dSvY5FOSW3iuW0Z49rGfMUkWUzJ7wyGKGY8d9K6aeiFs4rLAwy XB9094INs8Q9Xd5pYWF6Vf1n71TlKWhQzGceYFfDrsq/DGISjxzPeBQxytxP0XTZF/pG 93M+tFcPV/ScsJsYUYvfcnXZZo194Z9asDE6aQwzEakpujYcyj6arzEOU5Lk9yrvflpz Oe8pFwTG4f46k7BIn6uBarciQg888L7xuYpOEURNBE6qDSeRddgIPp3sDylLx+uO/1/6 SB+w== X-Gm-Message-State: AOJu0YxBDXLJ+ysNFTuIvnD9mp1LrpD420dq+qZu0dLgmsc4q2Ouxrnx XPsFSbCKTpOq9NJkU5D2FbKR99qZE0S68oLxZa87Hw== X-Received: by 2002:a0c:cb09:0:b0:63d:6fb:c8da with SMTP id o9-20020a0ccb09000000b0063d06fbc8damr1804085qvk.14.1691163989483; Fri, 04 Aug 2023 08:46:29 -0700 (PDT) MIME-Version: 1.0 References: <20230804125609.2054719-1-kernel@xen0n.name> In-Reply-To: From: Nick Desaulniers Date: Fri, 4 Aug 2023 08:46:18 -0700 Message-ID: Subject: Re: [PATCH] LoongArch: Drop -ffreestanding from CFLAGS To: Huacai Chen Cc: WANG Xuerui , Nathan Chancellor , loongarch@lists.linux.dev, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_BLOCKED,SPF_HELO_NONE,SPF_PASS, USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL 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 On Fri, Aug 4, 2023 at 8:26=E2=80=AFAM Huacai Chen = wrote: > > Hi, Xuerui, > > On Fri, Aug 4, 2023 at 8:56=E2=80=AFPM WANG Xuerui wr= ote: > > > > 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, removing the flag does not impact the > > LoongArch kernel's normal operation at all; so just remove it to > > restore expected libcall semantics globally on this architecture. > > > Not all processors support unaligned access, so we need the > alternative mechanism to select memset/memcpy/memmove implementations. > If remove -ffreestanding, the builtin implementation cannot be used on > all hardware. That sounds like a compiler bug in that compiler's implementation of string.h builtins then; it should default to the safest implementation (aligned accesses) until instructed otherwise. Have you filed a bug against your compiler vendor for which compiler you observe that behavior from? At the very least, there should be a comment above the addition of -ffreestanding justifying why it's being used, probably with a link to the above bug report. I would expect either -mcpu or perhaps some other -m flag to guide the compiler when it is safe to emit memcpy (and friends) in terms of unaligned access or not. > > Huacai > > > Closes: https://github.com/ClangBuiltLinux/linux/issues/1897 > > Reported-by: Nathan Chancellor > > Suggested-by: Nick Desaulniers > > Signed-off-by: WANG Xuerui > > --- > > arch/loongarch/Makefile | 1 - > > 1 file changed, 1 deletion(-) > > > > diff --git a/arch/loongarch/Makefile b/arch/loongarch/Makefile > > index b1e5db51b61c..db0d7210272d 100644 > > --- a/arch/loongarch/Makefile > > +++ b/arch/loongarch/Makefile > > @@ -83,7 +83,6 @@ KBUILD_CFLAGS_KERNEL +=3D -fPIE > > LDFLAGS_vmlinux +=3D -static -pie --no-dynamic-= linker -z notext > > endif > > > > -cflags-y +=3D -ffreestanding > > cflags-y +=3D $(call cc-option, -mno-check-zero-division) > > > > load-y =3D 0x9000000000200000 > > -- > > 2.40.0 > > > --=20 Thanks, ~Nick Desaulniers