微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有以下的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个字节包含标识文件类型,目标平台,版本等所需的标头.读取标头后,代码跳转到此特定类型文件的处理程序.

原文地址:https://www.jb51.cc/linux/397661.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