Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Libraries that use Template Haskell cannot use atomic-primops (cas symbol problem) #10

Closed
robstewart57 opened this issue Jul 18, 2013 · 7 comments

Comments

@robstewart57
Copy link
Contributor

Libraries or programs that use Template Haskell will not be able to use the atomic-primops library. The root cause is a combination of two things. First, need to use -threaded for code that ultimately uses atomic-primops, as described in this issue. Second, Template Haskell runs at compile time, via a bytecode interpreter, GHCi. This does not invoke -threaded, so the error is thrown, once GHCI attempts to load packages:

Loading package atomic-primops-0.2.2.1 ... linking ... ghc: ~/.cabal/lib/atomic-primops-0.2.2.1/ghc-7.6.1/HSatomic-primops-0.2.2.1.o: unknown symbol `cas'

As a simply example, try compiling this demo library I put together: chaselev-user-libX-0.0.1.tar.gz. The case is straight forward: if you comment out remotable on line 17 of Foo.Bar, the library compiles. If you leave it in, the library does not compile.

@rrnewton
Copy link
Owner

Yes, I got the same error with your reproducer.

Aha, it looks like GHCI provides a third scenario beyond "ghc" and "ghc -threaded".

In fixing Issue #8, I made sure that duplicate versions of the relevant functions were there to support normal compilation/linking with or without -threaded. Actually, in both of THOSE cases "cas" is available, but the other barrier functions are not. Yet it looks like in the GHCI case "cas" is not available.

I think the fix can simply be extended to cover this.

@rrnewton
Copy link
Owner

Ugh, working on it. Past the 'cas' error and now getting this:

Loading package atomic-primops-0.4 ... linking ... ghc: /u/rrnewton/.cabal/lib/atomic-primops-0.4/ghc-7.6.3/HSatomic-primops-0.4.o: unknown symbol `stg_MUT_VAR_CLEAN_info'

Also, I'd welcome a pull request with a simplified version of the reproducer in it. Or any other tests you have that are giving problems.

robstewart57 added a commit to robstewart57/haskell-lockfree-queue that referenced this issue Jul 19, 2013
Using GHCi via TemplateHaskell bytecode interpretation with Data.Atomics.
Related to rrnewton#10 .
Note:  hello-word-atomic-primops.hs missing.
robstewart57 added a commit to robstewart57/haskell-lockfree-queue that referenced this issue Jul 19, 2013
Using GHCi via TemplateHaskell bytecode interpretation with Data.Atomics.
Related to rrnewton#10 .
Note:  hello-word-atomic-primops.hs missing.
@rrnewton
Copy link
Owner

I'm afraid I'm stumped on this until I dig a bit more into how GHCI works. The library has a bunch of undefined symbols which need to be satisfied by the RTS.

             U base_GHCziBase_zpzp_info
             U base_GHCziForeignPtr_ForeignPtr_con_info
             U base_GHCziForeignPtr_MallocPtr_con_info
             U base_GHCziForeignPtr_mallocForeignPtr3_closure
             U base_GHCziSTRef_STRef_con_info
             U base_GHCziSTRef_readSTRef1_info
             U base_GHCziShow_DZCShow_static_info
             U base_GHCziShow_showListzuzu_info
             U dirty_MUT_VAR
             U fetch_and_add_word
             U ghczmprim_GHCziCString_unpackCStringzh_info
             U ghczmprim_GHCziClasses_DZCEq_static_info
             U ghczmprim_GHCziTuple_Z0T_closure
             U ghczmprim_GHCziTuple_Z2T_con_info
             U ghczmprim_GHCziTypes_Bool_closure_tbl
             U ghczmprim_GHCziTypes_False_closure
             U ghczmprim_GHCziTypes_Izh_con_info
             U ghczmprim_GHCziTypes_True_closure
             U newCAF
             U stg_CAF_BLACKHOLE_info
             U stg_MUT_ARR_PTRS_DIRTY_info
             U stg_MUT_VAR_CLEAN_info
             U stg_ap_0_fast
             U stg_atomicModifyMutVarzh
             U stg_bh_upd_frame_info
             U stg_gc_ut
             U stg_newAlignedPinnedByteArrayzh
             U stg_newByteArrayzh
             U stg_newMutVarzh
             U stg_upd_frame_info
             U val_compare_and_swap_word

Maybe there's some library or object that atomic-primops can explicitly depend on to make sure this stuff gets linked?

@rrnewton
Copy link
Owner

Update: Simon Marlow said this is a GHC bug and that he'll fix it:

http://www.haskell.org/pipermail/ghc-devs/2013-July/001714.html

@rrnewton
Copy link
Owner

By the way, I don't run into this bug on Mac. This is a Linux-specific bug it seems.

@rrnewton
Copy link
Owner

rrnewton commented Feb 4, 2014

This bug remains for 7.6 but it's fixed in 7.8 so I'm closing this now.

@rrnewton rrnewton closed this as completed Feb 4, 2014
robstewart57 added a commit to robstewart57/haskell-lockfree-queue that referenced this issue Feb 6, 2014
This change automatically turns on the template-haskell-atomic-primops
test when GHC >7.8 is used. This is a test case for issue rrnewton#8 . The test
case remains disabled for <=7.6.3 due to a bug in GHC 7.6 described
in issue rrnewton#10 .
@JohnLato
Copy link

I'm running into this bug with ghc-7.8.3 on linux. We're using ghc with the following

 ,("Dynamic by default","NO")
 ,("GHC Dynamic","NO")

but otherwise it's a standard build. I've hacked around it by enabling RtsDup for now, but I think it may be a remaining bug in ghc. Just wanted to point it out in case other users run into the same problem. Also I wonder if it works on Windows at all (which AFAIK is also not dynamic by default).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants