janestreet/core

opam/4.07.1/lib/stublibs/dllcore_stubs.so: undefined symbol: caml_exn_Invalid_argument.

bramford opened this issue · 13 comments

Environment

OS

Distro: Debian 10 (testing)
Kernel: Linux 4.19.0-5-amd64 #1 SMP Debian 4.19.37-3 (2019-05-15) x86_64 GNU/Linux
Glibc: Debian GLIBC 2.28-10

OCaml

ocaml: 4.07.1
utop: 2.3.0
core & core_kernel: v0.12.2

Issue

I get this error when attempting to load core in to utop (or utop-full)

utop # #require "core";;
Cannot load required shared library dllcore_stubs.
Reason: /opt/opam/4.07.1/lib/stublibs/dllcore_stubs.so: /opt/opam/4.07.1/lib/stublibs/dllcore_stubs.so: undefined symbol: caml_exn_Invalid_argument.

Looks very similar to #117 which suggests the cause is choice of Glibc version.

I'll test with a different Glibc version and add further notes to this issue.

ocaml/opam2:latest docker image

  • Debian 9.9
  • OCaml: 4.07.1
  • Glibc: Debian GLIBC 2.24-11+deb9u4
  • core: v0.12.1
  • core_kernel: v0.12.0

No issues.

debian:testing docker image

  • Debian 10
  • OCaml: 4.07.1
  • Glibc: Debian GLIBC 2.28-10
  • core: v0.12.2
  • core_kernel: v0.12.2

Same issue as originally reported

Run these commands on a machine with docker installed to reproduce:

docker run -ti debian:testing /bin/bash
apt update && apt install opam build-essential m4
opam init --disable-sandboxing
opam switch create 4.07.1
opam install core utop
utop
#require "core";;

debian:stable docker image

This version of Debian runs opam 1.2.2 which doesn't appear to support ocaml 4.07.1.

Reproduces on macOS 10.14.5 with Nix overlay.

$ otool -L /Users/paul/.opam/4.07.1/lib/stublibs/dllcore_stubs.so
/Users/paul/.opam/4.07.1/lib/stublibs/dllcore_stubs.so:
        src/dllcore_stubs.so (compatibility version 0.0.0, current version 0.0.0)
        /nix/store/yjy1ix56rvqgk1526zlrfb6mk9b3x0p5-Libsystem-osx-10.12.6/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)

(This appears to be a regression relative to v0.12.1 .)

I am having the same problem on Linux (ocaml 4.07.0):

/home/lord/.opam/4.07.0+flambda/lib/core/libcore_stubs.a(unix_stubs.o): In function `core_copy_to_c_string':
/home/lord/.opam/4.07.0+flambda/.opam-switch/build/core.v0.12.2/_build/default/src/unix_stubs.c:173: undefined reference to `caml_exn_Invalid_argument'
/home/lord/.opam/4.07.0+flambda/lib/core/libcore_stubs.a(ocaml_utils_stubs.o): In function `string_ocaml_to_c':
/home/lord/.opam/4.07.0+flambda/.opam-switch/build/core.v0.12.2/_build/default/src/ocaml_utils_stubs.c:73: undefined reference to `caml_exn_Invalid_argument'
collect2: error: ld returned 1 exit status
File "_none_", line 1:
Error: Error while building custom runtime system

and MacOS (ocaml 4.07.1):

Undefined symbols for architecture x86_64:
  "_caml_exn_Invalid_argument", referenced from:
      _core_unix_remove in libcore_stubs.a(unix_stubs.o)
      _string_ocaml_to_c in libcore_stubs.a(ocaml_utils_stubs.o)
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
File "_none_", line 1:

core v0.12.2 (installed via OPAM).

UPD: Pinning core to 0.12.1 fixed that.

There's something that was fixed in d371128 (see src/ocaml_utils_stubs.c) that is probably the reason.
The symptom is that the library doesn't work in bytecode and I don't know of any workaround (short of actually defining the symbol or applying the fix).
Native code should work.

With macOS 10.14.5 and Ocaml 4.08.0 I am having the same problem with #require "core";;

Error:

utop # #require "core";;
Cannot load required shared library dllcore_stubs.
Reason: /abc/xyz/ocaml408/_opam/lib/stublibs/dllcore_stubs.so: dlopen(/abc/xyz/ocaml408/_opam/lib/stublibs/dllcore_stubs.so, 10): Symbol not found: _caml_exn_Invalid_argument
  Referenced from: /abc/xyz/ocaml408/_opam/lib/stublibs/dllcore_stubs.so
  Expected in: flat namespace
 in /abc/xyz/ocaml408/_opam/lib/stublibs/dllcore_stubs.so.

Same problem with on my Linux machine as well.

# opam config report
# opam-version      2.0.4 
# self-upgrade      no
# system            arch=x86_64 os=linux os-distribution=ubuntu os-version=18.04
# solver            builtin-mccs+glpk
# install-criteria  -removed,-count[version-lag,request],-count[version-lag,changed],-changed
# upgrade-criteria  -removed,-count[version-lag,solution],-new
# jobs              3
# repositories      1 (http) (default repo at 24059019)
# pinned            0
# current-switch    4.08.0+flambda

Same problem on:

uname -srv  
Linux 5.1.9-arch1-1-ARCH #1 SMP PREEMPT Tue Jun 11 16:18:09 UTC 2019
# opam-version      2.0.4 
# self-upgrade      no
# system            arch=x86_64 os=linux os-distribution=arch os-version=unknown
# solver            builtin-mccs+glpk
# install-criteria  -removed,-count[version-lag,request],-count[version-lag,changed],-changed
# upgrade-criteria  -removed,-count[version-lag,solution],-new
# jobs              3
# repositories      1 (http), 1 (version-controlled) (default repo at 08cc4d5c)
# pinned            0
# current-switch    /home/marc/src/mtswitch
opam switch create ./ 4.08.0
opam install dune core utop
dune utop

In the case stated above, utop still starts throwing:

Cannot load required shared library dllcore_stubs.
Reason: /home/marc/src/mtswitch/_opam/lib/stublibs/dllcore_stubs.so: /home/marc/src/mtswitch/_opam/lib/stublibs/dllcore_stubs.so: undefined symbol: caml_exn_Invalid_argument.
Exception: Symtable.Error (Symtable.Undefined_global "Core__Core_time_ns").
Raised at file "bytecomp/symtable.ml", line 75, characters 9-49
Called from file "bytecomp/symtable.ml", line 330, characters 24-45
Called from file "toplevel/toploop.ml", line 66, characters 16-32
Called from file "toplevel/toploop.ml", line 66, characters 16-32
Called from file "toplevel/topdirs.ml", line 361, characters 12-46
Called from file "toplevel/toploop.ml", line 361, characters 69-74
Called from file "toplevel/toploop.ml", line 370, characters 6-42
Re-raised at file "toplevel/toploop.ml", line 373, characters 10-13
Called from file "top/core_install_printers.ml", line 15, characters 4-19
Called from file "top/core_install_printers.ml", line 18, characters 9-36
Called from file "toplevel/topdirs.ml", line 157, characters 11-23
File "/home/marc/src/mtswitch/_opam/lib/toplevel/topfind", line 1:
Error: Reference to undefined global `Core'

My .ocamlinit is verbatim to the one in RWO.

In an other case/project, dune utop crashes hard

dune utop
      ocamlc .utop/utop.exe (exit 2)
[...]
/usr/bin/ld: /home/marc/src/attempt123/_opam/lib/core/libcore_stubs.a(unix_stubs.o): in function `core_copy_to_c_string':
/home/marc/src/attempt123/_opam/.opam-switch/build/core.v0.12.2/_build/default/src/unix_stubs.c:173: undefined reference to `caml_exn_Invalid_argument'
/usr/bin/ld: /home/marc/src/attempt123/_opam/lib/core/libcore_stubs.a(ocaml_utils_stubs.o): in function `string_ocaml_to_c':
/home/marc/src/attempt123/_opam/.opam-switch/build/core.v0.12.2/_build/default/src/ocaml_utils_stubs.c:73: undefined reference to `caml_exn_Invalid_argument'
collect2: error: ld returned 1 exit status
File "_none_", line 1:
Error: Error while building custom runtime system

Thanks! ❤️

Update:
@vzaliva is right, downgrading to 0.12.1 (and to 4.07) solves the issue.

I also tried pinning base, core_kernel and core to master. base builds fine and core_kernel fails to build.

What is, if there is, the proper way to pin master for core_kernel and core? I would have liked to quickly try to reproduce on master.

Thanks!

opam pin https://github.com/janestreet/core_kernel.git#master
[core_kernel] synchronised from git+https://github.com/janestreet/core_kernel.git#master
[NOTE] Package core_kernel is already pinned to git+https://github.com/janestreet/core_kernel.git#master (version v0.12.2).
[core_kernel.v0.12.2] no changes from git+https://github.com/janestreet/core_kernel.git#master
core_kernel is now pinned to git+https://github.com/janestreet/core_kernel.git#master (version v0.12.2)
The following actions will be performed:
  ∗ install core_kernel v0.12.2*
Do you want to continue? [Y/n] y
[core_kernel.v0.12.2] synchronised from git+https://github.com/janestreet/core_kernel.git#master

<><> Processing actions <><><><><><><><><><><><><><><><><><><><><><><><><><><><>
[ERROR] The compilation of core_kernel failed at "/home/marc/.opam/opam-init/hooks/sandbox.sh build dune build -p core_kernel -j 3".

#=== ERROR while compiling core_kernel.v0.12.2 ================================#
# context     2.0.4 | linux/x86_64 | ocaml-variants.4.07.1+flambda | pinned(git+https://github.com/janestreet/core_kernel.git#master#c25b36bf)
# path        ~/src/mtswitch/_opam/.opam-switch/build/core_kernel.v0.12.2
# command     ~/.opam/opam-init/hooks/sandbox.sh build dune build -p core_kernel -j 3
# exit-code   1
# env-file    ~/.opam/log/core_kernel-12308-0325cb.env
# output-file ~/.opam/log/core_kernel-12308-0325cb.out
### output ###
# [...]
# Because your project was written for dune 1.5, I am closing my eyes on this
# and I am acting as if the rule didn't exist. However, you should really
# delete these files from your source tree. I will no longer accept this once
# you upgrade your project to dune >= 1.10.
#       ocamlc src/md5_stubs.o
# md5_stubs.c:11:32: warning: ‘-pedantic’ is not an option that controls warnings [-Wpragmas]
#  #pragma GCC diagnostic ignored "-pedantic"
#                                 ^~~~~~~~~~~
#       ocamlc src/.core_kernel.objs/byte/core_kernel__Or_error.{cmi,cmti} (exit 2)
# (cd _build/default && /home/marc/src/mtswitch/_opam/bin/ocamlc.opt -w -40 -g -bin-annot -I src/.core_kernel.objs/byte -I /home/marc/src/mtswitch/_opam/lib/base -I /home/marc/src/mtswitch/_opam/lib/base/base_internalhash_types -I /home/marc/src/mtswitch/_opam/lib/base/caml -I /home/marc/src/mtswitch/_opam/lib/base/md5 -I /home/marc/src/mtswitch/_opam/lib/base/shadow_stdlib -I /home/marc/src/mt[...]
# File "src/or_error.mli", line 15, characters 2-53:
# Error: The signature constrained by `with' has no component named IO_flush.t

This should be fixed in v0.13-preview.120.26+17 (d371128).

As for how to use bleeding edge versions of Jane Street packages, this repo should help:

https://github.com/janestreet/opam-repository

I have created a branch, namely issue-131, with what I assume is
the necessary subset from d371128 pointed by @aalekseyev.
If someone can confirm it fixes the problem (I have not been able
to reproduce it locally), it will be used to release a v0.12.3.

It seems unlikely the issue is a regression from v0.12.1 to v0.12.2,
as the diff seems unrelated (unless I made a mistake with tags).

Update:
Using https://github.com/janestreet/opam-repository and doing a couple pins (core, base to v0.13-preview.120.41+17 and ppxlib to master) does not lead to the issue.

sergi commented

For the record, having the same issue on OSX:

Cannot load required shared library dllcore_stubs.
Reason: /Users/sergimansilla/.opam/default/lib/stublibs/dllcore_stubs.so: dlopen(/Users/sergimansilla/.opam/default/lib/stublibs/dllcore_stubs.so, 10): Symbol not found: _caml_exn_Invalid_argument
  Referenced from: /Users/sergimansilla/.opam/default/lib/stublibs/dllcore_stubs.so
  Expected in: flat namespace
 in /Users/sergimansilla/.opam/default/lib/stublibs/dllcore_stubs.so.
Exception: Symtable.Error _.
Raised at file "bytecomp/symtable.ml", line 75, characters 9-49
Called from file "bytecomp/symtable.ml", line 330, characters 24-45
Called from file "toplevel/toploop.ml", line 66, characters 16-32
Called from file "toplevel/toploop.ml", line 66, characters 16-32
Called from file "toplevel/topdirs.ml", line 361, characters 12-46
Called from file "toplevel/toploop.ml", line 361, characters 69-74
Called from file "toplevel/toploop.ml", line 370, characters 6-42
Re-raised at file "toplevel/toploop.ml", line 373, characters 10-13
Called from file "top/core_install_printers.ml", line 15, characters 4-19
Called from file "top/core_install_printers.ml", line 18, characters 9-36
Called from file "toplevel/topdirs.ml", line 157, characters 11-23

This is my .ocamlinit (RWO):

#use "topfind";;
#thread;;
#require "core.top";;
#require "core.syntax";;
open Core

Update:
Pined on https://github.com/janestreet/core.git#v0.12.3 and all is back to 💯 (at least on my end)!
Thanks for fixing :)