Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0003866OCaml~DO NOT USE (was: OCaml general)public2005-11-15 20:192009-04-01 18:53
Assigned Toxleroy 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version3.11.0 
Summary0003866: Patch to build and install
DescriptionFull_Name: Richard Jones
Version: 3.09.0
OS: Linux
Submission from: (

It's occasionally useful to be able to link the bytecode interpreter
into a shared library. mod_caml (the Apache module for running OCaml
programs) is one program which does this.

On x86 this is possible just by linking your shared library with libcamlrun.a.
However on AMD64 (and Solaris 64 bit) this is not possible. The patch below
is very minimal - it simply builds, compiled with -fPIC, provided
the platform supports shared libraries.

It is against OCaml 3.09.0.

(Patch also available here: [^] )

diff -ur ocaml-3.09.0.orig/byterun/Makefile ocaml-3.09.0/byterun/Makefile
--- ocaml-3.09.0.orig/byterun/Makefile 2005-10-18 15:03:52.000000000 +0100
+++ ocaml-3.09.0/byterun/Makefile 2005-11-15 19:12:54.000000000 +0000
@@ -29,6 +29,8 @@

 DOBJS=$(OBJS:.o=.d.o) instrtrace.d.o

 PRIMS=alloc.c array.c compare.c extern.c floats.c gc_ctrl.c hash.c \
   intern.c interp.c ints.c io.c lexing.c md5.c meta.c obj.c parsing.c \
   signals.c str.c sys.c terminfo.c callback.c weak.c finalise.c stacks.c \
@@ -37,7 +39,12 @@
 PUBLIC_INCLUDES=alloc.h callback.h config.h custom.h fail.h intext.h \
   memory.h misc.h mlvalues.h printexc.h signals.h compatibility.h

+all: ocamlrun$(EXE) ld.conf
 all: ocamlrun$(EXE) ld.conf

 ocamlrun$(EXE): libcamlrun.a prims.o
@@ -51,6 +58,9 @@
        cp ocamlrun$(EXE) $(BINDIR)/ocamlrun$(EXE)
        cp libcamlrun.a $(LIBDIR)/libcamlrun.a
        cd $(LIBDIR); $(RANLIB) libcamlrun.a
+ cp $(LIBDIR)/
        if test -d $(LIBDIR)/caml; then : ; else mkdir $(LIBDIR)/caml; fi
        for i in $(PUBLIC_INCLUDES); do \
           sed -f ../tools/cleanup-header $$i > $(LIBDIR)/caml/$$i; \
@@ -69,8 +79,11 @@
        ar rc libcamlrund.a $(DOBJS)
        $(RANLIB) libcamlrund.a $(PICOBJS)
- rm -f ocamlrun$(EXE) ocamlrund$(EXE) *.o lib*.a
+ rm -f ocamlrun$(EXE) ocamlrund$(EXE) *.o lib*.a lib*.so
        rm -f primitives prims.c opnames.h jumptbl.h ld.conf

 primitives : $(PRIMS)
@@ -105,7 +118,7 @@
             -e '/let *ocaml_version *= */s//#define OCAML_VERSION /p' \
             <../stdlib/ >version.h

-.SUFFIXES: .d.o
+.SUFFIXES: .d.o .pic.o

        @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi
@@ -113,6 +126,12 @@
        mv $*.o $*.d.o
        @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi

+ @ if test -f $*.o; then mv $*.o $*.f.o; else :; fi
+ mv $*.o $*.pic.o
+ @ if test -f $*.f.o; then mv $*.f.o $*.o; else :; fi
 depend : prims.c opnames.h jumptbl.h version.h
        gcc -MM $(BYTECCCOMPOPTS) *.c > .depend
        gcc -MM $(BYTECCCOMPOPTS) -DDEBUG *.c | sed -e 's/\.o/.d.o/' >> .depend

TagsNo tags attached.
Attached Files? file icon camlrun_shared.dpatch [^] (2,328 bytes) 2007-09-28 17:03

- Relationships

-  Notes
zack (reporter)
2005-12-02 17:09

Using the above patch will make "ocamlc -custom" always prefer linking over libcamlrun.a (at least on i386 with binutils 2.16.1). This means that custom executable will need to be run with a proper LD_LIBRARY_PATH environment variable and that they will be slower. Quick benchmarks seem to suggest a 15% slowdown.

A proper solution seems to be to add a command line switch to ocamlc that let the user choose which runtime he wants to be linked in; or, as an alternative, a command line switch "-picruntime" which choose a "libcamlrun_pic.a" instead of the default "libcamlrun.a".

I can provide a patch if someone has the autority to decide on the proper solution.

Richard Jones (reporter)
2006-07-10 16:43

I guess this issue isn't progressing anywhere, but we still very much need a way to link the OCaml runtime into shared libraries on AMD64.

I think it's enough just to rename the shared library as (or something similar). This can be completely ignored by ordinary users, and it won't get linked into custom toplevels. But for those of us requiring the feature, we will know where to look and how to link it in.

Is this sufficient to get this into OCaml?

zack (reporter)
2007-09-28 17:02

An updated patch implementing the proposed solution (i.e. not changing how libcamlrun is currently linked, but instead providing an alternative version of the library called which includes only PIC code) is available at [^]

It is working against ocaml 3.10 (note indeed that the initial patch, 2 year old now, does not longer work with 3.10).

The patch reflects what we are going to ship in the ocaml Debian package.

Can you please someone consider adopting this patch also in the official ocaml package? The feature we are asking here is badly needed in several cases and no one gave so far evidence that it would be worst than the status quo in any respect ...

Richard Jones (reporter)
2007-09-28 18:31

We need this change in Fedora too, but in order to accept it
we need an indication from INRIA that they would be prepared
to make this change in an upcoming version of OCaml.

See also: [^]
xleroy (administrator)
2007-11-06 16:46

I'm OK with the proposed solution (build and install a DLL) and will incorporate it in 3.11.
xleroy (administrator)
2008-08-06 10:57

As promised, the CVS working sources (soon to become release 3.11) now build and install

- Issue History
Date Modified Username Field Change
2005-11-18 10:13 administrator New Issue
2005-12-02 17:09 zack Note Added: 0003413
2006-07-10 16:43 Richard Jones Note Added: 0003704
2007-09-28 17:02 zack Note Added: 0004167
2007-09-28 17:03 zack File Added: camlrun_shared.dpatch
2007-09-28 18:31 Richard Jones Note Added: 0004168
2007-11-06 16:46 xleroy Note Added: 0004240
2007-11-06 16:46 xleroy Assigned To => xleroy
2007-11-06 16:46 xleroy Description Updated
2008-08-06 10:57 xleroy Note Added: 0004573
2008-08-06 10:57 xleroy Status acknowledged => resolved
2008-08-06 10:57 xleroy Resolution open => fixed
2009-04-01 18:53 xleroy Status resolved => closed
2009-04-01 18:53 xleroy Fixed in Version => 3.11.0
2017-02-23 16:36 doligez Category OCaml general => -OCaml general
2017-03-03 17:55 doligez Category -OCaml general => -(deprecated) general
2017-03-03 18:01 doligez Category -(deprecated) general => ~deprecated (was: OCaml general)
2017-03-06 17:04 doligez Category ~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker