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

i#5383: Fix macOS preload on a64 #7170

Open
wants to merge 13 commits into
base: master
Choose a base branch
from

Conversation

ndrewh
Copy link
Contributor

@ndrewh ndrewh commented Dec 26, 2024

This fixes several build and runtime issues under macOS on ARM64 on macOS 14.4.1 (Sonoma)

  • FEATURE_PAUTH is now detected on macOS using a sysctl (capability MSRs cannot be read in userspace on M3 at least)
  • In the preload library, _init needs __attribute__((constructor)) to be run by dyld
  • In the preload library, dynamorio_set_envp needs to be called before get_application_short_name can work (on macOS the application path is placed after envp)
  • PLATFORM_SUPPORTS_SCATTER_GATHER was broken, disabled for now on a64 macOS
  • Fixed sigcontext/mcontext conversion which assumes old simd size and was failing on an assert
  • Fixed random compile issues under apple clang (whatever ships with Xcode) on ARM64
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.4.0
Thread model: posix
InstalledDir: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin

Known issues that remain:

  • VM allocation frequently but nondeterministically fails reachability constraints. -vm_size 500M seems to fix this. i#5383: Fix macOS arm64 test build/run #7171 adds this flag to tests on macOS+ARM64.
  • Sometimes some bookkeeping asserts in vmh_exit are reached upon process exit

The end result is that the bbcount tool works on a simple toy program on macOS, in debug mode, without hitting any asserts:

bin64/drrun -debug -vm_size 500M -c api/bin/libbbcount.dylib -- ./main

@ndrewh
Copy link
Contributor Author

ndrewh commented Dec 26, 2024

It appears I broke the x86 macOS tests, not sure what's going on there yet

@ndrewh ndrewh changed the title i#5383: Fix macOS hello world on a64 i#5383: Fix macOS preload on a64 Dec 26, 2024
@abhinav92003
Copy link
Contributor

It appears I broke the x86 macOS tests, not sure what's going on there yet

If it helps: check out the "Debugging Tests on Github Actions Runner" section at https://dynamorio.org/page_test_suite.html, which documents a way to ssh into the failing test machine.

@ndrewh
Copy link
Contributor Author

ndrewh commented Dec 27, 2024

Alright somehow adding IF_MACOS(__attribute__((constructor))) to the _init function in preload.c is breaking the x86 tests. I can't say I understand the situation at all:

  • on ARM64 macOS 14.4 the preload doesn't work at all without __attribute__((constructor)), which causes ~all of the client tests to fail
  • on the x86 macOS runner (which is on macOS 13):
    • All of the tests seem to pass without the attribute (??? did dyld stop running _init in macOS 14? I searched https://github.com/apple-oss-distributions/dyld and i'm not seeing where they ever ran _init -- maybe some compilers were automatically putting it in the appropriate section but recently changed this behavior)
    • Once you add the attribute some (but not all!) of the client tests fail with some seemingly random instrumentation assert.

@ndrewh
Copy link
Contributor Author

ndrewh commented Dec 27, 2024

I don't think api.startstop fail is my fault, but I also don't see anything to suggest it's #6928

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.

2 participants