AdaCore / gnat-llvm

LLVM based GNAT compiler
179 stars 18 forks source link

Undefined symbol ___muloti4 #36

Closed simonjwright closed 11 months ago

simonjwright commented 11 months ago

Having build gnat-llvm as in #35, i tried building zertovitch’s HAC. Aside from the linking problem with clang: error: unsupported option '-static-libgcc', I encountered this:

Undefined symbols for architecture arm64:
  "___muloti4", referenced from:
      _hac_sys__multi_precision_integers__div_rem_internal_both in hac_sys-multi_precision_integers.o
Undefined symbols for architecture arm64:
  "___muloti4", referenced from:
      _hac_sys__multi_precision_integers__div_rem_internal_both in hac_sys-multi_precision_integers.o
Undefined symbols for architecture arm64:
  "___muloti4", referenced from:
      _hac_sys__multi_precision_integers__div_rem_internal_both in hac_sys-multi_precision_integers.o

I think GCC PR103034 may relate.

simonjwright commented 11 months ago

This can be fixed by linking with

-largs -L$HOMEBREW_PREFIX/opt/llvm/lib/c++ -lc++

(note, writing just

-largs -lc++

so as to use Apple’s libc++ fails)

simonjwright commented 11 months ago

Using my release 0.1.0, and ignoring gnatbind’s output of -static with the appropriate binder package, this issue doesn’t occur, in spite of the fact that

$ nm -A *.o | grep muloti4
hac_sys-multi_precision_integers.o:                  U ___muloti4

The link was done using clang, and the relevant link libraries (gnat-llvm was installed in /Users/simon/gnat-llvm) were

/Users/simon/gnat-llvm//lib/rts-native/adalib/libgnarl.a 
/Users/simon/gnat-llvm//lib/rts-native/adalib/libgnat.a 
-lm

and with some investigation it turns out that ___muloti4 is provided in several of the system libraries, specifically in /Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib’s libm.tbd, libSystem.B.tbd -- the latter is the one that hac depends on at runtime.

ArnaudCharlet commented 11 months ago

It's most likely an issue on how LLVM itself is setup/configured, since this symbol is supposed to be provided either by libgcc, or llvm's equivalent compiler-rt, so not something directly in the scope of GNAT LLVM itself.