免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12
最近访问板块 发新帖
楼主: rtcontrol
打印 上一主题 下一主题

[C] 和printf有关的一个小程序 [复制链接]

论坛徽章:
0
11 [报告]
发表于 2011-08-09 18:33 |只看该作者
一些分析,我怀疑是printf传参导致寄存器esi出了问题。

错误信息如下:
root@ubuntu:~/test# gdb ./stack_test
GNU gdb (GDB) 7.2-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.  Type "show copying"
and "show warranty" for details.
This GDB was configured as "i686-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>...
Reading symbols from /root/test/stack_test...(no debugging symbols found)...done.
(gdb) r
Starting program: /root/test/stack_test
hello

Program received signal SIGSEGV, Segmentation fault.
0xb7ff37d5 in allocate_dtv (mem=0x6) at dl-tls.c:310
310        dl-tls.c: No such file or directory.
        in dl-tls.c
(gdb) info registers
eax            0x804b010        134524944
ecx            0x0        0
edx            0x0        0
ebx            0xb7ffeff4        -1207963660
esp            0xbffff3e4        0xbffff3e4
ebp            0xbffff3f8        0xbffff3f8
esi            0x6        6
edi            0xf        15
eip            0xb7ff37d5        0xb7ff37d5 <_dl_allocate_tls+69>
eflags         0x210212        [ AF IF RF ID ]
cs             0x73        115
ss             0x7b        123
ds             0x7b        123
es             0x7b        123
fs             0x0        0
gs             0x33        51




00011790 <_dl_allocate_tls>:
   11790:        55                           push   %ebp
   11791:        89 e5                        mov    %esp,%ebp
   11793:        83 ec 14                     sub    $0x14,%esp
   11796:        89 5d f4                     mov    %ebx,-0xc(%ebp)
   11799:        e8 cd 5e 00 00               call   1766b <calloc+0x20bb>
   1179e:        81 c3 56 b8 00 00            add    $0xb856,%ebx
   117a4:        85 c0                        test   %eax,%eax
   117a6:        89 75 f8                     mov    %esi,-0x8(%ebp)
   117a9:        89 c6                        mov    %eax,%esi
   117ab:        89 7d fc                     mov    %edi,-0x4(%ebp)
   117ae:        74 48                        je     117f8 <_dl_allocate_tls+0x68>
   117b0:        8b 83 34 08 00 00            mov    0x834(%ebx),%eax
   117b6:        c7 44 24 04 08 00 00         movl   $0x8,0x4(%esp)
   117bd:        00
   117be:        8d 78 0e                     lea    0xe(%eax),%edi
   117c1:        83 c0 10                     add    $0x10,%eax
   117c4:        89 04 24                     mov    %eax,(%esp)
   117c7:        e8 20 f0 fe ff               call   7ec <calloc@plt>
   117cc:        85 c0                        test   %eax,%eax
   117ce:        74 20                        je     117f0 <_dl_allocate_tls+0x60>
   117d0:        89 38                        mov    %edi,(%eax)
   117d2:        83 c0 08                     add    $0x8,%eax
   117d5:        89 46 04                     mov    %eax,0x4(%esi)
   117d8:        8b 5d f4                     mov    -0xc(%ebp),%ebx
   117db:        89 f0                        mov    %esi,%eax
   117dd:        8b 7d fc                     mov    -0x4(%ebp),%edi
   117e0:        8b 75 f8                     mov    -0x8(%ebp),%esi

论坛徽章:
0
12 [报告]
发表于 2011-08-09 18:37 |只看该作者
_dl_allocate_tls在/lib/ld-linux.so.2里面

objdump -S /lib/ld-linux.so.2 >/root/ld.txt

可以搜到

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
13 [报告]
发表于 2011-08-09 19:45 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
14 [报告]
发表于 2011-08-09 19:57 |只看该作者
回复  rtcontrol


    哦,我的意思是说,在你调用这个函数的源文件中为什么没写上这个函数的原型,我 ...
pmerofc 发表于 2011-08-09 19:45



加上原型还有错误。解决这类奇怪错误,感觉得加强汇编功底。
  1. #include <stdio.h>

  2. extern void *_dl_allocate_tls(void *mem);

  3. int main(int argc,char *argv[])
  4. {
  5.         printf("hello\n");
  6.         _dl_allocate_tls(NULL);
  7.         return 0;
  8. }
复制代码

论坛徽章:
2
程序设计版块每日发帖之星
日期:2015-06-17 22:20:00每日论坛发贴之星
日期:2015-06-17 22:20:00
15 [报告]
发表于 2011-08-09 21:51 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP