Nasm - 符号`printf'在R_X86_64_PC32重定位中导致溢出 [英] Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation
问题描述
我正在尝试在nasm中创建一个简单的应该显示字母 a
的程序。但是,它给了我一个Segfault并说这个:
./ a.out:符号`printf'在R_X86_64_PC32中导致溢出重定位
分段错误(核心转储)
基本上,我试图将值 0x61
(字母a的十六进制)写入内存地址1234,然后将其作为参数传递给printf。这是我确切的代码:
extern printf
section .text
全局主元
main :
push rbp
mov rax,0
mov qword [1234],0x61;移动0x61到地址1234
mov rdi,qword [1234]; mov地址1234到rdi
调用printf;应打印信件a
pop rbp
mov rax,0
ret
我正在运行Linux x86_64
尝试编译 -no-pie
,查看这些帖子的解释:
使用GCC进行组装会导致怪异的数据重定位错误
Debian在64位模式下切换到PIC / PIE二进制文件& GCC在你的情况下
试图链接你的对象作为PIC,但是它会在mov $ str,%rdi中遇到绝对的
地址。
I am trying to create a simple program in nasm that should display the letter a
. however, It is giving me a Segfault and saying this:
./a.out: Symbol `printf' causes overflow in R_X86_64_PC32 relocation
Segmentation fault (core dumped)
Basically, I am trying to move the value 0x61
(hex for letter a) into memory address 1234, and then pass that as an argument to printf. Here is my exact code:
extern printf
section .text
global main
main:
push rbp
mov rax,0
mov qword [1234], 0x61 ; move 0x61 into address 1234
mov rdi, qword [1234] ; mov address 1234 into rdi
call printf ; should print the letter a
pop rbp
mov rax,0
ret
I am running Linux x86_64
try compiling with -no-pie
, check out these posts for explanation:
Assembling with GCC causes weird relocation error with regards to .data
in short:
Debian switched to PIC/PIE binaries in 64-bits mode & GCC in your case is trying to link your object as PIC, but it will encounter absolute address in mov $str, %rdi.
这篇关于Nasm - 符号`printf'在R_X86_64_PC32重定位中导致溢出的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!