Author Topic: Accessing floating point constants on MacOSX  (Read 16800 times)

nobody

  • Guest
Accessing floating point constants on MacOSX
« on: January 12, 2010, 08:58:33 PM »
Hi there,
I'm porting some optimization stuff from Windows to Mac OS X and found a pretty interesting trouble.
What I need is simply to load a constant into a XMM register (things like 0.5f, or 0x7FFFFFFF DWORD retyped to float to emulate absolute value...). Using MASM I just need to write something like

movss xmm0, [xxxxConstant]

This worked under Win32/Win64 and EXE/DLL. Now I moved to NASM, because I needed Mac OS X support and under Win32 it stays the some. Under Win64 I needed to use

mov rax, xxxxConstant
mov xmm0, [rax]

but ok, so be it, let's say NASM cannot generate 64-bit addresses or something (though it is weird, 'cos MASM could).
But the real trouble is on Mac OS X (macho), where it works only in executables, not shared libraries. In that case GCC linker generates error something like that it cannot use absolute addressing.

I know it uses some sort of rellocation, but why it cannot use some relative offsets it uses for jumps? Documentation says we can use some GOT stuff, but that is a huge mess and when I tried it, the NASM errors with "unknown symbol got".

So my question is, how can I simply load a constant (float/double) into a XMM register on Mac OS X shared library? And is that some way to do it on all platforms?

Thanks in advance!

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Accessing floating point constants on MacOSX
« Reply #1 on: January 13, 2010, 01:28:10 AM »
Dunno much about 64-bit. Will "movss xmm0, [rel the_address]" do what you want?

Best,
Frank

Vojtech

  • Guest
Re: Accessing floating point constants on MacOSX
« Reply #2 on: January 13, 2010, 01:34:28 AM »
Thanks Frank, but unfortunately no :(. On Mac OS X shared library it still generates the error "Cannot use absolute addressing in sliding image " or something like that. Maybe bug in NASM? Or another genius thing about Mac OS X...

Regards,
Vojtech