2019-01-04 03:23:19

by Stefan Agner

[permalink] [raw]
Subject: [PATCH v2 0/3] ARM: trivial assembly fixes to enable LLVM as

This patchset is a starting point to enable LLVM integrated assembler and
contains some trivial changes. With this patchset the LLVM integrated
assembler can be used to assemble almost all C files.

Changes since v1:
- Explicitly use unified syntax for inline assembly where necessary

Stefan Agner (3):
ARM: fix argument count to match macro definition
ARM: uaccess: use unified assembler language syntax
ARM: spinlock: use unified assembler language syntax

arch/arm/include/asm/spinlock.h | 3 ++-
arch/arm/include/asm/uaccess.h | 3 ++-
arch/arm/lib/copy_template.S | 2 +-
3 files changed, 5 insertions(+), 3 deletions(-)

--
2.20.1



2019-01-04 03:23:19

by Stefan Agner

[permalink] [raw]
Subject: [PATCH v2 2/3] ARM: uaccess: use unified assembler language syntax

Convert the conditional infix to a postfix to make sure this inline
assembly is unified syntax. Since gcc assumes non-unified syntax
when emitting ARM instructions, make sure to define the syntax as
unified.

This allows to use LLVM's integrated assembler.

Signed-off-by: Stefan Agner <[email protected]>
---
Changes since v1:
- Explicitly use unified syntax for inline assembly


arch/arm/include/asm/uaccess.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
index 6390a40f16e7..a50f9b4e2574 100644
--- a/arch/arm/include/asm/uaccess.h
+++ b/arch/arm/include/asm/uaccess.h
@@ -86,7 +86,8 @@ static inline void set_fs(mm_segment_t fs)
#define __range_ok(addr, size) ({ \
unsigned long flag, roksum; \
__chk_user_ptr(addr); \
- __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
+ __asm__(".syntax unified\n" \
+ "adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \
: "=&r" (flag), "=&r" (roksum) \
: "r" (addr), "Ir" (size), "0" (current_thread_info()->addr_limit) \
: "cc"); \
--
2.20.1


2019-01-04 03:23:35

by Stefan Agner

[permalink] [raw]
Subject: [PATCH v2 1/3] ARM: fix argument count to match macro definition

The macro str8w takes 10 arguments, abort being the 10th. In this
particular instantiation the abort argument is passed as 11th
argument leading to an error when using LLVM's integrated
assembler:
<instantiation>:46:47: error: too many positional arguments
str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
^
arch/arm/lib/copy_template.S:277:5: note: while in macro instantiation
18: forward_copy_shift pull=24 push=8
^

The argument is not used in the macro hence this does not change
code generation.

Signed-off-by: Stefan Agner <[email protected]>
---
arch/arm/lib/copy_template.S | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/lib/copy_template.S b/arch/arm/lib/copy_template.S
index 652e4d98cd47..2d54491b0e22 100644
--- a/arch/arm/lib/copy_template.S
+++ b/arch/arm/lib/copy_template.S
@@ -241,7 +241,7 @@
orr r9, r9, ip, lspush #\push
mov ip, ip, lspull #\pull
orr ip, ip, lr, lspush #\push
- str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
+ str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, abort=19f
bge 12b
PLD( cmn r2, #96 )
PLD( bge 13b )
--
2.20.1


2019-01-04 03:23:35

by Stefan Agner

[permalink] [raw]
Subject: [PATCH v2 3/3] ARM: spinlock: use unified assembler language syntax

Convert the conditional infix to a postfix to make sure this inline
assembly is unified syntax. Since gcc assumes non-unified syntax
when emitting ARM instructions, make sure to define the syntax as
unified.

This allows to use LLVM's integrated assembler.

Signed-off-by: Stefan Agner <[email protected]>
---
Changes since v1:
- Explicitly use unified syntax for inline assembly


arch/arm/include/asm/spinlock.h | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
index 099c78fcf62d..8f009e788ad4 100644
--- a/arch/arm/include/asm/spinlock.h
+++ b/arch/arm/include/asm/spinlock.h
@@ -210,11 +210,12 @@ static inline void arch_read_lock(arch_rwlock_t *rw)

prefetchw(&rw->lock);
__asm__ __volatile__(
+" .syntax unified\n"
"1: ldrex %0, [%2]\n"
" adds %0, %0, #1\n"
" strexpl %1, %0, [%2]\n"
WFE("mi")
-" rsbpls %0, %1, #0\n"
+" rsbspl %0, %1, #0\n"
" bmi 1b"
: "=&r" (tmp), "=&r" (tmp2)
: "r" (&rw->lock)
--
2.20.1


2019-01-05 16:08:13

by Nicolas Pitre

[permalink] [raw]
Subject: Re: [PATCH v2 1/3] ARM: fix argument count to match macro definition

On Thu, 3 Jan 2019, Stefan Agner wrote:

> The macro str8w takes 10 arguments, abort being the 10th. In this
> particular instantiation the abort argument is passed as 11th
> argument leading to an error when using LLVM's integrated
> assembler:
> <instantiation>:46:47: error: too many positional arguments
> str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
> ^
> arch/arm/lib/copy_template.S:277:5: note: while in macro instantiation
> 18: forward_copy_shift pull=24 push=8
> ^
>
> The argument is not used in the macro hence this does not change
> code generation.
>
> Signed-off-by: Stefan Agner <[email protected]>

Reviewed-by: Nicolas Pitre <[email protected]>

> ---
> arch/arm/lib/copy_template.S | 2 +-
> 1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/arch/arm/lib/copy_template.S b/arch/arm/lib/copy_template.S
> index 652e4d98cd47..2d54491b0e22 100644
> --- a/arch/arm/lib/copy_template.S
> +++ b/arch/arm/lib/copy_template.S
> @@ -241,7 +241,7 @@
> orr r9, r9, ip, lspush #\push
> mov ip, ip, lspull #\pull
> orr ip, ip, lr, lspush #\push
> - str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, , abort=19f
> + str8w r0, r3, r4, r5, r6, r7, r8, r9, ip, abort=19f
> bge 12b
> PLD( cmn r2, #96 )
> PLD( bge 13b )
> --
> 2.20.1
>
>

2019-01-05 16:16:47

by Nicolas Pitre

[permalink] [raw]
Subject: Re: [PATCH v2 3/3] ARM: spinlock: use unified assembler language syntax

On Thu, 3 Jan 2019, Stefan Agner wrote:

> Convert the conditional infix to a postfix to make sure this inline
> assembly is unified syntax. Since gcc assumes non-unified syntax
> when emitting ARM instructions, make sure to define the syntax as
> unified.
>
> This allows to use LLVM's integrated assembler.

Same comment as for patch 2/3.


>
> Signed-off-by: Stefan Agner <[email protected]>
> ---
> Changes since v1:
> - Explicitly use unified syntax for inline assembly
>
>
> arch/arm/include/asm/spinlock.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/include/asm/spinlock.h b/arch/arm/include/asm/spinlock.h
> index 099c78fcf62d..8f009e788ad4 100644
> --- a/arch/arm/include/asm/spinlock.h
> +++ b/arch/arm/include/asm/spinlock.h
> @@ -210,11 +210,12 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
>
> prefetchw(&rw->lock);
> __asm__ __volatile__(
> +" .syntax unified\n"
> "1: ldrex %0, [%2]\n"
> " adds %0, %0, #1\n"
> " strexpl %1, %0, [%2]\n"
> WFE("mi")
> -" rsbpls %0, %1, #0\n"
> +" rsbspl %0, %1, #0\n"
> " bmi 1b"
> : "=&r" (tmp), "=&r" (tmp2)
> : "r" (&rw->lock)
> --
> 2.20.1
>
>

2019-01-05 16:19:20

by Nicolas Pitre

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] ARM: uaccess: use unified assembler language syntax

On Thu, 3 Jan 2019, Stefan Agner wrote:

> Convert the conditional infix to a postfix to make sure this inline
> assembly is unified syntax. Since gcc assumes non-unified syntax
> when emitting ARM instructions, make sure to define the syntax as
> unified.
>
> This allows to use LLVM's integrated assembler.
>
> Signed-off-by: Stefan Agner <[email protected]>
> ---
> Changes since v1:
> - Explicitly use unified syntax for inline assembly
>
>
> arch/arm/include/asm/uaccess.h | 3 ++-
> 1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
> index 6390a40f16e7..a50f9b4e2574 100644
> --- a/arch/arm/include/asm/uaccess.h
> +++ b/arch/arm/include/asm/uaccess.h
> @@ -86,7 +86,8 @@ static inline void set_fs(mm_segment_t fs)
> #define __range_ok(addr, size) ({ \
> unsigned long flag, roksum; \
> __chk_user_ptr(addr); \
> - __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
> + __asm__(".syntax unified\n" \
> + "adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \

Instead of sprinkling ".syntax unified" around, you could consider
including <asm/unified.h> when needed.


Nicolas

2019-01-07 21:52:16

by Stefan Agner

[permalink] [raw]
Subject: Re: [PATCH v2 2/3] ARM: uaccess: use unified assembler language syntax

On 05.01.2019 17:12, Nicolas Pitre wrote:
> On Thu, 3 Jan 2019, Stefan Agner wrote:
>
>> Convert the conditional infix to a postfix to make sure this inline
>> assembly is unified syntax. Since gcc assumes non-unified syntax
>> when emitting ARM instructions, make sure to define the syntax as
>> unified.
>>
>> This allows to use LLVM's integrated assembler.
>>
>> Signed-off-by: Stefan Agner <[email protected]>
>> ---
>> Changes since v1:
>> - Explicitly use unified syntax for inline assembly
>>
>>
>> arch/arm/include/asm/uaccess.h | 3 ++-
>> 1 file changed, 2 insertions(+), 1 deletion(-)
>>
>> diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
>> index 6390a40f16e7..a50f9b4e2574 100644
>> --- a/arch/arm/include/asm/uaccess.h
>> +++ b/arch/arm/include/asm/uaccess.h
>> @@ -86,7 +86,8 @@ static inline void set_fs(mm_segment_t fs)
>> #define __range_ok(addr, size) ({ \
>> unsigned long flag, roksum; \
>> __chk_user_ptr(addr); \
>> - __asm__("adds %1, %2, %3; sbcccs %1, %1, %0; movcc %0, #0" \
>> + __asm__(".syntax unified\n" \
>> + "adds %1, %2, %3; sbcscc %1, %1, %0; movcc %0, #0" \
>
> Instead of sprinkling ".syntax unified" around, you could consider
> including <asm/unified.h> when needed.

This seems not to help in this case. When I include <asm/unified.h> at
the beginning of uaccess.h GCC still seems to emit ".syntax unified".

I guess this is since we are dealing with inline assembly. As far as I
understand its really gcc which emits a ".syntax divided" by default
when compiling ARM mode. There is an option "-masm-syntax-unified" which
according to the gcc man page should do what we need, but it seems
broken, see also: https://gcc.gnu.org/bugzilla/show_bug.cgi?id=88648

I agree this patch is not particularly pretty, but it is the only
solution I found to make this inline assembly work with gcc and Clang.

--
Stefan