本帖最后由 landker 于 2012-04-28 15:08 编辑 一段简单的汇编代码(nasm),用以下2种方式编译: 1)nasm test.asm -o test.bin 2)nasm test.asm -f elf -o test.o ld -Ttext 0x0 test.o -o test.bin 从结果来看,在有效代码部分是有差别的(已排除elf相关的信息,只根据program header table 里的相关信息找到有效代码)。具体是 2)里的二进制量比1)的稍多,这是为什么?且到底是多了些什么?
elf: Executable and Linking Format 1、elf的三种类型: (1)、一个可重定位(relocatable)文件保存着代码和适当的数据,用来和其他的object文件一起来创建一个可执行文件或者是一个共享文件。 (2)、一个可执行(executable)文件保存着一个用来执行的程序;该文件指出了exec(BA_OS)如何来创建程序进程映象。 (3)、一个共享object文件保存着代码和合适的数据,用来被下面的两个链接器链接。第一个是连接编辑器[请参...
Classification of Sections in Executable Files The elf format allows many sections, which are classified according to type. Exact section names vary by target processor; consult your processor’s application binary interface specification for the section names valid on your processor. (1) A section of type text is read-only and contains executable code. Typically this section is called .text....
elf文件头(elf header ),顾名思义,就是指一个elf文件字节流的最开头的一部分。 它是多大呢?请看下面的小程序: /*打印elf32_Ehdr和elf64_Ehdr结构的大小*/ #include #include int main() { printf("elf32_Ehdr:%d\n",sizeof(elf32_Ehdr)); printf("elf64_Ehdr:%d\n",sizeof(elf64_Ehdr)); return 0; } 编译命令: $ gcc -o test test.c $ ./test elf32_Ehdr:52 elf64_Ehdr:64 $ 程序中包含了elf....
[color="#ff4500"]; 最近研究elf格式,hack了一把。 [color="#ff4500"]; 参考文档: ; 1。 elf_format.pdf http://www.skyfree.org/linux/references/elf_Format.pdf ; 2。A Whirlwind Tutorial on Creating Really Teensy elf Executables for Linux ; http://www.muppetlabs.com/~breadbox/software/tiny/teensy.html [color="#ff4500"]; 各文件: [color="#ff4500"];;; ************************************************** ...
我看到一本书上说elf header位与elf文件的开头,但是program header里的offset值为0,也就是说该段的第一个字节在elf文件中的偏移为0,那么elf header与程序段不是互相覆盖了吗?请问是什么原因?谢谢
本帖最后由 kernel359 于 2013-12-25 21:23 编辑 以下主要是参照《深入理解计算机系统》的理解。 以下是在centos 6.3 x86_64上测试的 主要用到的命令有 readelf、objdump,它们是GNU提供的,我这系统自带的有,所以没安装 一个可执行目标文件,从原代码,要经历预处理器、编译器、汇编器和加载器,才会加载到内存中执行。而目标文件,分为可重定位文件和可执行文件,目标中分成不同的节。 ...