How to write an absolute target for a near direct relative call/jmp in MASM

谁都会走 提交于 2019-11-28 13:50:22

MASM doesn't support this because the COFF object file format doesn't support the necessary relocation. (Or doesn't correctly support it? According to a NASM error message.)

Using the call 0x76cd75c0 syntax in nasm -f win32 gives an error:

error: Win32 COFF does not correctly support relative references to absolute addresses

I don't know if MASM targeting real mode flat binaries could do it (where there are no object files that have to describe the relocations to the linker), but probably MASM was just designed without syntax for it at all, unfortunately.


See also Error when calling function in user32.dll directly. I did try nasm -fwin32 2.13.02 myself on my Linux desktop and got the same error.


An untested possible workaround might be to create a .obj with a symbol definition for that absolute address, like

org 0deadbeefH
global my_target
my_target:

in NASM or however you do that in MASM.

Then in MASM or MSVC inline-asm you can use jmp my_target and link with that .obj. In theory that might work around the problem of representing relocations in the object file, and get the linker to calculate the relative branch displacement.

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