[09/15] microblaze: Avoid clobbering register parameters in syscall
diff mbox series

Message ID 20200210192038.23588-9-adhemerval.zanella@linaro.org
State New
Headers show
Series
  • [01/15] powerpc: Consolidate Linux syscall definition
Related show

Commit Message

Adhemerval Zanella Feb. 10, 2020, 7:20 p.m. UTC
The microblaze INTERNAL_SYSCALL macro might clobber the register
parameter if the argument itself might clobber any register (a function
call for instance).

This patch fixes it by using temporary variables for the expressions
between the register assignments (as indicated by GCC documentation,
6.47.5.2 Specifying Registers for Local Variables).

It is similar to the fix done for MIPS (BZ#25523).

Checked with microblaze-linux-gnu and microblazeel-linux-gnu build.
---
 sysdeps/unix/sysv/linux/microblaze/sysdep.h | 63 ++++++++++++++-------
 1 file changed, 42 insertions(+), 21 deletions(-)

Comments

Florian Weimer Feb. 11, 2020, 11:21 a.m. UTC | #1
* Adhemerval Zanella:

> The microblaze INTERNAL_SYSCALL macro might clobber the register
> parameter if the argument itself might clobber any register (a function
> call for instance).
>
> This patch fixes it by using temporary variables for the expressions
> between the register assignments (as indicated by GCC documentation,
> 6.47.5.2 Specifying Registers for Local Variables).
>
> It is similar to the fix done for MIPS (BZ#25523).

(bug 25523) for the bug reference, so that it will be recognized by the
commit hook.  Rest looks good.

Thanks,
Florian
Adhemerval Zanella Feb. 11, 2020, 7:10 p.m. UTC | #2
On 11/02/2020 08:21, Florian Weimer wrote:
> * Adhemerval Zanella:
> 
>> The microblaze INTERNAL_SYSCALL macro might clobber the register
>> parameter if the argument itself might clobber any register (a function
>> call for instance).
>>
>> This patch fixes it by using temporary variables for the expressions
>> between the register assignments (as indicated by GCC documentation,
>> 6.47.5.2 Specifying Registers for Local Variables).
>>
>> It is similar to the fix done for MIPS (BZ#25523).
> 
> (bug 25523) for the bug reference, so that it will be recognized by the
> commit hook.  Rest looks good.

Ack.

Patch
diff mbox series

diff --git a/sysdeps/unix/sysv/linux/microblaze/sysdep.h b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
index ed873d9dd4..b4a6ee89f1 100644
--- a/sysdeps/unix/sysv/linux/microblaze/sysdep.h
+++ b/sysdeps/unix/sysv/linux/microblaze/sysdep.h
@@ -219,9 +219,10 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall1(name,arg1)                                           \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
+    register long __r5 __asm__("r5") = __arg1;                                \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r12)                                                 \
@@ -230,10 +231,12 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall2(name,arg1,arg2)                                      \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
+    long __arg2 = (long) (arg2);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
-    register long __r6 __asm__("r6") = (long)(arg2);                          \
+    register long __r5 __asm__("r5") = __arg1;                                \
+    register long __r6 __asm__("r6") = __arg2;                                \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r6), "r"(__r12)                                      \
@@ -243,11 +246,14 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall3(name,arg1,arg2,arg3)                                 \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
+    long __arg2 = (long) (arg2);                                              \
+    long __arg3 = (long) (arg3);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
-    register long __r6 __asm__("r6") = (long)(arg2);                          \
-    register long __r7 __asm__("r7") = (long)(arg3);                          \
+    register long __r5 __asm__("r5") = __arg1;                                \
+    register long __r6 __asm__("r6") = __arg2;                                \
+    register long __r7 __asm__("r7") = __arg3;                                \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r12)                           \
@@ -257,12 +263,16 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall4(name,arg1,arg2,arg3,arg4)                            \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
+    long __arg2 = (long) (arg2);                                              \
+    long __arg3 = (long) (arg3);                                              \
+    long __arg4 = (long) (arg4);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
-    register long __r6 __asm__("r6") = (long)(arg2);                          \
-    register long __r7 __asm__("r7") = (long)(arg3);                          \
-    register long __r8 __asm__("r8") = (long)(arg4);                          \
+    register long __r5 __asm__("r5") = __arg1;                                \
+    register long __r6 __asm__("r6") = __arg2;                                \
+    register long __r7 __asm__("r7") = __arg3;                                \
+    register long __r8 __asm__("r8") = __arg4;                                \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r12)                 \
@@ -272,13 +282,18 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall5(name,arg1,arg2,arg3,arg4,arg5)                       \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
+    long __arg2 = (long) (arg2);                                              \
+    long __arg3 = (long) (arg3);                                              \
+    long __arg4 = (long) (arg4);                                              \
+    long __arg5 = (long) (arg5);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
-    register long __r6 __asm__("r6") = (long)(arg2);                          \
-    register long __r7 __asm__("r7") = (long)(arg3);                          \
-    register long __r8 __asm__("r8") = (long)(arg4);                          \
-    register long __r9 __asm__("r9") = (long)(arg5);                          \
+    register long __r5 __asm__("r5") = __arg1;                                \
+    register long __r6 __asm__("r6") = __arg2;                                \
+    register long __r7 __asm__("r7") = __arg3;                                \
+    register long __r8 __asm__("r8") = __arg4;                                \
+    register long __r9 __asm__("r9") = __arg5;                                \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r9), "r"(__r12)      \
@@ -288,14 +303,20 @@  SYSCALL_ERROR_LABEL_DCL:                            \
 
 # define inline_syscall6(name,arg1,arg2,arg3,arg4,arg5,arg6)                  \
   ({                                                                          \
+    long __arg1 = (long) (arg1);                                              \
+    long __arg2 = (long) (arg2);                                              \
+    long __arg3 = (long) (arg3);                                              \
+    long __arg4 = (long) (arg4);                                              \
+    long __arg5 = (long) (arg5);                                              \
+    long __arg6 = (long) (arg6);                                              \
     register long __ret __asm__("r3");                                        \
     register long __r12 __asm__("r12") = name;                                \
-    register long __r5 __asm__("r5") = (long)(arg1);                          \
-    register long __r6 __asm__("r6") = (long)(arg2);                          \
-    register long __r7 __asm__("r7") = (long)(arg3);                          \
-    register long __r8 __asm__("r8") = (long)(arg4);                          \
-    register long __r9 __asm__("r9") = (long)(arg5);                          \
-    register long __r10 __asm__("r10") = (long)(arg6);                        \
+    register long __r5 __asm__("r5") = __arg1;                                \
+    register long __r6 __asm__("r6") = __arg2;                                \
+    register long __r7 __asm__("r7") = __arg3;                                \
+    register long __r8 __asm__("r8") = __arg4;                                \
+    register long __r9 __asm__("r9") = __arg5;                                \
+    register long __r10 __asm__("r10") = __arg6;                              \
     __asm__ __volatile__( "brki r14,8; nop;"                                  \
       : "=r"(__ret)                                                           \
       : "r"(__r5), "r"(__r6), "r"(__r7), "r"(__r8),"r"(__r9), "r"(__r10),     \