'I suppose it is technically possible, though I am already in my pyjamas' patch
The patch itself
Sigh
3a as it is contains at least 3 serious bugs therefore you will need
3a fix to build LablGTK, Hevea and others.
Unfortunately one of the bugs is nasty and therefore unloading of modules
loaded with Natdynlink is disabled, until i find enough motivation to fix it.
3a fix should be applied AFTER 3a, it's NOT standalone patch.
What is it?
A patch, against OCaml 3.04, making it possible to:
create, link against and dynamically load shared objects on i386 ELF platforms.
Changes
The user will notice 4 new command line options for ocamlopt
compiler, all four only meaningful at the linking stage:
- -shared: output shared object instead of standard executable
- -dynamic: needed if executable will use Natdynlink library
- -noasmrun: do not link against libasmrun.a
- -nostdlib: do not link against stdlib.cmxa
For detailed list of changes look at ChangeLog
What's new compared to second patch
- Rather ad hoc workaround for "mangled" function names
(No more names like Module_function_123 (for visible functions))
- By name(instead of default by position) external symbol resolver
[1]
- A tool, to remove all inlining and constants from .cmx
Installation
- mkdir scaml
- cd scaml
- wget
OCaml 3.04
- wget patch
- tar xvfz ocaml-3.04.tar.gz
- cd ocaml-3.04
- zcat ../3a_shared.patch.gz | patch -p1
- zcat ../3a_fix_shared.patch.gz | patch -p1
- ./configure -with -your -favorite -options
- make world bootstrap opt opt.opt install
You are all set now.
Binutils
SCaml needs most recent release(2.12 at the time of the writing)
of GNU Binutils for some operations. (Technically only ld that
supports -z nocopyreloc is required)
Recent binutils REQUIRED to:
- Link against OCaml produced shared objects
Recent binutils NOT REQUIRED to:
- Build shared objects with OCaml
- Load and sucessfuly use shared objects via Natdynlink
- Run executables
Using it
Simple example that uses shared
LablTk (Recent binutils required)
You can use results of this patch indirectly:
camlp4.opt pa_r.cms pa_extend.cms q_MLast.cms pr_o.cms revised.ml
Problems
- Linking against shared objects created by OCaml requires
GNU Binutils 2.12(or better)
- Currently only works on Linux i386.
- The code is not well tested
- Slightly slower compilation times(not noticable on my machine)
- Slightly bigger executables(couple of bytes)
- Somewhat bigger intermediate assembly output
- Possibly slower run times(due to some compilcations in GC)
Other platfomrs
In theory this should work on all platforms with sufficiently
smart dynamic linker and ld that can omit copy relocs: GNU
ld(i386-elf, ia64-elf) with '-z nocopyreloc', SUN's linker with
-b. Windows port is a bit more complicated(or so i think).
Feedback
Send comments, suggestions, falme to
malc@pulsesoft.com or
av1474@comtv.ru
Ways to get recent GNU Binutils 2.12 or better:
Previous patches
Second
First
-
As a side effect by name symbol resolution makes OCaml immune to
this very unlikely failure.
God knows, though, what horrible BAD side effects this patch has.
Malcy
Last modified: Sun Jan 4 20:58:21 MSK 2004