Closed lunaris closed 5 years ago
Hello. The haskell_binary
call is not passing "-pie" to ghc. The BUILD file shows how to do it, but not the example in the readme. I will mention it in the readme.
https://github.com/tweag/clodl#usage talks about the PIE requirement, but the binary_closure section should be made consistent with this later section.
Hi both. Thanks very much for responding to this. So I've added -pie
(and -dynamic
and -threaded
, though those too appear to already be in the generated command line) to both my haskell_binary
and, when that failed, to the haskell_library
it depends on, to no avail. I then set about seeing if perhaps I needed to play the bootstrap
trick you are playing in this repository (in which you export a cc_library
of GHC's RTS includes and make main
a weak symbol), but before I did so thought I'd check in here to see whether or not that's an expected requirement.
The bootstrap bit shoudn't be necessary. At least bazel run clotestbin
doesn't use it and works in CI.
If you have a repo to share (or a gist or whatever), I could have a look.
I've created https://github.com/lunaris/bazel-example, which I think is a reproduction of the issue I'm seeing. It depends on a few common Haskell libraries to make sure there are a variety of cbits
etc. floating around -- you can try and build a closure using bazel build //engine:test-closure
. Many thanks!
Adding -rdynamic
to compiler_flags
fixes it for me. But I don't understand yet why it isn't necessary in the clodl repo.
Interesting. Is it perhaps that your bootstrapping stuff references main
in a way that means it is considered a "used" symbol whereas in my example that recognition is missing for some reason?
That would explain it for the cases where we use the bootstrap library. But it also works without it.
That would explain it for the cases where we use the bootstrap library. But it also works without it.
I was wrong. Linking bootstrap does have an effect here, and we are always linking bootstrap.
Linking bootstrap into hello-hs
includes main in the table of dynamic symbols:
$ nm -D bazel-bin/hello-hs | grep main
U hs_main
U __libc_start_main
00000000000024d3 T main
But if we don't link bootstrap, main is missing.
$ nm -D bazel-bin/engine/test-bin | grep main
U hs_main
U __libc_start_main
We will have to update the documentation to account for this. We either ask -rdynamic
, or -Wl,--dynamic-list=<file with a list of symbols including main>
. Also, we can test if the input binary defines main when using binary_closure and suggest in the error message one of these alternatives.
Thanks so much for helping out with this!
You're welcome. Thanks for reporting the issue and putting the testing repo together.
I'm trying to use
binary_closure
(commited9be32ef539ea3645847987e11609028d6491f5
,master
at time of writing) to create a closure of ahaskell_binary
, but when I do I'm getting:which presumably indicates that the binary's main function isn't being picked up correctly. For reference, the
haskell_binary
looks like:while the closure is built with:
(If context needed,
hazel_library
is provided by FormationAI/hazel and creates external dependencies out of Hackage packages)The binary works when built and run with
bazel run //engine:test-bin
. When I runbazel build --subcommands //engine:test-closure
I see:test-closure_closure_wrapper-2.params
contains:So it looks like
-ltest-bin
is being linked against, but perhaps not in the right way? Not sure if there's any useful information I've omitted that might also help debug this; thanks!