Tooling/linker issue in FreeBSD

First of all, I am new to OCaml so apologies in advance if I’ve missed something terribly obvious. I am super excited to be able to work on OCaml and FreeBSD!

I also acknowledge this is a FreeBSD specific topic but I’ve not been able to find anything in that community that addresses this issue. I promise that I will write up anything I learn and share it with both communities. I do believe there is nothing currently that addresses this topic specifically, but am happy to be shown that my search skills are weak :grin:.

That said, I am working on the Tezos project and work primarily in FreeBSD. There are a number of libraries that are used that frequently have GNU/Linux specific linker flags which cause difficulties. In the past I have installed the binutils package and this has seemed to fix things.

After spending more time on this and looking into it a bit further, I’m sure I’m not doing the right thing. I’ve come across issues [1][2] that indicate just throwing some GNU tools at the problem is not sufficient (and is likely causing issues).

I do have a specific example [3] that I’m working through now and I’m hoping to come out of this exercise with a solid understanding of how I should be building OCaml libraries on FreeBSD.

As it says in [3] I just symlinked ld to get the package to build, but this is clearly not a long term solution. Can someone help me understand how OCaml (or dune?) can potentially choose between different toolchains/tools?

Thanks so much for any advice.

  1. configure: use cc as assembler with clang and for all FreeBSD platforms by xavierleroy · Pull Request #9437 · ocaml/ocaml · GitHub
  2. Fix mergeable section flags. by jacobly0 · Pull Request #9981 · ocaml/ocaml · GitHub
  3. Build fails on FreeBSD (#50) · Issues · Danny Willems / ocaml-bls12-381 · GitLab

ocaml hardcodes the choice of toolchain at ./configure time, and dune just calls into ocaml, so there isn’t much that can be done at this level.

If you have trouble building a package on FreeBSD this is typically something for the upstream developer to fix by avoiding use of Linux-isms or by providing similar -isms for FreeBSD.

Cheers,
Nicolas

Interesting … my normal workflow is to create a local switch with opam. I will dig into what’s happening when I create that switch. I know there’s a ./configure step but hadn’t thought to inspect that.

Is there a way to show ocaml’s configuration after it’s built? (e.g. what toolchain it may be using/which linker/etc). I didn’t see anything obvious on the CLI.

Try ocamlc -config.

Cheers,
Nicolas

1 Like

Concerning your failure case:

This doesn’t look like an OCaml problem to me, rather a problem with the bls12-381-unix package you’re using. It seems to be building a C shared library using GNU ld-specific options:

cc -shared -o libblst.so libblst.a -O -fno-builtin-memcpy -fPIC -Wall -Wextra -Werror -Wno-missing-braces -mno-avx '-Wl,-Bsymbolic,--require-defined=blst_keygen' '-Wl,--version-script=/dev/fd/0'
ld: error: unknown argument '--require-defined=blst_keygen'           

The require-defined option is definitely not inserted by OCaml, so it comes from the build instructions for this blst package, and that’s where you should look for a fix.

Concerning your more general point about OCaml and BSD: the core OCaml system is developed both under Linux and under macOS, and our CI also includes FreeBSD and OpenBSD, so you can expect reasonable BSD support here. Some OPAM packages contain Linux-isms, indeed, but I think these are being chased out as OPAM-wide CI is being deployed.

1 Like