From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-3.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=no autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 58475C388F7 for ; Tue, 10 Nov 2020 20:11:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id DD77920731 for ; Tue, 10 Nov 2020 20:11:28 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=infradead.org header.i=@infradead.org header.b="djPwDpKG" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727018AbgKJUL2 (ORCPT ); Tue, 10 Nov 2020 15:11:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726428AbgKJUL2 (ORCPT ); Tue, 10 Nov 2020 15:11:28 -0500 Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BD20C0613D1 for ; Tue, 10 Nov 2020 12:11:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=In-Reply-To:Content-Transfer-Encoding: Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Sender:Reply-To:Content-ID:Content-Description; bh=OEdejAq9JyTldwtkkTwVWnsgfoK09UjFDo7aHSBmnzk=; b=djPwDpKGHpe/EJ/vJg8Wk6it8A dluzWIRLQXv4s44+2rsP1Qv71BFnSwqvs8hj/aPucnPBccUF5p33Fk349E9cXdD7d9/8s+ImbD7Tn z5K2zeoXE5vgRgQv42omih4BuKYOwH7UDaufipCqry8pyDWNYvze1kJTaGDF6K7Xwzj9Em4lTsR6X +jIIlXpTXwCHUGRvcLKPwV6lvn4PTJsigonwb45dOKX/VaFq2HkRDa0E8YA8DJBCM1vxI/By9kBtC 3gk507sMs6SNQAF97HkuSkdw2yCGdZjLSLvgfTGyEuuILO2U0fnA+x8Rqc5SYygK8QDVDGbXxfgvI RWwqiLLg==; Received: from j217100.upc-j.chello.nl ([24.132.217.100] helo=noisy.programming.kicks-ass.net) by merlin.infradead.org with esmtpsa (Exim 4.92.3 #3 (Red Hat Linux)) id 1kcZyy-000592-S7; Tue, 10 Nov 2020 20:11:13 +0000 Received: from hirez.programming.kicks-ass.net (hirez.programming.kicks-ass.net [192.168.1.225]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by noisy.programming.kicks-ass.net (Postfix) with ESMTPS id 62942301324; Tue, 10 Nov 2020 21:11:08 +0100 (CET) Received: by hirez.programming.kicks-ass.net (Postfix, from userid 1000) id 41FB1203DACA7; Tue, 10 Nov 2020 21:11:08 +0100 (CET) Date: Tue, 10 Nov 2020 21:11:08 +0100 From: Peter Zijlstra To: Nick Desaulniers Cc: Segher Boessenkool , Uros Bizjak , GCC Development , X86 ML , Jakub Jelinek , Andy Lutomirski , linux-toolchains@vger.kernel.org, Christian Borntraeger , Will Deacon , Linus Torvalds , Michael Ellerman Subject: Re: typeof and operands in named address spaces Message-ID: <20201110201108.GQ2611@hirez.programming.kicks-ass.net> References: <20201109124713.GP2594@hirez.programming.kicks-ass.net> <20201109193851.GI2672@gate.crashing.org> <20201110075742.GT2594@hirez.programming.kicks-ass.net> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: linux-toolchains@vger.kernel.org On Tue, Nov 10, 2020 at 10:42:58AM -0800, Nick Desaulniers wrote: > When I think of qualifiers, I think of const and volatile. I'm not > sure why the first post I'm cc'ed on talks about "segment" qualifiers. > Maybe it's in reference to a variable attribute that the kernel > defines? Looking at Clang's Qualifier class, I see const, volatile, > restrict (ah, right), some Objective-C stuff, and address space > (TR18037 is referenced, I haven't looked up what that is) though maybe > "segment" pseudo qualifiers the kernel defines expand to address space > variable attributes? Right, x86 Named Address Space: https://gcc.gnu.org/onlinedocs/gcc-10.2.0/gcc/Named-Address-Spaces.html#Named-Address-Spaces Also, Google found me this: https://reviews.llvm.org/D64676 The basic problem seems to be they act exactly like qualifiers in that typeof() preserves them, so if you have: ( and now I realize the parent isn't Cc'd to LKML, find here: https://gcc.gnu.org/pipermail/gcc/2020-November/234119.html ) > --cut here-- > #define foo(_var) \ > ({ \ > typeof(_var) tmp__; \ > asm ("mov %1, %0" : "=r"(tmp__) : "m"(_var)); \ > tmp__; \ > }) > > __seg_fs int x; > > int test (void) > { > int y; > > y = foo (x); > return y; > } > --cut here-- > when compiled with -O2 for x86 target, the compiler reports: > > pcpu.c: In function ‘test’: > pcpu.c:14:3: error: ‘__seg_fs’ specified for auto variable ‘tmp__’ > Maybe stripping all qualifiers is fine since you can add them back in > if necessary? So far that seems sufficient. Although the Devil's advocate in me is trying to construct a case where we need to preserve const but strip volatile and that's then means we need to detect if the original has const or not, because unconditionally adding it will be wrong.