Hello world 的一生

Wen Liao
Hello World 的一生
Wen Liao
Taiwan Linux Kernel Hackers
1
About Wen
/41
● 測試環境
● 懷胎九月及出生
● 短暫的一生
● QA
目錄
3
測試環境 (1)
4
測試環境 (2)
5
● 測試環境
● 懷胎九月及出生
● 短暫的一生
● QA
目錄
6
cc 就搞定
7
事情當然沒有我們憨人
想的那麼簡單
8
● 現實是,除了執行檔以外,在編
譯的過程的副產品
○ hello.i // 展開巨集後的C 語言
○ hello.s // 將C語言轉成組合語言
○ hello.o // 將組合語言轉成ELF格式的object file
GCC = GNU Compiler Collection
9
hello.i 節錄
八百行
stdio.h
10
hello.s 節錄 (1)
11
hello.s 節錄 (2)
12
hello.s 節錄 (2)
13
hello.s 節錄 (1)
14
hello.s 節錄 (2)
https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf
15
hello.s 節錄 (2)
https://software.intel.com/sites/default/files/article/402129/mpx-linux64-abi.pdf
16
囉唆的真實編譯 (1)
17
囉唆的真實編譯 (2)
18
囉唆的真實編譯 (3)
ld 節錄 (1)
19
囉唆的真實編譯 (3)
ld 節錄 (2)
20
Link時除了你的object外,還有
21
/usr/lib/x86_64-linux-gnu/Scrt1.o
/usr/lib/x86_64-linux-gnu/crti.o
/usr/lib/gcc/x86_64-linux-gnu/7/crtbeginS.o
/lib64/ld-linux-x86-64.so.2
/usr/lib/gcc/x86_64-linux-gnu/7/crtendS.o
/usr/lib/x86_64-linux-gnu/crtn.o
...
除了你的object外,還有
22
Why?
23
反組譯
參數
呼叫函數 24
__libc_start_main (1)
25
__libc_start_main (2)
26
● 檢查權限,確保安全性
● thread subsystem初始化 (我可不知道什麼thread subsystem唷)
● 向rtld_fini註冊release callback function,當shared object結束時使用該
callback釋放資源
● 呼叫init callback function
● 呼叫main callback function並且帶入參數
● 當main callback function結束後,將回傳值作為參數呼叫exit
__libc_start_main (3)
27
● 測試環境
● 懷胎九月及出生
● 短暫的一生
● QA
目錄
28
linux/fs/exec.c
29
do_execve()
30
register_binfmt()
31
binfmt 資料結構
32
linux/fs/binfmt_elf.c
33
linux/fs/exec.c
/41
load_elf_binary
35
struct linux_binprm 省略版
36
struct linux_binprm
buf[128]
struct vm_area_struct *vma;
unsigned long vma_pages
struct mm_struct *mm
struct file * file
int argc, envc
const char * filename
const char * interp
unsigned long loader, exec
struct cred *cred
... 37
load_elf_binary()
38
load_elf_binary()
39
● Load_elf_binary Trace
○ http://wen00072.github.io/blog/2019/08/03/load-elf-binary-trace/
Load_elf_binary Trace
40
● Sections
○ text
○ bss
○ data
○ …
● ABI
● Link script
● ELF
● Binutils
● vDSO
● ASLR
● man proc
延伸關鍵字
41
Q & A
/41
1 of 42

More Related Content

What's hot(20)

OPTEE on QEMU - Build TutorialOPTEE on QEMU - Build Tutorial
OPTEE on QEMU - Build Tutorial
Dalton Valadares1.4K views
Linux IOLinux IO
Linux IO
Liran Ben Haim2.6K views
Basic Linux InternalsBasic Linux Internals
Basic Linux Internals
mukul bhardwaj41.3K views
Audio DriversAudio Drivers
Audio Drivers
Anil Kumar Pugalia20.8K views
Inside Android's UIInside Android's UI
Inside Android's UI
Opersys inc.7.6K views
Android InternalsAndroid Internals
Android Internals
Opersys inc.14.1K views
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
Emertxe Information Technologies Pvt Ltd3K views
BootloadersBootloaders
Bootloaders
Anil Kumar Pugalia10K views
Secure boot generalSecure boot general
Secure boot general
Prabhu Swamy361 views
U boot porting guide for SoCU boot porting guide for SoC
U boot porting guide for SoC
Macpaul Lin11.9K views
OpenWrt From Top to BottomOpenWrt From Top to Bottom
OpenWrt From Top to Bottom
Kernel TLV4.3K views
Video DriversVideo Drivers
Video Drivers
Anil Kumar Pugalia23.4K views
Interview preparation workshopInterview preparation workshop
Interview preparation workshop
Emertxe Information Technologies Pvt Ltd2.6K views

Similar to Hello world 的一生(20)

from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
National Cheng Kung University13.5K views
Hcsm lect-20120913Hcsm lect-20120913
Hcsm lect-20120913
lusecheng5.3K views
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
National Cheng Kung University4.1K views
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command line
Wen Liao16.6K views
Ch01Ch01
Ch01
jashliao3.4K views
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
Bo-Yi Wu15.8K views
Cygwin introCygwin intro
Cygwin intro
cri fan947 views
Cygwin introCygwin intro
Cygwin intro
cri fan546 views
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
Philip Zheng2.8K views
2010 08-14 web-sitei18n2010 08-14 web-sitei18n
2010 08-14 web-sitei18n
tsunghaolee1.9K views
軟體組裝心得分享軟體組裝心得分享
軟體組裝心得分享
Wen Liao9.5K views
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU
承翰 蔡1.4K views
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7
hs12502.1K views
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShop
Philip Zheng1.2K views
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CI
Yihsuan Chen85 views

Hello world 的一生