[m-rev.] for review: Link thread library to libpar_gc.

Peter Wang novalazy at gmail.com
Tue Feb 19 16:56:36 AEDT 2013


On Linux (and others) the threaded copy of Boehm GC that we build,
libpar_gc.so, inadvertently did not link to the POSIX thread library.
When producing an executable we link with both libpar_gc and libpthread
but recent versions of gcc/GNU ld have different default behaviour,
such that pthread symbol references in libpar_gc will NOT be resolved by
passing -lpthread at the executable linking step.  libpar_gc itself
needs to be linked to libpthread.  The error message looks like:

	/usr/bin/ld: test: hidden symbol `pthread_atfork' in
	/usr/lib/i386-linux-gnu/libpthread_nonshared.a(pthread_atfork.oS)
	is referenced by DSO

(Another workaround I found was to use the gcc -pthread option instead
of linking using -lpthread.  I don't know why that works.)

boehm_gc/Makefile.direct:
	Make the Mercury project-specific rule that builds libpar_gc.so
	link with $THREAD_LIBS that was set by configure.

	Add a comment about NOT using the threadlibs.c helper program.

diff --git a/boehm_gc/Makefile.direct b/boehm_gc/Makefile.direct
index 0da285d..a02f99c 100644
--- a/boehm_gc/Makefile.direct
+++ b/boehm_gc/Makefile.direct
@@ -94,6 +94,7 @@ CFLAGS= -I$(srcdir)/include -I$(AO_INSTALL_DIR)/include \
 
 ifeq ($(findstring par,$(GRADE)),par)
 CFLAGS += $(BOEHM_CFLAGS_FOR_THREADS)
+MAYBE_THREAD_LIBS = $(THREAD_LIBS)
 endif
 
 # If we are in the gcd grade then don't define -DNO_DEBUGGING
@@ -109,6 +110,8 @@ endif
 # Note that HOSTCFLAGS should include any -D flags that affect thread support.
 #
 # Mercury-specific: we set HOSTCC in Mmake.common
+# CFLAGS_FOR_THREADS is NOT expanded into HOSTCFLAGS but that only affects
+# threadlibs.c; we use our THREAD_LIBS variable instead.
 ifndef HOSTCC
 HOSTCC=$(CC)
 endif
@@ -354,10 +357,11 @@ lib$(GC_GRADE).so: $(OBJS) $(UTILS) # dyn_load_sunos53.o
 	./if_mach SPARC SOLARIS $(MAKE) dyn_load_sunos53.o
 	./if_mach SPARC SOLARIS \
 	$(LINK_SHARED_OBJ) -o lib$(GC_GRADE).so $(OBJS) dyn_load_sunos53.o \
-		-ldl `./threadlibs`
+		-ldl $(MAYBE_THREAD_LIBS)
 	./if_not_there on_sparc_sunos5_so $(MAKE) dyn_load.o
 	./if_not_there on_sparc_sunos5_so \
-	$(LINK_SHARED_OBJ) -o lib$(GC_GRADE).so $(OBJS) dyn_load.o -lc
+	$(LINK_SHARED_OBJ) -o lib$(GC_GRADE).so $(OBJS) dyn_load.o \
+		-lc $(MAYBE_THREAD_LIBS)
 
 # Darwin shared library version of the gc.
 lib$(GC_GRADE).dylib: $(OBJS) $(UTILS)




More information about the reviews mailing list