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

formula_cellar_checks: check keg for mismatched arches #11737

Merged
merged 2 commits into from Jul 19, 2021

Conversation

carlocab
Copy link
Member

  • Have you followed the guidelines in our Contributing document?
  • Have you checked to ensure there aren't other open Pull Requests for the same change?
  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes? Here's an example.
  • Have you successfully run brew style with your changes locally?
  • Have you successfully run brew typecheck with your changes locally?
  • Have you successfully run brew tests with your changes locally?

There have been a few instances I've noticed that we've been silently
installing binaries built for x86_64 on ARM. There's probably more that
I haven't found yet, so it seems useful to check this with an audit.

This is usually a sign that the formula is installing pre-built binaries.
I'm not sure if the error from the audit should reflect this, so I've left
it out for now. Happy to tweak the wording as needed.

There have been a few instances I've noticed that we've been silently
installing binaries built for x86_64 on ARM. There's probably more that
I haven't found yet, so it seems useful to check this with an audit.
@BrewTestBot
Copy link
Member

Review period will end on 2021-07-20 at 00:00:00 UTC.

@BrewTestBot BrewTestBot added the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 18, 2021
The current offset results in ELF binaries returning an `#arch` of
`:dunno`.

Also, skip the `check_binary_arches` audit on the generic OS.
@carlocab carlocab requested a review from sjackman July 18, 2021 08:57
ARCHITECTURE_X86_64 = 0x62
ARCHITECTURE_X86_64 = 0x3E
Copy link
Member Author

@carlocab carlocab Jul 18, 2021

Choose a reason for hiding this comment

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

This is needed because checking the arch of ELF files on Linux currently returns :dunno. See the CI failures from my first commit.


keg = Keg.new(formula.prefix)
mismatches = keg.binary_executable_or_library_files.reject do |file|
file.arch == Hardware::CPU.arch
Copy link
Member Author

Choose a reason for hiding this comment

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

Hardware::CPU.arch returns :x86_64 when running under Rosetta, so this audit should behave as expected on ARM in /usr/local too.

Copy link
Member Author

Choose a reason for hiding this comment

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

Though, one corner case worth considering, where I don't know what happens (and don't have the hardware to test...): a user who has an M1 machine with brew installed into /usr/local, and runs /usr/local/bin/brew install without running the process under Rosetta2. I suspect this audit will produce errors for them, but I don't know if brew will error out for that case earlier than that.

Copy link
Member

Choose a reason for hiding this comment

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

I don't know if brew will error out for that case earlier than that.

it will 🎉

Comment on lines +319 to +320
# There is no `binary_executable_or_library_files` method for the generic OS
return if !OS.mac? && !OS.linux?
Copy link
Member

Choose a reason for hiding this comment

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

I'm just curious, why is this the case? I thought the default for this was to use the Linux version and, on macOS, the method was overridden. Is that not what happens with --generic?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes. The default behaviour is to call the method elf_files, but that's Linux-only too.

Copy link
Member

@MikeMcQuaid MikeMcQuaid left a comment

Choose a reason for hiding this comment

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

Great work 🎉


keg = Keg.new(formula.prefix)
mismatches = keg.binary_executable_or_library_files.reject do |file|
file.arch == Hardware::CPU.arch
Copy link
Member

Choose a reason for hiding this comment

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

I don't know if brew will error out for that case earlier than that.

it will 🎉

@MikeMcQuaid MikeMcQuaid added the critical Critical change which should be shipped as soon as possible. label Jul 19, 2021
@BrewTestBot
Copy link
Member

Review period skipped due to critical label.

@BrewTestBot BrewTestBot removed the waiting for feedback Merging is blocked until sufficient time has passed for review label Jul 19, 2021
@carlocab carlocab merged commit 16b01d6 into Homebrew:master Jul 19, 2021
@carlocab carlocab deleted the audit-arches branch July 19, 2021 12:15
carlocab added a commit to carlocab/homebrew-core that referenced this pull request Jul 21, 2021
The LLVM formulae build universal binaries for compiler-rt. This is why
these formulae use `ENV.permit_arch_flags`. Infer vendors its own clang,
and so also has its own compiler-rt.

`babel` and `contentful-cli` both install the npm package `fsevents`,
which installs a universal native module `fsevents.node`. I suggest
adding them to the allowlist for now so we have a list that keeps track
of them. (It would be nice if JSON files allowed comments though.)

I have changes in mind for `brew` that will allow us to easily extract
the native slices from these binaries, but I'd like to see it needed by
more formulae before we add it to `brew`. This list should help us keep
track of the number of formulae that would need this.

This commit unblocks Homebrew#81556 and Homebrew#81582.

See Homebrew/brew#11737 for context.
carlocab added a commit to Homebrew/homebrew-core that referenced this pull request Jul 21, 2021
The LLVM formulae build universal binaries for compiler-rt. This is why
these formulae use `ENV.permit_arch_flags`. Infer vendors its own clang,
and so also has its own compiler-rt.

`babel` and `contentful-cli` both install the npm package `fsevents`,
which installs a universal native module `fsevents.node`. I suggest
adding them to the allowlist for now so we have a list that keeps track
of them. (It would be nice if JSON files allowed comments though.)

I have changes in mind for `brew` that will allow us to easily extract
the native slices from these binaries, but I'd like to see it needed by
more formulae before we add it to `brew`. This list should help us keep
track of the number of formulae that would need this.

This commit unblocks #81556 and #81582.

See Homebrew/brew#11737 for context.
@github-actions github-actions bot added the outdated PR was locked due to age label Aug 25, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 25, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
critical Critical change which should be shipped as soon as possible. outdated PR was locked due to age
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants