Posts

Showing posts from November, 2018

Don't Recompile with -no-pie

X86-64 NASM Assembly and PIE If you get the following runtime error when attempting to execute a 64-bit C application that links with a 64-bit NASM assembly object on Linux: ./a.out: Symbol `printf' causes overflow in R_X86_64_PC32 relocation Segmentation fault (core dumped) Don't do what is commonly suggested on other blogs and recompile with -no-pie . From the NASM Manual: Calling procedures outside your shared library has to be done by means of a procedure linkage table, or PLT All this means is that in order to be PIE-compatible under Linux, change: call printf To: call printf wrt ..plt Then recompile everything and the 64-bit NASM assembly object will be able to call printf in a position-independent way.

Don't Recompile With -fPIC

X86-64 NASM Assembly and PIE If you get the following error when attempting to compile a 64-bit C application that links with a 64-bit NASM assembly object on Linux: /usr/bin/ld: foo.o: relocation R_X86_64_32S against `.data' can not be used when making a PIE object; recompile with -fPIC Don't do what the error message suggests and recompile with -fPIC . From the NASM Manual: In 64-bit mode, NASM will by default generate absolute addresses. The REL keyword makes it produce RIP-relative addresses When you have a .data section defined in the NASM 64-bit assembly object: section .data ; DX directives align 16 ten: dd 10.0 error_code: dd -1.0 All this means is that in order to be PIE-compatible under Linux, change: movss xmm2, [ten] To: movss xmm2, [rel ten] Then recompile everything and the linker will no longer complain about not being able to make a PIE object. Set REL as the DEFAULT Again, acc