Commit 8ceae50d authored by Martin Storsjö's avatar Martin Storsjö

contrib: pthreads: Backport a winpthreads patch to fix building for armv7/aarch64

parent df739c3e
From 43a3c0bdb1f9e31db1d096d67aed0d575b6e2093 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Martin=20Storsj=C3=B6?= <martin@martin.st>
Date: Fri, 4 May 2018 12:05:20 +0300
Subject: [PATCH] winpthreads: Fix building for ARM and ARM64
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
The libgcc stubs aren't necessary if building this when using
compiler-rt, after those stubs are available.
Just make the fake libgcc assembly file a no-op if targeting another
architecture.
Signed-off-by: Martin Storsjö <martin@martin.st>
---
mingw-w64-libraries/winpthreads/src/libgcc/dll_dependency.S | 2 ++
mingw-w64-libraries/winpthreads/src/spinlock.c | 6 ++++++
mingw-w64-libraries/winpthreads/src/thread.c | 6 +++++-
3 files changed, 13 insertions(+), 1 deletion(-)
diff --git a/mingw-w64-libraries/winpthreads/src/libgcc/dll_dependency.S b/mingw-w64-libraries/winpthreads/src/libgcc/dll_dependency.S
index 2262eb0..0496e94 100644
--- a/mingw-w64-libraries/winpthreads/src/libgcc/dll_dependency.S
+++ b/mingw-w64-libraries/winpthreads/src/libgcc/dll_dependency.S
@@ -1,4 +1,5 @@
/* Implementation for gcc's internal stack-allocation routines. */
+#if defined(__i386__) || defined(__x86_64__)
.global ___chkstk
.global __alloca
@@ -86,3 +87,4 @@ chkstk_end:
pushl 4(%eax)
ret
#endif
+#endif
diff --git a/mingw-w64-libraries/winpthreads/src/spinlock.c b/mingw-w64-libraries/winpthreads/src/spinlock.c
index e55e929..2032d60 100644
--- a/mingw-w64-libraries/winpthreads/src/spinlock.c
+++ b/mingw-w64-libraries/winpthreads/src/spinlock.c
@@ -53,7 +53,13 @@ pthread_spin_lock (pthread_spinlock_t *lock)
volatile spinlock_word_t *lk = (volatile spinlock_word_t *)lock;
while (unlikely(__sync_lock_test_and_set(lk, 0) == 0))
do {
+#if defined(__i386__) || defined(__x86_64__)
asm("pause" ::: "memory");
+#elif defined(__arm__) || defined(__aarch64__)
+ asm("wfe" ::: "memory");
+#else
+#error Unsupported architecture
+#endif
} while (*lk == 0);
return 0;
}
diff --git a/mingw-w64-libraries/winpthreads/src/thread.c b/mingw-w64-libraries/winpthreads/src/thread.c
index fafd915..2b7c7be 100644
--- a/mingw-w64-libraries/winpthreads/src/thread.c
+++ b/mingw-w64-libraries/winpthreads/src/thread.c
@@ -1237,8 +1237,12 @@ pthread_cancel (pthread_t t)
GetThreadContext(tv->h, &ctxt);
#ifdef _M_X64
ctxt.Rip = (uintptr_t) _pthread_invoke_cancel;
-#else
+#elif defined(_M_IX86)
ctxt.Eip = (uintptr_t) _pthread_invoke_cancel;
+#elif defined(_M_ARM) || defined(_M_ARM64)
+ ctxt.Pc = (uintptr_t) _pthread_invoke_cancel;
+#else
+#error Unsupported architecture
#endif
SetThreadContext (tv->h, &ctxt);
--
2.7.4
......@@ -14,6 +14,7 @@ $(TARBALLS)/mingw-w64-v$(WINPTHREADS_VERSION).tar.bz2:
pthreads: mingw-w64-v$(WINPTHREADS_VERSION).tar.bz2 .sum-pthreads
$(UNPACK)
$(APPLY) $(SRC)/pthreads/0001-winpthreads-Fix-building-for-ARM-and-ARM64.patch
$(MOVE)
.pthreads: pthreads
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment