加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 为什么strace打开,读取512字节,然后是fstat libncurses

发布时间:2020-12-14 03:06:44 所属栏目:Linux 来源:网络整理
导读:我有以下的strace输出,我正在通过自学,更多地了解程序的流程.这是令我困惑的部分: 16:08:02 open("/lib/libncurses.so.5",O_RDONLY) = 3 0.00004616:08:02 read(3,"x7f"...,512) = 512 0.00004816:08:02 fstat64(3,{st_dev=makedev(202,0),st_ino=16548,s
我有以下的strace输出,我正在通过自学,更多地了解程序的流程.这是令我困惑的部分:
16:08:02 open("/lib/libncurses.so.5",O_RDONLY) = 3 <0.000046>
16:08:02 read(3,"x7f"...,512) = 512 <0.000048>
16:08:02 fstat64(3,{st_dev=makedev(202,0),st_ino=16548,st_mode=S_IFREG|0644,st_nlink=1,st_uid=0,st_gid=0,st_blksize=4096,st_blocks=464,st_size=231576,st_atime=2011/02/06-15:37:43,st_mtime=2011/01/04-06:05:23,st_ctime=2011/02/06-15:37:43}) = 0 <0.000038>

通过读取前512个字节获得了什么?看起来这种模式在共享库中很常见.

更新:我刚刚得到一个great answer,它澄清了512字节的长度.具体来自elf / dl-load.c中的注释:

The ELF header 32-bit files is 52 bytes long and in 64-bit files is 64 bytes long. Each program header entry is again 32 and 56 bytes long respectively. I.e.,even with a file which has 10 program header entries we only have to read 372B/624B respectively. Add to this a bit of margin for program notes and reading 512B and 832B for 32-bit and 64-bit files respecitvely is enough.

解决方法

前512个字节包含标识文件类型,目标平台,版本等所需的标头.读取标头后,代码将跳转到此特定类型文件的处理程序.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读