如何在Linux装配程序中使用RIP相对寻址来进行AMD64架构?
我正在寻找一个使用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"
我猜测使用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"
正常版本运行正常,编译时:
as -o hello.o hello.s && ld -s -o hello hello.o && ./hello