[vlc-devel] [PATCH] contrib: pthreads: Fix building with llvm-mingw

Martin Storsjö martin at martin.st
Wed Feb 21 12:58:27 CET 2018


This avoids doing things with dlltool that llvm-dlltool doesn't
implement.

I don't see the need of running a second pass with dlltool to
produce an output def file and yet another pass to produce
an import library out of it; just make the linker output the
import library while linking the dll. (If the import library is
to be used by MSVC, there is a point in generating it with dlltool
instead of with ld though. Even then, there's no point in generating
the def file using dlltool though, when it could just be generated by
the linker.)

Remove an inline declaration on a function that can't be inline-only
(static inline).

For non-static inline functions in C, the compiler can choose to
use the inline function itself, or assume that a definition exists
in a different translation unit. In this case, clang seems to
not inline ptw32_cond_check_need_init and creates an undefined
reference to the same function that should be defined in another
translation unit (which doesn't exist).

See https://www.greenend.org.uk/rjk/tech/inline.html for more details
on this.
---
 contrib/src/pthreads/implib.patch        | 33 ++++++++++++++++++++++++++++++++
 contrib/src/pthreads/remove-inline.patch | 12 ++++++++++++
 contrib/src/pthreads/rules.mak           |  2 ++
 3 files changed, 47 insertions(+)
 create mode 100644 contrib/src/pthreads/implib.patch
 create mode 100644 contrib/src/pthreads/remove-inline.patch

diff --git a/contrib/src/pthreads/implib.patch b/contrib/src/pthreads/implib.patch
new file mode 100644
index 0000000..01ad44b
--- /dev/null
+++ b/contrib/src/pthreads/implib.patch
@@ -0,0 +1,33 @@
+diff -urN pthreads-orig/GNUmakefile pthreads/GNUmakefile
+--- pthreads-orig/GNUmakefile	2018-01-05 21:45:34.478551838 +0000
++++ pthreads/GNUmakefile	2018-01-05 21:51:37.918541470 +0000
+@@ -523,25 +523,17 @@
+ 
+ 
+ $(GC_DLL) $(GCD_DLL): $(DLL_OBJS)
+-	$(CC) $(OPT) -shared -o $(GC_DLL) $(DLL_OBJS) $(LFLAGS)
+-	$(DLLTOOL) -z pthread.def $(DLL_OBJS)
+-	$(DLLTOOL) -k --dllname $@ --output-lib $(GC_LIB) --def $(PTHREAD_DEF)
++	$(CC) $(OPT) -shared -o $(GC_DLL) -Wl,--out-implib,$(GC_LIB) $(DLL_OBJS) $(LFLAGS)
+ 
+ $(GCE_DLL): $(DLL_OBJS)
+-	$(CC) $(OPT) -mthreads -shared -o $(GCE_DLL) $(DLL_OBJS) $(LFLAGS)
+-	$(DLLTOOL) -z pthread.def $(DLL_OBJS)
+-	$(DLLTOOL) -k --dllname $@ --output-lib $(GCE_LIB) --def $(PTHREAD_DEF)
++	$(CC) $(OPT) -mthreads -shared -o $(GCE_DLL) -Wl,--out-implib,$(GCE_LIB) $(DLL_OBJS) $(LFLAGS)
+ 
+ $(GC_INLINED_STAMP) $(GCD_INLINED_STAMP): $(DLL_INLINED_OBJS)
+-	$(CC) $(OPT) $(XOPT) -shared -o $(GC_DLL) $(DLL_INLINED_OBJS) $(LFLAGS)
+-	$(DLLTOOL) -z pthread.def $(DLL_INLINED_OBJS)
+-	$(DLLTOOL) -k --dllname $(GC_DLL) --output-lib $(GC_LIB) --def $(PTHREAD_DEF)
++	$(CC) $(OPT) $(XOPT) -shared -o $(GC_DLL) -Wl,--out-implib,$(GC_LIB) $(DLL_INLINED_OBJS) $(LFLAGS)
+ 	echo touched > $(GC_INLINED_STAMP)
+ 
+ $(GCE_INLINED_STAMP) $(GCED_INLINED_STAMP): $(DLL_INLINED_OBJS)
+-	$(CC) $(OPT) $(XOPT) -mthreads -shared -o $(GCE_DLL) $(DLL_INLINED_OBJS)  $(LFLAGS)
+-	$(DLLTOOL) -z pthread.def $(DLL_INLINED_OBJS)
+-	$(DLLTOOL) -k --dllname $(GCE_DLL) --output-lib $(GCE_LIB) --def $(PTHREAD_DEF)
++	$(CC) $(OPT) $(XOPT) -mthreads -shared -o $(GCE_DLL) -Wl,--out-implib,$(GCE_LIB) $(DLL_INLINED_OBJS)  $(LFLAGS)
+ 	echo touched > $(GCE_INLINED_STAMP)
+ 
+ $(GC_STATIC_STAMP) $(GCD_STATIC_STAMP): $(DLL_INLINED_OBJS)
diff --git a/contrib/src/pthreads/remove-inline.patch b/contrib/src/pthreads/remove-inline.patch
new file mode 100644
index 0000000..ef21bde
--- /dev/null
+++ b/contrib/src/pthreads/remove-inline.patch
@@ -0,0 +1,12 @@
+diff -urN pthreads-orig/ptw32_spinlock_check_need_init.c pthreads/ptw32_spinlock_check_need_init.c
+--- pthreads-orig/ptw32_spinlock_check_need_init.c	2011-03-10 13:40:17.000000000 +0000
++++ pthreads/ptw32_spinlock_check_need_init.c	2018-01-06 07:22:18.399696662 +0000
+@@ -38,7 +38,7 @@
+ #include "implement.h"
+ 
+ 
+-INLINE int
++int
+ ptw32_spinlock_check_need_init (pthread_spinlock_t * lock)
+ {
+   int result = 0;
diff --git a/contrib/src/pthreads/rules.mak b/contrib/src/pthreads/rules.mak
index 9c1a03db..8aeaf90 100644
--- a/contrib/src/pthreads/rules.mak
+++ b/contrib/src/pthreads/rules.mak
@@ -19,6 +19,8 @@ pthreads: pthreads-w32-$(PTHREADS_W32_VERSION)-release.tar.gz .sum-pthreads
 ifdef HAVE_WINSTORE
 	$(APPLY) $(SRC)/pthreads/winrt.patch
 endif
+	$(APPLY) $(SRC)/pthreads/implib.patch
+	$(APPLY) $(SRC)/pthreads/remove-inline.patch
 	$(MOVE)
 
 ifdef HAVE_CROSS_COMPILE
-- 
2.7.4



More information about the vlc-devel mailing list