Nasm - 符号“printf"导致 R_X86_64_PC32 重定位溢出 [英] Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation

查看:9
本文介绍了Nasm - 符号“printf"导致 R_X86_64_PC32 重定位溢出的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 nasm 中创建一个应该显示字母 a 的简单程序.但是,它给了我一个 Segfault 并说:

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)

基本上,我试图将值 0x61(字母 a 的十六进制)移动到内存地址 1234,然后将其作为参数传递给 printf.这是我的确切代码:

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

我正在运行 Linux x86_64

I am running Linux x86_64

推荐答案

尝试用 -no-pie 编译,查看这些帖子以获得解释:使用 GCC 组装会导致奇怪的重定位错误.数据

try compiling with -no-pie, check out these posts for explanation: Assembling with GCC causes weird relocation error with regards to .data

简而言之:

Debian 切换到 64 位模式下的 PIC/PIE 二进制文件 &海湾合作委员会在你的情况下正在尝试将您的对象链接为 PIC,但它会遇到绝对地址在 mov $str, %rdi.

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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