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...@intel.com>
Cc: Liming Gao <liming....@intel.com>
Cc: Michael Kinney <michael.d.kin...@intel.com>
Cc: Laszlo Ersek <ler...@redhat.com>
Cc: Philippe Mathieu-Daudé <phi...@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

_______________________________________________
edk2-devel mailing list
edk2-devel@lists.01.org
https://lists.01.org/mailman/listinfo/edk2-devel

Reply via email to