Thread (42 messages) 42 messages, 6 authors, 2019-09-06

Re: [PATCH v5 10/10] arm64: atomics: Use K constraint when toolchain appears to support it

From: Mark Rutland <mark.rutland@arm.com>
Date: 2019-08-30 10:41:05

On Fri, Aug 30, 2019 at 10:11:55AM +0100, Andrew Murray wrote:
On Fri, Aug 30, 2019 at 08:52:20AM +0100, Will Deacon wrote:
quoted
On Fri, Aug 30, 2019 at 01:08:03AM +0100, Andrew Murray wrote:
quoted
On Thu, Aug 29, 2019 at 05:54:58PM +0100, Will Deacon wrote:
quoted
On Thu, Aug 29, 2019 at 04:48:34PM +0100, Will Deacon wrote:
quoted
diff --git a/arch/arm64/include/asm/atomic_ll_sc.h b/arch/arm64/include/asm/atomic_ll_sc.h
index 95091f72228b..7fa042f5444e 100644
--- a/arch/arm64/include/asm/atomic_ll_sc.h
+++ b/arch/arm64/include/asm/atomic_ll_sc.h
@@ -23,6 +23,10 @@ asm_ops "\n"								\
 #define __LL_SC_FALLBACK(asm_ops) asm_ops
 #endif
I downloaded your original patches and tried them, and also got the
build error. After playing with this I think something isn't quite right...
Can you post the error you see?
This is your current test:

 echo 'int main(void) {asm volatile("and w0, w0, %w0" :: "K" (4294967295)); return 0; }' |  aarch64-linux-gnu-gcc -S -x c  - ; echo $?

But on my machine this returns 0, i.e. no error. 
IIUC that's expected, as this is testing if the compiler erroneously
accepts the invalid immediate.

Note that try-run takes (option,option-ok,otherwise), so:

| cc_has_k_constraint := $(call try-run,echo                             \
|        'int main(void) {                                               \
|                asm volatile("and w0, w0, %w0" :: "K" (4294967295));    \
|                return 0;                                               \
|        }' | $(CC) -S -x c -o "$$TMP" -,,-DCONFIG_CC_HAS_K_CONSTRAINT=1)

... means we do nothing when the compile is successful (i.e. when the compiler
is broken), and we set -DCONFIG_CC_HAS_K_CONSTRAINT=1 when the compiler
correctly rejects the invalid immediate.

If we drop the -S, we'll get an error in all cases, as either:

* GCC silently accepts the immediate, GAS aborts
* GCC aborts as it can't satisfy the constraint
quoted
quoted
quoted
quoted
+#ifndef CONFIG_CC_HAS_K_CONSTRAINT
+#define K
+#endif
Here we define K to nothing if the compiler accepts the broken immediate.

If the compiler rejects invalid immediates we don't define K to anything, so
it's treated as a literal later on, and gets added as a constaint.

Thanks,
Mark.

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help