免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1819 | 回复: 1
打印 上一主题 下一主题

[其他] 关于x86_64位系统下的long jump [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2012-11-11 11:23 |只看该作者 |倒序浏览
我自己写了一段汇编程序,其实有一个远跳(long jump),原本在32位模式下面运行的,但是后来转到64位上面编译能通过,但是运行的时候有错误产生。程序如下:
jmp 8:jmp_ok
这段在32位上运行没有问题,但是在64位上运行就有问题了。我是用nasm编译的,后面加了-f elf64,但后来通过反汇编来看这一段就是(bad),不知道哪位大虾能够帮帮忙,或者能够提供一点Linux内核处理这方面问题的线索也行。

论坛徽章:
1
处女座
日期:2013-08-19 12:39:10
2 [报告]
发表于 2012-11-11 21:42 |只看该作者
There is no jump of the form JMP absaddr to an absolute address in 64 bit mode. The operand of a jump is always a 32 bit relative displacement to rip, which gets sign extended to 64 bit.

The reason you see no consistency is possibly that the offset depends on the the current instruction pointer and you didn't recognize that.

jmp eax isn't allowed either, as addresses are of course always 64 bit wide on a 64 bit architecture. A sequence mov rax, addr + jmp rax is possible, it would look like

48 c7 c0 35 08 40 00            mov rax, 0x00400835
ff e0                           jmp rax
or

48 b8 35 08 40 00 00 00 00 00   mov rax, 0x0000000000400835
ff e0                           jmp rax
How did I know these hex codes? Well, I did ask my compiler. I compiled with gcc -c and disassembled with objdump. I didn't bother to use Intel syntax, because I don't need it. So this is in AT&T syntax.

echo 'asm("mov $400835, %rax\n jmp *%rax\n");' > test.c
gcc -c test.c
objdump -d test.o
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP