wolfcw / libfaketime

libfaketime modifies the system time for a single application
https://github.com/wolfcw/libfaketime
GNU General Public License v2.0
2.62k stars 319 forks source link

Check if the user is on ARM64, add target to CFLAGS/LDFLAGS #466

Closed joshuataylor closed 3 months ago

joshuataylor commented 3 months ago

Fixes #334

This pull requests adds support for MacOS ARM64, by adding -target to the CFLAGS/LDFLAGS.

Without this, the user will receieve the following error:

dyld[6675]: terminating because inserted dylib '/usr/local/lib/faketime/libfaketime.1.dylib' could not be loaded: tried: '/usr/local/lib/faketime/libfaketime.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/faketime/libfaketime.1.dylib' (no such file), '/usr/local/lib/faketime/libfaketime.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))
dyld[6675]: tried: '/usr/local/lib/faketime/libfaketime.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e')), '/System/Volumes/Preboot/Cryptexes/OS/usr/local/lib/faketime/libfaketime.1.dylib' (no such file), '/usr/local/lib/faketime/libfaketime.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64', need 'arm64e'))

The trick seems to be adding -target arm64e-apple-macos14.4 to CFLAGS and LIB_LDFLAGS.

So 14.4 is the version of MacOS I'm on:

$ sw_vers
ProductName:            macOS
ProductVersion:         14.4
BuildVersion:           23E214
uname -a
Darwin joshs-MBP.lan 23.4.0 Darwin Kernel Version 23.4.0: Wed Feb 21 21:45:49 PST 2024; root:xnu-10063.101.15~2/RELEASE_ARM64_T6020 arm64 arm Darwin

Showing the version:

sw_vers --productVersion
14.4

Checking if the user is on arm64:

$ uname -m
arm64

So we can just check in the Makefile.OSX if the user is on ARM64, then just add the flag.

You can test this yourself without this patch by appending the CFLAGS/LIB_LDFLAGS environment variables:

MACOS_PRODUCT_VERSION=$(sw_vers --productVersion | cut -d. -f1,2)
export CFLAGS="$CFLAGS -target arm64e-apple-macos${MACOS_PRODUCT_VERSION}"
export LIB_LDFLAGS="$LIB_LDFLAGS -target arm64e-apple-macos${MACOS_PRODUCT_VERSION}"

Happy for this PR to be altered as you see fit, this issue poked something in my brain and I was curious how to fix it, fun way to spend a lunch :-).

wolfcw commented 3 months ago

Thank you, that's very nifty!

Hope the lunch was good, too. =)

anthonyra commented 3 months ago

I don't think this works if you're running 14.2 ... because you get the following error instead

'/opt/homebrew/opt/libfaketime/lib/faketime/libfaketime.1.dylib' (mach-o file, but is an incompatible architecture (have 'arm64e', need 'arm64'))
$ sw_vers
ProductName:            macOS
ProductVersion:         14.2.1
BuildVersion:           23C71
Darwin Mac-Studio.local 23.2.0 Darwin Kernel Version 23.2.0: Wed Nov 15 21:53:18 PST 2023; root:xnu-10002.61.3~2/RELEASE_ARM64_T6000 arm64
joshuataylor commented 3 months ago

I think you'll need to compile this yourself, and also that homebrew will need to have versions for arm64, I'm not sure if they cross compile or something, but the .rb file would probably need to be updated.