Comments (7)
System call numbers on macOS are not stable, so Apple would like you to go through libc. Go used to create static binaries on macOS but they would constantly break whenever an update came out, so they've starting linking against the system libraries. The only reason you should be making system calls yourself is curiosity or if you have an extremely good reason that you cannot link against libSystem ;)
from hellosilicon.
Oh, no, Mach-O totally does static binaries. In fact, here's how to make one you can run on your Intel machine:
$ clang -x assembler-with-cpp -static -nostdlib -
.intel_syntax noprefix
#include <sys/syscall.h>
#define UNIX_SYSCALL 0x2000000
.globl start
start:
mov rax, UNIX_SYSCALL | SYS_write
mov rdi, 1
lea rsi, text[rip]
lea rdx, length
syscall
mov rax, UNIX_SYSCALL | SYS_exit
xor rdi, rdi
syscall
text:
.asciz "Hello, world!\n"
.equ length, . - text
$ ./a.out
Hello, world!
from hellosilicon.
Oh, no, Mach-O totally does static binaries. In fact, here's how to make one you can run on your Intel machine:
…
While you can create static binaries, the macOS kernel (XNU) allows the execution of static binaries on x86_64 only (or with debug kernels, which probably nobody outside Apple is using). On all other platforms (ARM64), the kernel enforces that an executable must use the dynamic linker (this was already linked to in the issue above). It's a restriction that cannot be bypassed. However, you can create a dynamically linked executable and simply not link to any library/framework.
from hellosilicon.
I lied, that code is likely outdated/not complete. I know of at least one statically linked binary running.
from hellosilicon.
That's cool to know! Although now that I have solved the issue of in the makefile, I will continue to work on that!
from hellosilicon.
I lied, that code is likely outdated/not complete. I know of at least one statically linked binary running.
Most interesting, the documentation I could find is also that Mach-O doesn't do static binaries.
That said, currently I am happy as long as I can easily build and deploy assembler source from the command line, and I might come back to the issue of building a Mach-O binary later ;)
from hellosilicon.
Most interesting! Any idea why the documentation would claim such a thing?
from hellosilicon.
Related Issues (15)
- Chapter 13, NEON: Invalid operand for instruction MUL HOT 2
- openat syscall not working HOT 1
- Access command line arguments (argv and argc) in AAarch64/Darwin assembly HOT 3
- Linking failing after installing Big Sur 11.0.1 HOT 5
- can't use the command `objdump` command with no-aliases option HOT 3
- 'Hello world' doesn't work on silicon HOT 3
- build 32-bit binary on Apple Silicon Mac HOT 4
- GAS generates local symbols for labels starting with the letter L
- Authoritative documentation of assembler for M1 machines? HOT 8
- objdump's `--macho` option makes `-M no-aliases` have no effect?
- Brief explanation of changes HOT 2
- incorrect `chapter4::printword.s` assembly program HOT 2
- write on Linux requires a length HOT 1
- Change "as" to "clang" in all examples HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hellosilicon.