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

linkage_checker: replace Fiddle.dlopen with libSystem call #18486

Merged
merged 1 commit into from
Oct 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 14 additions & 7 deletions Library/Homebrew/linkage_checker.rb
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,9 @@

if (dep = dylib_to_dep(dylib))
@broken_deps[dep] |= [dylib]
elsif system_libraries_exist_in_cache? && dylib_found_via_dlopen(dylib)
elsif system_libraries_exist_in_cache? && dylib_found_in_shared_cache?(dylib)
# If we cannot associate the dylib with a dependency, then it may be a system library.
# If dlopen finds the dylib, then the linkage is not broken.
# Check the dylib shared cache for the library to verify this.
@system_dylibs << dylib
elsif !system_framework?(dylib) && !broken_dylibs_allowed?(file.to_s)
@broken_dylibs << dylib
Expand Down Expand Up @@ -195,11 +195,18 @@
end
alias generic_system_libraries_exist_in_cache? system_libraries_exist_in_cache?

def dylib_found_via_dlopen(dylib)
Fiddle.dlopen(dylib).close
true
rescue Fiddle::DLError
false
def dylib_found_in_shared_cache?(dylib)
@dyld_shared_cache_contains_path ||= begin
libc = Fiddle.dlopen("/usr/lib/libSystem.B.dylib")

Check warning on line 200 in Library/Homebrew/linkage_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/linkage_checker.rb#L199-L200

Added lines #L199 - L200 were not covered by tests

Fiddle::Function.new(

Check warning on line 202 in Library/Homebrew/linkage_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/linkage_checker.rb#L202

Added line #L202 was not covered by tests
libc["_dyld_shared_cache_contains_path"],
[Fiddle::TYPE_CONST_STRING],
Fiddle::TYPE_BOOL,
)
end

@dyld_shared_cache_contains_path.call(dylib)

Check warning on line 209 in Library/Homebrew/linkage_checker.rb

View check run for this annotation

Codecov / codecov/patch

Library/Homebrew/linkage_checker.rb#L209

Added line #L209 was not covered by tests
end

def check_formula_deps
Expand Down
14 changes: 14 additions & 0 deletions Library/Homebrew/sorbet/rbi/upstream.rbi
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,17 @@

# This file contains temporary definitions for fixes that have
# been submitted upstream to https://github.com/sorbet/sorbet.

# Missing constants we use in `linkage_checker.rb`
# https://github.com/sorbet/sorbet/pull/8215
module Fiddle
# [`TYPE_BOOL`](https://github.com/ruby/fiddle/blob/v1.1.2/ext/fiddle/fiddle.h#L129)
#
# C type - bool
TYPE_BOOL = T.let(T.unsafe(nil).freeze, Integer)

# [`TYPE_CONST_STRING`](https://github.com/ruby/fiddle/blob/v1.1.2/ext/fiddle/fiddle.h#L128)
#
# C type - char\*
TYPE_CONST_STRING = T.let(T.unsafe(nil).freeze, Integer)
end
Loading