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

Add MacOS on AArch64 support #5383

Open
derekbruening opened this issue Feb 23, 2022 · 0 comments
Open

Add MacOS on AArch64 support #5383

derekbruening opened this issue Feb 23, 2022 · 0 comments

Comments

@derekbruening
Copy link
Contributor

Xref https://groups.google.com/d/msgid/dynamorio-users/01e7e991-675c-4ff4-85f3-e4745e8fecfbn%40googlegroups.com?utm_medium=email&utm_source=footer

This issue covers adding support for DR on MacOS on AArch64 such as M1.

heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 22, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 26, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 26, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue May 31, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue Jun 1, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue Jun 1, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue Jun 1, 2022
This patch adds enough support to run simple hello world on M1 macs.

Issue: DynamoRIO#5383
heyitsanthony pushed a commit to heyitsanthony/dynamorio that referenced this issue Jun 1, 2022
Updates to aarch64 to execute code with PAC features; mainly just strips
off any PAC bits before jumping anywhere.

Issue: DynamoRIO#5383
derekbruening added a commit that referenced this issue Aug 26, 2022
This patch adds enough support to run simple hello world on M1 MacOS.
It separates x86 and aarch64 Mac code in many places, adjusts the TLS
from tpidr_el0 to tpidrro_el0, tweaks the assembly syntax, adds support
for decoding and handling some of the pointer authentication opcodes
in ARMv8.3 (mainly just strips off any PAC bits before jumping anywhere),
adds pthread_jit_write_protect_np() calls for written executable code,
and updates the system call number register.

There are a number of unresolved and missing pieces, which are marked
with comments in the code:
+ DR_TLS_BASE_OFFSET needs further investigation
+ dynamorio_{sigreturn,exit} are NYI
+ The pointer authentication opcodes need tests, and the full set of opcodes
   needs to be added
+ The gettimeofday library call inserted here should be replaced with a
   system call.
+ The PTHREAD_JIT_WRITE calls are likely missing from some places and
   not at the right level to be most efficient.

Original version contributed by: Anthony Romano <anthony@forallsecure.com>
Co-authored-by: Anthony Romano <anthony@forallsecure.com>

Issue: #5383
derekbruening added a commit that referenced this issue Aug 29, 2022
Fixes many unused-variable warnings when building the core and
extension libraries.  This enables a config without tests or docs to
build.  The drsyms libraries are missing so clients/ is not yet built.

Issue: #5383
derekbruening added a commit that referenced this issue Aug 30, 2022
Fixes many unused-variable warnings when building the core and
extension libraries.  This enables a config without tests or docs to
build.  The drsyms libraries are missing so clients/ is not yet built.

Increases the clang-format version from 12 to 14 to match local versions,
as 12 has bugs in clang-format-diff that showed up in many places in
this PR.

Adds alignment of adjusted stack size options to page sizes in options_enable_code_api_dependences().

Issue: #5383
derekbruening added a commit that referenced this issue Nov 14, 2022
Adds static libdwarf and libelftc libraries built for Mach-O AArch64.
These are not yet fully tested but this is a first pass to able
configuring and building drsyms and components that depend on it such
as drcachesim.  This enables using local M1 builds to replication GA
CI OSX build warnings.

Fixes build warnings and issues from things like the oldest OSX
supported.

Fixes configuration issues from x86-only tests.  Building the tests
does not yet succeed.

Issue: #5383
derekbruening added a commit that referenced this issue Nov 15, 2022
Adds static libdwarf and libelftc libraries built for Mach-O AArch64.
These are not yet fully tested but this is a first pass to able
configuring and building drsyms and components that depend on it such
as drcachesim.  This enables using local M1 builds to replication GA
CI OSX build warnings.

Fixes build warnings and issues from things like the oldest OSX
supported, which we update to 11.7.
Eliminates syscall() from signal.dll.c as it is deprecated in 11.7.

Fixes configuration issues from x86-only tests.  Building the tests
does not yet succeed.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 3, 2023
Enables BUILD_TESTS to compile for M1: a combination of fixing and
disabling tests.  Many issues came from assembler and pre-processor
differences.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 4, 2023
Enables BUILD_TESTS to compile for M1: a combination of fixing and
disabling tests.  Many issues came from assembler and pre-processor
differences.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 4, 2023
Fixes global references in aarch64.asm which were loading the value
instead of the address (the Linux a64 assembler auto-magically gives
the address whether using ADD or LDR!).

Fixes and clarifies the Mac64 x86 and arm TLS slots vs offsets.

Uses gettimeofday() for query_time_seconds() instead of SYS_gettimeofday.

Removes an invalid hardcoded 0 sysnum for global_do_syscall.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 4, 2023
Fixes global references in aarch64.asm which were loading the value
instead of the address (the Linux a64 assembler auto-magically gives
the address whether using ADD or LDR!).

