--
Best regards,
LIU Hao
From b3d95248f2f8bf2e5863671dbc00ff8dcf2b8aac Mon Sep 17 00:00:00 2001
From: LIU Hao
Date: Mon, 2 May 2022 19:53:55 +0800
Subject: [PATCH] winpthreads: Do not use `dllimport` when building 3rd-party
DLLs (V4)
Existent code that is linked against the winpthreads static library has
not been aware of `WINPTHREAD_STATIC` and attempts to import those
functions, such as libstdc++. Eventually we decide to do the opposite
to 2bf18054ca5206e1a64f2305a5ba07ab2661dd43. All winpthreads APIs are
now undecorated by default, unless `WINPTHREADS_USE_DLLIMPORT` is
defined which makes them `dllimport`. GCC is able to import functions
even without `dllimport` attributes.
Signed-off-by: LIU Hao
---
mingw-w64-libraries/winpthreads/README| 10 +-
mingw-w64-libraries/winpthreads/include/pthread.h | 15 +++
mingw-w64-libraries/winpthreads/include/sched.h | 13 ++---
.../winpthreads/include/semaphore.h | 13 ++---
4 files changed, 24 insertions(+), 27 deletions(-)
diff --git a/mingw-w64-libraries/winpthreads/README
b/mingw-w64-libraries/winpthreads/README
index 50d8dbe9b..55922f00f 100644
--- a/mingw-w64-libraries/winpthreads/README
+++ b/mingw-w64-libraries/winpthreads/README
@@ -3,8 +3,8 @@ The Winpthreads Library
This library provides POSIX threading APIs for mingw-w64.
-Programs are usually linked against the winpthreads DLL, and winpthreads
-headers expose `dllimport` APIs by default. When linking against the
-static library, especially when building a user DLL with libtool, it is
-necessary to define the `WINPTHREAD_STATIC` macro to avoid undefined
-references.
+For maximum compatibility, winpthreads headers expose APIs without the
+`dllimport` attribute by default. If your program is linked against the
+DLL, you may define the `WINPTHREADS_USE_DLLIMPORT` macro to add the
+`dllimport` attribute to all APIs, which makes function calls to them a
+bit more efficient.
diff --git a/mingw-w64-libraries/winpthreads/include/pthread.h
b/mingw-w64-libraries/winpthreads/include/pthread.h
index d17df3352..732e11a10 100644
--- a/mingw-w64-libraries/winpthreads/include/pthread.h
+++ b/mingw-w64-libraries/winpthreads/include/pthread.h
@@ -83,18 +83,17 @@ extern "C" {
/* MSB 8-bit major version, 8-bit minor version, 16-bit patch level. */
#define __WINPTHREADS_VERSION 0x0005
-#ifdef IN_WINPTHREAD
-# ifdef DLL_EXPORT
-#define WINPTHREAD_API __declspec(dllexport)
+#if defined(IN_WINPTHREAD)
+# if defined(DLL_EXPORT)
+#define WINPTHREAD_API __declspec(dllexport) /* building the DLL */
# else
-#define WINPTHREAD_API
+#define WINPTHREAD_API /* building the static library */
# endif
#else
-# ifdef WINPTHREAD_STATIC
-#define WINPTHREAD_API
+# if defined(WINPTHREADS_USE_DLLIMPORT)
+#define WINPTHREAD_API __declspec(dllimport) /* user wants explicit
`dllimport` */
# else
-#define WINPTHREAD_API __declspec(dllimport)
-# endif
+#define WINPTHREAD_API /* the default; auto imported in case of DLL */
#endif
/* #define WINPTHREAD_DBG 1 */
diff --git a/mingw-w64-libraries/winpthreads/include/sched.h
b/mingw-w64-libraries/winpthreads/include/sched.h
index 2f6ce7c49..8d0478413 100644
--- a/mingw-w64-libraries/winpthreads/include/sched.h
+++ b/mingw-w64-libraries/winpthreads/include/sched.h
@@ -49,18 +49,17 @@ struct sched_param {
extern "C" {
#endif
-#ifdef IN_WINPTHREAD
+#if defined(IN_WINPTHREAD)
# if defined(DLL_EXPORT) && !defined(WINPTHREAD_EXPORT_ALL_DEBUG)
-#define WINPTHREAD_SCHED_API __declspec(dllexport)
+#define WINPTHREAD_SCHED_API __declspec(dllexport) /* building the DLL
*/
# else
-#define WINPTHREAD_SCHED_API
+#define WINPTHREAD_SCHED_API /* building the static library */
# endif
#else
-# ifdef WINPTHREAD_STATIC
-#define WINPTHREAD_SCHED_API
+# if defined(WINPTHREADS_USE_DLLIMPORT)
+#define WINPTHREAD_SCHED_API __declspec(dllimport) /* user wants
explicit `dllimport` */
# else
-#define WINPTHREAD_SCHED_API __declspec(dllimport)
-# endif
+#define WINPTHREAD_SCHED_API /* the default; auto imported in case of DLL
*/
#endif
int WINPTHREAD_SCHED_API sched_yield(void);
diff --git a/mingw-w64-libraries/winpthreads/include/semaphore.h
b/mingw-w64-libraries/winpthreads/include/semaphore.h
index fb08d58d7..4d332e8b4 100644
--- a/mingw-w64-libraries/winpthreads/include/semaphore.h
+++ b/mingw-w64-libraries/winpthreads/include/semaphore.h
@@ -27,18 +27,17 @@
extern "C" {
#endif
-#ifdef IN_WINPTHREAD
+#if defined(IN_WINPTHREAD)
# if defined(DLL_EXPORT) && !defined(WINPTHREAD_EXPORT_ALL_DEBUG)
-#define WINPTHREAD_SEMA_API __declspec(dllexport)
+#define WINPTHREAD_SEMA_API __declspec(dllexport) /* building the DLL */
# else
-#define WINPTHREAD_SEMA_API
+#define WINPTHREAD_SEMA_API /* building the static library */
# endif
#else
-# ifdef WINPTHREAD_STATIC
-#define WINPTHREAD_SEMA_API
+#