[m-dev.] for review: report undef symbols for shared libs

Fergus Henderson fjh at cs.mu.OZ.AU
Fri Apr 23 02:47:29 AEST 1999


Estimated hours taken: 1.5

Ensure that `ml' by default reports errors about undefined symbols
when building shared libraries.  Add a new option `--allow-undefined'
to enable the previous, more permissive behaviour.

configure.in:
	Define new variables ALLOW_UNDEFINED and ERROR_UNDEFINED,
	which get set to the appropriate linker options for
	allowing/disallowing undefined symbol errors when building
	shared libraries.
	
scripts/ml.in:
	Add new option --allow-undefined.  When building shared libraries,
	pass either $ALLOW_UNDEFINED or $ERROR_UNDEFINED to the linker,
	depending on the setting of this new option.

Workspace: /home/mercury0/fjh/mercury-other
Index: configure.in
===================================================================
RCS file: /home/mercury1/repository/mercury/configure.in,v
retrieving revision 1.161
diff -u -r1.161 configure.in
--- configure.in	1999/04/16 06:03:59	1.161
+++ configure.in	1999/04/19 06:42:11
@@ -1695,6 +1695,10 @@
 EXT_FOR_PIC_OBJECTS=pic_o
 EXT_FOR_SHARED_LIB=a
 USE_DLLS=no
+# The following variables specify options to $LINK_SHARED_OBJ to
+# allow/disallow unresolved symbols when building shared libraries.
+ALLOW_UNDEFINED=""
+ERROR_UNDEFINED=""
 
 case "$host" in
 	i?86-*-linux|i?86-*-linux-gnu)
@@ -1720,6 +1724,7 @@
 		AC_MSG_RESULT(yes)
 		SHARED_LIBS="-lm -lc"	# don't link in libgcc.a
 		LINK_SHARED_OBJ="$CC -G"
+		ERROR_UNDEFINED="-Wl,-z,defs"
 		EXE_RPATH_OPT="-R"
 		EXE_RPATH_SEP=" -R"
 		SHLIB_RPATH_OPT="-R"
@@ -1744,7 +1749,8 @@
 		# does the fixups, it gets copied.  Hence the lack of
 		# runtime sharing.)  We need to link with `gcc -G'
 		# rather than `gcc -shared', because `gcc -shared'
-		# reports an error if any runtime fixups would be needed.
+		# passes `-z text' to the linker, which causes it to
+		# report an error if any runtime fixups would be needed.
 		#
 		# If you *do* use `-fpic', you must also use `-DPIC'.
 		#
@@ -1760,6 +1766,7 @@
 		AC_MSG_RESULT(yes)
 		LINK_SHARED_OBJ="gcc -shared \
 			-Wl,-O3,-update_registry,../so_locations"
+		ERROR_UNDEFINED="-Wl,-error_unresolved"
 		EXE_RPATH_OPT="-Wl,-rpath,"
 		EXE_RPATH_SEP=":"
 		SHLIB_RPATH_OPT="-Wl,-rpath,"
@@ -1771,7 +1778,8 @@
 		;;
 	mips-sgi-irix5.*)
 		LINK_SHARED_OBJ="ld -shared -update_registry ../so_locations\
-			-quickstart_info -rdata_shared -no_unresolved"
+			-quickstart_info -rdata_shared"
+		ERROR_UNDEFINED="-no_unresolved"
 		EXE_RPATH_OPT="-Wl,-rpath,"
 		EXE_RPATH_SEP=":"
 		SHLIB_RPATH_OPT="-rpath "
@@ -1837,6 +1845,8 @@
 #-----------------------------------------------------------------------------#
 
 AC_SUBST(LINK_SHARED_OBJ)
+AC_SUBST(ERROR_UNDEFINED)
+AC_SUBST(ALLOW_UNDEFINED)
 AC_SUBST(EXE_RPATH_OPT)
 AC_SUBST(EXE_RPATH_SEP)
 AC_SUBST(SHLIB_RPATH_OPT)
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.60
diff -u -r1.60 ml.in
--- ml.in	1999/04/06 18:27:27	1.60
+++ ml.in	1999/04/14 17:11:59
@@ -27,6 +27,14 @@
 	--no-demangle
 		Don't pipe the output of the linker through the Mercury
 		demangler.
