caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Compiling a shared library with amd64
@ 2008-07-22  9:08 Jonathan Marchand
  2008-07-22  9:16 ` [Caml-list] " Alain Frisch
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Marchand @ 2008-07-22  9:08 UTC (permalink / raw)
  To: caml-list

Hi,

I would like to compile a native shared library with ocaml on amd64. I
googled the problem and as far as I understand, I need both runtimes
and libraries (the ones used in my library) compiled with -fPIC:

http://caml.inria.fr/mantis/view.php?id=3924

The above trick allowed me to compile ocaml runtimes with -fPIC
(linker doesn't complain about libasmrun.a anymore):

BYTECCCOMPOPTS=-fno-defer-pop -Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -fPIC
NATIVECCCOMPOPTS=-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -fPIC
NATIVECCPROFOPTS=-Wall -D_FILE_OFFSET_BITS=64 -D_REENTRANT -fPIC
SUPPORTS_SHARED_LIBRARIES=true
BNG_ARCH=amd64

http://caml.inria.fr/pub/ml-archives/caml-list/2005/12/6ac193aca085629903e7efd79ae0274f.en.html

But I still have issues with the ocaml libraries. I don't know how to
compile the standard library from the ocaml tarball with -fPIC. I
looked at the Makefiles, but I could'nt figure out what to change to
achieve this task.

I've looked at rocaml (http://eigenclass.org/hiki/rocaml) which fails
to compile amd64 library too, so I imagine the problem is definitly in
the way of compiling the ocaml libraries.

Any hints how to compile these libraries with -fPIC ?

Jonathan


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

* Re: [Caml-list] Compiling a shared library with amd64
  2008-07-22  9:08 Compiling a shared library with amd64 Jonathan Marchand
@ 2008-07-22  9:16 ` Alain Frisch
  2008-07-23  7:08   ` Jonathan Marchand
  0 siblings, 1 reply; 5+ messages in thread
From: Alain Frisch @ 2008-07-22  9:16 UTC (permalink / raw)
  To: Jonathan Marchand; +Cc: caml-list

Jonathan Marchand wrote:
> But I still have issues with the ocaml libraries. I don't know how to
> compile the standard library from the ocaml tarball with -fPIC.

You should try the current CVS version of OCaml. Under AMD64, ocamlopt 
now produces PIC code by default.

-- Alain


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

* Re: [Caml-list] Compiling a shared library with amd64
  2008-07-22  9:16 ` [Caml-list] " Alain Frisch
@ 2008-07-23  7:08   ` Jonathan Marchand
  2008-07-23  7:16     ` Alain Frisch
  0 siblings, 1 reply; 5+ messages in thread
From: Jonathan Marchand @ 2008-07-23  7:08 UTC (permalink / raw)
  To: caml-list

I still have the same problem with ocaml from CVS (exemple from rocaml):

cc -shared -o foo.so foo_rocaml_wrapper.o -L. -L/usr/lib -L.
-rdynamic -Wl,-export-dynamic   foo_rocaml_runtime.o
/usr/local/lib/ocaml/libasmrun.a /usr/local/lib/ocaml/libunix.a
/usr/local/lib/ocaml/libnums.a -lruby1.8  -lpthread -ldl -lcrypt -lm
-lc
/usr/bin/ld: /usr/local/lib/ocaml/libasmrun.a(startup.o): relocation
R_X86_64_32 against `a local symbol' can not be used when making a
shared object; recompile with -fPIC
/usr/local/lib/ocaml/libasmrun.a: could not read symbols: Bad value
collect2: ld returned 1 exit status
make: *** [foo.so] Erreur 1

Is there any specific tag to check out from CVS?

On Tue, Jul 22, 2008 at 11:16 AM, Alain Frisch <alain@frisch.fr> wrote:
> Jonathan Marchand wrote:
>>
>> But I still have issues with the ocaml libraries. I don't know how to
>> compile the standard library from the ocaml tarball with -fPIC.
>
> You should try the current CVS version of OCaml. Under AMD64, ocamlopt now
> produces PIC code by default.
>
> -- Alain
>
>


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

* Re: [Caml-list] Compiling a shared library with amd64
  2008-07-23  7:08   ` Jonathan Marchand
@ 2008-07-23  7:16     ` Alain Frisch
       [not found]       ` <9a3dee4b0807230117m102363a1ubca8ed069e15db41@mail.gmail.com>
  0 siblings, 1 reply; 5+ messages in thread
From: Alain Frisch @ 2008-07-23  7:16 UTC (permalink / raw)
  To: Jonathan Marchand; +Cc: caml-list

Jonathan Marchand wrote:
> I still have the same problem with ocaml from CVS (exemple from rocaml):
> 
> cc -shared -o foo.so foo_rocaml_wrapper.o -L. -L/usr/lib -L.
> -rdynamic -Wl,-export-dynamic   foo_rocaml_runtime.o
> /usr/local/lib/ocaml/libasmrun.a /usr/local/lib/ocaml/libunix.a
> /usr/local/lib/ocaml/libnums.a -lruby1.8  -lpthread -ldl -lcrypt -lm
> -lc
> /usr/bin/ld: /usr/local/lib/ocaml/libasmrun.a(startup.o): relocation
> R_X86_64_32 against `a local symbol' can not be used when making a
> shared object; recompile with -fPIC
> /usr/local/lib/ocaml/libasmrun.a: could not read symbols: Bad value
> collect2: ld returned 1 exit status
> make: *** [foo.so] Erreur 1

You mentioned in your previous email that you got rid of such errors by 
adding -fPIC to *COMPOPTS variables. Cannot you do the same for other C 
libraries?  The changes in the CVS only affect the code generated by 
OCaml, like stdlib.a (the  native code produced by ocamlopt for the 
standard library).

-- Alain


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

* Re: [Caml-list] Compiling a shared library with amd64
       [not found]       ` <9a3dee4b0807230117m102363a1ubca8ed069e15db41@mail.gmail.com>
@ 2008-07-23  8:24         ` Alain Frisch
  0 siblings, 0 replies; 5+ messages in thread
From: Alain Frisch @ 2008-07-23  8:24 UTC (permalink / raw)
  To: Jonathan Marchand; +Cc: Caml mailing list

Jonathan Marchand wrote:
> I got rid of the complains with 3.10.2 version (for libasmrun.a only).
> In the CVS version, if I compile by adding -fPIC in *COMOPTS, I  still
> have some errors with libasmrun.a:
> 
> Here is the complete build trace for rocaml (I use it as an exemple as
> it the same problem with the library I'm making and it is freely
> available):
> 
> cc -I. -I/usr/lib/ruby/1.8/x86_64-linux
> -I/usr/lib/ruby/1.8/x86_64-linux -I.   -fPIC -fno-strict-aliasing -g
> -g -O2  -fPIC   -c foo_rocaml_wrapper.c
> ocamlc -c -I +camlp4 -pp "camlp4orf -loc _loc" pa_rocaml.ml
> ocamlopt.opt -c -pp 'camlp4o -I . pa_rocaml.cmo'  rubyOCamlUtil.ml
> ocamlopt.opt  -output-obj -o foo_rocaml_runtime.o nums.cmxa
> rubyOCamlUtil.cmx rubyOCamlUtil.o
> cc -shared -o foo.so foo_rocaml_wrapper.o -L. -L/usr/lib -L.
> -rdynamic -Wl,-export-dynamic   foo_rocaml_runtime.o
> /usr/local/lib/ocaml/libasmrun.a /usr/local/lib/ocaml/libunix.a
> /usr/local/lib/ocaml/libnums.a -lruby1.8  -lpthread -ldl -lcrypt -lm
> -lc
> /usr/bin/ld: /usr/local/lib/ocaml/libasmrun.a(amd64.o): relocation
> R_X86_64_PC32 against `caml_last_return_address' 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
> make: *** [foo.so] Erreur 1
> 
> I don't know how to compile every libraries with -fPIC. I tried to add
> more or less randomly the -fPIC flag in the Makefiles, but they are a
> bit obscure to me.
> The best I achieved is printed above.

Now the error is in code written directly in assembler (asmrun/amd64.S).
Unfortunately, I don't think there is an easy solution here: this code 
should be adapted to be position-independent.


-- Alain


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

end of thread, other threads:[~2008-07-23  8:24 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-07-22  9:08 Compiling a shared library with amd64 Jonathan Marchand
2008-07-22  9:16 ` [Caml-list] " Alain Frisch
2008-07-23  7:08   ` Jonathan Marchand
2008-07-23  7:16     ` Alain Frisch
     [not found]       ` <9a3dee4b0807230117m102363a1ubca8ed069e15db41@mail.gmail.com>
2008-07-23  8:24         ` Alain Frisch

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).