Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ocaml compiler presents static link libraries to GCC backwards #5260

Closed
vicuna opened this issue May 1, 2011 · 1 comment
Closed

ocaml compiler presents static link libraries to GCC backwards #5260

vicuna opened this issue May 1, 2011 · 1 comment
Labels

Comments

@vicuna
Copy link

vicuna commented May 1, 2011

Original bug ID: 5260
Reporter: nacl
Status: closed (set by @xavierleroy on 2013-08-31T10:43:55Z)
Resolution: not a bug
Priority: normal
Severity: major
Version: 3.12.0
Category: ~DO NOT USE (was: OCaml general)
Related to: #5234

Bug description

Yeah, the title says it all.

OS: Linux/openSUSE 11.4
Kernel Version: 2.6.37.6
Arch: x86_64

The openSUSE build service compiles static libraries with the --as-needed linker flag, which causes the statically linking against the pcre library fail with GCC linker errors. This likely extends to other libraries as well.

This can be set to ocamlc or ocamlopt by adding '-ccopt -Wl,--as-needed'

For example, compiling the attached file with

ocamlc.opt -verbose -g -o test.byt -thread -I /usr/lib64/ocaml/pcre/ /usr/lib64/ocaml/pcre/pcre.cma test.ml

Works fine. The relevant linker arguments are '-lpcre' and '-lpcre_stubs', in that order However, when called as:

ocamlc.opt -ccopt -Wl,--as-needed -verbose -g -o test.byt -thread -I /usr/lib64/ocaml/pcre/ /usr/lib64/ocaml/pcre/pcre.cma test.ml

It fails. However, It works when I explicitly add a 'cclib -lpcre' to the mix, like so:

ocamlc.opt -ccopt -Wl,--as-needed -cclib -lpcre -verbose -g -o test.byt -thread -I /usr/lib64/ocaml/pcre/ /usr/lib64/ocaml/pcre/pcre.cma test.ml

It works perfectly fine, dumping the pcre linker flags as -lpcre -lpcre_stubs -lpcre, with the last '-lpcre' appearing to be appended as a result of the '-cclib -lpcre' argument.

The linker args at the bottom of the pcre.cma file appear to be specified in the correct order of '-lpcre_stubs -lpcre' as was seen by opening it in a text editor. Attempting to reverse the order of the flags in the file resulted in the compiler segfaulting.

It was suggested that the problem is somehow related to a list reversal, but I do not know for sure.

Additional information

This problem was first noted in this thread: http://www.mail-archive.com/godi-list@ocaml-programming.de/msg00347.html

It was unclear whether this was a problem with pcre or ocaml itself, but Gerd seems to suggest that it was related to ocaml itself.

This bug is likely the same as described in #5234

File attachments

@vicuna
Copy link
Author

vicuna commented May 17, 2011

Comment author: @damiendoligez

When I compile pcre 6.2.2, the command line that compiles pcre.cmxa is the following:

ocamlopt -a -cclib "-L/opt/local/lib -lpcre" -cclib -lpcre_stubs -o pcre.cmxa pcre.cmx

Note that "-lpcre" and "-lpcre_stubs" appear in this order (which is the wrong order, given the strange semantics of the Unix linker). OCaml preserves this order, as it should.

I strongly claim that the problem is in pcre itself: it should list -lpcre_stubs before -lpcre.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant