NASM - The Netwide Assembler
NASM Forum => Programming with NASM => Topic started by: dduong on January 08, 2014, 10:40:45 PM
-
Hello, I am having some trouble writing a shared library.
func1.s
SECTION .text
GLOBAL func1
func1:
mov rax, rdi
ret
func2.s
SECTION .text
EXTERN func1
GLOBAL func2
func2:
call func1
add rax, rsi
ret
huy@xguard:~/shared$ nasm -f elf64 func1.s
huy@xguard:~/shared$ nasm -f elf64 func2.s
huy@xguard:~/shared$ ld -shared -o libfunc.so func1.o func2.o
ld: func2.o: relocation R_X86_64_PC32 against symbol `func1' can not be used when making a shared object; recompile with -fPIC
ld: final link failed: Bad value
Under mac os x when I do ld -dylib, I don't have any issue. But with linux, I have this error. Could you help me with this issue ?
-
I don't know if it's right, but simply adding "-pic" to ld's command line seems to get it past that point - complains about not finding an entrypoint. I would have thought that "-shared" implied "-pic", but perhaps not. I'm not sure a shared library should need an entrypoint. The second thing I might try is adding "default rel" to one or both files. I'm too new to 64-bit code to know if that's any help or not.
Best,
Frank