【发布时间】:2019-03-20 16:37:56
【问题描述】:
我正在尝试组装一个简单的 Hello World,它在以前的 macOS 版本中运行良好:
global start
section .text
start: mov rax, 0x02000004
mov rdi, 1
mov rsi, msg
mov rdx, 13
syscall
mov rax, 0x02000001
xor rdi, rdi
syscall
section .data
msg: db "Hello world!", 10
然后我像以前一样使用nasm 和ld:
$ nasm -f macho64 hello.asm
$ ld hello.o -o hello
但是ld 给了我以下错误:
ld: warning: No version-min specified on command line
Undefined symbols for architecture x86_64:
"_main", referenced from:
implicit entry/start for main executable
ld: symbol(s) not found for inferred architecture x86_64
我尝试将start 切换为_main,但得到以下结果:
ld: warning: No version-min specified on command line
ld: dynamic main executables must link with libSystem.dylib for inferred architecture x86_64
甚至不知道这可能意味着什么。
【问题讨论】:
-
这就是你通常链接
cc hello.o -o hello的原因,因为C编译器知道如何将目标文件链接到可执行文件中。顺便说一句,您应该使用lea rdi, [rel msg],而不是需要运行时重定位的mov rdi, imm64绝对形式。