Using RIP-relative addressing in OSX x64 assembly

混江龙づ霸主 提交于 2019-12-05 14:29:55

The problem is that the original mov rdi, msg loaded the memory address of msg into rdi at assemble time.

When it was changed to mov rdi, [rel msg], this produced code which used the value in msg as the relative address, as seen when debugging:

Program received signal EXC_BAD_ACCESS, Could not access memory.
Reason: KERN_INVALID_ADDRESS at address: 0x00000a6f6c6c6568

Notice how the address contains the bytes from msg, 0x00000a<olleh>.

The correct solution is to use the lea instruction to load the effective RIP-relative address of msg at runtime, like so:

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