简体   繁体   English

ELF 符号的确切大小是多少(64 位和 32 位)以及如何解析它

[英]What exactly is the size of an ELF symbol (both for 64 & 32 bit) & how do you parse it

According to oracles documentation on the ELF file format a 64 bit elf symbol is 30 bytes in size (8 + 1 + 1 + 4 + 8 + 8), However when i use readelf to print out the sections headers of an elf file, & then inspect the "EntSize" (entry size) member of the symbol table section header, it reads that the symbol entries are in fact only hex 0x18 (dec 24) in size.根据关于 ELF 文件格式的 oracles 文档, 64 位 elf 符号的大小为 30 个字节(8 + 1 + 1 + 4 + 8 + 8),但是当我使用 readelf 打印出 elf 文件的部分标题时,&然后检查符号表部分 header 的“EntSize”(条目大小)成员,它读取符号条目实际上只有十六进制 0x18(dec 24)大小。

I have attached a picture of readelfs output next to the oracle documentation.我在 oracle 文档旁边附上了一张 readelfs output 的图片。 The highlighted characters under "SYMTAB" is the "EntSize" member. “SYMTAB”下突出显示的字符是“EntSize”成员。 在此处输入图像描述

As i am about to write an ELF parser i am curious as to which i should believe?当我即将编写一个 ELF 解析器时,我很好奇我应该相信哪个? the read value of the EntSize member or the documentation? EntSize 成员或文档的读取值?

I have also attempted to look for an answer in this ELF documentation however it doesn't seem to go into any detail of the 64 bit ELF structures.我也试图在这个ELF 文档中寻找答案,但是 go 似乎没有进入 64 位 ELF 结构的任何细节。

It should be noted that the ELF file i run readelf on, in the above picture, is a 64bit executable需要注意的是,我在上面运行readelf的ELF文件,在上图中,是一个64位的可执行文件

EICLASS, the byte just after the ELF magic number, contains the "class" of the ELF file, with the value "2" (in hex of course) meaning a 64 bit class. EICLASS,ELF 幻数之后的字节,包含 ELF 文件的“类”,值“2”(当然是十六进制)表示 64 位 class。

When the 32 bit standard was drafted there were competing popular 64 bit architectures.在起草 32 位标准时,存在竞争的流行 64 位架构。 The 32 bit standard was a bit vague about the 64 bit standard as it was quite possible at that time to imagine multiple competing 64 bit standards 32 位标准对 64 位标准有点模糊,因为当时很可能想象多个相互竞争的 64 位标准

https://www.uclibc.org/docs/elf-64-gen.pdf https://www.uclibc.org/docs/elf-64-gen.pdf

should cover the 64 bit standard with better attention to the 64 bit layouts.应该涵盖 64 位标准,并更好地关注 64 位布局。

The way you "parse" it is to read the bytes in the order described in the struct.您“解析”它的方式是按照结构中描述的顺序读取字节。

typedef struct { Elf64_Word st_name; typedef struct { Elf64_Word st_name; unsigned char st_info;无符号字符 st_info; unsigned char st_other;无符号字符 st_other; Elf64_Half st_shndx; Elf64_Half st_shndx; Elf64_Addr st_value; Elf64_Addr st_value; Elf64_Xword st_size; Elf64_Xword st_size; } Elf64_Sym; } Elf64_Sym;

The first 8 bytes are a st_name, the next byte is a st_info, and so on.前 8 个字节是 st_name,下一个字节是 st_info,依此类推。 Of course, it is critical to know where the struct "starts" within the file, and the spec above should help with that.当然,了解结构在文件中“开始”的位置至关重要,上面的规范应该对此有所帮助。

"64" in this case means a "64 bit entry", byte means an 8 bit entry, and so on.在这种情况下,“64”表示“64 位条目”,字节表示 8 位条目,依此类推。

the Elf64_Sym has 8+1+1+8+8+8 bytes in it, or 34 bytes. Elf64_Sym 中有 8+1+1+8+8+8 字节,即 34 字节。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何确定我要安装的应用程序是32位还是64位? - How do I determine whether an application I am installing is 32-bit or 64-bit? 如何将64位和32位可执行文件绑定到一个? - How to bind 64-bit and 32-bit executable into one? 收到错误:bash:(程序):无法执行二进制文件:执行格式错误,在 32 位和 64 位 Windows - Getting the error: bash: (program): cannot execute binary file: Exec format error, on both 32-bit and 64-bit Windows 64位与32位可执行文件 - 64 bit Vs 32 bit Executables 如何知道您构建的iOS App是否适用于64位。 - How to know if the iOS App you build is for 64 bit. 是否有一个工具可以将32位+ 64位应用程序组合在一起并将它们打包在一个32 + 64位应用程序中 - Is there a tool that will combine a 32 bit + 64 bit application and pack them together in one 32+64 bit application Qt 64位可以生成32位可执行文件吗? - Can Qt 64 bit generate 32 bit executable? 在python中将工具从32bit转换为64bit - convert a tool from 32bit to 64bit in python 在64位操作系统上以32位运行AnyCPU应用程序 - Running an AnyCPU application as 32-bit on a 64-bit OS 找到32位ELF Linux二进制文件的结尾,并开始填充? - Find where 32-bit ELF Linux binary ends, and padding begins?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM