Repository navigation
Closed
Description
Hello,
some days ago tidal was updated to have link support, this is done by the following package https://hackage.haskell.org/package/tidal-link.
unfortunately this seems to break running tidal inside a hint interpreter. Here is a minimal example:
module Main where
import Language.Haskell.Interpreter
main :: IO ()
main = do
x <- runInterpreter interpreter
case x of
Left e -> putStrLn (show e)
Right _ -> return ()
interpreter :: Interpreter ()
interpreter = do
setImportsF [ModuleImport "Sound.Tidal.Context" NotQualified NoImportList, ModuleImport "Prelude" NotQualified NoImportList]
runStmt "tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = \"127.0.0.1\", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20})"
it throws the following errors:
hint-try: /home/martin/.cabal/store/ghc-9.2.3/tidal-link-1.0.1-e904e203bf8f1a5046be19d3e454931fcff763f9b9920cad70d59e090bc3569f/lib/libHStidal-link-1.0.1-e904e203bf8f1a5046be19d3e454931fcff763f9b9920cad70d59e090bc3569f.a: ELF TLSGD relocation for symbol `_ZN4asio6detail15keyword_tss_ptrINS0_10call_stackINS0_14thread_contextENS0_16thread_info_baseEE7contextEE6value_E' not supported on the target platform
hint-try: /home/martin/.cabal/store/ghc-9.2.3/tidal-1.9.2-54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e/lib/libHStidal-1.9.2-54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e.a: unknown symbol `abl_link_create_session_state'
hint-try: ^^ Could not load 'tidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_con_info', dependency unresolved. See top entry above.
hint-try: ^^ Could not load 'tidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_static_info', dependency unresolved. See top entry above.
GhcException "\nGHC.ByteCode.Linker.lookupIE\nDuring interactive linking, GHCi couldn't find the following symbol:\n tidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_con_info or tidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_static_info\nThis may be due to you not asking GHCi to load extra object files,\narchives or DLLs needed by your current session. Restart GHCi, specifying\nthe missing library using the -L/path/to/object/dir and -lmissinglibname\nflags, or simply by naming the relevant files on the GHCi command line.\nAlternatively, this link failure might indicate a bug in GHCi.\nIf you suspect the latter, please report this as a GHC bug:\n https://www.haskell.org/ghc/reportabug\n"
note that running the same line of code in a ghci session works fine.
i'm really lost here, so i hope someone can help!
Metadata
Metadata
Assignees
Labels
No labels
Activity
gelisam commentedon Sep 16, 2022
I need more information.
ldand.so/.dllfiles?hint-try: ...errors are from cabal, not hint, and thus the problem occurs before hint can do anything about it?gelisam commentedon Sep 16, 2022
Do you start your ghci session in a way which also causes those
hint-try: ...errors to appear?polymorphicengine commentedon Sep 16, 2022
thanks for the quick reply,
no, in ghci i just import Sound.Tidal.Context and run
tidal <- startTidal (superdirtTarget {oLatency = 0.1, oAddress = "127.0.0.1", oPort = 57120}) (defaultConfig {cVerbose = True, cFrameTimespan = 1/20})which throws no errors and starts the tidal stream as expected
polymorphicengine commentedon Sep 16, 2022
the following only imports tidal-link and fails with basically the same error:
only importing tidal-link, without executing any code related to it works fine.
i tried some other functions from https://hackage.haskell.org/package/tidal-link-1.0.1/docs/Sound-Tidal-Link.html aswell and all seem to fail..
zalastax, author of tidal-link suggested to call ghc with argument "-Lstdc++", so i tried using
unsafeRunInterpreterWithArgs ["-Lstdc++"], but it results in the same error message toogelisam commentedon Sep 16, 2022
Let's take a closer look at the error messages.
The
hint-try: ...messages complain about the following symbols:_ZN4asio6detail15keyword_tss_ptrINS0_10call_stackINS0_14thread_contextENS0_16thread_info_baseEE7contextEE6value_Eabl_link_create_session_statetidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_con_infotidalzm1zi9zi2zm54c2e1be48d3c91b38aa9169eaa072a94363b15bbbc85dac3185686222ca970e_SoundziTidalziStream_Target_static_infoThe shape of these symbols tell us that they are, respectively:
And once we decode those names, we get something a lot more readable:
asio::detail::keyword_tss_ptr<asio::detail::call_stack<asio::detail::thread_contextasio::detail::thread_info_base>::context>::value_abl_link_create_session_state3.
tidal-1.9.2-012aac824dcb46a140aefc0b0d9e9c6e5504cdb417cbaf42de9ebe02634045b9_Sound.Tidal.Stream_Target_con_infotidal-1.9.2-012aac824dcb46a140aefc0b0d9e9c6e5504cdb417cbaf42de9ebe02634045b9_Sound.Tidal.Stream_Target_static_infogelisam commentedon Sep 16, 2022
By adding a print statement before the
runInterpretercall, or simply by compiling the program with cabal and then running the executable manually afterwards, I have determined that on the contrary, the errors are thrown by the executable, not by cabal, somewhere during the execution of thestartTidalline.gelisam commentedon Sep 16, 2022
The error occurs even if the interpreted code is simplified to
but not if it is further simplified to
Therefore, the issue doesn't happen when the
startTidalorcreateSessionStateIO action is executed, but rather, when the module which providessuperdirtTargetis loaded. Note that it is lazily loaded, which is why importing that module is insufficient to trigger the error.gelisam commentedon Sep 16, 2022
I see you've added a tidal-link-1.0.1 exporting an extra
hello :: IO ()action. Thanks, this helps to eliminate a whole bunch of code, as the following still fails:This time the unmangled symbols are:
asio::detail::keyword_tss_ptr<asio::detail::call_stack<asio::detail::thread_contextasio::detail::thread_info_base>::context>::value_abl_link_createtidal-link-1.0.1-0358d4e416ad055e1e148187987824589541f00f08ddb5855faa8ff4af619c66_Sound.Tidal.Link_hello_closureThe
asio::...::value_symbol is the same, which makes me think that this is the cause of all the other missing symbols.gelisam commentedon Sep 16, 2022
My mistake, now that I am taking a look at the source for
hello, I see that it's actually exercising the library's other functions, it's not justhello = putStrLn "hello"as I expected from the name.gelisam commentedon Sep 16, 2022
If I change the implementation to
hello = putStrLn "hello", I still get the error, so we're back to "Thanks, this helps to eliminate a whole bunch of code" :)gelisam commentedon Sep 16, 2022
Deleting the rest of the hsc file makes the error disappear, so it's definitely the lazy-loading of this module which is triggering the errors.
gelisam commentedon Sep 16, 2022
Here's a minimal hsc module which still reproduces the problem:
{-# LANGUAGE ForeignFunctionInterface #-} module Sound.Tidal.Link where foreign import ccall "abl_link.h abl_link_create" create :: IO () hello :: IO () hello = print "hello"I'm lying about the type of
abl_link_createin order to minimize the imports, socreatewould fail at runtime when the IO action is called, but here we're not even calling it, we're callinghello. It doesn't matter whether I keepabl_link_createor any of the other foreign imports of this file. I suspect the problem is in the linkedabl_link.hfile.gelisam commentedon Sep 16, 2022
I've narrowed it down to this line:
https://github.com/tidalcycles/Tidal/blob/a9208569cbd86ee0c0c39052f354ee4984d701d9/tidal-link/link/extensions/abl_link/src/abl_link.cpp#L21
I have simplified the
.h,.cpp, and.hscfiles to their bare minimum:The error disappears if I remove the
#include <ableton/Link.hpp>line.Note that cabal doesn't automatically recompile when I change those C++ files, so I had to delete the
dist-newstylefolder after each change.gelisam commentedon Sep 16, 2022
Narrowed it down further tohttps://github.com/tidalcycles/Tidal/blob/a9208569cbd86ee0c0c39052f354ee4984d701d9/tidal-link/link/include/ableton/Link.hpp#L25That is, I'm now hopping fromableton/Link.hpptoableton/platforms/Config.hpp...gelisam commentedon Sep 16, 2022
...totidal-link/link/include/ableton/platforms/asio/Context.hpp...16 remaining items
gelisam commentedon Sep 20, 2022
Do you have a file which looks like
~/.ghc/x86_64-linux-8.10.7/environments/default?You mentioned that you did not include
cabal repl'spackage-dbarguments, and that surprised me since they seem pretty important. On my side, I was usingwrite-ghc-environment-files: alwaysin mycabal.projectin order forcabal.buildto generate a.ghc.environment.x86_64-linux-8.10.7file listing all the package databases and package ids, so even whenunsafeRunInterpreterWithArgswas receiving zero arguments,hintwas still getting its package-db information from that file. I tried deleting it in order to make sure I was usingcabal repl's package-db flags and only that package-db information, but something surprising happened instead: I started getting errors about megaparsec?? I got that error with bothcabal replandcabal run. It turns out that in the absence of a.ghc.environment.x86_64-linux-8.10.7, ghc is using a file~/.ghc/x86_64-linux-8.10.7/environments/defaultinstead, and I had a stale line about megaparsec in there. I deleted the file, and the megaparsec error went away.With neither
~/.ghc/x86_64-linux-8.10.7/environments/defaultnor.ghc.environment.x86_64-linux-8.10.7nor passing the package-db flags tounsafeRunInterpreterWithArgs, bothcabal replandcabal runfail withCould not find module Sound.Tidal.Link.With either a
~/.ghc/x86_64-linux-8.10.7/environments/defaultwhich includes tidal-link (by installing it globally viacabal install --lib tidal-link), a.ghc.environment.x86_64-linux-8.10.7file which includes tidal-link (by including it inhint-try.cabal's list of dependencies), or by passing package-db flags which include-package-id tidal-link-1.0.1-[...]tounsafeRunInterpreterWithArgs(as obtained fromcabal repl -vwhen tidal-link is included inhint-try.cabal's list of dependencies),cabal replsucceeds whilecabal runfails withunknown symbol blah.gelisam commentedon Sep 20, 2022
In particular, you mentioned
-Lstdc++early on, and I see anextra-libraries: stdc++line in my package database'stidal-link-1.0.1-[...].conffile, so if hint doesn't get to see this file, that could explain the error. I don't think so though, because as the above comment explains, hint would fail earlier withSound.Tidal.Linkif it did not see that file.gelisam commentedon Sep 20, 2022
That was a lot of information, so, to summarize: I was wrong about the difference between
cabal replandcabal runbeing the arguments being passed tounsafeRunInterpreterWithArgs. We're back to square one: trying to minimize the repro steps to something smaller than all of boost::asio.gelisam commentedon Sep 20, 2022
The other obvious difference between
cabal replandcabal runis the environment variables. Here are the differences I see:Only with
cabal repl:HASKELL_DIST_DIR="/.../dist-newstyle/build/x86_64-linux/ghc-8.10.7/toy-0.1.0.0/x/hint-try"PATH="...:$HOME/.cabal/bin"SHLVL=1Only with
cabal run:_="$HOME//.ghcup/bin/cabalPATH="..."SHLVL=2But this is a red herring too, because if I add a couple of
setEnvcalls at the beginning ofmainto force the environment to match thecabal replvalues in both runs, I still see a success withcabal repland a failure withcabal run. What else could it be?gelisam commentedon Sep 20, 2022
Interesting. If I try to run
createSessionStateinmain, before running it inside hint, the one inhintfails with a different error:I actually recognize that error message: deep in the bowels of ghc, there's some custom linking code handling various types of "relocations", whatever that is, and ghc doesn't support all the types of relocations which can be found in the wild. So it could be that the root of the issue is that boost::asio, as compiled by g++, produces a symbol which needs a relocation code which ghc does not support. It still doesn't explain why
cabal runneeds to relocate the symbol whilecabal repldoesn't.gelisam commentedon Sep 20, 2022
Interestingly, when I upgrade to ghc-9.2, I no longer get
unhandled ELF relocation(RelA) type 19, I get the usualELF TLSGD relocation for symbol blah. Those two messages are awfully similar, but it's only the first message which I recognize.polymorphicengine commentedon Sep 21, 2022
I'm still struggling to understand what is really going on here but i tried
cabal run --ghc-options=-dynamicwhich fixes the error (with the original tidal-link library).. note that when using-dynamicas an argument forunsafeRunInterpreterWithArgsthe following error is thrown (by hint and not the binary):GhcException "<interactive>: fatal:\n Cannot load -dynamic objects when GHC is built the normal way\n To fix this, either:\n (1) Use -fexternal-interpreter, or\n (2) Build the program twice: once the normal way, and then\n with -dynamic using -osuf to set a different object file suffix."While it is great that this fixes the problem, I strongly suspect that this will not really work when I'm trying to package everything so that tidal can be run on systems without an installation of ghc (which is kind of the whole point of this!), so it would be great to understand the problem a bit better and see what is actually going on
polymorphicengine commentedon Oct 19, 2022
coming back to this, i am still very lost.. hope someone can find some time to help me out!
yaxu commentedon Dec 19, 2022
Just a bump on this as it would be lovely to resolve our very long running aim to have an easy binary distribution of tidal !
gelisam commentedon Dec 19, 2022
Sorry, I don't have much time for open source work these days. Keep reminding me though, so that once I do find time I can make sure I spend it on something useful!
polymorphicengine commentedon Jun 16, 2023
great to see that hint is now working with ghc 9.6.2!
unfortunately, this error still persists with the new version. it would be great if we could fix it!
gelisam commentedon Jun 16, 2023
You have once again solved the case!
While googling for
-dynamic, I found this wiki page. It explains that the GHC runtime contains a custom linker, and that maintaining it is a pain. Indeed, that linker is missing some of the more exotic types of relocation, and that's why we see a relocation error forasio::...::value_.To work around these holes in the custom linker, ghci is compiled using
-dynamic, which allows it to reuse the system's linker instead of relying on its custom linker. This explains why ghci is able to loadsio::...::value_and whycabal run -dynamiccan load it too.Thus, the next steps are: figure out whether you're okay with using
-dynamic, and if not, figure out how to add the missing relocation implementation to GHC's custom linker.Feel free to continue the discussion on this thread if you have more questions, but now that I understand the problem, I no longer think that there is a bug in hint's codebase, so I will mark this ticket as closed.
polymorphicengine commentedon Jun 18, 2023
alright, so i tried the following things:
-dynamicand-fexternal-interpreterto hints rununsafeRunInterpreterWithArgsLibdirand compile the usual waythis results in the following error:
/home/martin/Downloads/artifact/linux/tidal/haskell-libs/bin/ghc-iserv-dyn: error while loading shared libraries: libHSlibiserv-9.4.2-ghc9.4.2.so: cannot open shared object file: No such file or directoryif i do
ldd ghc-iserv-dyni can see that it can't find the shared libraries, so then i tried to link to all of the neccessary .so files via symbolic links andexport LD_LIBRARY_PATH=$LD_LIBRARY_PATH:../ghc-packages, now i see with ldd that all libs are found but it still fails with the same error.--ghc-options=-dynamic, this will produce a binary that is, similar to above can't find the shared libraries, and if i try to link them the issue also persists.is there something else i could try?
you can have a look at the workflow and produced artifact here: https://github.com/polymorphicengine/Tidal/actions/runs/5303831109
polymorphicengine commentedon Jun 19, 2023
ok, i forgot to add the `ld-options` field in the .cabal file. now it seems to find the shared libraries, but the following error is thrown:
tidal-listener: /home/martin/Downloads/tidal-release-linux/tidal-listener-linux/binary/haskell-libs/bin/ghc-iserv-dyn: createProcess: posix_spawnp: does not exist (No such file or directory)very cryptic. what exactly does not exist?
ok this was just me messing up where i put the bin folder