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

Add extraLibDirs to runtime lib search paths of library (backport #9554) #9639

Merged
merged 1 commit into from
Jan 25, 2024

Conversation

mergify[bot]
Copy link
Contributor

@mergify mergify bot commented Jan 20, 2024

This is an automatic backport of pull request #9554 done by Mergify.
Cherry-pick of addbcbf has failed:

On branch mergify/bp/3.10/pr-9554
Your branch is up to date with 'origin/3.10'.

You are currently cherry-picking commit addbcbfbb.
  (fix conflicts and run "git cherry-pick --continue")
  (use "git cherry-pick --skip" to skip this patch)
  (use "git cherry-pick --abort" to cancel the cherry-pick operation)

Changes to be committed:
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/T19350.script
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/clib/lib.c
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/Hello.hs
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/Setup.hs
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/lib/T7339.cabal
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/setup.out
	new file:   cabal-testsuite/PackageTests/LinkerOptions/T7339/setup.test.hs

Unmerged paths:
  (use "git add/rm <file>..." as appropriate to mark resolution)
	deleted by us:   Cabal/src/Distribution/Simple/GHC/BuildGeneric.hs
	deleted by us:   Cabal/src/Distribution/Simple/GHC/BuildOrRepl.hs
	both modified:   Cabal/src/Distribution/Simple/Program/GHC.hs

To fix up this pull request, you can check it out locally. See documentation: https://docs.github.com/en/github/collaborating-with-pull-requests/reviewing-changes-in-pull-requests/checking-out-pull-requests-locally


Mergify commands and options

More conditions and actions can be found in the documentation.

You can also trigger Mergify actions by commenting on this pull request:

  • @Mergifyio refresh will re-evaluate the rules
  • @Mergifyio rebase will rebase this PR on its base branch
  • @Mergifyio update will merge the base branch into this PR
  • @Mergifyio backport <destination> will backport this PR on <destination> branch

Additionally, on Mergify dashboard you can:

  • look at your merge queues
  • generate the Mergify configuration with the config editor.

Finally, you can contact us on https://mergify.com

@Mikolaj
Copy link
Member

Mikolaj commented Jan 25, 2024

I remember this failiure

-Preprocessing library for T7339-1.0...
-Building library for T7339-1.0...
+Preprocessing library for T7339-1.0..
+Building library for T7339-1.0..

from another recent backport. Something changed the way the dots are printed. But I forgot how it was resolved.

@Mikolaj
Copy link
Member

Mikolaj commented Jan 25, 2024

Oh, I see, the test result has just been changed exclusively in the backport: #9145

@alt-romes alt-romes force-pushed the mergify/bp/3.10/pr-9554 branch from d3f1881 to 76d6b1f Compare January 25, 2024 13:40
@Kleidukos Kleidukos added merge me Tell Mergify Bot to merge merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days labels Jan 25, 2024
Runtime search paths are hard. Here's the current picture to understand
why this patch exists:

* When linking a shared library, GHC will include in the rpath entries
  of the shared library all the paths listed in the library dirs section
  of the installed package info of all packages the shared library
  depends on.
    * On darwin, GHC has special logic to inject the library dirs listed
      in the installed dependent packages info into the rpath section
      instead of passing the dirs as -rpath flags to the linker.
      However, only the dirs where used libraries are found are
      actually injected. The others are ignored. This works around
      limitations of the darwin loader.

* Cabal, in addition, passes directly to the linker (via
  -optl-Wl,-rpath,...) the library dirs of packages the
  shared library for the package being built depends on.
    * In a vanilla cabal installation, this will typically only be the
      path to the cabal store and the path to the installed GHC's boot
      libraries store.
    * When using nix there will a different library dir per installed
      package. Since these lib dirs are passed directly to the linker as
      rpaths, we bypass the darwin loader logic and, for very big
      packages, on darwin, we could end up reaching the load command
      limit and fail linking. We don't address this situation in this MR.

When we specify `extra-lib-dirs` in Cabal, these extra-lib-dirs will be
added to the library dirs listed in the installed package info of the
library they were specified for. Furthermore, when building a shared
library, extra-lib-dirs will be passed as `-L` flags to the linker
invocation. However, the same extra-lib-dirs will not be passed as
`-rpath` to the linker.

The end situation is as follows:

    1. The shared library `libA` built for a package `A` will be linked
       against some libraries `libExtra` found in extra-lib-dirs
       `extraA`.

    2. The RPATH section of `A` will NOT contain `extraA`, because we
       don't pass -rpath extra-lib-dirs when linking the library, but it
       will depend on `libExtra`.

    3. The installed package info of that package `A` will contain, in
       the library dirs section, the extra-lib-dirs `extraA` and the
       path to `libA`.

    4. When a package `B` depends on package `A`, it will include in the
       RPATH section of the shared library `libB` the lib dirs from the
       installed package info of `A`, i.e. `/path/to/libA` and `extraA`,
       and depends on `libA` and, transitively, on `libExtra`.

The conclusion is:

    5. When we load `libB`, we will load `libA`, which is found in
       `/path/to/libA`, and, transitively, load `libExtra` which is
       found in `extraA` -- they are both found because both
       `/path/to/libA` and `extraA` are listed in the RPATH entries.

    6. However, if we load `libA` directly we will /NOT/ find
       `libExtra`, because `extraA` is not included in the RPATH
       entries.

So, ultimately, what this commit fixes, is the failure described in (6),
caused by the incorrect behaviour of (2), by specifying `-rpath
extra-lib-dirs` when linking the shared library of a package, to include
the extra lib dirs in the RPATH entries of that shared library (even
though dependents of this library would already get the extra-lib-dirs
in their RPATH, the library itself didn't, resulting in cabal#7339 and
ghc#19350)

Fixes #7339
Fixes ghc#19350
@Mikolaj Mikolaj force-pushed the mergify/bp/3.10/pr-9554 branch from 76d6b1f to 40f9073 Compare January 25, 2024 17:04
@Mikolaj
Copy link
Member

Mikolaj commented Jan 25, 2024

A strange error "cabal-plan not found", despite in an earlier step a successful build of cabal-plan. Let me restart.

@geekosaur
Copy link
Collaborator

That happened on both the backports I did as well, only on the macos-latest dogfooding job. Restarting worked.

@mergify mergify bot merged commit 6af97ba into 3.10 Jan 25, 2024
40 checks passed
@mergify mergify bot deleted the mergify/bp/3.10/pr-9554 branch January 25, 2024 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport conflicts merge delay passed Applied (usually by Mergify) when PR approved and received no updates for 2 days merge me Tell Mergify Bot to merge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants