caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* [Caml-list] Manually linking generated native code
@ 2017-01-19  9:44 Christoph Höger
  2017-01-19 10:05 ` Bernhard Schommer
  2017-01-19 12:11 ` Gerd Stolpmann
  0 siblings, 2 replies; 5+ messages in thread
From: Christoph Höger @ 2017-01-19  9:44 UTC (permalink / raw)
  To: caml-list

[-- Attachment #1: Type: text/plain, Size: 663 bytes --]

Dear all,

consider a simple test program:

  let _ = Printf.printf "Hello world!\n"

I can generate the relevant assembly just fine, e.g.:

ocamlopt -dstartup -S test.ml
gcc -c a.out.startup.s -c

But I cannot link it:

gcc a.out.startup.o -L$(ocamlc -where) -lasmrun_shared
....
a.out.startup.o(.data+0x6e8): error: undefined reference to
'camlStd_exit__frametable'
collect2: Fehler: ld gab 1 als Ende-Status zurück
distcc[9960] ERROR: compile (null) on localhost failed

It seems that the whole Pervasives is missing (which is kind of expected).

How do I link it, manually? Where are the relevant object files?

thanks,

Christoph

[-- Attachment #2: Type: text/html, Size: 911 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Manually linking generated native code
  2017-01-19  9:44 [Caml-list] Manually linking generated native code Christoph Höger
@ 2017-01-19 10:05 ` Bernhard Schommer
  2017-01-19 12:11 ` Gerd Stolpmann
  1 sibling, 0 replies; 5+ messages in thread
From: Bernhard Schommer @ 2017-01-19 10:05 UTC (permalink / raw)
  To: Christoph Höger; +Cc: caml-list

Hi,

you might want to use the -verbose switch to get the actual output of
the linker call. For me it is:
clang  -o 'a.out'   '-L$(ocamlc -where)'  'a.out.startup.s' '$(ocamlc
-where)/std_exit.o' 'test.s' '$(ocamlc -where)/stdlib.a' '$(ocamlc
-where)/libasmrun.a' -lm  -ldl

Best,
-Bernhard

2017-01-19 10:44 GMT+01:00 Christoph Höger <christoph.hoeger@celeraone.com>:
> Dear all,
>
> consider a simple test program:
>
>   let _ = Printf.printf "Hello world!\n"
>
> I can generate the relevant assembly just fine, e.g.:
>
> ocamlopt -dstartup -S test.ml
> gcc -c a.out.startup.s -c
>
> But I cannot link it:
>
> gcc a.out.startup.o -L$(ocamlc -where) -lasmrun_shared
> ....
> a.out.startup.o(.data+0x6e8): error: undefined reference to
> 'camlStd_exit__frametable'
> collect2: Fehler: ld gab 1 als Ende-Status zurück
> distcc[9960] ERROR: compile (null) on localhost failed
>
> It seems that the whole Pervasives is missing (which is kind of expected).
>
> How do I link it, manually? Where are the relevant object files?
>
> thanks,
>
> Christoph
>

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Manually linking generated native code
  2017-01-19  9:44 [Caml-list] Manually linking generated native code Christoph Höger
  2017-01-19 10:05 ` Bernhard Schommer
@ 2017-01-19 12:11 ` Gerd Stolpmann
  2017-01-19 12:24   ` Christoph Höger
  1 sibling, 1 reply; 5+ messages in thread
From: Gerd Stolpmann @ 2017-01-19 12:11 UTC (permalink / raw)
  To: Christoph Höger, caml-list


[-- Attachment #1.1: Type: text/plain, Size: 1685 bytes --]

Am Donnerstag, den 19.01.2017, 10:44 +0100 schrieb Christoph Höger:
> Dear all,
> 
> consider a simple test program:
> 
>   let _ = Printf.printf "Hello world!\n"
> 
> I can generate the relevant assembly just fine, e.g.:
> 
> ocamlopt -dstartup -S test.ml
> gcc -c a.out.startup.s -c
> 
> But I cannot link it:
> 
> gcc a.out.startup.o -L$(ocamlc -where) -lasmrun_shared
> ....
> a.out.startup.o(.data+0x6e8): error: undefined reference to
> 'camlStd_exit__frametable'
> collect2: Fehler: ld gab 1 als Ende-Status zurück
> distcc[9960] ERROR: compile (null) on localhost failed
> 
> It seems that the whole Pervasives is missing (which is kind of
> expected). 
> 
> How do I link it, manually? Where are the relevant object files?
There's stdlib.a in the OCaml library directory.
This is not the only problem with your approach. The OCaml linker
generates a number of functions that are global to the whole OCaml
program (in particular currying helpers). These are first known at link
time and thus generated that late. AFAIK you cannot generate these
functions outside the linker step. 
The only official way how to turn OCaml code into a linkable object is
described here: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#s
%3Aembedded-code
Gerd
> > thanks,> 
> Christoph> 
> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------



[-- Attachment #1.2: Type: text/html, Size: 2246 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Manually linking generated native code
  2017-01-19 12:11 ` Gerd Stolpmann
@ 2017-01-19 12:24   ` Christoph Höger
  2017-01-19 13:10     ` Gerd Stolpmann
  0 siblings, 1 reply; 5+ messages in thread
From: Christoph Höger @ 2017-01-19 12:24 UTC (permalink / raw)
  To: Gerd Stolpmann; +Cc: caml-list

[-- Attachment #1: Type: text/plain, Size: 2449 bytes --]

Could you elaborate a little bit, how that should work? AFAIK, e.g. the
curry helpers are generated in Cmmgen, which is absolutely sensible, since
they certainly do not depend on the machine architecture, right? So when
and where does the linker use this generation?

To motivate my question a little bit, I was wondering whether I could load
two different OCaml executables inside the same process by using LLVM's
runtime linker. In principle, when I load them, they should be able to
cooperate across the shared heap, but otherwise live in total isolation (in
particular their garbage collectors should not interfere).

On Thu, Jan 19, 2017 at 1:11 PM, Gerd Stolpmann <info@gerd-stolpmann.de>
wrote:

> Am Donnerstag, den 19.01.2017, 10:44 +0100 schrieb Christoph Höger:
>
> Dear all,
>
> consider a simple test program:
>
>   let _ = Printf.printf "Hello world!\n"
>
> I can generate the relevant assembly just fine, e.g.:
>
> ocamlopt -dstartup -S test.ml
> gcc -c a.out.startup.s -c
>
> But I cannot link it:
>
> gcc a.out.startup.o -L$(ocamlc -where) -lasmrun_shared
> ....
> a.out.startup.o(.data+0x6e8): error: undefined reference to
> 'camlStd_exit__frametable'
> collect2: Fehler: ld gab 1 als Ende-Status zurück
> distcc[9960] ERROR: compile (null) on localhost failed
>
> It seems that the whole Pervasives is missing (which is kind of expected).
>
> How do I link it, manually? Where are the relevant object files?
>
>
> There's stdlib.a in the OCaml library directory.
>
> This is not the only problem with your approach. The OCaml linker
> generates a number of functions that are global to the whole OCaml program
> (in particular currying helpers). These are first known at link time and
> thus generated that late. AFAIK you cannot generate these functions outside
> the linker step.
>
> The only official way how to turn OCaml code into a linkable object is
> described here: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.
> html#s%3Aembedded-code
>
> Gerd
>
>
> thanks,
>
> Christoph
>
> --
> ------------------------------------------------------------
> Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> My OCaml site:          http://www.camlcity.org
> Contact details:        http://www.camlcity.org/contact.html
> Company homepage:       http://www.gerd-stolpmann.de
> ------------------------------------------------------------
>
>
>

[-- Attachment #2: Type: text/html, Size: 3686 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [Caml-list] Manually linking generated native code
  2017-01-19 12:24   ` Christoph Höger
@ 2017-01-19 13:10     ` Gerd Stolpmann
  0 siblings, 0 replies; 5+ messages in thread
From: Gerd Stolpmann @ 2017-01-19 13:10 UTC (permalink / raw)
  To: Christoph Höger; +Cc: caml-list


[-- Attachment #1.1: Type: text/plain, Size: 3521 bytes --]

Am Donnerstag, den 19.01.2017, 13:24 +0100 schrieb Christoph Höger:
> Could you elaborate a little bit, how that should work? AFAIK, e.g.
> the curry helpers are generated in Cmmgen, which is absolutely
> sensible, since they certainly do not depend on the machine
> architecture, right? So when and where does the linker use this
> generation?
What I know is that the linker gathers up the required functions from
the cmx and cmxa files. E.g. that could be a helper that returns the
closure for a 5-argument function that is called with only 3 arguments.
Such helpers are only needed once for the whole program.
> > To motivate my question a little bit, I was wondering whether I could load two different OCaml executables inside the same process by using LLVM's runtime linker. In principle, when I load them, they should be able to cooperate across the shared heap, but otherwise live in total isolation (in particular their garbage collectors should not interfere).
Well, you could try whether the object file emitted by "ocamlopt
-output-obj" works. This object contains everything but the main
program and the additional libraries needed (like libasmrun).
Gerd

> On Thu, Jan 19, 2017 at 1:11 PM, Gerd Stolpmann > <info@gerd-stolpmann.de>>  wrote:
> > Am Donnerstag, den 19.01.2017, 10:44 +0100 schrieb Christoph Höger:
> > > Dear all,> > > 
> > > consider a simple test program:> > > 

> > >   let _ = Printf.printf "Hello world!\n"> > > 
> > > I can generate the relevant assembly just fine, e.g.:> > > 

> > > ocamlopt -dstartup -S test.ml> > > gcc -c a.out.startup.s -c> > > 
> > > But I cannot link it:> > > 
> > > gcc a.out.startup.o -L$(ocamlc -where) -lasmrun_shared
> > > ....
> > > a.out.startup.o(.data+0x6e8): error: undefined reference to 'camlStd_exit__frametable'
> > > collect2: Fehler: ld gab 1 als Ende-Status zurück
> > > distcc[9960] ERROR: compile (null) on localhost failed> > > 
> > > It seems that the whole Pervasives is missing (which is kind of expected). > > > 
> > > How do I link it, manually? Where are the relevant object files?
> > > > There's stdlib.a in the OCaml library directory.
> > > > This is not the only problem with your approach. The OCaml linker generates a number of functions that are global to the whole OCaml program (in particular currying helpers). These are first known at link time and thus generated that late. AFAIK you cannot generate these functions outside the linker step. 
> > > > The only official way how to turn OCaml code into a linkable object is described here: http://caml.inria.fr/pub/docs/manual-ocaml/intfc.html#s%3Aembedded-code
> > > > Gerd
> > > > > > > > thanks,> > > 
> > > Christoph> > > 
> > > 

> > -- 
> > ------------------------------> > ------------------------------
> > Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
> > 
> > My OCaml site:          http://www.camlcity.org
> > 
> > Contact details:        http://www.camlcity.org/contact.html
> > 
> > Company homepage:       http://www.gerd-stolpmann.de
> > 
> > ------------------------------> > ------------------------------
> > 
> > 



> 

-- 
------------------------------------------------------------
Gerd Stolpmann, Darmstadt, Germany    gerd@gerd-stolpmann.de
My OCaml site:          http://www.camlcity.org
Contact details:        http://www.camlcity.org/contact.html
Company homepage:       http://www.gerd-stolpmann.de
------------------------------------------------------------



[-- Attachment #1.2: Type: text/html, Size: 4822 bytes --]

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 473 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2017-01-19 13:11 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-01-19  9:44 [Caml-list] Manually linking generated native code Christoph Höger
2017-01-19 10:05 ` Bernhard Schommer
2017-01-19 12:11 ` Gerd Stolpmann
2017-01-19 12:24   ` Christoph Höger
2017-01-19 13:10     ` Gerd Stolpmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).