我有以下的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.