When I compile print.s using gcc I get the following error:
/usr/bin/ld: /tmp/cc45uyZj.o: relocation R_X86_64_32S against `.data' can not be used when making a shared object; recompile with -fPIC
/usr/bin/ld: final link failed: Nonrepresentable section on output
collect2: error: ld returned 1 exit status
I tried the same in another linux distribution and it worked perfectly.
Adding -fPIC
doesn't help. Nor does apt-get update.
if you want to see the code: https://github.com/NEGU93/Compilation.git inside the Practice > Part1. Of course is the file print.s (btw. all the .s files have similar errors when I do gcc).
I guess something is missing in the Kali distro but I don't know what can it be.
It seems that your distro enables -pie
by default (check gcc -v
output) but your assembly is not position-independent. Try compiling a sample .c file under -fPIC
and see how it generates calls. In your case it should be
call printf@PLT
or you can try compiling with gcc -no-pie
.
I get the same error as you when trying to link some object files compiled with clang and some with gcc. I guess these two compilers have different default settings regarding whether to produce position independent code.
So make sure you're not accidentally using the wrong compiler on part of your project.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With