From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received-SPF: Pass (sender SPF authorized) identity=mailfrom; client-ip=192.55.52.88; helo=mga01.intel.com; envelope-from=ruiyu.ni@intel.com; receiver=edk2-devel@lists.01.org Received: from mga01.intel.com (mga01.intel.com [192.55.52.88]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ml01.01.org (Postfix) with ESMTPS id 353BA21163248 for ; Tue, 6 Nov 2018 20:02:26 -0800 (PST) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga006.fm.intel.com ([10.253.24.20]) by fmsmga101.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 06 Nov 2018 20:02:26 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,474,1534834800"; d="scan'208";a="278956797" Received: from ray-dev.ccr.corp.intel.com ([10.239.9.11]) by fmsmga006.fm.intel.com with ESMTP; 06 Nov 2018 20:02:25 -0800 From: Ruiyu Ni To: edk2-devel@lists.01.org Cc: Liming Gao , Michael Kinney , Laszlo Ersek , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= Date: Wed, 7 Nov 2018 12:03:46 +0800 Message-Id: <20181107040346.153720-1-ruiyu.ni@intel.com> X-Mailer: git-send-email 2.16.1.windows.1 MIME-Version: 1.0 Subject: [PATCH] MdePkg/BaseSynchronizationLib XCODE: fix InternalSync[De|In]crement X-BeenThere: edk2-devel@lists.01.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: EDK II Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 07 Nov 2018 04:02:27 -0000 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Cc: Liming Gao Cc: Michael Kinney Cc: Laszlo Ersek Cc: Philippe Mathieu-Daudé --- 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