Relative Addressing errors - Mac 10.10

纵然是瞬间 提交于 2019-11-29 11:22:09

Mach-O 64-bit does not support 32-bit absolute addressing because the image base is greater than 2^32.

Normally you should use RIP relative addressing for accessing a single memory element. In your case however you're accessing a static array (arrays allocated in the data section/bss section) and
as explained in the the section Addressing static arrays in 64 bit mode in Agner Fog's Optimizing Assembly manual.

It is not possible to access static arrays with RIP-relative addressing and an index register.

So when NASM processes your code

mov rax, [data_items+rbx*4]

it can't do RIP relative addressing so it tries to 32-bit absolute + index address which is not allow with Mach-O 64-bit which causes NASM to report the error.

Exampels 3.11b-3.11d In Agner's manual presents three ways to access static arrays. However, since 64-bit OSX does not allow 32bit absolute addressing (though it's possible in Linux) the first example 3.11b is not possible.

Example 3.11c uses the image base reference point __mh_execute_header. I have not looked into this but 3.11d is easy to understand. Use lea to load the RIP+offset into a register like this:

lea rsi, [rel data_items]

And then change your code using mov rax, [data_items+rbx*4] to

mov rax, [rsi+rbx*4]

Since you have delcared DEFAULT REL you should be able to ommit the rel in [rel data_items].

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!