其他答案没有告诉我如何编译,我被卡住了
我在汇编中有一个简单的Hello World
.global start
.align 2
start: mov X0, #1
adr X1, hello
mov X2, #13
mov X16, #4
svc 0
mov X0, #0
mov X16, #1
svc 0
hello: .ascii "Hello\n"
我用clang hello.s -nostdlib -static
编译了它
文件上说
% file ./a.out
./a.out: Mach-O 64-bit executable arm64
obj dump显示了这一点,也许UNKNOWN_ARCHITECTURE是问题所在?
./a.out: file format mach-o-arm64
Disassembly of section .text:
0000000100003fd8 <start>:
100003fd8: d2800020 mov x0, #0x1 // #1
100003fdc: 100000e1 adr x1, 100003ff8 <hello>
100003fe0: d28001a2 mov x2, #0xd // #13
100003fe4: d2800090 mov x16, #0x4 // #4
100003fe8: d4000001 svc #0x0
100003fec: d2800000 mov x0, #0x0 // #0
100003ff0: d2800030 mov x16, #0x1 // #1
100003ff4: d4000001 svc #0x0
0000000100003ff8 <hello>:
100003ff8: 6c6c6548 ldnp d8, d25, [x10, #-320]
100003ffc: Address 0x0000000100003ffc is out of bounds.
Disassembly of section LC_THREAD.UNKNOWN_ARCHITECTURE.0:
0000000000000000 <LC_THREAD.UNKNOWN_ARCHITECTURE.0>:
...
100: 00003fd8 udf #16344
104: 00000001 udf #1
...
在zsh中运行时显示“killed”,错误代码为137。
这是dtruss说的
% sudo dtruss ./a.out
dtrace: system integrity protection is on, some features will not be available
dtrace: failed to execute ./a.out: Bad executable (or shared library)
我哪里做错了?我在M2上
1条答案
按热度按时间ql3eal8s1#
arm64 macOS上的内核不允许静态二进制文件。
但是你不需要你的二进制文件是静态的,只要把
start
重命名为_main
,然后用clang hello.s
编译,它就会工作。