It is currently Mon Apr 24, 2017 4:19 pm

All times are UTC + 1 hour




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: get address of label: (Mac x64)
PostPosted: Tue Dec 20, 2016 10:59 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
How to get the address of a label in Mac x64?
The following works fine in Win64 and Linux64:
Code:
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:
Quote:
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)

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Last edited by Keya on Tue Dec 20, 2016 11:07 am, edited 1 time in total.

Top
 Profile  
Reply with quote  
 Post subject: Re: get address of label: (Mac x64)
PostPosted: Tue Dec 20, 2016 11:06 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Sun Aug 08, 2004 5:21 am
Posts: 2812
Location: Netherlands
You need to use LEA .
Code:
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

_________________
MacOS 10.12, PB 5.51 x64


Top
 Profile  
Reply with quote  
 Post subject: Re: get address of label: (Mac x64)
PostPosted: Tue Dec 20, 2016 11:11 am 
Offline
Addict
Addict
User avatar

Joined: Thu Jun 04, 2015 7:10 am
Posts: 1673
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!

_________________
Thankyou to all the coders who generously helped & encouraged me in the nearly 2yrs when i was welcome here,
it was a tremendous privilege. I learned a lot. I wish you and your families all the best and success for the future.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye