[m-rev.] For review: Shared Mercury libs on Mac OS X

Ian MacLarty maclarty at cs.mu.OZ.AU
Tue Oct 12 00:35:10 AEST 2004


On 10 Oct 2004, at 05:08, Julien Fischer wrote:

> > 	1. The -undefined_suppress linker option doesn't work with two level
> > 		namespaces which is the default on Darwin.  Is the
> > 		--allow-undefined ml option used?  If so should shared libs
> > 		rather use flat namespaces.  Alternatively the ALLOW_UNDEFINED
> > 		configuration variable can be set to "-undefined
> > 		dynamic_lookup", but that'll only work for Mac OS >= 10.3.  I
> > 		didn't get any undefined symbols when compiling the compiler.
> >
> At the moment we should probably just support versions >= 10.3.
> 
I guess, but everything seems to work okay without having to use "-undefined
dynamic_lookup", so I don't see the need to resort to this 10.3 specific
feature.  Currently everything should in theory still work on 10.2 and 10.1.

> You should probably an XXX somewhere to this log message that this change
> is not sufficient to get dynamic linking working on OS X (and consequently
> queries in the debugger still won't work).
> 
I've added the following to the log message:

This diff only fixes shared libraries on Darwin, not "bundles" which are shared
objects that can be loaded dynamically at runtime using the dlopen c function.
Therefore the interactive query tool in the debugger still doesn't work on Mac
OS X.

> > Added three new compiler options :
> >
> > --shlib-linker-use-install-name :
> > 	A boolean flag to tell the compiler to use the -install_name option
> > 	when building shared libraries.  When this flag is set the following
> > 	options have no effect: --linker-rpath-flag, --linker-rpath-separator,
> > 	--shlib-linker-rpath-flag, --shlib-linker-rpath-separator.
> >
> > --shlib-linker-install-name-flag :
> > 	The flag name to use ("-install_name" for Darwin).
> >
> > --shlib-linker-install-name-path :
> > 	The path where the shared library will eventually end up, excluding the
> > 	file name.  The file name is appended to the end before the option
> > 	is passed on to the linker.
> Do I need to provide these to the compiler or will mmake do it for me?
> 
mmake will do it all for you.

> >
> > Mmake.common.in
> > 	Added variables used for install-name on/off switch and flag name.
> >
> Do you need to make any changes to Mmake.workspace?
> 
I don't know.  tools/lmc seems to work, although it only seems to 
statically link in the mercury libraries.  --mercury-linkage may not be an
option lmc recognises.

> > configure.in
> > 	Make shared libs the default when on Darwin and the compiler is gcc.
> >
> Is there a way that I can use static linking if I really want it?
> 
Yes.  Specify "--mercury-linkage static" to mmc or add 
"EXTRA_MLFLAGS = --mercury-libs static" to the Mmakefile.

> It would have been better if you had not updated all the module
> qualifiers - it's quite difficult to see the relevant changes amidst
> all the syntax updates.
> 
Good point - here's the new diff:
Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.62
diff -u -r1.62 compile_target_code.m
--- compiler/compile_target_code.m	28 Sep 2004 01:59:00 -0000	1.62
+++ compiler/compile_target_code.m	11 Oct 2004 14:07:03 -0000
@@ -1222,7 +1222,10 @@
 		%
 		% Set up the runtime library path.
 		%
+		globals__io_lookup_bool_option(shlib_linker_use_install_name,
+			UseInstallName, !IO),
 		(
+			UseInstallName = no,
 			SharedLibExt \= LibExt,
 			( Linkage = "shared"
 			; LinkTargetType = shared_library
@@ -1245,6 +1248,19 @@
 		;
 			RpathOpts = ""
 		),
+				
+		%
+		% Set up the installed name for shared libraries.
+		%
+		(
+			UseInstallName = yes,
+			LinkTargetType = shared_library
+		->
+			get_install_name_option(OutputFileName, InstallNameOpt,
+				!IO)
+		;
+			InstallNameOpt = ""
+		),
 
 		globals__io_get_trace_level(TraceLevel, !IO),
 		( given_trace_level_is_none(TraceLevel) = yes ->
@@ -1290,9 +1306,9 @@
 				ThreadOpts, " ", TraceOpts, " ",
 				" -o ", OutputFileName, " ", Objects, " ",
 				LinkOptSep, " ", LinkLibraryDirectories, " ",
-				RpathOpts, " ", DebugOpts, " ", LDFlags, " ",
-				LinkLibraries, " ", MercuryStdLibs, " ",
-				SystemLibs],
+				RpathOpts, " ", InstallNameOpt, " ", DebugOpts,
+				" ", LDFlags, " ", LinkLibraries, " ",
+				MercuryStdLibs, " ", SystemLibs],
 				LinkCmd),
 
 			globals__io_lookup_bool_option(demangle, Demangle,

> > doc/user_guide.texi
> > 	Documented the --shlib-linker-install-name-path option.  The other
> > 	options will be automatically set by the configure script and
> > 	should never need to be set by the user, so they're not documented in
> > 	the user guide.
> Are there any changes that need to be made to the section on building
> libraries?
> 
No, the documented method can be used (I tested it). 

> > +# These variables can be used to set the install-name for the mercury
> > +# shared libraries.
> > +SHLIB_USE_INSTALL_NAME = @SHLIB_USE_INSTALL_NAME@
> > +SHLIB_INSTALL_NAME_FLAG = @SHLIB_INSTALL_NAME_FLAG@''
> > +
> I'd suggest changing the above comment to mention that this is for
> shared libraries on darwin.
> 
+# These variables can be used to set the install-name for the mercury
+# shared libraries on systems that use the install-name option (such as 
+# Darwin).
+SHLIB_USE_INSTALL_NAME = @SHLIB_USE_INSTALL_NAME@
+SHLIB_INSTALL_NAME_FLAG = @SHLIB_INSTALL_NAME_FLAG@''
+

> Why are you deleting this, Ralph only added it the other day?
> 
I mistakenly copied over the file after doing a cvs update. I've fixed this.

> > +	*powerpc*apple*darwin*)
> > +		# If the compiler is gcc then use darwin style dynamic linking.
> > +		# Otherwise use static linking.
> > +		if test "$GCC_PROG" != ""; then
> > +		    SHLIB_USE_INSTALL_NAME="--shlib-linker-use-install-name"
> > +		    SHLIB_INSTALL_NAME_FLAG="-install_name "
> > +		    LINK_SHARED_OBJ="$GCC_PROG -dynamiclib -single_module"
> > +		    LINK_SHARED_OBJ_SH="$GCC_PROG -dynamiclib -single_module"
> > +		    EXT_FOR_SHARED_LIB=dylib
> > +		    EXT_FOR_LINK_WITH_PIC_OBJECTS=o
> > +		    CFLAGS_FOR_PIC="-fPIC -DMR_PIC"
> > +		    ERROR_UNDEFINED="-undefined error"
> > +		    ALLOW_UNDEFINED="-undefined suppress"
> > +		    AC_MSG_RESULT(yes)
> > +		else
> > +		    CFLAGS_FOR_PIC=
> > +		    EXT_FOR_PIC_OBJECTS=o
> > +		    EXT_FOR_LINK_WITH_PIC_OBJECTS=o
> > +		    DEFAULT_LINKAGE=static
> > +		    AC_MSG_RESULT(no)
> > +		fi
> > +		;;
> >  	*)
> As I mentioned above, there really ought to be a way to tell it
> use static linking (perhaps an option to configure?).
> 
You can still use static linking as explained above, but shared is just now the
default (as it seems to be for other systems that support it).

