Andi Kleen writes:
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 .
* Adapted for use as log2 by Ulrich Drepper .
* Public domain.
*
* Changed to use fyl2xp1 for values near 1, .
* Adapted for x86-64 by Andreas Jaeger .
*/
#include
#ifdef __ELF__
.section .rodata
#else
.text
#endif
.align ALIGNARG(4)
ASM_TYPE_DIRECTIVE(one,@object)
one: .double 1.0
ASM_SIZE_DIRECTIVE(one)
/* It is not important that this constant is precise. It is only
a value which is known to be on the safe side for using the
fyl2xp1 instruction. */
ASM_TYPE_DIRECTIVE(limit,@object)
limit: .double 0.29
ASM_SIZE_DIRECTIVE(limit)
#ifdef PIC
#define MO(op) op##(%rip)
#else
#define MO(op) op
#endif
.text
ENTRY(__ieee754_log2l)
fldl MO(one)
fldt 8(%rsp) // x : 1
fxam
fnstsw
fld %st // x : x : 1
andb $1,%ah
jnz 3f // in case x is NaN or ±Inf
4: fsub %st(2), %st // x-1 : x : 1
fld %st // x-1 : x-1 : x : 1
fabs // |x-1| : x-1 : x : 1
fcompl MO(limit) // x-1 : x : 1
fnstsw // x-1 : x : 1
andb $0x45, %ah
jz 2f
fstp %st(1) // x-1 : 1
fyl2xp1 // log(x)
ret
2: fstp %st(0) // x : 1
fyl2x // log(x)
ret
3: jp 4b // in case x is ±Inf
fstp %st(1)
fstp %st(1)
ret
END (__ieee754_log2l)
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