当前位置: 代码迷 >> 汇编语言 >> gas一个很好玩的容错处理方法,该怎么解决
  详细解决方案

gas一个很好玩的容错处理方法,该怎么解决

热度:4132   发布时间:2013-02-26 00:00:00.0
gas一个很好玩的容错处理方法
.section .data #此处是第一个需要注意的地方
Str_Output:
.asciz "This is a Debug String!!!\n"

.section .text
.globl _start
_start:
nop
call func
pushl $0
call exit

.section .text
.type func, @function
func:
pushl %ebp
movl %esp, %ebp

pushl $Str_Output
call printf #此处是第二个需要注意的地方
addl $4, %esp

movl %ebp, %esp
popl %ebp
ret

在第一个注意点,如果我们把段名修改为.rdata 程序运行到printf 的地方就会出错,但是写成.data就没有问题
我最开始不知道为什么会这样,怎么看都是对的

后来去看编译出来的汇编代码,发现如果str_output是只读的,编译器在压栈的时候会变成 pushl $0,
而只要str_output 是读写的就没有问题,这是为什么呢?好奇怪

------解决方案--------------------------------------------------------
请楼主讲解下.data和.rdata的区别?read-only data?我觉得你可以去看看printf的函数原型,也许就知道答案了。
  相关解决方案