> > Index: scripts/mgnuc.in
> > ===================================================================
> > RCS file: /home/mercury1/repository/mercury/scripts/mgnuc.in,v
> > retrieving revision 1.105
> > diff -u -r1.105 mgnuc.in
> > --- scripts/mgnuc.in	20 Jul 2004 04:41:31 -0000	1.105
> > +++ scripts/mgnuc.in	8 Oct 2004 11:03:35 -0000
> > @@ -502,6 +502,11 @@
> >  			;;
> >  		esac
> >  		;;
> > +	*powerpc*apple*darwin*)
> > +		# This environment variable needs to be set on Darwin so the
> > +		# executable knows where to find the mercury shared libraries.
> > +		dyld_LIBRARY_PATH=@LIBDIR@
> > +		;;
> >  esac
> >
> Shouldn't that be DYLD_LIBRARY_PATH there?  This doesn't really
> look like the right spot for this.  Is it needed by every executable
> that uses shared libraries or just the Mercury compiler?
>
This shouldn't have been included - sorry.  There are no changes to mgnuc.in.
DYLD_LIBRARY_PATH doesn't need to be set at all because we pass the 
-install_name option when building a shared library.

> 
> I assume that everything still works on Linux after this change
> has been applied?  That's all for now.
> 
Yep.  I compiled phase 1 (the changes to the compiler to accept the new
options), installed it and then used it to bootcheck phase 2 (all the changes
posted in the diff) using grade asm_fast.gc with default settings.

Ian.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list