[m-dev.] for review: enforce library self-containedness

Fergus Henderson fjh at cs.mu.OZ.AU
Tue Feb 6 22:55:00 AEDT 2001


Estimated hours taken: 2

On platforms which support it, check that there are no undefined
symbols when linking the Mercury shared libraries. 
Some platforms (AIX, Windows, and BeOS) require this when building
shared libraries.  This change means that we check it on our usual
platforms, including Linux.

configure.in:
	Set ERROR_UNDEFINED to `-Wl,--no-undefined' on x86 Linux.
	Using --no-undefined on Linux requires linking in ld-linux.so,
	so add some code to figure out the right version of that to
	link with.

Mmake.common.in:
	Set ALLOW_UNDEFINED and ERROR_UNDEFINED to the values
	determined by configure.in.  Also pass down the values of
	SOCKET_LIBRARY, NSL_LIBRARY, and DL_LIBRARY, since we need
	to link with those libraries to resolve all the undefined
	symbols.

runtime/Mmakefile:
library/Mmakefile:
browser/Mmakefile:
trace/Mmakefile:
	Pass $(ERROR_UNDEFINED) to $(LINK_SHARED_OBJ).

browser/Mmakefile:
trace/Mmakefile:
	Link in SOCKET_LIBRARY, NSL_LIBRARY, and DL_LIBRARY.

Workspace: /home/venus/fjh/ws-venus2/mercury
Index: Mmake.common.in
===================================================================
RCS file: /home/mercury1/repository/mercury/Mmake.common.in,v
retrieving revision 1.50
diff -u -d -r1.50 Mmake.common.in
--- Mmake.common.in	2001/01/19 04:04:19	1.50
+++ Mmake.common.in	2001/02/06 11:47:49
@@ -80,6 +80,11 @@
 # ${SO_LOCATIONS_DIR} rather than $(SO_LOCATIONS_DIR).
 LINK_SHARED_OBJ_SH  	= @LINK_SHARED_OBJ_SH@
 
+# The following variables specify options to $LINK_SHARED_OBJ to
+# allow/disallow unresolved symbols when building shared libraries.
+ALLOW_UNDEFINED	= @ALLOW_UNDEFINED@
+ERROR_UNDEFINED	= @ERROR_UNDEFINED@
+
 # 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.
@@ -102,8 +107,6 @@
 # objects.
 SHARED_LIBS		= @SHARED_LIBS@
 
-# You should not need to modify anything below here
-
 #-----------------------------------------------------------------------------#
 
 INSTALL_MERC_GC_LIB_DIR	= $(INSTALL_MERC_GRADELESS_LIB_DIR)
@@ -199,6 +202,13 @@
 # The linker option to use to link in the math library, if any.
 # Typically `-lm'.
 MATH_LIB=@MATH_LIB@
+
+# More libraries to link
+SOCKET_LIBRARY=@SOCKET_LIBRARY@
+NSL_LIBRARY=@NSL_LIBRARY@
+DL_LIBRARY=@DL_LIBRARY@
+READLINE_LIBRARIES=@READLINE_LIBRARIES@
+TERMCAP_LIBRARY=@TERMCAP_LIBRARY@
 
 # Extensions to use
 O=@OBJ_SUFFIX@
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.243
diff -u -d -r1.243 configure.in
--- configure.in	2001/01/22 04:41:54	1.243
+++ configure.in	2001/02/06 11:21:06
@@ -2251,13 +2251,28 @@
 case "$host" in
 	i?86-*-linux|i?86-*-linux-gnu)
 		case $ac_cv_prog_gcc in
-			yes)
-				AC_MSG_RESULT(yes)
-				EXT_FOR_SHARED_LIB=so
+		yes)
+			AC_MSG_RESULT(yes)
+			EXT_FOR_SHARED_LIB=so
+			AC_MSG_CHECKING(for ld-linux.so)
+			echo "int main(void) { return 0; }" > conftest.c
+			$CC -o conftest conftest.c
+			ld_linux=`ldd ./conftest | awk '/ld-linux/{print $1;}'`
+			case $ld_linux in /lib/ld-linux.so*)
+				AC_MSG_RESULT($ld_linux)
+				ERROR_UNDEFINED="-Wl,--no-undefined"
+				SHARED_LIBS="$SHARED_LIBS $ld_linux"
+				SHARED_LIBS_SH="$SHARED_LIBS_SH $ld_linux"
 				;;
 			*)
 				AC_MSG_RESULT(no)
 				;;
+			esac
+			rm -f conftest*
+			;;
+		*)
+			AC_MSG_RESULT(no)
+			;;
 		esac
 		;;
 	m68*-linux|m68*-linux-gnu)
Index: browser/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/browser/Mmakefile,v
retrieving revision 1.13
diff -u -d -r1.13 Mmakefile
--- browser/Mmakefile	2001/01/29 06:47:12	1.13
+++ browser/Mmakefile	2001/02/06 11:50:11
@@ -143,10 +143,13 @@
 RPATH_2=$(SHLIB_RPATH_SEP)$(FINAL_INSTALL_MERC_GC_LIB_DIR)
 
 lib$(BROWSER_LIB_NAME).so : $(mdb.pic_os)
-	$(LINK_SHARED_OBJ) -o lib$(BROWSER_LIB_NAME).so \
-		$(mdb.pic_os)				\
+	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
+		-o lib$(BROWSER_LIB_NAME).so				\
+		$(mdb.pic_os)						\
 		$(RPATH_1)$(RPATH_2)					\
 		$(LDFLAGS) $(LDLIBS)					\
+		$(SOCKET_LIBRARY) $(NSL_LIBRARY) $(DL_LIBRARY)		\
+		$(READLINE_LIBRARIES)					\
 		$(SHARED_LIBS)
 
 $(BROWSER_LIB_NAME).init: $(deps_subdir)mdb.dep mdb.init
Index: library/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/library/Mmakefile,v
retrieving revision 1.56
diff -u -d -r1.56 Mmakefile
--- library/Mmakefile	2001/01/29 06:47:28	1.56
+++ library/Mmakefile	2001/02/06 11:23:51
@@ -274,7 +274,8 @@
 RPATH_2=$(SHLIB_RPATH_SEP)$(FINAL_INSTALL_MERC_GC_LIB_DIR)
 
 lib$(STD_LIB_NAME).so : $(library.pic_os)
-	$(LINK_SHARED_OBJ) -o lib$(STD_LIB_NAME).so $(library.pic_os)	\
+	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED) 				\
+		-o lib$(STD_LIB_NAME).so $(library.pic_os)		\
 		$(RPATH_1)$(RPATH_2)					\
 		$(ALL_LDFLAGS) $(ALL_LDLIBS)				\
 		$(SHARED_LIBS)
Index: runtime/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/runtime/Mmakefile,v
retrieving revision 1.67
diff -u -d -r1.67 Mmakefile
--- runtime/Mmakefile	2001/01/15 03:14:40	1.67
+++ runtime/Mmakefile	2001/02/06 11:21:40
@@ -238,7 +238,8 @@
 	$(RANLIB) lib$(RT_LIB_NAME)$(DLL_DEF_LIB).$A
 
 lib$(RT_LIB_NAME).so: $(PIC_OBJS)
-	$(LINK_SHARED_OBJ) -o lib$(RT_LIB_NAME).so $(PIC_OBJS)		\
+	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
+		-o lib$(RT_LIB_NAME).so $(PIC_OBJS)			\
 		$(SHLIB_RPATH_OPT)$(FINAL_INSTALL_MERC_GC_LIB_DIR)	\
 		$(LDFLAGS) $(LDLIBS) $(THREADLIBS)			\
 		$(SHARED_LIBS)
Index: trace/Mmakefile
===================================================================
RCS file: /home/mercury1/repository/mercury/trace/Mmakefile,v
retrieving revision 1.18
diff -u -d -r1.18 Mmakefile
--- trace/Mmakefile	2000/08/17 05:31:11	1.18
+++ trace/Mmakefile	2001/02/06 11:49:52
@@ -85,7 +85,9 @@
 		    *.gc*.prof*)	echo "-lgc_prof" ;;		\
 		    *.gc*)		echo "-lgc" ;;			\
 		  esac							\
-		`
+		` 							\
+		$(SOCKET_LIBRARY) $(NSL_LIBRARY) $(DL_LIBRARY)		\
+		$(READLINE_LIBRARIES)
 THREADLIBS	= \
 		` case "$(GRADE)" in					\
 		    *.par*) echo "-lpthread" ;;				\
@@ -132,7 +134,8 @@
 	$(RANLIB) lib$(TRACE_LIB_NAME)$(DLL_DEF_LIB).$A
 
 lib$(TRACE_LIB_NAME).so: $(PIC_OBJS)
-	$(LINK_SHARED_OBJ) -o lib$(TRACE_LIB_NAME).so $(PIC_OBJS)	\
+	$(LINK_SHARED_OBJ) $(ERROR_UNDEFINED)				\
+		-o lib$(TRACE_LIB_NAME).so $(PIC_OBJS)			\
 		$(SHLIB_RPATH_OPT)$(FINAL_INSTALL_MERC_GC_LIB_DIR)	\
 		$(LDFLAGS) $(LDLIBS) $(THREADLIBS)			\
 		$(SHARED_LIBS)
-- 
Fergus Henderson <fjh at cs.mu.oz.au>  |  "I have always known that the pursuit
                                    |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list