You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+8Lines changed: 8 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -71,6 +71,13 @@ If you are reading this, I assume you already knew that the macOS Terminal can b
71
71
To make "Hello World" run on Apple Silicon, first the changes from page 78 (Chapter 3) have to be applied to account for the differences between Darwin and the Linux kernel.
72
72
To silence the warning, I insert `.align 4` (or `.p2align 2`), because Darwin likes things to be aligned on even boundaries. The books mentions this in Aligning Data in Chapter 5, page 114.
73
73
74
+
System calls in Linux and macOS have several differences due to the unique conventions of each system. Here are some key distinctions:
75
+
* Function Number: The function numbers differ between the two systems, with Linux using 64 and macOS using 4. The table for Darwin (Apple) system calls can be found at this link: [Darwin System Calls](https://opensource.apple.com/source/xnu/xnu-7195.81.3/bsd/kern/syscalls.master.auto.html). Please note that this is a specific version (the most recent at the time of writing), and newer versions can be found [here](https://opensource.apple.com/source/xnu/).
76
+
* Address for Storing Function Numbers: The address used for storing function numbers also varies. In Linux, it’s on X8, while in macOS, it’s on X16.
77
+
* Interruption Call: The call for interruption is 0 in Linux, whereas it’s 0x80 on Apple Silicon.
78
+
79
+
80
+
74
81
To make the linker work, a little more is needed, most of it should look familiar to Mac/iOS developers. These changes need to be applied to the `makefile` and to the `build` file. The complete call to the linker looks like this:
75
82
76
83
```
@@ -89,6 +96,7 @@ We know the `-o` switch, let's examine the others:
89
96
*`-e _start`: Darwin expects an entrypoint `_main`. In order to keep the sample both as close as possible to the book, and to allow it's use within the C-Sample from _Chapter 3_, I opted to keep `_start` and tell the linker that this is the entry point we want to use
90
97
*`-arch arm64` for good measure, let's throw in the option to cross-compile this from an Intel Mac. You can leave this off when running on Apple Silicon.
91
98
99
+
92
100
### Reverse Engineering Our Program
93
101
94
102
While the objdump command line programm works just as well on Darwin and produces the expected output, also try the “--macho” (or “-m”) option, which causes objdump to use the Mach-O specific object file parser.
0 commit comments