gpt4 book ai didi

macos - Mac OS X : YASM: error: macho: sorry, 无法在 64 位模式下应用 32 位绝对重定位

转载 作者:行者123 更新时间:2023-12-04 05:15:28 25 4
gpt4 key购买 nike

这个问题在这里已经有了答案:





Mach-O 64-bit format does not support 32-bit absolute addresses. NASM Accessing Array

(1 个回答)


3年前关闭。




NASM 编译得很好,但是当我使用 YASM 时,出现以下错误:

hello.asm:12: error: macho: sorry, cannot apply 32 bit absolute relocations in 64 bit mode, consider "[_symbol wrt rip]" for mem access, "qword" and "dq _foo" for pointers.



生成文件
test: hello
./hello
hello:
yasm -f macho64 hello.asm
ld -o hello hello.o
clean:
rm *.o *.core hello

系统公司
%define stdin       0
%define stdout 1
%define stderr 2

%define SYS_nosys 0
%define SYS_exit 1
%define SYS_fork 2
%define SYS_read 3
%define SYS_write 4

section .text
align 4
access.the.osx.kernel:
syscall
ret

%macro system 1
mov rax, %1
call access.the.osx.kernel
%endmacro

%macro sys.exit 0
system SYS_exit
%endmacro

%macro sys.write 0
system SYS_write
%endmacro

你好.asm
%include 'system.inc'

section .data
hello db 'Hello, World!', 0Ah
hbytes equ $-hello

section .text
global start
start:
mov rax, 0x2000004
mov rdi, stdout
mov rsi, hello
mov rdx, hbytes
syscall
;sys.write

xor rdi, rdi
mov rax, 0x2000001
syscall
;sys.exit

有谁知道这是怎么回事?如果你能解释为什么 NASM 有效,但 YASM 没有,那将是一个奖励。

最佳答案

我让它工作了。在 yasm你必须明确地告诉它地址是 64 位的,如下所示:

mov rsi, qword hello

文档在这里讨论了这种情况: https://github.com/yasm/yasm/wiki/AMD64

关于macos - Mac OS X : YASM: error: macho: sorry, 无法在 64 位模式下应用 32 位绝对重定位,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14343190/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com