The OCaml compiler has a flag (-runtime-variant foo) that has the effect of linking libasmrunfoo.a instead.

In OCaml 4.02.2, whitequark contributed both the build of libasmrun_pic.a and an ocamlbuild flag runtime_variant(foo) to enable this feature in ocamlbuild. So you can use the tag 'runtime_variant(_pic)' at the level of one OCamlbuild project to enable this.

I suppose that what you would actually be looking for here is a way to set this runtime variant as the default at the level of the whole OCaml package tree (one opam switch). Unfortunately, I don't know whether the ocaml configure/build system makes this easy today. Could you consider opening an issue on the bugtracker ( http://caml.inria.fr/mantis/view_all_bug_page.php ) to track this feature request?

Do you have some documentation on what precisely is the change in gcc7 that causes this compatibility breakage?

On Wed, May 31, 2017 at 4:12 AM, Olaf Hering <olaf@aepfle.de> wrote:
openSUSE Tumbleweed switched to gcc7, with the result that most ocaml
related packages fail to build. The reason is that libasmrun.a instead
of libasmrun_pic.a is used during linking:


[   44s] + ocamlfind ocamlopt unix.cmxa -I /usr/lib64/ocaml/ocamlbuild /usr/lib64/ocaml/ocamlbuild/ocamlbuildlib.cmxa -linkpkg myocamlbuild.ml /usr/lib64/ocaml/ocamlbuild/ocamlbuild.cmx -o myocamlbuild
...
[   44s] /usr/lib64/gcc/x86_64-suse-linux/7/../../../../x86_64-suse-linux/bin/ld: /usr/lib64/ocaml/libasmrun.a(startup_aux.o): relocation R_X86_64_32 against `.rodata.str1.1' can not be used when making a shared object; recompile with -fPIC
...
[   44s] E: Failure("Command ''/usr/bin/ocamlbuild' src/oasis/oasis.cma src/oasis/oasis.cmxa src/oasis/oasis.a src/oasis/oasis.cmxs src/base/base.cma src/base/base.cmxa src/base/base.a src/base/base.cmxs src/builtin-plugins.cma src/builtin-plugins.cmxa src/builtin-plugins.a src/builtin-plugins.cmxs src/dynrun/dynrun.cma src/dynrun/dynrun.cmxa src/dynrun/dynrun.a src/dynrun/dynrun.cmxs src/ext/plugin-loader/src/plugin-loader.cma src/ext/plugin-loader/src/plugin-loader.cmxa src/ext/plugin-loader/src/plugin-loader.a src/ext/plugin-loader/src/plugin-loader.cmxs src/cli/cli.cma src/cli/Main.byte src/ext/userconf/src/userconf.cma src/ext/userconf/src/userconf.cmxa src/ext/userconf/src/userconf.a src/ext/userconf/src/userconf.cmxs -use-ocamlfind -tag debug' terminated with error code 10")

The workaround is to overwrite libasmrun.a in ocaml like this:
cp -av --remove-destination \
        %{buildroot}%{_libdir}/ocaml/libasmrun_pic.a \
        %{buildroot}%{_libdir}/ocaml/libasmrun.a

Is there a secret knob to let ocamlbuild select the pic version of libasmrun?


Olaf