Your SlideShare is downloading. ×
  • Like
程式設計師的自我修養 Chapter 3.4
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×

Now you can save presentations on your phone or tablet

Available for both IPhone and Android

Text the download link to your phone

Standard text messaging rates apply

程式設計師的自我修養 Chapter 3.4

  • 1,062 views
Published

 

  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,062
On SlideShare
0
From Embeds
0
Number of Embeds
0

Actions

Shares
Downloads
26
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. 程式設計師的自我修養Chapter 3.4 ELF檔結構描述 Shu-Yu Fu
  • 2. ELF結構
  • 3. 檔頭 常量 值 含义 ET_REL 1 可重定位文件,一般 为.o文件typedef struct { ET_EXEC 2 可执行文件 ET_DYN 3 共享目标文件,一般为.so文件 unsigned char e_ident[16]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; 常量 值 含义 EM_M32 1 AT&T WE 32100 Elf32_Off e_shoff; Magic: 7f 45 4c 46 01 01 01 00 00 00 00 00 00 00SPARC EM_SPARC 2 00 00 Elf32_Word e_flags; ELF32 Class: EM_386 3 Intel x86 Elf32_Half e_ehsize; complement, little endian Data: 2s EM_68K 4 Motorola Version: 1 (current) Elf32_Half e_phentsize;- System V OS/ABI: UNIX 68000 EM_88K 5 Motorola Elf32_Half e_phnum; 0 ABI Version: 88000 Elf32_Half e_shentsize; EM_860 6 Intel 80860 Elf32_Half e_shnum; Elf32_Half e_shstrndx;} Elf32_Ehdr;
  • 4. 段頭表【Section Header Table】● 描述了ELF各個區段的資 訊● 是Elf32_Shdr陣列● 第一個是無效的段述項 【Section Descriptor】● 編譯器、連結器和載入器 都是依靠段頭表來定位和 存取各個區段的屬性● 段頭表在ELF檔案中的位 置由ELF檔頭的e_shoff成 員決定
  • 5. 段頭表【續】 區段名稱是個字串, 它位於一個叫做. shstrtab的字串表。typedef struct { sh_name是區段名稱 Elf32_Word sh_name; 字串在.shstrtab中的 Elf32_Word sh_type; 偏移 Elf32_Word sh_flags; Elf32_Addr sh_addr; Elf32_Off sh_offset; Elf32_Word sh_size; 區段類型和區段旗標 Elf32_Word sh_link; 位元決定區段屬性 Elf32_Word sh_info; 我們接下來會看到 Elf32_Word sh_addralign; SHT_REL和 Elf32_Word sh_entsize; SHT_STRTAB} Elf32_Shdr;
  • 6. 重定表【Relocation Table】● 一個重定表同時也是ELF的一個區段 ○ 它的sh_type為SHT_REL ○ sh_link表示符號表的索引 ○ sh_info表示它作用的區段● 細節可參考4.2.2節【重定表】
  • 7. 字串表● 把ELF檔中用到的字串集中起來存放● 一般常見的區段名稱為.strtab或.shstrtab ○ 字串表【String Table】用來保存普通字串 ○ 段頭字串表【Section Header String Table】用來保存段 頭表中用到的字串● ELF檔頭中的e_shstrndx表示.shstrtab在段頭表 中的索引
  • 8. 作業● 平常我們在程式裡用的const char *是存在那 個section?● 用sh_name去查找在.shstrtab對應的字串