Add -dynamic when linking shared haskell_binary#1345
Open
jbellerb wants to merge 1 commit into
Open
Conversation
This matches the behavior of Cabal when linking binaries. Without this flag, will GHC statically link every implicit dependency provided by the global package database. I've noticed a few strange behaviors caused by this, all involving `haskell_prebuilt_library`: - `examples/with_prelude/haskell` segfaults on macOS. The binary contains both statically and dynamically linked copies of `rts`, but only the static copy is initialized. The dynamic copy comes via `//haskell:library` (`haskell_library` passes `-dynamic`). Linux symbol namespacing would merge the two, but macOS doesn't. - if the global package database is limited to only `rts` (GHC is hard-coded to require this), linking fails on Linux using lld. Linking the static `rts` against a dynamic `base` would require creating copy relocations for read-only symbols in `base`. - if the global package database is limited as above, any resulting binary would throw a runtime linker error on macOS. On macOS, GHC sets `-dead_strip_dylibs` to remove unused dylibs. During static linking, symbols required by `base` are removed and the `rts` dylib is stripped as dead code. I can't find a reason for why the flag was originally excluded. Based on the issues it causes, including it seems like the correct behavior.
Contributor
|
This pull request has been imported. If you are a Meta employee, you can view this in D108573242. (Because this pull request was imported automatically, there will not be any future comments.) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This matches the behavior of Cabal when linking binaries. Without this flag, will GHC statically link every implicit dependency provided by the global package database. I've noticed a few strange behaviors caused by this, all involving
haskell_prebuilt_library:examples/with_prelude/haskellsegfaults on macOS. The binary contains both statically and dynamically linked copies ofrts, but only the static copy is initialized. The dynamic copy comes via//haskell:library(haskell_librarypasses-dynamic). Linux symbol namespacing would merge the two, but macOS doesn't.if the global package database is limited to only
rts(GHC is hard-coded to require this), linking fails on Linux using lld. Linking the staticrtsagainst a dynamicbasewould require creating copy relocations for read-only symbols inbase.if the global package database is limited as above, any resulting binary would throw a runtime linker error on macOS. On macOS, GHC sets
-dead_strip_dylibsto remove unused dylibs. During static linking, symbols required bybaseare removed and thertsdylib is stripped as dead code.I can't find a reason for why the flag was originally excluded. Based on the issues it causes, including it seems like the correct behavior.