Official build: Statically linked 'mars' binary can't execute LLVM code

Bug #1338058 reported by Matt Giuca
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Mars
Fix Committed
Critical
Matt Giuca

Bug Description

The official build (running setup/Makefile instead of src/Makefile) statically links Mercury and LibGC libraries into the 'mars' and 'marsc' binaries. The original rationale for this is to allow distribution on systems without Mercury installed (since there is no easy way to install Mercury on Linux without building from source, and no way to have Mercury runtime libraries without the full Mercury compiler).

However, now that we have LLVM execution engines running in the 'mars' binary itself, it seems they require a dynamically linked version of libgc. Therefore, while the development build works, the official (static) build has this error whenever code execution is attempted:

$ ./mars
?> 4
LLVM ERROR: Program used external function 'GC_malloc' which could not be resolved!

To make things (much) worse, it seems that the libgc.so included with Mercury is a modified version specially for Mercury -- it includes Mercury-only functions prefixed with GC_mercury_*. This means that 'mars' can't be linked with a system version of libgc -- it has to be the Mercury one. (This is... super lame.)

To get around this, distribute the dynamic build, but include the required .so files (libmer_*.so and libgc.so), and provide a wrapper script to get the .so files onto the LD_LIBRARY_PATH.

Tags: build
Revision history for this message
Matt Giuca (mgiuca) wrote :

I have succeeded in setting up my system to use Mars without Mercury *by hand* but it will take some work to automate the setup process.

Here is the setup:

1. The 'mars' and 'marsc' binaries are installed in /usr/local/lib/mars/bin (not /usr/local/bin).
2. The 'libmer_std.so', 'libmer_rt.so' and 'libgc.so' (Mercury version) are installed in /usr/local/lib/mars/lib.
3. Create an executable shell script /usr/local/bin/mars, with the following contents:

#!/bin/sh
MARS_DIR=/usr/local/lib/mars
BINARY=mars

# Runs a Mars binary, with LD_LIBRARY_PATH set to grant access to the Mercury
# and libgc libraries.
LD_LIBRARY_PATH=$MARS_DIR/lib:$LD_LIBRARY_PATH
$MARS_DIR/bin/$BINARY "$@"

An almost-identical script will be in /usr/local/bin/marsc, with BINARY changed.

The script will have to be generated by the install process, with the MARS_DIR variable set to the correct prefix.

This means that typing 'mars' or 'marsc' from anywhere in the system will run the program correctly, without installing Mercury or bogus libgc libraries system-wide.

(Note: if it wasn't for Mercury's bogus libgc implementation, I could just install libmer*.so into /usr/local/lib and be done with it.)

Revision history for this message
Matt Giuca (mgiuca) wrote :

Fixed in trunk r1384.

Changed in mars:
status: In Progress → Fix Committed
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.