Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp4056251pxb; Fri, 11 Feb 2022 14:11:43 -0800 (PST) X-Google-Smtp-Source: ABdhPJxUyftNNv45ouoipGrkPzuHOB3ionI9972xkhvZfX4MBjO6KCM+wrlhuVx2bYmkP9P3t4Hx X-Received: by 2002:a05:6402:3489:: with SMTP id v9mr4042088edc.249.1644617503300; Fri, 11 Feb 2022 14:11:43 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1644617503; cv=none; d=google.com; s=arc-20160816; b=dtM+F9MRvWU/ANxy9hBzbBfkRWHu8CGSBs7NOM/H1egr2w2NseJM6r9Mlh0D0TDnPA 94yqhKlqD//mU9ope4llz4Zkl9N/olf72W/U3Tn+A4Pu5hozfIIEyIKO15k+AeENMtPX diCVpL1mestWOaGwK8X9wqFNKi0rcDdTDmmPNbd/WNnuKQapvpugMFCl3pR+bHoiQr7r bMwelXee1WSZLYa/A3kRmno1jANb7bpFrC0pO2+hvGuHKsSkKfXVZe8pmqWNENrKX0aL 8rHSdVPTuPsOA3NoixGAJj5mw/QIeM7284+eBC7LC2GhqTm830/7Je7v+nQkZJzVg3wt sH2g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=MfHrUQ5r32hIgZ6XDqxUl3QNIeyQSp80lAQGJ5kc2jU=; b=KDepAd/+CgGQo2gNzul91Zu8veX0dO8XNB2cK32Mu5wAy6CWp/OtLe35HnXyxEdScH 3jjbf3t3gsg5lNMe1AIUFiFXA1aBhrl1EHXGZk6qjUhm/ZtmfoMcB4athVt4aVekxI4N pl962grvOfVAsXYS2y8dMNu0kcxQkjFvvX+bIp3VX+MF9gXnWnzzk56358u//XNE7CPH UyBvD4idffuFyuqngVSD0Lzd3XuTcTQub4hSj3kpvyRPAMcsGHdlixqokfrt377eW8L8 zwMwMwUvMK7kKMIGSJYlHDST+SF13Xv41ICFlliacyC3sev2RNZa5veYljE7xjnNkKn5 km5A== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i22si19694701ejw.671.2022.02.11.14.11.19; Fri, 11 Feb 2022 14:11:43 -0800 (PST) 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; 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=fail (p=NONE sp=NONE dis=NONE) header.from=arm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349454AbiBKLck (ORCPT + 99 others); Fri, 11 Feb 2022 06:32:40 -0500 Received: from mxb-00190b01.gslb.pphosted.com ([23.128.96.19]:48594 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234009AbiBKLci (ORCPT ); Fri, 11 Feb 2022 06:32:38 -0500 Received: from foss.arm.com (foss.arm.com [217.140.110.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 691AEE86 for ; Fri, 11 Feb 2022 03:32:37 -0800 (PST) Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id D23A51042; Fri, 11 Feb 2022 03:32:36 -0800 (PST) Received: from FVFF77S0Q05N (unknown [10.57.87.94]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 54B423F73B; Fri, 11 Feb 2022 03:32:32 -0800 (PST) Date: Fri, 11 Feb 2022 11:32:27 +0000 From: Mark Rutland To: Nick Desaulniers Cc: linux-kernel@vger.kernel.org, Nathan Chancellor , acme@redhat.com, ardb@kernel.org, bp@alien8.de, broonie@kernel.org, catalin.marinas@arm.com, dave.hansen@linux.intel.com, jpoimboe@redhat.com, jslaby@suse.cz, linux-arm-kernel@lists.infradead.org, linux@armlinux.org.uk, mingo@redhat.com, peterz@infradead.org, tglx@linutronix.de, will@kernel.org, llvm@lists.linux.dev, James Y Knight Subject: Re: [PATCH v2 2/7] linkage: add SYM_{ENTRY,START,END}_AT() Message-ID: References: <20220125113200.3829108-1-mark.rutland@arm.com> <20220125113200.3829108-3-mark.rutland@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE 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 Thu, Feb 10, 2022 at 05:20:10PM -0800, Nick Desaulniers wrote: > On Thu, Feb 10, 2022 at 6:52 AM Mark Rutland wrote: > > > > Both GCC and clang are happy to treat labels as constant expressions: > > > > | [mark@lakrids:~/asm-test]% cat test-label.S > > | .text > > | > > | start: > > | nop > > | end: > > | > > | .if (end - start) == 0 > > | .err > > | .endif > > | > > | [mark@lakrids:~/asm-test]% usekorg 11.1.0 aarch64-linux-gcc -c test-label.S > > | [mark@lakrids:~/asm-test]% usellvm 13.0.0 clang --target=aarch64-linux -c test-label.S > > > > ... but only GCC is happy to treat symbol definitions as constants: > > > > | [mark@lakrids:~/asm-test]% cat test-symbol.S > > | .text > > | > > | .set start, .; > > | nop > > | .set end, .; > > | > > | .if (end - start) == 0 > > | .err > > | .endif > > | > > | [mark@lakrids:~/asm-test]% usekorg 11.1.0 aarch64-linux-gcc -c test-symbol.S > > | [mark@lakrids:~/asm-test]% usellvm 13.0.0 clang --target=aarch64-linux -c test-symbol.S > > | test-symbol.S:7:6: error: expected absolute expression > > | .if (end - start) == 0 > > | ^ > > | test-symbol.S:8:2: error: .err encountered > > | .err > > | ^ > > > > This is obviously a behavioural difference, but I'm not sure whether it's > > intentional, or just an artifact of the differing implementation of GNU as and > > LLVM's integrated assembler. Nich, Nathan, any thoughts on that? > > > > Does clang have any mechanism other than labels to define location constants > > that can be used as absolute expressions? e.g. is there any mechanism to alias > > a label which results in the alias also being a constant? > > s/constant/absolute/ Sorry, yes. I wasn't clear on the terminology when I wrote this, and I realise now what I said was a bit confused. IIUC the symbols themselves are relocatable (rather than absolute) whether they're labels or created via `.set`, since the base of the section hasn't been set yet. The difference between the two *should* be absolute (since they're both relocatable relative to the same base), and LLVM can figure that out for two labels, but not when either is created via `.set`, so it seems some information is tracked differently for labels and othey symbols? I note LLVM *can* treat the result of a `.set` as absolute, eg. if I do: .set sym_offset (label_end - label_start) .if sym_offset == 0 .err .endif ... LLVM treats `sym_offset` as an absolute value. > Nothing off the top of my head comes to mind as a substitute that will > work as expected today. > > I've filed https://github.com/llvm/llvm-project/issues/53728 to > discuss more with folks that understand our AsmParser better. Thanks! > From what I can tell, our AsmParser is falling down because the > operands of the binary expression themselves are not considered > absolute. IIUC even in the label case the operands aren't absolute, but rather that they're relocatable relative to the same base, and hence the expression can be evaluate to be absolute (since the base gets cancelled out, removing the relocation). So is there something that gets tracked differently for labels and other symbols? > I doubt we will be able to handle the general case of symbol > differencing; the symbol reference operands could refer to symbols in > different sections that haven't been laid out yet (or whose order > could be shuffled by the linker). But if they're in the same section > (or "fragment" of a section), we might be able to special case this. Sure, I think the only case that needs to work (or can work conceptually) is when they're in the same section (of fragment thereof), and that's all the GNU assembler supports. > For the expression > > > .if (qwerty_fiqin_end - qwerty_fiqin_start) > (0x200 - 0x1c) > > can you use local labels (`.L` prefix) rather than symbolic > references? or is there a risk of them not being unique per TU? For the problem in this patch I might be able to do something of that shape, but I'll need to factor the SYM_*() helpers differently so that I can use labels for the primary definition. I can't do that for the aliases, since I don't know the set of aliases until after the primary definition is created. Since there's no label aliasing mechanism, I must use symbol references. However, I think I can propagate the size by calculating alongside the primary definition, e.g. primary_start: nop primary_end: .set primary_size, (primary_end - primary_start) .set alias_start, primary_start .set alias_end, primary_end .set alias_size, primary_size ... so I'll have a go at that. However, that still means I can't treat aliases as entirely equivalent to the primary definition, e.g. .if (alias_end - alias_start) == 0 .err .endif ... and there might be more things of that sort of shape, so it'd be good if LLVM could handle this for symbol references (in the same section or fragment thereof), so that we have the chance to use that in future. Thanks, Mark.