Received: by 2002:a05:6359:6284:b0:131:369:b2a3 with SMTP id se4csp108639rwb; Fri, 4 Aug 2023 09:51:26 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhSODB3WceXtmxfyFnD+0+azNm9HD9bb7fXP2cdXo2/oqflHLtemdsE6luQ1wErVcROQQq X-Received: by 2002:a05:6512:445:b0:4f8:4245:ed57 with SMTP id y5-20020a056512044500b004f84245ed57mr1639985lfk.35.1691167886458; Fri, 04 Aug 2023 09:51:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1691167886; cv=none; d=google.com; s=arc-20160816; b=YMYnsmoS82QKiJSFCGllSRMNKSW/54sF6qRt7ZSRPeSnrsFZMsUrrWrp066gnrA58C g33ntpSGQhhoeFK8z78Y2iWd++/cgPgqg5fTydbQtjDprbAqomvNipLhni6S05B5pEEu YWWPyJJYAMOjL3OyptcoFLgNoDArKZ0ADB7CBHCnnJ3MZftf+q0YfeglReUqDvcPC33V yl/LpsoktFjYtM0mcEqbJ8FfYu1xfzryasIfwoU1w7SzISyl11eTcG9Q4SJso95VQxvk twdd5G0YShnPEEomAUcKiRnuY7E/19BSgt/SQqBjXcWn5SVpvSYZuofCHP9mkb8D9j2U ABYQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:cc:to:from :subject:message-id:dkim-signature; bh=NJJQA6jFa44UfhiUt6WI7g4z6iecv/ylkonR3EpAEPY=; fh=1jWo16g/XDp+dk3OR5KMyZaXFA2wMK68AGck62X32OQ=; b=nZYOdIuzyf7G8U0Y0DR3L8MsrYF01Beww1oVbYyPogpnPbCSbqoePXej2ZcsEy2sTP tdGzRU1o9fY+aLFte8ElWbA81YJolDqVWU9mKZLlNFdGF0E11GudwCD83B2djmgFAmp5 +n0sqahQS//BLZAYrBf9wFsGczg3pyigunUqkscJpLzvv097/QiAMI4a+A1jPnhEBFNf HksNDB1lBKnCj35ph3LP+CKmT7lhUvLJHi4x9vOhUQw4Ry5hn7Clo/+jAqFjUUy29r/0 zeuaCrgjZKbihEgM8AoJ2cNTZ2+FZ551hWaC7MoKmI2zRsPnYgufWkzBN1fqpDt7qtel DaYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@xry111.site header.s=default header.b=mm6arzXT; 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=xry111.site Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id q7-20020aa7d447000000b00522567926c8si1750983edr.11.2023.08.04.09.51.00; Fri, 04 Aug 2023 09:51:26 -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=@xry111.site header.s=default header.b=mm6arzXT; 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=xry111.site Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232233AbjHDP4R (ORCPT + 99 others); Fri, 4 Aug 2023 11:56:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51036 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229634AbjHDP4P (ORCPT ); Fri, 4 Aug 2023 11:56:15 -0400 Received: from xry111.site (xry111.site [IPv6:2001:470:683e::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E69D0170F for ; Fri, 4 Aug 2023 08:56:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=xry111.site; s=default; t=1691164570; bh=UamAAPVxLlb4vLDRTAEBwV6EBxinnwPqEAjS6+WRhUE=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=mm6arzXTW2JF1RsjidNfqSIiw1lbWWRWOlaqLM+OF1IR2XYrXNuzKz27Rm7VQ6oNJ 0aLNFrShYbd+6mLzPHc8J54W5c88wEVFJCjyRMXbTwYs06jl5gtynbfXTZGwOqDI/u a1PRqp1+oF7NDFA64LkPU0DW8ujDgKJmIcIeaTbA= Received: from localhost.localdomain (xry111.site [IPv6:2001:470:683e::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature ECDSA (P-384) server-digest SHA384) (Client did not present a certificate) (Authenticated sender: xry111@xry111.site) by xry111.site (Postfix) with ESMTPSA id 110BA6599C; Fri, 4 Aug 2023 11:56:08 -0400 (EDT) Message-ID: Subject: Re: [PATCH] LoongArch: Drop -ffreestanding from CFLAGS From: Xi Ruoyao To: Nick Desaulniers , Huacai Chen Cc: WANG Xuerui , Nathan Chancellor , loongarch@lists.linux.dev, llvm@lists.linux.dev, linux-kernel@vger.kernel.org, WANG Xuerui Date: Fri, 04 Aug 2023 23:56:07 +0800 In-Reply-To: References: <20230804125609.2054719-1-kernel@xen0n.name> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable User-Agent: Evolution 3.48.4 MIME-Version: 1.0 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_PASS,SPF_PASS,URIBL_BLOCKED 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, 2023-08-04 at 08:46 -0700, Nick Desaulniers wrote: > > 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. >=20 > 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.=C2=A0 Have you filed a bug > against your compiler vendor for which compiler you observe that > behavior from? AFAIK there is no such bug in GCC. But GCC indeed has a bug about builtin expansion: it generates really stupid code for __builtin_memcpy and friends. See https://gcc.gnu.org/PR109465. The bug is fixed for GCC 14, but GCC 14 won't be released soon. > 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. >=20 > 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. It's controlled by -m{no-,}strict-align. LoongArch kernel defaults to - mstrict-align, with this the compiler should not generate unaligned access. -mno-strict-align is hidden behind CONFIG_EXPERT (FWIW I personally dislike the decision to hide it). --=20 Xi Ruoyao School of Aerospace Science and Technology, Xidian University