Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

amd64 PIC code

0 views
Skip to first unread message

Mark Wong-VanHaren

unread,
Mar 29, 2010, 4:55:51 PM3/29/10
to
Hi, folks-

Until today, there's been a problem compiling dynamic libraries on
AMD64:
http://caml.inria.fr/mantis/view.php?id=4795

The ticket is now "resolved", but I cannot make it work. It works
fine with ocamlc, but not with ocamlopt. Perhaps it's not supposed
to? Or I'm doing something wrong?

The fix involves a replacement asmrun/amd64.S which properly enables
PIC (position-independent code). To use it, I did the following:
- downloaded OCaml 3.11.2
- swapped in the patched asmrun/amd64.S
- modified that file, to set EMIT_PIC to 1
- built OCaml 3.11.2, configuring thusly:
$ ./configure -cc "gcc -fPIC" -aspp "gcc -fPIC -c"
- installed

Then, using ocamlc, things work fine:
$ echo "let x = 5" > lib.ml
$ ocamlc -output-obj -o lib.so lib.ml

But with ocamlopt, it doesn't work:
$ ocamlopt -output-obj -o lib.so lib.ml
/usr/bin/ld: /usr/local/lib/ocaml/libasmrun.a(amd64.o): relocation
R_X86_64_PC32 against `caml_alloc1' can not be used when making a
shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Bad value
collect2: ld returned 1 exit status
File "caml_startup", line 1, characters 0-1:
Error: Error during linking

Is it not supposed to work with ocamlopt?

Did I provide the wrong arguments to ./configure?

Many thanks!
-Mark

0 new messages