Skip to content

Commit

Permalink
linkage_checker: attempt dlopen before reporting broken linkage.
Browse files Browse the repository at this point in the history
When `dyld` is not able to find a library at its install name, it
attempts to find it inside its default search path.

This means that for libraries we ship that are also provided by the
system (e.g. `libc++`), `brew linkage` can fail even if the formula
still works (i.e. `brew test` succeeds).

Given this, it makes sense to attempt to `dlopen` the library first
before deciding the linkage is broken. This will be useful when we ship
Homebrew/homebrew-core#106925, which will move the install location of
`libc++`, causing `brew linkage` to fail for any formula that links with
that `libc++`.

Those formulae that link with LLVM's `libc++` will fall back to Apple's
`libc++`, which is why we see multiple `brew test`s succeed even when
`brew linkage` failed in the LLVM PR linked above.

This change helps avoid unnecessary source rebuilds for formulae that
link with LLVM's `libc++` after LLVM 15 ships.
  • Loading branch information
carlocab committed Sep 9, 2022
1 parent 5524b30 commit 8eaa33b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,14 @@ def check_dylibs(rebuild_cache:)
rescue Errno::ENOENT
next if harmless_broken_link?(dylib)

if (dep = dylib_to_dep(dylib))
basename = File.basename(dylib)
if dylib_found_via_dlopen(basename)
# `dyld` will fall back to its default search path when it cannot
# resolve an install name. Calling `dlopen` on the basename simulates
# this search procedure. If this succeeds, the formula is unlikely
# to be broken.
@system_dylibs << basename
elsif (dep = dylib_to_dep(dylib))
@broken_deps[dep] |= [dylib]
elsif MacOS.version >= :big_sur && dylib_found_via_dlopen(dylib)
# If we cannot associate the dylib with a dependency, then it may be a system library.
Expand Down

0 comments on commit 8eaa33b

Please sign in to comment.