Skip to content

Select the native architecture's dynamic linker on Linux - #23622

Open
p-linnane wants to merge 2 commits into
mainfrom
linux-ld-native-arch
Open

Select the native architecture's dynamic linker on Linux#23622
p-linnane wants to merge 2 commits into
mainfrom
linux-ld-native-arch

Conversation

@p-linnane

Copy link
Copy Markdown
Contributor

On ARM64 Linux with amd64 multi-arch libc installed, OS::Linux::Ld.system_ld_so returned the first executable path from a flat, cross-architecture list, so $HOMEBREW_PREFIX/lib/ld.so was symlinked to /lib64/ld-linux-x86-64.so.2 and ARM binaries stopped running. Reported in discussion #6179.

DYNAMIC_LINKERS is now keyed by Hardware::CPU.arch and only the native architecture's candidates are searched, so a foreign loader can no longer be selected when the native one is missing.

The second commit fixes something that surfaced while testing the first. brew tests --changed could select a spec that OS filtering then removed, leaving RSpec invoked with an empty file list and failing brew lgtm on macOS. --changed now warns and returns, while every other invocation fails, including an explicit --only for a spec the current OS filters out, rather than exiting green without running anything.


  • Have you followed our Contributing guidelines?
  • Have you checked for other open Pull Requests for the same change?
  • Have you explained what your changes do? Performance claims (e.g. "this is faster") must include brew benchmark results.
  • Have you explained why you'd like these changes included, not just what they do?
  • For bug fixes, have you given step-by-step brew commands to reproduce the bug?
  • Have you written new tests (excluding integration tests)? Here's an example.
  • Have you successfully run brew lgtm (style, typechecking and tests) locally?

  • I did not use AI/LLM to create this PR, or I disclosed the tool/model below and reviewed its output; I did not attribute commits to AI and will answer maintainer questions and review comments myself without AI/LLM.

Claude Code (Opus 5) drafted the implementation and tests; I reviewed the diff, verified the new tests fail without the fix and pass with it, and ran brew lgtm --online plus targeted specs.


Signed-off-by: Patrick Linnane <patrick@linnane.io>
Signed-off-by: Patrick Linnane <patrick@linnane.io>
Copilot AI lite review requested due to automatic review settings August 22, 2026 18:21

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes Linux dynamic linker selection so Homebrew doesn’t accidentally choose a foreign-architecture loader (e.g., x86_64) on multi-arch systems where the native loader (e.g., arm64) is present, preventing broken execution of native binaries. It also hardens brew tests so OS-specific filtering can’t lead to “successful” runs where no specs actually execute.

Changes:

  • Key OS::Linux::Ld::DYNAMIC_LINKERS by Hardware::CPU.arch and search only native-arch candidates in system_ld_so.
  • Add/adjust Linux Ld specs to cover native-vs-foreign loader preference.
  • Update brew tests to warn+return for --changed when OS filtering removes all tests, and to error for explicit invocations that result in no runnable tests; add corresponding unit tests.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
Library/Homebrew/os/linux/ld.rb Restricts dynamic linker discovery to native-architecture candidates.
Library/Homebrew/test/os/linux/ld_spec.rb Updates/extends specs to validate native linker preference behavior.
Library/Homebrew/dev-cmd/tests.rb Adds handling for OS-filtered empty test sets (warn for --changed, error otherwise).
Library/Homebrew/test/dev-cmd/tests_spec.rb Adds coverage for brew tests behavior when OS filtering removes all runnable specs.

💡 Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.

Comment thread Library/Homebrew/dev-cmd/tests.rb
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants