get address of label: (Mac x64)

Mac OSX specific forum
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

get address of label: (Mac x64)

Post by Keya »

How to get the address of a label in Mac x64?
The following works fine in Win64 and Linux64:

Code: Select all

DisableDebugger
Define address.i

! mov rax, mylabel   ;<-- fine in Win/Linux, not Mac?

! mov qword [v_address], rax
MessageRequester("Label address", Hex(address))

DataSection
  !mylabel:
  !db 1,2,3,4,5,6,7,8
EndDataSection
But it won't compile in Mac64:
purebasic.asm:115: error: macho: sorry, cannot apply 32 bit absolute relocations in 64 bit mode, consider "[_symbol wrt rip]" for mem access, "qword" And "dq _foo" for pointers.
I tried with EnableAsm and PB inline (as opposed to !-forced inline) but same problem

(I tried - amongst a thousand other things - l_mylabel but no go, as well as [mylabel] encapsulated in square brackets but obviously that just ended up displaying 01020304 - the data at the address, not the address itself)
Last edited by Keya on Tue Dec 20, 2016 11:07 am, edited 1 time in total.
wilbert
PureBasic Expert
PureBasic Expert
Posts: 3870
Joined: Sun Aug 08, 2004 5:21 am
Location: Netherlands

Re: get address of label: (Mac x64)

Post by wilbert »

You need to use LEA .

Code: Select all

DisableDebugger
Define address.i
! lea rax, [mylabel]
! mov qword [v_address], rax
MessageRequester("Label address", Hex(address))

DataSection
  !mylabel:
  !db 1,2,3,4,5,6,7,8
EndDataSection
Windows (x64)
Raspberry Pi OS (Arm64)
User avatar
Keya
Addict
Addict
Posts: 1891
Joined: Thu Jun 04, 2015 7:10 am

Re: get address of label: (Mac x64)

Post by Keya »

whew! thanks for prompt help and im relieved its a simple solution. Lea is working fine on Win/Linux too so maybe i should start using that more often hehe (its not really part of my toolbelt yet like inc and dec are, lol) - my loss because i've seen there's some cool tricks that can be done with it
Always great to knock these roadblocks over quickly to get back to the real task at hand so many thanks again!
Post Reply