Linux 下的文件
一般来说我们写的代码都是 ASCII text 或者 Unicode Utf-8 的txt
文件
编程语言分为 编译 解释 两种
- java c go
- php python
用到编译的语言
java c 的class 文件 gcc 的 .o .out .so 文件
php 的解释器 php python的 解释器 EXEC 文件
是一种 ELF 文件
ELF 文件
- REL 可重定位文件 .a .o
- EXEC 可执行文件
- 共享目标文件 动态库文件 比如php的拓展 swoole.o event.o socket.o
- core dump 文件 中断后的系统错误文件
ELF 文件的组成
- ELF 文件信息 是以节 Section 或者段 segment 来存储的
ELF 文件组成
- 头 .Header 头信息
- 正文段 .text 代码段 指令段
- 数据段 .data 程序数据
- 初始化段 .bbs 初始化变量
- 只读数据段 .rodata
header头信息
ELF Header:
魔数 7f: DEL (Delete) 45:E 4c:L 46:F 02 :64位操作系统 01 :32 位操作系统
01:小段字节序 01:elf 文件主版本号
* Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
* Class: ELF64
* Data: 2's complement, little endian
* Version: 1 (current)
* OS/ABI: UNIX - System V
* ABI Version: 0
* Type: EXEC (Executable file)
* Machine: Advanced Micro Devices X86-64
* Version: 0x1
* Entry point address: 0x45e027 可执行文件入口地址 虚拟内存地址
* Start of program headers: 64 (bytes into file)
* Start of section headers: 42766224 (bytes into file)
* Flags: 0x0
* Size of this header: 64 (bytes)
* Size of program headers: 56 (bytes)
* Number of program headers: 9
* Size of section headers: 64 (bytes)
* Number of section headers: 39
* Section header string table index: 38
linux 下的一些命令
- objdump -h 查看 elf 文件段
- EXEC 加载一个可执行文件变成一个进程
- strace -f -s 6550 ./demo.i 查看系统底层调用了哪些函数
- size 查看 elf 文件数据大小