Mach-O 64位格式不支持32位绝对地址。NASM

时间:2021-04-04 02:52:59

When I use nasm -f macho64 asm1.asm I get the following error:

当我使用nasm -f macho64 asm1时。asm我得到以下错误:

asm1.asm:14: error: Mach-O 64-bit format does not support 32-bit absolute addresses

asm1。asm:14:错误:Mach-O 64位格式不支持32位绝对地址。

This is asm1.asm

这是asm1.asm

SECTION .data           ;initialized data

msg: db "Hello world, this is assembly", 10, 0

SECTION .text           ;asm code

extern printf
global _main

_main:
    push rbp
    mov rbp, rsp

    push msg
    call printf

    mov rsp, rbp
    pop rbp
    ret

I'm really new to assembly and barely know what these commands do. Any idea what's wrong here?

我真的是一个新手,几乎不知道这些命令的作用。有什么问题吗?

2 个解决方案

#1


3  

Mac OS X, like other UNIX/POSIX systems, uses a different calling convention for 64-bit code. Instead of pushing all the arguments to the stack, it uses RDI, RSI, RDX, RCX, R8, and R9 for the first 6 arguments. So instead of using push msg, you'll need to use something like mov RDI, msg.

与其他UNIX/POSIX系统一样,Mac OS X使用了不同的64位代码调用约定。它使用RDI、RSI、RDX、RCX、R8和R9来处理前6个参数,而不是将所有参数都推到堆栈中。因此,你需要使用像mov RDI, msg这样的东西来代替push msg。

#2


0  

Besides what Drew McGowen points out, rax needs to be zeroed (no vector parameters).

除了Drew McGowen所指出的,rax需要归零(没有矢量参数)。

But -f win64 or -f elf64 will work on this code. I suspect a bug in -f macho64 (but I'm not sure what macho64 is "supposed" to do). Until this gets fixed(?), the workaround is to use default rel or mov rdi, rel msg. I "think" that'll work for ya.

但是-f win64或-f elf64将处理这段代码。我怀疑在-f macho64(但是我不知道macho64应该是什么)。在此之前,解决方法是使用默认的rel或mov rdi, rel msg。我想这对你是有用的。

#1


3  

Mac OS X, like other UNIX/POSIX systems, uses a different calling convention for 64-bit code. Instead of pushing all the arguments to the stack, it uses RDI, RSI, RDX, RCX, R8, and R9 for the first 6 arguments. So instead of using push msg, you'll need to use something like mov RDI, msg.

与其他UNIX/POSIX系统一样,Mac OS X使用了不同的64位代码调用约定。它使用RDI、RSI、RDX、RCX、R8和R9来处理前6个参数,而不是将所有参数都推到堆栈中。因此,你需要使用像mov RDI, msg这样的东西来代替push msg。

#2


0  

Besides what Drew McGowen points out, rax needs to be zeroed (no vector parameters).

除了Drew McGowen所指出的,rax需要归零(没有矢量参数)。

But -f win64 or -f elf64 will work on this code. I suspect a bug in -f macho64 (but I'm not sure what macho64 is "supposed" to do). Until this gets fixed(?), the workaround is to use default rel or mov rdi, rel msg. I "think" that'll work for ya.

但是-f win64或-f elf64将处理这段代码。我怀疑在-f macho64(但是我不知道macho64应该是什么)。在此之前,解决方法是使用默认的rel或mov rdi, rel msg。我想这对你是有用的。