Nasm - Symbol `printf' causes overflow in R_X86_64_PC32 relocation

Unknown picture Unknown · Jan 3, 2018 · Viewed 8.2k times · Source

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

Answer

brian picture brian · Mar 18, 2018

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.