一)可执行脚本
可执行脚本是内核指向解释程序的一个文本文件,这个文件必须是一个可执行目标文件,如果不可执行,execve会产生错误。
二)可执行目标文件
可执行目标文件主要有三种格式:a。out,COFF,ELF
1)a。out
a。
out是assembler output的缩写格式,代表汇编程序输出。
a。out是早期UNIX系统使用的可执行文件,现在已被ELF文件格式代替,用gcc编译出的a。out也只是一个可执行文件,而不再是文件格式。
用file a。out或od -c a。
out|head或者readelf -h a。out来确认它的文件格式确实是ELF。
2)ECOFF
在MIPS结构下进行编译时,内核也可以识别ECOFF格式,它是一个ELF格式出现之前的COFF(通用对象文件格式)的变体。
同样微软的PE文件格式也是从COFF发展而来的。
3)ELF
ELF文件有三种类型:
可重定位文件:也就是通常称的目标文件,后缀为。o
共享文件:也就是通常称的库文件,后缀为。so
可执行文件:也就是二进制可执行程序,我们所指的ELF文件正是这种类型。
内核通过查找文件中的魔法数来识别目标文件,例如,ELF文件的标签在文件的头4个字节,分别是7F,45,4c,46
也就是大家经常看到177,'E','L','F'。
例如:
readelf -h test
ELF Header:
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:
0x4003e0
Start of program headers:
64 (bytes into file)
Start of section headers:
4304 (bytes into file)
Flags:
0x0
Size of this header:
64 (bytes)
Size of program headers:
56 (bytes)
Number of program headers:
8
Size of section headers:
64 (bytes)
Number of section headers:
37
Section header string table index: 34
但是可重定位文件(。
o文件)的前四个字节也是7F,45,4C,46
例如:
readelf -h test。
o
ELF Header:
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:
REL (Relocatable file)
Machine:
Advanced Micro Devices X86-64
Version:
0x1
Entry point address:
0x0
Start of program headers:
0 (bytes into file)
Start of section headers:
288 (bytes into file)
Flags:
0x0
Size of this header:
64 (bytes)
Size of program headers:
0 (bytes)
Number of program headers:
0
Size of section headers:
64 (bytes)
Number of section headers:
13
Section header string table index: 10。
全部