+	--allow-undef
+	--allow-undefined
+		Don't report an error if there are unresolved symbols.
+		This option is only used if you are building a shared
+		library (with \`--make-shared-lib); when building
+		executables, unresolved symbols are always errors.
+		This option is useful when building shared libraries
+		that are not intended to be self-contained.
 
 Dynamic/static linking options:
 	--mercury-libs {shared, static, none}
@@ -97,6 +105,8 @@
 DEMANGLER=${MERCURY_DEMANGLER=mdemangle}
 CC=${MERCURY_C_COMPILER="@CC@"}
 MKFIFO=${MERCURY_MKFIFO="@MKFIFO@"}
+ERROR_UNDEFINED="@ERROR_UNDEFINED@"
+ALLOW_UNDEFINED="@ALLOW_UNDEFINED@"
 EXE_RPATH_OPT=${MERCURY_EXE_RPATH_OPT="@EXE_RPATH_OPT@"}
 EXE_RPATH_SEP=${MERCURY_EXE_RPATH_SEP="@EXE_RPATH_SEP@"}
 EXT_FOR_SHARED_LIB=${MERCURY_EXT_FOR_SHARED_LIB="@EXT_FOR_SHARED_LIB@"}
@@ -125,6 +135,7 @@
 BROWSER_LIB_NAME=mer_browser
 
 verbose=false
+allow_undefined=false
 trace=false
 readline=true
 case $FULLARCH in
@@ -161,6 +172,12 @@
 	--no-demangle)
 		demangle=false
 		;;
+	--allow-undef|--allow-undefined)
+		allow_undef=true
+		;;
+	--no-allow-undef|--no-allow-undefined)
+		allow_undef=false
+		;;
 	-t|--trace)
 		trace=true
 		;;
@@ -295,6 +312,7 @@
 esac
 
 # Defaults have been set, now set options.
+
 case $all_libs in static)
 	case $FULLARCH in
 		*-linux*)
@@ -419,12 +437,17 @@
 case $make_shared_lib in
     true)
 	LINKER="$LINK_SHARED_OBJ"
+	case $allow_undef in
+	    true)  UNDEF_OPT="$ALLOW_UNDEFINED" ;;
+	    false) UNDEF_OPT="$ERROR_UNDEFINED" ;;
+	esac
 	RPATH_OPT="$SHLIB_RPATH_OPT"
 	RPATH_SEP="$SHLIB_RPATH_SEP"
 	STDLIBS="$SHARED_LIBS $THREAD_LIBS"
 	;;
     false)
 	LINKER="$CC"
+	UNDEF_OPT=""
 	RPATH_OPT="$EXE_RPATH_OPT"
 	RPATH_SEP="$EXE_RPATH_SEP"
 	STDLIBS="-lm $THREAD_LIBS"
@@ -521,12 +544,12 @@
 	echo "ml: using grade \`$GRADE'"
 	case $demangle in
 	    false)
-		echo $LINKER $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS
+		echo $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
+			$ARCH_OPTS $LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS
 		;;
 	    true)
-		echo $LINKER $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
-			$LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS "|"
+		echo $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT \
+			$ARCH_OPTS $LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS "|"
 		echo "$DEMANGLER"
 		;;
 	esac
@@ -568,8 +591,8 @@
 	;;
 esac
 case $# in
-	0) exec $LINKER $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
+	0) exec $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
 		$LIBDIR_OPTS $RPATH_OPT_LIST $LIBS ;;
-	*) exec $LINKER $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
+	*) exec $LINKER $UNDEF_OPT $STRIP_OPTS $MAYBE_STATIC_OPT $ARCH_OPTS \
 		$LIBDIR_OPTS $RPATH_OPT_LIST "$@" $LIBS ;;
 esac

-- 
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.
--------------------------------------------------------------------------
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