Skip to content

Commit 46c4dd5

Browse files
authored
Merge pull request #47 from francopan/main
Issue #46 - Add brief explanation of system call differences
2 parents abc7b8e + c4f7d0d commit 46c4dd5

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,13 @@ If you are reading this, I assume you already knew that the macOS Terminal can b
7171
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.
7272
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.
7373

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+
7481
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:
7582

7683
```
@@ -89,6 +96,7 @@ We know the `-o` switch, let's examine the others:
8996
* `-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
9097
* `-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.
9198

99+
92100
### Reverse Engineering Our Program
93101

94102
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

Comments
 (0)