Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0006733OCaml-for ocamlbuild use https://github.com/ocaml/ocamlbuild/issuespublic2014-12-24 15:192017-02-16 15:15
Reporterwhitequark 
Assigned Togasche 
PrioritynormalSeverityfeatureReproducibilityalways
StatusclosedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.02.2+dev / +rc1 
Summary0006733: Teach ocamlbuild to create shared libraries using -output-obj
DescriptionCurrently I am using the following code (parts of which are pulled into myocamlbuild, not being accessible from ocamlbuild library):

      let native_link_gen linker =
        Ocaml_compiler.link_gen "cmx" "cmxa"
          !Options.ext_lib [!Options.ext_obj; "cmi"] linker
      in
      let native_output_obj x = native_link_gen Ocaml_compiler.ocamlopt_link_prog
        (fun tags -> tags++"ocaml"++"link"++"native"++"output_obj"++"output_so") x
      in
      flag ["ocaml"; "link"; "output_so"] & S[A"-cclib"; A"-shared"];
      flag ["ocaml"; "link"; "output_obj"; "debug"] & A"-g";
      rule "ocaml: cmx & o -> native.(so|dll|dylib)"
        ~prod:("%.native"-.-(!Options.ext_dll))
        ~deps:["%.cmx"; "%.o"]
        (native_output_obj "%.cmx" ("%.native"-.-(!Options.ext_dll)));

Then, I just do `ocamlbuild foo.native.so`. It works flawlessly.

Possibly it is also useful to provide `foo.byte.so`.
Tagspatch
Attached Filespatch file icon sharedlib.patch [^] (5,930 bytes) 2014-12-29 01:53 [Show Content]

- Relationships
related to 0006693closedgasche RFE: build libasmrun_shared too 
related to 0006797closeddoligez -output-obj should support autolink 
related to 0006845closeddoligez New mode where ocamlc doesn't check list of primitives 
related to 0006927resolvedwhitequark Patch from PR6733 does not work on OS X 
related to 0006918resolved Using ocamlbuild to generate dynamic libraries (*.so/*.dll) with a C-API and an OCaml implementation? 

-  Notes
(0012982)
gasche (administrator)
2014-12-24 16:02

If you have a working patch to provide, I'm interested.
(0012997)
whitequark (developer)
2014-12-29 01:58
edited on: 2015-01-09 18:26

@gasche, I added a patch. It adds the .so targets, and also a runtime_variant parametric flag.

The flag is needed on, I think, mainly x86, where all code in a shared library must be linked with -fPIC. On e.g. ARM, there is no such restriction.

Until 0006693 is fixed, the ocamlbuild testsuite will fail (on x86, at least).

I did not add a runtime_variant(_shared) flag to the default tags for .so targets, because:

  * tags++"runtime_variant(x)" doesn't seem to do anything;
  * the _shared variant of the tag is probably not what most users of the .so targets want, as libcamlrun_shared.so is not even in default library search path.

I think it is OK to leave the default tags as-is, or if there will be a _pic variant of the runtime--a .a archive built with -fPIC--we could add runtime_variant(_pic) so that everything builds by default on all platforms. Having to manually specify "-runtime_variant(_pic), runtime_variant(_some_other)" is a bit awkward, but should be rarely needed.

(0013790)
gasche (administrator)
2015-05-02 17:59

Using the proposed patch, the test fails on my machine with the following log:

/home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamldep.opt -modules hello.ml > hello.ml.depends
/home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamlc.opt -c -o hello.cmo hello.ml
/home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamlc.opt -output-obj -cclib -shared -runtime-variant _shared hello.cmo -o hello.byte.so
/home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamlopt.opt -c -o hello.cmx hello.ml
/home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamlopt.opt -output-obj -cclib -shared -runtime-variant _shared hello.cmx -o hello.native.so
+ /home/gasche/.opam/4.03.0+local-git-trunk/bin/ocamlopt.opt -output-obj -cclib -shared -runtime-variant _shared hello.cmx -o hello.native.so
File "caml_startup", line 1:
Error: Cannot find file libasmrun_shared.a
Command exited with code 2.

Indeed, PR#6693 builds no libasmrun_shared.a, only libasmrun_shared.so.
(0013792)
whitequark (developer)
2015-05-02 18:06

It should work if you replace runtime_variant(_shared) with runtime_variant(_pic) (which really makes much more sense for users, as libasmrun_shared.so is not in the library search path.)
(0013793)
gasche (administrator)
2015-05-02 18:11

Indeed, I can confirm that the proposed change works. I have the patch ready to apply, but I may wait a bit to see what happens to 0006693.
(0013886)
gasche (administrator)
2015-05-10 07:50

Merged in 4.02 and trunk, thanks!

- Issue History
Date Modified Username Field Change
2014-12-24 15:19 whitequark New Issue
2014-12-24 16:02 gasche Note Added: 0012982
2014-12-29 01:08 whitequark Relationship added related to 0006693
2014-12-29 01:53 whitequark File Added: sharedlib.patch
2014-12-29 01:58 whitequark Note Added: 0012997
2015-01-09 18:25 doligez Tag Attached: patch
2015-01-09 18:26 doligez Note Edited: 0012997 View Revisions
2015-01-09 18:26 doligez Status new => acknowledged
2015-02-27 15:35 whitequark Relationship added related to 0006797
2015-05-02 17:59 gasche Note Added: 0013790
2015-05-02 18:06 whitequark Note Added: 0013792
2015-05-02 18:11 gasche Note Added: 0013793
2015-05-10 07:50 gasche Note Added: 0013886
2015-05-10 07:50 gasche Status acknowledged => resolved
2015-05-10 07:50 gasche Fixed in Version => 4.02.2+dev / +rc1
2015-05-10 07:50 gasche Resolution open => fixed
2015-05-10 07:50 gasche Assigned To => gasche
2015-05-12 16:55 doligez Relationship added related to 0006845
2015-07-12 10:24 whitequark Relationship added related to 0006927
2015-07-22 17:28 doligez Relationship added related to 0006918
2017-02-16 15:15 xleroy Status resolved => closed
2017-02-23 16:34 doligez Category OCamlbuild (the tool) => for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues [^]
2017-02-23 16:44 doligez Category for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues [^] => -for ocamlbuild use https://github.com/ocaml/ocamlbuild/issues [^]


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker