Utop not working

Hi,

I installed utop from opam but I am not able to lauch it,
here is my error

I m on windows, If someone can help :slight_smile:

Nothing comes to mind at the moment, but just to flesh out the issue description:
which toolchain are you using? MSVC or Mingw? 32-bit or 64-bit? Which version of OCaml? How did you build your packages?

Cheers,
Nicolas

I have tested on my environment (cygwin/mingw) just after a fresh install (though opam, comming from the fdopen repo)

$ opam install utop
The following actions will be performed:
  ↘ downgrade zed         3.2.0 to 3.1.0 [required by lambda-term]
  ∗ install   lambda-term 3.2.0          [required by utop]
  ∗ install   utop        2.9.2
…

Then the same issue:

D:\home\.opam\4.14.0+flambda+mingw64\bin>utop
Fatal error: cannot load shared library dlllwt_unix_stubs
Reason: flexdll error: cannot relocate uerror RELOC_REL32, target is too far: ffff8009fdb66776  fffffffffdb66776

This sounds like an issue that had been reported some time ago. Due to a change in the Mingw binutils 64bit Windows builds were broken: "Cannot relocate" error with flexdll in OCaml for Windows 4.11 (and older versions) ¡ Issue #92 ¡ ocaml/flexdll ¡ GitHub
In the issue mingw64-x86_64-binutils version 2.35.2-1 were reported to work.
Currently, I am using version 2.38-1 which also seem to be ok. For the newer version of binutils, there was also a constraint on the ocaml version, but I can’t remember that exactly (4.14.0 should be ok, but I don’t know about the flambda config).

What’s the output of:

x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-ld --version

Did you compile 4.14.0+flambda+mingw64,lwt, utop, etc. with the same versions of gcc/binutils that are currently installed? Or were cygwin packages updated in the meantime?

I hope that the problem disappears again when all packages are built with the same versions of gcc/binutils. Otherwise I guess I have to reintroduce the old hack for flexdll, which is still used for msvc64, and leads to other problems…

Well, looking at the error message again and at ocaml/unixsupport.h at 4.14 ¡ ocaml/ocaml ¡ GitHub
Why is CAMLextern not used inside unixsupport.h? ( e.g. ocaml/unixsupport.h at d2689fced77bd09b4c67fd629cd46ac07740c5f8 ¡ ocaml/ocaml ¡ GitHub )
@dra27, @nojb?

Does the error disappear when it is changed manually?

cp -p "$(opam var lib)/ocaml/caml/unixsupport.h" "$(opam var lib)/ocaml/caml/unixsupport.h.bak"
sed -i 's|extern |CAMLextern |g' "$(opam var lib)/ocaml/caml/unixsupport.h"
opam reinstall lwt

When the __declspec(dllimport) part was reintroduced for Cygwin, it wasn’t necessary to do it for symbols outside the runtime. IIRC Cygwin’s address space layout not only guarantees that the main executable will be more than 2GiB away from shared libraries, but also guarantees that DLLs will be loaded within the same 2GiB area. I just co-opted that change when binutils 2.35 changed the default base addresses for mingw-w64.

I’m struggling to reproduce it “naturally” (i.e. without manually setting DLL base addresses to be a long way apart), but unixsupport.h can be updated, naturally.

I have recreated a new opam switch

$ opam switch create "4.14.0+flambda+mingw64_for_utop" 4.14.0+flambda+mingw64

Then install utop again and now the issue is gone. Maybe was it caused by a (not so) old previous installation. Anyway, here is the requested output:

$ x86_64-w64-mingw32-gcc --version
x86_64-w64-mingw32-gcc (GCC) 11.3.0
$ x86_64-w64-mingw32-ld --version
GNU ld (GNU Binutils) 2.38