for review: handle linking under x86 Linux

Tyson Dowd trd at stimpy.cs.mu.oz.au
Sun Feb 15 10:54:38 AEDT 1998


Hi,

DJ can you review this?

Here's a quick fix for the (troublesome) handling of linking
under x86 Linux. 

I'm still not entirely happy with this - unfortunately nothing
short of a complete product recall of all x86 machines would really
fix the whole situation.

===================================================================



Estimated hours taken: 0.5

Fix the handling of the default linking options (shared or static).

Under Linux, the default linkage is supposed to be static, but
only the linkage of the mercury libraries was being set, so
if you tried to link with another library, you needed to add
-static by hand.

Note that this will link in all other libraries (such as the C library)
statically as well. It's probably possible to do this change another
way so that you can have more selection about what is static and what
isn't.  This is just intended to remove errors when using it in
the "default" fashion.

scripts/ml.in:
	Set link flags after handling options, so the flags are
	only set in one place.
	Add default handling for -static and -shared, previously
	there were only defaults for --mercury-libs static/shared.

README.Linux:
	Document that you should use --shared, not just --mercury-libs
	shared, if you want to link statically against other libraries.


Index: README.Linux
===================================================================
RCS file: /home/mercury1/repository/mercury/README.Linux,v
retrieving revision 1.8
diff -u -r1.8 README.Linux
--- README.Linux	1998/02/11 03:54:06	1.8
+++ README.Linux	1998/02/13 12:45:57
@@ -32,7 +32,9 @@
 To use the shared libraries, you must compile your program with
 `mmc --pic-reg' and link with `ml --mercury-libs shared'
 or add `MGNUCFLAGS=--pic-reg' and `MLFLAGS=--mercury-libs shared'
-to your Mmake file.
+to your Mmake file.  If you are linking against Mercury
+libraries other than the standard library, replace `--mercury-libs shared'
+with `--shared'.
 
 Mercury code compiled with `--pic-reg' or with gcc's `-fpic' option has
 what we shall call "PIC linkage", whereas Mercury code compiled without
Index: scripts/ml.in
===================================================================
RCS file: /home/mercury1/repository/mercury/scripts/ml.in,v
retrieving revision 1.36
diff -u -r1.36 ml.in
--- ml.in	1997/12/05 15:58:30	1.36
+++ ml.in	1998/02/13 12:46:07
@@ -91,6 +91,7 @@
 		;;
 esac
 mercury_libs=default
+all_libs=default
 demangle=true
 MAYBE_STATIC_OPT=""
 make_shared_lib=false
@@ -152,26 +153,14 @@
 		esac
 		;;
 	-shared|--shared)
+		all_libs=shared
 		MAYBE_STATIC_OPT=""
 		case $mercury_libs in static|default)
 			mercury_libs=shared ;;
 		esac
 		;;
 	-static|--static)
-		case $FULLARCH in
-		    *-linux*)
-		    	# On Linux, if we're linking statically, we need to
-		    	# pass `-defsym _DYNAMIC=0' to the linker, to avoid
-		    	# undefined references to _DYNAMIC in
-		    	# boehm_gc/dyn_load.c.
-		    	# (We might eventually need similar treatment
-		    	# for other OSs too)
-			MAYBE_STATIC_OPT="-static -Wl,-defsym,_DYNAMIC=0"
-			;;
-		    *)
-			MAYBE_STATIC_OPT=-static
-			;;
-		esac
+		all_libs=static
 		case $mercury_libs in shared|default)
 			mercury_libs=static ;;
 		esac
@@ -198,6 +187,9 @@
     shift
 done
 
+# If you haven't set mercury_libs, set it to the default value
+# (shared on most systems). Note that if you have set all_libs,
+# it will also have set mercury_libs.
 case $mercury_libs in default)
 	mercury_libs=shared
 	case $FULLARCH in i?86-*-linux*)
@@ -211,6 +203,41 @@
 	esac
 	;;
 esac
+
+# If you haven't set all_libs, set it to the default value
+# (shared on most systems).
+case $all_libs in default)
+	all_libs=shared
+	case $FULLARCH in i?86-*-linux*)
+		# shared libraries are not the default on Linux
+		# -- see README.Linux
+		case $make_shared_lib in false)
+			all_libs=static
+			;;
+		esac
+		;;
+	esac
+	;;
+esac
+
+# Defaults have been set, now set options.
+case $all_libs in static)
+	case $FULLARCH in
+		*-linux*)
+			# On Linux, if we're linking statically, we need to
+			# pass `-defsym _DYNAMIC=0' to the linker, to avoid
+			# undefined references to _DYNAMIC in
+			# boehm_gc/dyn_load.c.
+			# (We might eventually need similar treatment
+			# for other OSs too)
+			MAYBE_STATIC_OPT="-static -Wl,-defsym,_DYNAMIC=0"
+			;;
+		*)
+			MAYBE_STATIC_OPT=-static
+			;;
+	esac
+esac
+
 
 #
 # compute the grade from the options settings




More information about the developers mailing list