aboutsummaryrefslogtreecommitdiffstats
path: root/main/musl/0007-fix-missing-earlyclobber-flag-in-i386-a_ctz_64-asm.patch
blob: b72fc04a384605f87a77e7408bfc4b3b4a89e7a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
From 878887c50cccd45b5cabe6ed2ac743941f3417ea Mon Sep 17 00:00:00 2001
From: Rich Felker <dalias@aerifal.cx>
Date: Wed, 9 Sep 2015 07:18:28 +0000
Subject: [PATCH] fix missing earlyclobber flag in i386 a_ctz_64 asm

this error was only found by reading the code, but it seems to have
been causing gcc to produce wrong code in malloc: the same register
was used for the output and the high word of the input. in principle
this could have caused an infinite loop searching for an available
bin, but in practice most x86 models seem to implement the "undefined"
result of the bsf instruction as "unchanged".
---
 arch/i386/atomic.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/i386/atomic.h b/arch/i386/atomic.h
index 25441df..fd222ea 100644
--- a/arch/i386/atomic.h
+++ b/arch/i386/atomic.h
@@ -7,7 +7,7 @@ static inline int a_ctz_64(uint64_t x)
 {
 	int r;
 	__asm__( "bsf %1,%0 ; jnz 1f ; bsf %2,%0 ; addl $32,%0\n1:"
-		: "=r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
+		: "=&r"(r) : "r"((unsigned)x), "r"((unsigned)(x>>32)) );
 	return r;
 }
 
-- 
2.5.1