-
Notifications
You must be signed in to change notification settings - Fork 81
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
Fix linker errors on Ubuntu >= 18.04 with GHC bindist #1388
Conversation
Using the suggestion from bazelbuild/bazel#6876 (comment)
Covers R_X86_64_32 relocation errors and incompatibility of `-r` and `-pie` on Ubuntu>=18.04.
@@ -112,9 +113,6 @@ def cc_interop_info(ctx): | |||
cc_files = ctx.files._cc_toolchain + cc_wrapper.inputs.to_list() | |||
cc_manifests = cc_wrapper.manifests | |||
|
|||
# XXX Workaround https://github.com/bazelbuild/bazel/issues/6876. | |||
linker_flags = [flag for flag in linker_flags if flag not in ["-shared"]] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While debugging #1349 I noticed that this could be simplified by following the suggestion from bazelbuild/bazel#6876 (comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This looks good as a fix for the Ubuntu issue, but setting no-pie
everywhere seems like a bit of a sledgehammer. It would be good to get more clarity on the upstream issue.
We were seeing this on github/semantic#595, and I can confirm that this patch fixes our Linux builds. |
Addressing review comment #1388 (comment)
As pointed out in this GHC note that corresponds to GHC's behavior provided that the C compiler supports the |
When using GHC 8.10, passing `-no-pie` to the linker when building libraries leads to obscure linker errors. Since PIE pertains to executables, it doesn't make much sense passing that flag when building libraries anyways. Removing it, both for `haskell_library` and `haskell_cabal_library` fixes GHC 8.10 support. We make sure to keep the flag for executables. This would otherwise negate the effect of #1388.
Closes #1349
On some more recent Linux distributions (e.g. Ubuntu 18.04)
gcc
defaults to linking with-pie
. At the same time GHC passes-r
to the linker when joining object files. In order to avoid errors of the formwe need to pass
-no-pie
to the linker. Additionally, GHC compiles themain
function during linking with non-position independent code. Attempting to link this code with-pie
will cause the following error:This was not caught on rules_haskell's bindist CI since it was still running on Ubuntu 16.04 which hadn't enabled
-pie
by default, yet. I've upgraded the rules_haskell bindist CI image to Ubuntu 18.04. I've confirmed that this does not break the build on Ubuntu 16.04.