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

Link C libraries statically if possible on linkstatic = True binaries #587

Merged
merged 7 commits into from
Jan 18, 2019

Commits on Jan 17, 2019

  1. Move is_static/shared_lib to path_utils

    So these can be used in other `.bzl` files.
    aherrmann committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    36b22f5 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    bcf15fe View commit details
    Browse the repository at this point in the history
  3. Prefer static C libraries on static Haskell binary

    I.e. when building a Haskell binary with `linkstatic = True`, then link
    statically against Haskell and C library dependencies where possible.
    
    GHC's default behaviour (following from the linker's behaviour) is to
    prefer dynamic libraries over static libraries for C library
    dependencies, even when linking statically against Haskell libraries.
    
    By only passing static library versions (unless on static library is
    available) of C library dependencies as inputs to the linking action,
    the linker has no choice but to link statically.
    
    Closes #580
    aherrmann committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    f1cb907 View commit details
    Browse the repository at this point in the history
  4. Regression tests binary-linkstatic-flag

    Test that a Haskell binary compiled with `linkstatic = True`, will only
    link to static library dependencies (where available), and that a
    Haskell binary compiled with `linkstatic = False`, will link all its
    library dependencies dynamically (where available).
    
    The test cases assume that for each library dependency both a dynamic
    and a static version are available, i.e. the default of `linkstatic =
    False` for library dependencies.
    
    Uses `haskell_test` in place of `haskell_binary` to ensure that the
    resulting binaries can be executed without any runtime linker errors.
    aherrmann committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    b64d064 View commit details
    Browse the repository at this point in the history
  5. Skip test-binary-dynamic-only on dbg mode

    dbg mode enforces static linking in which case the test case for dynamic
    linking will fail.
    aherrmann committed Jan 17, 2019
    Configuration menu
    Copy the full SHA
    a1b55aa View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    8e994ec View commit details
    Browse the repository at this point in the history

Commits on Jan 18, 2019

  1. Fix //tests/binary-linkstatic-flag for MacOS

    `objdump` is not available on the MacOS build. Furthermore, on MacOS
    only direct library dependencies are listed under the shared library
    dependencies. Also, on MacOS the dynamic library dependency listed in
    the binary's header uses the library ID instead of the mangled library
    path as on Linux.
    
    This changes and simplifies the binary-linkstatic-flag tests to work on
    both Linux and MacOS seemlessly.
    
    First, we turn the indirect C library dependency into a direct
    dependency.
    
    Second, instead of checking for shared library dependencies, we directly
    check for the `value` and `*HsLib_value_closure` symbols. In a
    statically linked binary both those symbols will be defined directly in
    the binary. In a dynamically linked binary both symbols will be listed
    as undefined. The `nm` tool is available on both the Linux and MacOS
    builds and can list all undefined symbols in the binary.
    aherrmann committed Jan 18, 2019
    Configuration menu
    Copy the full SHA
    b0a7bd7 View commit details
    Browse the repository at this point in the history