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

Julien Fischer juliensf at cs.mu.OZ.AU
Tue Oct 12 01:51:22 AEST 2004


On Tue, 12 Oct 2004, Ian MacLarty wrote:

> 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.
>
It's probably worth mentioning in README.MacOS that this has not been
tested 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.
>
I'd suggest s/fixes/enables/ there - shared libraries weren't broken so
there is nothing to fix as such.

> > > 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.
>
You might want to add an XXX comment to the log message if shared
libraries don't work with mmc --make.

> > > 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.
>
I think it's meant to do that.

> > > 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.
>
(See comment below).

> > 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,
That looks fine.

> > > +	*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).
>
I was thinking more in terms of building the compiler, e.g.

./configure --link-statically

but I guess that's relatively unimportant.

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

That looks good.

Julien.


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