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

相关文章

文章浏览阅读1.8k次,点赞63次,收藏54次。Linux下的目录权限...
文章浏览阅读1.6k次,点赞44次,收藏38次。关于Qt的安装、Wi...
本文介绍了使用shell脚本编写一个 Hello
文章浏览阅读1.5k次,点赞37次,收藏43次。【Linux】初识Lin...
文章浏览阅读3k次,点赞34次,收藏156次。Linux超详细笔记,...
文章浏览阅读6.8k次,点赞109次,收藏114次。【Linux】 Open...