Files
mercury/README.Linux
Simon Taylor 886d2ae474 Make it easier to use shared libraries on x86 with
Estimated hours taken: 20
Branches: main

Make it easier to use shared libraries on x86 with
`mmc --make'.

There is now a third kind of object file, `.lpic_o'.
These files are compiled with `--pic-reg' but not with
CFLAGS_FOR_PIC, so they can be linked with shared Mercury
libraries.

On x86, executables which are linked with shared Mercury
libraries now depend on $(main_module.lpic_os), not
$(main_module.os).

This doesn't work with Mmake because ml doesn't know
which libraries are Mercury libraries, so it can't
link with the static versions of those libraries if
MERCURY_LINKAGE is set to "static".

configure.in:
bindist/bindist.configure.in:
bindist/bindist.build_vars.in:
	Work out whether `.lpic_o' files are needed.

compiler/modules.m:
	Add `.lpic_o' to the list of grade or architecture
	dependent files.

NEWS:
README.Linux:
compiler/options.m:
doc/user_guide.texi:
	Document MERCURY_LINKAGE, LINKAGE, --linkage,
	--mercury-linkage and -R.

compiler/options_file.m:
compiler/make.program_target.m:
	Handle LINKAGE and MERCURY_LINKAGE variables.

	Allow LIBGRADES, LINKAGE and MERCURY_LINKAGE to be target-specific.

scripts/mmc.in:
	Set up the default linkage using the MERCURY_LINKAGE
	variable.

compiler/compile_target_code.m:
	Build `.lpic_o' files.

	Work out which type of object files to link with.

	When linking statically with Mercury libraries,
	find the absolute pathname for the `.a' file
	for each Mercury library, and pass that to ml,
	rather than just using `-lname'.

	Pass `-R' options to ml for each `-R' option to mmc.

compiler/make.module_target.m:
compiler/make.program_target.m:
compiler/mercury_compile.m:
	Specify which type of object files to build.

compiler/make.program_target.m:
compiler/make.module_target.m:
	Make sure all generated object files are cleaned up.

compiler/prog_io.m:
	Add a better message for files which can't be found.

compiler/make.util.m:
	Add `.lpic_o' to the list of extensions.

compiler/Mmakefile:
profiler/Mmakefile:
deep_profiler/Mmakefile:
	Pass `--linkage shared' to mmc (`--shared' is in MLFLAGS).

tests/Mmakefile:
tests/mmc_make/Mmakefile:
tests/mmc_make/Mercury.options:
tests/mmc_make/complex_test.{m,exp}:
tests/mmc_make/hello.{m,exp}:
	Test `mmc --make'.

tests/lib/complex*.m:
	The complex numbers library from the extras distribution,
	for use in the mmc_make tests.
2003-01-23 00:24:20 +00:00

47 lines
2.5 KiB
Plaintext

This file documents just the Linux/x86 port.
For the Linux/PowerPC port, see README.Linux-PPC.
For the Linux/Alpha port, see README.Linux-Alpha.
(Ports to Linux on other architectures have not yet
been attempted, but should not be difficult.)
On Linux with a.out, shared libraries are not supported.
If you still have an old a.out system, the auto-configuration might
wrongly assume your Linux system uses ELF; if that happens, you will you
have to manually edit the EXT_FOR_SHARED_LIB variable in Mmake.common.
On Linux with ELF, shared libraries are supported. However, ELF shared
libraries require position-independent code, and (partly due to
limitations in our current compilation technology, but partly due to
limitations in the x86 architecture) this is quite costly for Mercury --
probably considerably more costly than it is for C.
Nevertheless, since shared libraries reduces disk usage, improve link
times, and allow run-time sharing of the Mercury libraries between
different applications, using them is a good idea.
Currently the default is that programs do *not* use the Mercury shared
libraries. (Probably it ought to be the other way around, but that
happened to be a little bit harder to implement. We may change this in
a future release.)
To use the shared libraries, you must compile your program with
`mmc --pic-reg' and link with `ml --shared' or add
`MGNUCFLAGS=--pic-reg' and `MLFLAGS=--shared' to your Mmake file.
If you are using `mmc --make' you can set the MERCURY_LINKAGE Mmake
variable to "shared" in the Mercury.options file or the environment,
or use `mmc --make --linkage 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
these options has "non-PIC linkage". The static version of the Mercury
libraries has non-PIC linkage, while the shared version has PIC linkage.
Be careful that you do not try to link Mercury code with PIC linkage and
Mercury code with non-PIC linkage into the same executable, otherwise you
will probably get an obscure link error about `MR_grade_...' undefined
or `MR_runtime_grade' multiply defined.
(The reason for this is that standard non-PIC Mercury code uses the
`ebx' register in ways that are incompatible with its uses as the global
offset table pointer register in PIC code. If only the Intel
architecture wasn't so register-starved, we wouldn't need to use `ebx',
and then PIC and non-PIC code could be mixed without any problems.)