Fixes and clarifies the Mac64 x86 and arm TLS slots vs offsets.

Uses gettimeofday() for query_time_seconds() instead of SYS_gettimeofday.

Removes an invalid hardcoded 0 sysnum for global_do_syscall.

Issue: #5383
github-merge-queue bot pushed a commit that referenced this issue Jul 5, 2023
Enables BUILD_TESTS to compile for M1: a combination of fixing and
disabling tests. Many issues came from assembler and pre-processor
differences.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 5, 2023
Fixes global references in aarch64.asm which were loading the value
instead of the address (the Linux a64 assembler auto-magically gives the
address whether using ADD or LDR!).

Fixes and clarifies the Mac64 x86 and arm TLS slots vs offsets.

Uses gettimeofday() for query_time_seconds() instead of
SYS_gettimeofday.

Removes an invalid hardcoded 0 sysnum for global_do_syscall.

Issue: #5383
derekbruening added a commit that referenced this issue Jul 5, 2023
8 of the 13 tests on Mac AArch64 labeled "OSX" fail prior to this PR.
Here we fix the following:

+ Syscall success is indicated by the carry flag just like x86 Mac
+ Handle sigreturn with its extra parameters just like x86 Mac
+ Fix signal handler parameters
+ Fix stolen register support in signal contexts
+ Use MAP_JIT and pthread_jit_write_protect_np for +rwx gencode in tests
+ Use DYLD_LIBRARY_PATH on Mac in tests

Now all 13 tests pass:
---------------------------------------------------------------------------------------
ctest -j 5 -L OSX
 1/13 Test  #13: code_api|common.fib ................................  Passed  0.59 sec
 2/13 Test #243: code_api|libutil.frontend_test .....................  Passed  0.63 sec
 3/13 Test #231: code_api|api.ir ....................................  Passed  0.67 sec
 4/13 Test   #9: code_api|linux.sigaction.native ....................  Passed  0.25 sec
 5/13 Test  #31: code_api|linux.signal0000 ..........................  Passed  0.10 sec
 6/13 Test #240: code_api|api.ir-static .............................  Passed  0.34 sec
 7/13 Test #241: code_api|api.drdecode ..............................  Passed  0.38 sec
 8/13 Test #245: code_api|api.dis-a64 ...............................  Passed  1.15 sec
 9/13 Test #264: no_code_api,no_intercept_all_signals|linux.sigaction  Passed  0.08 sec
10/13 Test  #33: code_api|linux.signal0010 ..........................  Passed  0.34 sec
11/13 Test  #35: code_api|linux.signal0100 ..........................  Passed  0.42 sec
12/13 Test  #37: code_api|linux.signal0110 ..........................  Passed  0.45 sec
13/13 Test   #7: samples_proj .......................................  Passed  1.89 sec
100% tests passed, 0 tests failed out of 13
---------------------------------------------------------------------------------------

Issue: #5383
github-merge-queue bot pushed a commit that referenced this issue Jul 7, 2023
8 of the 13 tests on Mac AArch64 labeled "OSX" fail prior to this PR.
Here we fix the following:

+ Syscall success is indicated by the carry flag just like x86 Mac
+ Handle sigreturn with its extra parameters just like x86 Mac
+ Fix signal handler parameters
+ Fix stolen register support in signal contexts
+ Use MAP_JIT and pthread_jit_write_protect_np for +rwx gencode in tests
+ Use DYLD_LIBRARY_PATH on Mac in tests

Now all 13 tests pass:
```
---------------------------------------------------------------------------------------
$ ctest -j 5 -L OSX
 1/13 Test  #13: code_api|common.fib ................................  Passed  0.59 sec
 2/13 Test #243: code_api|libutil.frontend_test .....................  Passed  0.63 sec
 3/13 Test #231: code_api|api.ir ....................................  Passed  0.67 sec
 4/13 Test   #9: code_api|linux.sigaction.native ....................  Passed  0.25 sec
 5/13 Test  #31: code_api|linux.signal0000 ..........................  Passed  0.10 sec
 6/13 Test #240: code_api|api.ir-static .............................  Passed  0.34 sec
 7/13 Test #241: code_api|api.drdecode ..............................  Passed  0.38 sec
 8/13 Test #245: code_api|api.dis-a64 ...............................  Passed  1.15 sec
 9/13 Test #264: no_code_api,no_intercept_all_signals|linux.sigaction  Passed  0.08 sec
10/13 Test  #33: code_api|linux.signal0010 ..........................  Passed  0.34 sec
11/13 Test  #35: code_api|linux.signal0100 ..........................  Passed  0.42 sec
12/13 Test  #37: code_api|linux.signal0110 ..........................  Passed  0.45 sec
13/13 Test   #7: samples_proj .......................................  Passed  1.89 sec
100% tests passed, 0 tests failed out of 13
---------------------------------------------------------------------------------------
```
Issue: #5383
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant