Creating PIC code from .asm under x86_64
Hi all, In my never ending quest to make my life as complicated as possible I'm in the process of converting code over to the x86_64 platform (and I'll even make rpm's if I can get this all to work) I've just converted all the assembly files for xvidcore over to x86_64/yasm format. All these file compile fine once adjusted for 64 bit. The problem is trying to create a shared library from the .o files. The same source under i386 just links into shared libs fine, but with x86_64 ld complains:
cpuid.o: relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
Of course recompiling with -fPIC isn't an option as cpuid.o is built from cpuid.asm. Is there an easy solution for this or am I looking at adding GOT references to the code and manually figuring out the relative locations ? Thanks Mike
On Sat, 15 Nov 2003 06:09:32 -0500
Mike Phillips
cpuid.o: relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
Of course recompiling with -fPIC isn't an option as cpuid.o is built from cpuid.asm.
When it is a code like movl bla,%edi replace it with movl bla(%rip),%edi Otherwise I would write a small C test program for the construct you want and look what gcc generates for it with gcc -S. -Andi
Andi Kleen
On Sat, 15 Nov 2003 06:09:32 -0500 Mike Phillips
wrote: cpuid.o: relocation R_X86_64_32 can not be used when making a shared object; recompile with -fPIC
Of course recompiling with -fPIC isn't an option as cpuid.o is built from cpuid.asm.
When it is a code like
movl bla,%edi
replace it with
movl bla(%rip),%edi
That's the right way. In glibc I did e.g.:
/*
* Written by J.T. Conklin
Otherwise I would write a small C test program for the construct you want and look what gcc generates for it with gcc -S.
You also might want to add the frame unwind information (check how glibc defines ENTRY and END)... Andreas -- Andreas Jaeger, aj@suse.de, http://www.suse.de/~aj SuSE Linux AG, Deutschherrnstr. 15-19, 90429 Nürnberg, Germany GPG fingerprint = 93A3 365E CE47 B889 DF7F FED1 389A 563C C272 A126
Andi Kleen may (or may not) have said:
When it is a code like
movl bla,%edi
replace it with
movl bla(%rip),%edi
Thanks, it works in yasm too, just a touch different because of the syntax variation: mov eax,bla becomes lea eax,[bla wrt rip] or lea eax,[bla+rip] You also need to pass yasm the -g stabs parameter otherwise it won't populate the symbol table properly. Mike
participants (3)
-
Andi Kleen
-
Andreas Jaeger
-
Mike Phillips