public inbox for devel@edk2.groups.io
 help / color / mirror / Atom feed
* [PATCH] MdePkg/BaseSynchronizationLib XCODE: fix InternalSync[De|In]crement
@ 2018-11-07  4:03 Ruiyu Ni
  2018-11-07  8:46 ` Gao, Liming
  2018-11-07 14:31 ` Laszlo Ersek
  0 siblings, 2 replies; 9+ messages in thread
From: Ruiyu Ni @ 2018-11-07  4:03 UTC (permalink / raw)
  To: edk2-devel
  Cc: Liming Gao, Michael Kinney, Laszlo Ersek,
	Philippe Mathieu-Daudé

REF: https://bugzilla.tianocore.org/show_bug.cgi?id=1303

XCODE disassembly code of InternalSyncDecrement with today's code is:

  __asm__ __volatile__ (
    "movl    $1, %%eax  \n\t"
    "lock               \n\t"
    "xadd    %%eax, %1  \n\t"
    "inc     %%eax      \n\t"
    : "=a" (Result),          // %0
      "+m" (*Value)           // %1
    :                         // no inputs that aren't also outputs
    : "memory",
      "cc"
    );

 0:       55      pushl   %ebp
 1:       89 e5   movl    %esp, %ebp
 3:       8b 45 08        movl    8(%ebp), %eax
 6:       b8 01 00 00 00  movl    $1, %eax
 b:       f0      lock
 c:       0f c1 00        xaddl   %eax, _InternalSyncIncrement(%eax)
 f:       40      incl    %eax
10:       5d      popl    %ebp
11:       c3      retl

%EAX value retrieved in line #3 is overwritten in line #6.

The patch uses the clobber list to tell GCC that EAX is used in ASM.

Contributed-under: TianoCore Contribution Agreement 1.1
Signed-off-by: Ruiyu Ni <ruiyu.ni@intel.com>
Cc: Liming Gao <liming.gao@intel.com>
Cc: Michael Kinney <michael.d.kinney@intel.com>
Cc: Laszlo Ersek <lersek@redhat.com>
Cc: Philippe Mathieu-Daudé <philmd@redhat.com>
---
 MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
index af39bdeb51..0a985529fd 100644
--- a/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
+++ b/MdePkg/Library/BaseSynchronizationLib/Ia32/GccInline.c
@@ -40,11 +40,13 @@ InternalSyncIncrement (
     "lock               \n\t"
     "xadd    %%eax, %1  \n\t"
     "inc     %%eax      \n\t"
-    : "=a" (Result),          // %0
+    "mov     %%eax, %0  \n\t"
+    : "=r" (Result),          // %0
       "+m" (*Value)           // %1
     :                         // no inputs that aren't also outputs
     : "memory",
-      "cc"
+      "cc",
+      "eax"
     );
 
   return Result;
@@ -76,11 +78,13 @@ InternalSyncDecrement (
     "lock                \n\t"
     "xadd    %%eax, %1   \n\t"
     "dec     %%eax       \n\t"
-    : "=a" (Result),           // %0
+    "mov     %%eax, %0  \n\t"
+    : "=r" (Result),           // %0
       "+m" (*Value)            // %1
     :                          // no inputs that aren't also outputs
     : "memory",
-      "cc"
+      "cc",
+      "eax"
     );
 
   return Result;
-- 
2.16.1.windows.1



^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-11-07 19:02 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-11-07  4:03 [PATCH] MdePkg/BaseSynchronizationLib XCODE: fix InternalSync[De|In]crement Ruiyu Ni
2018-11-07  8:46 ` Gao, Liming
2018-11-07 14:31 ` Laszlo Ersek
2018-11-07 14:41   ` Laszlo Ersek
2018-11-07 14:57     ` Ni, Ruiyu
2018-11-07 14:45   ` Ard Biesheuvel
2018-11-07 15:27     ` Ni, Ruiyu
2018-11-07 19:02       ` Laszlo Ersek
2018-11-07 14:53   ` Ni, Ruiyu

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox