diff: Linux shared libraries bug fix

Fergus Henderson fjh at hydra.cs.mu.oz.au
Mon Jun 16 23:32:45 AEST 1997


Fix a problem with shared libraries on Linux.
They weren't working because Linux requires the `-rpath' option
be specified when linking the shared libraries, as well as when
linking executables.  Previously we only passed `-rpath' option
when linking executables.

configure.in:
Mmake.common.in:
bindist/bindist.build_vars.in:
	Add new configuration variables for handling `-rpath' or `-R' options:
	EXE_RPATH_OPT, EXE_RPATH_SEP, SHLIB_RPATH_OPT, and SHLIB_RPATH_SEP.

scripts/ml.in:
	Rewrite the system-specific code for handling rpaths
	to instead use the new rpath configuration variables.

library/Mmakefile:
runtime/Mmakefile:
	When linking shared libraries that depend on other shared libraries,
	pass appropriate rpath options using the rpath configuration variables.

cvs diff: Diffing .
Index: Mmake.common.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/Mmake.common.in,v
retrieving revision 1.18
diff -u -u -5 -r1.18 Mmake.common.in
--- Mmake.common.in	1997/06/06 08:46:36	1.18
+++ Mmake.common.in	1997/06/16 12:51:00
@@ -77,10 +77,30 @@
 # LINK_SHARED_OBJ  	= gcc -assert nodefinitions
 #					# for SunOS 4 (completely untested)
 # LINK_SHARED_OBJ  	= gcc -shared	# for Solaris etc.
 LINK_SHARED_OBJ  	= @LINK_SHARED_OBJ@
 
+# The following variables specify how to pass options to the # $(CC) or
+# $(LINK_SHARED_OBJ) command to specify directories to be searched at
+# runtime for shared libraries.
+# Normally RPATH_OPT is either "-R" or "-rpath ", but you may need to
+# do something special to get the C compiler to pass this option on
+# to the linker (e.g. with gcc you can use "-Wl,-rpath,").
+# RPATH_SEP is a path separator; normally either ":"
+# or just RPATH_OPT with a space in front of it.
+# The SHLIB_ versions are used when linking shared libraries
+# (perhaps invoking ld directory, rather than gcc).
+# The EXE_ versions are used when linking executables.
+# The empty single quote pairs below are there to ensure that `make'
+# does not throw away any important trailing or leading whitespace.
+SHLIB_RPATH_OPT	= @SHLIB_RPATH_OPT@''
+SHLIB_RPATH_SEP	= ''@SHLIB_RPATH_SEP@''
+EXE_RPATH_OPT	= @EXE_RPATH_OPT@''
+EXE_RPATH_SEP	= ''@EXE_RPATH_SEP@''
+
+# Specify any extra libraries that must be linked in when linking shared
+# objects.
 SHARED_LIBS		= @SHARED_LIBS@
 
 # Set NUPROLOG to `nuprolog' and set INSTALL_NUPROLOG to `install_nuprolog'
 # if you have NU-Prolog and want use it for debugging Mercury programs.
 # Otherwise, leave them blank.
Index: configure.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/configure.in,v
retrieving revision 1.93
diff -u -u -5 -r1.93 configure.in
--- configure.in	1997/06/09 23:20:03	1.93
+++ configure.in	1997/06/16 12:55:27
@@ -1291,10 +1291,14 @@
 
 # set up some default values that should work on most systems
 # see Mmake.common.in for documentation on the meaning of these variables
 LINK_SHARED_OBJ="$CC -shared"
 SHARED_LIBS='`gcc -print-libgcc-file-name` -lm -lc'
+EXE_RPATH_OPT="-Wl,-rpath,"
+EXE_RPATH_SEP=" -Wl,-rpath,"
+SHLIB_RPATH_OPT="-Wl,-rpath,"
+SHLIB_RPATH_SEP=" -Wl,-rpath,"
 CFLAGS_FOR_PIC="-fpic -DPIC"
 EXT_FOR_PIC_OBJECTS=pic_o
 EXT_FOR_SHARED_LIB=a
 
 case "$host" in
@@ -1305,15 +1309,20 @@
 	i?86-*-freebsd*)
 		# From Cornelis van der Laan <nils at ims.uni-stuttgart.de>
 		AC_MSG_RESULT(yes)
 		LINK_SHARED_OBJ="ld -Bshareable"
 		EXT_FOR_SHARED_LIB=so
+		# XXX what about *_RPATH_*?
 		;;
 	sparc-sun-solaris2.*)
 		AC_MSG_RESULT(yes)
 		SHARED_LIBS="-lm -lc"	# don't link in libgcc.a
 		LINK_SHARED_OBJ="$CC -G"
+		EXE_RPATH_OPT="-R"
+		EXE_RPATH_SEP=" -R"
+		SHLIB_RPATH_OPT="-R"
+		SHLIB_RPATH_SEP=" -R"
 		CFLAGS_FOR_PIC="-fpic -DPIC"	# used only for libgc.{a,so}
 		EXT_FOR_PIC_OBJECTS=o
 		#
 		# Note that despite the above definition of CFLAGS_FOR_PIC,
 		# we don't use `-fpic' for shared libraries on Solaris
@@ -1345,18 +1354,26 @@
 		;;
 	alpha-dec-osf*)
 		AC_MSG_RESULT(yes)
 		LINK_SHARED_OBJ="ld -O3 -shared \
 			-update_registry ../so_locations"
+		EXE_RPATH_OPT="-Wl,-rpath,"
+		EXE_RPATH_SEP=":"
+		SHLIB_RPATH_OPT="-rpath "
+		SHLIB_RPATH_SEP=":"
 		EXT_FOR_SHARED_LIB=so
 		# -fpic not needed on Alpha/OSF, since it is the default
 		CFLAGS_FOR_PIC=
 		EXT_FOR_PIC_OBJECTS=o
 		;;
 	mips-sgi-irix5.*)
 		LINK_SHARED_OBJ="ld -shared -update_registry ../so_locations\
 			-quickstart_info -rdata_shared -no_unresolved"
+		EXE_RPATH_OPT="-rpath "
+		EXE_RPATH_SEP=":"
+		SHLIB_RPATH_OPT="-rpath "
+		SHLIB_RPATH_SEP=":"
 		# -fpic not needed on IRIX, since it is the default
 		CFLAGS_FOR_PIC=
 		EXT_FOR_PIC_OBJECTS=o
 		# shared libraries only work for reg.gc or none.gc
 		if test "$GRADE" = reg.gc || test "$GRADE" = none.gc; then
@@ -1388,10 +1405,14 @@
 		LIBRARY_RM_C=:
 		;;
 esac
 
 AC_SUBST(LINK_SHARED_OBJ)
+AC_SUBST(EXE_RPATH_OPT)
+AC_SUBST(EXE_RPATH_SEP)
+AC_SUBST(SHLIB_RPATH_OPT)
+AC_SUBST(SHLIB_RPATH_SEP)
 AC_SUBST(CFLAGS_FOR_PIC)
 AC_SUBST(EXT_FOR_PIC_OBJECTS)
 AC_SUBST(EXT_FOR_SHARED_LIB)
 AC_SUBST(SHARED_LIBS)
 AC_SUBST(LIBRARY_RM_C)
@@ -1416,8 +1437,15 @@
 # are no files in the list passed to chmod
 touch conftest.junk
 chmod a-w $CONFIG_FILES $CONFIG_HEADERS conftest.junk
 chmod +x `echo $CONFIG_FILES | sed -e 's/[^ ]*Mmake.common//' ` conftest.junk
 rm -f conftest.junk
+
+# The --prefix is hard-coded in the scripts, which are regenerated every
+# time you run configure, and also (unfortunately) in the .so files.
+# The following rm command is here to ensure that things will work correctly
+# if you rerun configure with a new --prefix and then don't do a `make clean'
+# before running `make'.
+rm -f runtime/libmer.so library/libmercury.so bytecode/libmbi.so
 )
 
 #-----------------------------------------------------------------------------#
cvs diff: Diffing bindist
Index: bindist/bindist.build_vars.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/bindist/bindist.build_vars.in,v
retrieving revision 1.4
diff -u -u -5 -r1.4 bindist.build_vars.in
--- bindist.build_vars.in	1996/12/13 02:37:45	1.4
+++ bindist.build_vars.in	1997/06/16 12:07:44
@@ -18,9 +18,13 @@
 BYTES_PER_WORD="@BYTES_PER_WORD@"
 LOW_TAG_BITS="@LOW_TAG_BITS@"
 CFLAGS_FOR_REGS="@CFLAGS_FOR_REGS@"
 CFLAGS_FOR_GOTOS="@CFLAGS_FOR_GOTOS@"
 LINK_SHARED_OBJ="@LINK_SHARED_OBJ@"
+EXE_RPATH_OPT="@EXE_RPATH_OPT@"
+EXE_RPATH_SEP="@EXE_RPATH_SEP@"
+SHLIB_RPATH_OPT="@SHLIB_RPATH_OPT@"
+SHLIB_RPATH_SEP="@SHLIB_RPATH_SEP@"
 EXT_FOR_PIC_OBJECTS="@EXT_FOR_PIC_OBJECTS@"
 EXT_FOR_SHARED_LIB="@EXT_FOR_SHARED_LIB@"
 CFLAGS_FOR_PIC="@CFLAGS_FOR_PIC@"
 HAVE_DELAY_SLOT="@HAVE_DELAY_SLOT@"
cvs diff: Diffing boehm_gc
cvs diff: Diffing boehm_gc/Mac_files
cvs diff: Diffing boehm_gc/cord
cvs diff: Diffing boehm_gc/cord/private
cvs diff: Diffing boehm_gc/include
cvs diff: Diffing boehm_gc/include/private
cvs diff: Diffing bytecode
cvs diff: Diffing compiler
cvs diff: Diffing compiler/notes
cvs diff: Diffing doc
cvs diff: Diffing library
Index: library/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/mercury/library/Mmakefile,v
retrieving revision 1.4
diff -u -u -5 -r1.4 Mmakefile
--- Mmakefile	1997/06/03 18:15:22	1.4
+++ Mmakefile	1997/06/16 12:10:41
@@ -135,18 +135,24 @@
 libmercury.a : $(library.os)
 	rm -f libmercury.a
 	ar cr libmercury.a $(library.os)
 	$(RANLIB) libmercury.a
 
+RPATH_1=$(SHLIB_RPATH_OPT)$(INSTALL_MERC_LIB_DIR)
+RPATH_2=$(SHLIB_RPATH_SEP)$(INSTALL_MERC_GC_LIB_DIR)
+
 libmercury.so : $(library.pic_os)
-	$(LINK_SHARED_OBJ) -o libmercury.so $(library.pic_os) \
-		-L$(RUNTIME_DIR) -lmer ` \
-		case "$(GRADE)" in \
-			*.gc.prof) echo "-L$(BOEHM_GC_DIR) -lgc_prof" ;; \
-			*.gc) echo "-L$(BOEHM_GC_DIR) -lgc" ;; \
-		esac \
-		` $(SHARED_LIBS)
+	$(LINK_SHARED_OBJ) -o libmercury.so $(library.pic_os)		\
+		$(RPATH_1)$(RPATH_2)					\
+		-L$(RUNTIME_DIR) -lmer 					\
+		-L$(BOEHM_GC_DIR)					\
+		` case "$(GRADE)" in					\
+			*.gc.prof) echo "-lgc_prof" ;;			\
+			*.gc) echo "-lgc" ;;				\
+		  esac							\
+		`							\
+		$(SHARED_LIBS)
 
 library.init: library.dep
 	for file in $(library.ms); do \
 		grep '^INIT ' $$file; \
 		echo "INIT mercury__`basename $$file .m`__init"; \
cvs diff: Diffing lp_solve
cvs diff: Diffing lp_solve/lp_examples
cvs diff: Diffing profiler
cvs diff: Diffing runtime
Index: runtime/Mmakefile
===================================================================
RCS file: /home/staff/zs/imp/mercury/runtime/Mmakefile,v
retrieving revision 1.5
diff -u -u -5 -r1.5 Mmakefile
--- Mmakefile	1997/05/30 15:33:34	1.5
+++ Mmakefile	1997/06/16 12:39:36
@@ -61,16 +61,19 @@
 	rm -f libmer.a
 	ar cr libmer.a $(OBJS)
 	$(RANLIB) libmer.a
 
 libmer.so: $(PIC_OBJS)
-	$(LINK_SHARED_OBJ) -o libmer.so $(PIC_OBJS) `\
-		case "$(GRADE)" in \
-			*.gc.prof) echo "-L$(BOEHM_GC_DIR) -lgc_prof" ;; \
-			*.gc) echo "-L$(BOEHM_GC_DIR) -lgc" ;; \
-		esac \
-		` $(SHARED_LIBS)
+	$(LINK_SHARED_OBJ) -o libmer.so $(PIC_OBJS)			\
+		$(SHLIB_RPATH_OPT)$(INSTALL_MERC_GC_LIB_DIR) 		\
+		-L$(BOEHM_GC_DIR)					\
+		` case "$(GRADE)" in 					\
+		    *.gc.prof)	echo "-lgc_prof" ;;			\
+		    *.gc)	echo "-lgc" ;;				\
+		  esac							\
+		`							\
+		$(SHARED_LIBS)
 
 runtime.init: $(MOD_CS)
 	cat `vpath_find $(MOD_CS)` | grep '^INIT ' > runtime.init
 
 conf.h.date: $(MERCURY_DIR)/config.status conf.h.in
cvs diff: Diffing runtime/machdeps
cvs diff: Diffing samples
cvs diff: Diffing samples/c_interface
cvs diff: Diffing samples/c_interface/c_calls_mercury
cvs diff: Diffing samples/c_interface/cplusplus_calls_mercury
cvs diff: Diffing samples/c_interface/mercury_calls_c
cvs diff: Diffing samples/c_interface/mercury_calls_cplusplus
cvs diff: Diffing samples/diff
cvs diff: Diffing scripts
Index: scripts/ml.in
===================================================================
RCS file: /home/staff/zs/imp/mercury/scripts/ml.in,v
retrieving revision 1.28
diff -u -u -5 -r1.28 ml.in
--- ml.in	1997/04/15 04:39:58	1.28
+++ ml.in	1997/06/16 12:59:26
@@ -54,10 +54,12 @@
 DEFAULT_GRADE=${MERCURY_DEFAULT_GRADE=@DEFAULT_GRADE@}
 # DEMANGLER=${MERCURY_DEMANGLER=@LIBDIR@/bin/@FULLARCH@/mdemangle}
 DEMANGLER=${MERCURY_DEMANGLER=mdemangle}
 CC=${MERCURY_C_COMPILER="@CC@"}
 MKFIFO=${MERCURY_MKFIFO="@MKFIFO@"}
+EXE_RPATH_SEP=${MERCURY_EXE_RPATH_SEP="@EXE_RPATH_SEP@"}
+EXE_RPATH_OPT=${MERCURY_EXE_RPATH_OPT="@EXE_RPATH_OPT@"}
 
 verbose=false
 case $FULLARCH in
 	*-win95|*-winnt|*-win32|*-cygwin32)
 		# `gcc -s' is broken in gnu-win32
@@ -187,61 +189,43 @@
 case $strip in
 	true)	STRIP_OPTS="-s" ;;
 	false)  STRIP_OPTS="" ;;
 esac
 
+LIBDIR_OPTS="
+	-L$LIBDIR/$GRADE/$FULLARCH
+	-L$LIBDIR/$FULLARCH
+"
 case $mercury_libs in
 	shared) LIBS=${MERCURY_LIBS="-lmercury -lmer $LIBGC -lm"}
+		RPATH_1="$EXE_RPATH_OPT$DEFAULT_LIBDIR/$GRADE/$FULLARCH"
+		RPATH_2="$EXE_RPATH_SEP$DEFAULT_LIBDIR/$FULLARCH"
+		LIBDIR_OPTS="$RPATH_1$RPATH_2 $LIBDIR_OPTS"
 		;;
 	static) LIBS=${MERCURY_LIBS="\
 			$LIBDIR/$GRADE/$FULLARCH/libmercury.a \
 			$LIBDIR/$GRADE/$FULLARCH/libmer.a \
 			$LIBGC_STATIC \
 			-lm"}
 		;;
 	none)	LIBS=""
+		LIBDIR_OPTS=""
 		;;
 esac
 
+# On Irix 5, grades `fast' and `jump' only work in non_shared mode.
 case $FULLARCH in
-	i?86-*-linux*)
-		LIBDIR_OPTS="
-		-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH -L$LIBDIR/$FULLARCH
-		-Wl,-rpath,$DEFAULT_LIBDIR/$GRADE/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
-		"
-		;;
-	*-solaris*)
-		LIBDIR_OPTS="
-		-R$DEFAULT_LIBDIR/$FULLARCH -L$LIBDIR/$FULLARCH
-		-R$DEFAULT_LIBDIR/$GRADE/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
-		"
-		;;
-	alpha-dec-osf*)
-		LIBDIR_OPTS="
-	-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH:$DEFAULT_LIBDIR/$GRADE/$FULLARCH
-		-L$LIBDIR/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
-		"
-		;;
-	*-sgi-irix5*)
-		LIBDIR_OPTS="
-	-Wl,-rpath,$DEFAULT_LIBDIR/$FULLARCH:$DEFAULT_LIBDIR/$GRADE/$FULLARCH
-		-L$LIBDIR/$FULLARCH -L$LIBDIR/$GRADE/$FULLARCH
-		"
-		case "$GRADE" in
-			*fast*|*jump*)
-				ARCH_OPTS=-non_shared
-LIBRARY_PATH="$NONSHARED_LIB_DIR:/usr/lib/nonshared:$LIBRARY_PATH"
-				export LIBRARY_PATH
-				;;
-		esac
-		;;
-	*)
-		LIBDIR_OPTS="
-		-L$LIBDIR/$FULLARCH
-		-L$LIBDIR/$GRADE/$FULLARCH
-		"
+    *-sgi-irix5*)
+	case "$GRADE" in
+	    *fast*|*jump*)
+		ARCH_OPTS=-non_shared
+		NONSHARED_PATH="$NONSHARED_LIB_DIR:/usr/lib/nonshared"
+		LIBRARY_PATH="$NONSHARED_PATH:$LIBRARY_PATH"
+		export LIBRARY_PATH
 		;;
+	esac
+	;;
 esac
 
 case "$MKFIFO" in
     none) demangle=false ;;
 esac
cvs diff: Diffing tests
cvs diff: Diffing tests/benchmarks
cvs diff: Diffing tests/general
cvs diff: Diffing tests/hard_coded
cvs diff: Diffing tests/invalid
cvs diff: Diffing tests/misc_tests
cvs diff: Diffing tests/valid
cvs diff: Diffing tests/warnings
cvs diff: Diffing tools
cvs diff: Diffing trial
cvs diff: Diffing util

-- 
Fergus Henderson <fjh at cs.mu.oz.au>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3         |     -- the last words of T. S. Garp.



More information about the developers mailing list