-
Notifications
You must be signed in to change notification settings - Fork 498
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
On MacOS on ARM hardware, the "processors.isa", "os.architecture", "architecture", and "hardwareisa" facts report incorrect values when running under Rosetta 2 #2716
Comments
The > diff <(arch -arch arm64 facter) <(arch -arch x86_64 facter)
< ... snip temporally-dependent info >
< architecture => "arm64",
---
> architecture => "x86_64",
498c498
< hardware => "arm64",
---
> hardware => "x86_64",
520c520
< isa => "arm",
---
> isa => "i386",
533a534
> speed => "2.40 GHz",
|
A workaround for this issue can be achieved by overriding the affected facts with the values returned by them when forced to run as the native architecture. An example such custom fact file is below (in Puppet, I store and access this fact as close to the entry points to my Puppet manifest evaluation as possible): Facter.add('_oldfacts') do
confine kernel: 'Darwin'
setcode do
Puppet::Util::Json.load(Facter::Core::Execution.execute('arch -64 facter --no-ruby --show-legacy --no-cache --no-external-facts --no-color --json'))
end
end
['architecture', 'hardwareisa', 'hardwaremodel', 'processors', 'os'].each do |fact|
Facter.add(fact) do
confine kernel: 'Darwin'
setcode do
Facter.value('_oldfacts').fetch(fact)
end
end
end |
Upon digging into it a little, I'm honestly not wild about While MacOS uses a BSD-based |
Might be related to #2703, our process has some outdated tooling that we need to update. Once the above issue is resolved we'll try to reproduce this issue you have described here. |
I don't understand how this would interact with #2703 (other than that I had to get pre-built Facter for the to-reproduce steps). What does the documentation generation gem have to do with |
Thanks @zbentley for bringing this up; have you tried building the gem excluding documentation, which would exclude While we agree this is likely an improvement, we do not anticipate addressing this any time soon, so hopefully you can build it without |
@tvpartytonight the issue arises from Rosetta, not any of the gems against which this package is compiled. Facter provides these values by shelling out to Regardless of what gems facter is built with, if I do, say, an x86 Bash spawning an ARM Ruby to run Facter, and Facter in turn spawns the universal binary |
This can be reproduced without Facter at all, via the following on an M1 mac:
The problem is that Facter uses |
@zbentley Running puppet in Rosetta isn't something we support and is only going to cause problems when trying to manage the OS (similar to WOW32 on Windows). We ship both x86_64 and ARM agents, so why not install from https://downloads.puppet.com/mac/puppet8/14/arm64? |
Many Puppet installation guides direct users to install Puppet in such a way that a Rosetta environment is used:
@joshcooper In light of how easy it is to accidentally run Puppet under Rosetta, and how many folks and official docs have been recommending Puppet installations under Rosetta, I'd urge you to reconsider making Rosetta execution unsupported. If that's not something you're interested in, could we make the unsupportedness louder? In other words, if Facter cannot reliably be run in Rosetta without breakage as described here, could we make facter and/or Puppet itself fail to supply architecture-specific facts entirely if running in Rosetta? Ordinarily that isn't something I'd suggest, preferring to avoid extra work/complexity and trust users to manage their runtime environments correctly. However, given how seamless Rosetta's integration with MacOS is, it's extremely common for programs to run under Rosetta by accident, so I think in this case it makes more sense to error or warn loudly when that's happening in an unsupported way. |
Thanks for listing out the issues @zbentley! That said I think we should work on adding ARM support where it's missing (like bolt) and fixing homebrew installation instructions so that users install the correct package for their architecture. It's only a matter of time before
I thought all of our current formulas for puppet7 and up support ARM. Or are you saying if you install x86 homebrew on macOS ARM, then you'll get x86 puppet due to? https://github.com/puppetlabs/homebrew-puppet/blob/24f8e42983872f5f5184edfe140945a6b9202a91/Casks/puppet-agent-7.rb#L5
Yes that would make sense. What is the best way to detect when facter is running in Rosetta? Related, can we improve our homebrew formula so that they always install arm packages on arm hosts, even when homebrew is x86? |
Thanks for replying! You're correct that Puppet will currently be installed by Homebrew as ARM; I was either mistaken or using outdated distributions at the original time of writing. Even if present-day installers have the right arch, I still suspect this issue will remain widespread for quite some time, though: since the inaccurate
I'm not sure if it's the best way, but a reliable technique I have used is to compare the values of some command with and without an
I think the same technique would work in a Homebrew formula, though I'm not sure if it's blessed by the Homebrew maintainers. |
Describe the Bug
On an ARM MacOS environment,
facter
's builtinprocessors.isa
andos.architecture
facts report the architecture being emulated by Rosetta, not the architecture of the host hardware.Rosetta 2 is MacOS's system for the execution of Intel binaries on ARM-based (M1/2/3) Macs.
When a binary is Intel-only, or when a binary is "universal" and contains segments for both Intel and ARM, Rosetta 2 can be used to run it as x86_64.
Expected Behavior
processors
don't change to contain different silicon based on whether an emulation layer is present, soprocessors.isa
(andhardwareisa
) should not change based on whetherfacter
is being run in an emulated capacity.os.architecture
(andarchitecture
) should not change based on whetherfacter
is being run in an emulated capacity.Steps to Reproduce
arch
command run without arguments should reportarm64
orarm64e
.softwareupdate --install-rosetta
facter
.facter
in the arm64 architecture (should be the default), and observe that the isa/architecture related facts match the computer's hardware:facter
via Rosetta emulation, and observe that the isa/architecture facts are now incorrect:Environment
MacOS 14.5, also reproduced on MacOS 13.
I was unable to install
facter
directly via gem as the dependency on the now-deprecatedhpricot
prevented compilation on my machine.Instead, I reproduced this using two puppetlabs-official distributions of facter: facter 4.6.1 via
brew install --cask puppet-agent
(which ships with an ARM-onlyruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [arm64-darwin23]
), and facter 4.7.0 viabrew install --cask puppet-bolt
(which ships with an x86_64ruby 2.7.8p225 (2023-03-30 revision 1f4d455848) [x86_64-darwin21]
. The x86-ness isn't implicated here, and is likely temporary pending resolution of a low-priority issue I reported))Additional Context
This seems to be due to the os/processor facts' dependency on the
uname
propvider (e.g. here).uname
is not an appropriate way to get hardware information on MacOS. It reports information about the current runtime/emulation context, not about the machine itself:The text was updated successfully, but these errors were encountered: