如何在AMD64架构的Linux汇编程序中使用RIP相对寻址?我正在寻找一个使用AMD64 RIP相对地址模式的简单示例(Hello world程序).
例如,以下64位汇编程序将与普通(绝对寻址)一起使用:
.text
.global _start
_start:
mov $0xd, %rdx
mov $msg, %rsi
pushq $0x1
pop %rax
mov %rax, %rdi
syscall
xor %rdi, %rdi
pushq $0x3c
pop %rax
syscall
.data
msg:
.ascii "Hello world!\n"
Run Code Online (Sandbox Code Playgroud)
我猜测使用RIP相对寻址的相同程序将是这样的:
.text
.global _start
_start:
mov $0xd, %rdx
mov msg(%rip), %rsi
pushq $0x1
pop %rax
mov %rax, %rdi
syscall
xor %rdi, %rdi
pushq $0x3c
pop %rax
syscall
msg:
.ascii "Hello world!\n"
Run Code Online (Sandbox Code Playgroud)
编译时,正常版本运行正常:
as -o hello.o hello.s && ld -s -o hello hello.o && ./hello
Run Code Online (Sandbox Code Playgroud)
但我无法使RIP版本正常工作. …