1

I'm trying to make a dynamic library with assembly code. So i convert my .asm files to .o with nasm (nasm -f elf64 filename.asm). And when i link them with ld (ld files.o -shared -o libasm.so -fPIC), it gives me an error ld: strstr.o: relocation R_X86_64_PC32 against symbol `strlen' can not be used when making a shared object; recompile with -fPIC ld: final link failed: Bad value. Could someone can help me, how to compile them ?

Thanks in advance.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
Progear
  • 157
  • 8
  • Those are the right commands, but you have to write position-independent code and that also doesn't try to reach libc symbols directly with a 32-bit relative offset. Instead you have to call library functions via the PLT. Just like for a PIE executable. See [Can't call C standard library function on 64-bit Linux from assembly (yasm) code](https://stackoverflow.com/q/52126328) – Peter Cordes Mar 01 '20 at 22:17
  • Try to call `strlen` as `strlen wrt ..plt` to fix this issue. – fuz Mar 02 '20 at 09:31

0 Answers0