SlideShare a Scribd company logo
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

More Related Content

What's hot

HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & ChromiumHKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
Linaro
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
Houcheng Lin
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
Nikhil Jain
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
Jarod Wang
 

What's hot (20)

HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & ChromiumHKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
HKG18-217 - OpenCDM/CDMi (Multi DRM) work with WPE & Chromium
 
TMUX Rocks!
TMUX Rocks!TMUX Rocks!
TMUX Rocks!
 
Understanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panicUnderstanding a kernel oops and a kernel panic
Understanding a kernel oops and a kernel panic
 
[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020[KubeCon NA 2020] containerd: Rootless Containers 2020
[KubeCon NA 2020] containerd: Rootless Containers 2020
 
How To Build Android for ARM Chip boards
How To Build Android for ARM Chip boardsHow To Build Android for ARM Chip boards
How To Build Android for ARM Chip boards
 
Uboot startup sequence
Uboot startup sequenceUboot startup sequence
Uboot startup sequence
 
High availability virtualization with proxmox
High availability virtualization with proxmoxHigh availability virtualization with proxmox
High availability virtualization with proxmox
 
Understanding binder in android
Understanding binder in androidUnderstanding binder in android
Understanding binder in android
 
Slab Allocator in Linux Kernel
Slab Allocator in Linux KernelSlab Allocator in Linux Kernel
Slab Allocator in Linux Kernel
 
Linux kernel modules
Linux kernel modulesLinux kernel modules
Linux kernel modules
 
Linux presentation
Linux presentationLinux presentation
Linux presentation
 
Comparing Next-Generation Container Image Building Tools
 Comparing Next-Generation Container Image Building Tools Comparing Next-Generation Container Image Building Tools
Comparing Next-Generation Container Image Building Tools
 
Linux Kernel Tour
Linux Kernel TourLinux Kernel Tour
Linux Kernel Tour
 
Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0Solaris Kernel Debugging V1.0
Solaris Kernel Debugging V1.0
 
Virtual Machine Constructions for Dummies
Virtual Machine Constructions for DummiesVirtual Machine Constructions for Dummies
Virtual Machine Constructions for Dummies
 
spinlock.pdf
spinlock.pdfspinlock.pdf
spinlock.pdf
 
Luca Ceresoli - Buildroot vs Yocto: Differences for Your Daily Job
Luca Ceresoli - Buildroot vs Yocto: Differences for Your Daily JobLuca Ceresoli - Buildroot vs Yocto: Differences for Your Daily Job
Luca Ceresoli - Buildroot vs Yocto: Differences for Your Daily Job
 
An Overview of [Linux] Kernel Lock Improvements -- Linuxcon NA 2014
An Overview of [Linux] Kernel Lock Improvements -- Linuxcon NA 2014An Overview of [Linux] Kernel Lock Improvements -- Linuxcon NA 2014
An Overview of [Linux] Kernel Lock Improvements -- Linuxcon NA 2014
 
Launch the First Process in Linux System
Launch the First Process in Linux SystemLaunch the First Process in Linux System
Launch the First Process in Linux System
 
Linux Administration
Linux AdministrationLinux Administration
Linux Administration
 

Similar to Hello world 的一生

Cygwin intro
Cygwin introCygwin intro
Cygwin intro
cri fan
 
Cygwin intro
Cygwin introCygwin intro
Cygwin intro
cri fan
 
Clonezilla tutorial.v7
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7
hs1250
 

Similar to Hello world 的一生 (20)

Hcsm lect-20120913
Hcsm lect-20120913Hcsm lect-20120913
Hcsm lect-20120913
 
運用 Docker 整合 Laravel 提升團隊開發效率
運用 Docker 整合 Laravel 提升團隊開發效率運用 Docker 整合 Laravel 提升團隊開發效率
運用 Docker 整合 Laravel 提升團隊開發效率
 
Build Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratchBuild Your Own Android Toolchain from scratch
Build Your Own Android Toolchain from scratch
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command line
 
Ch01
Ch01Ch01
Ch01
 
Continuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CIContinuous Delivery Workshop with Ansible x GitLab CI
Continuous Delivery Workshop with Ansible x GitLab CI
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰
 
Cygwin intro
Cygwin introCygwin intro
Cygwin intro
 
Cygwin intro
Cygwin introCygwin intro
Cygwin intro
 
Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)Continuous Delivery with Ansible x GitLab CI (2e)
Continuous Delivery with Ansible x GitLab CI (2e)
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用
 
2010 08-14 web-sitei18n
2010 08-14 web-sitei18n2010 08-14 web-sitei18n
2010 08-14 web-sitei18n
 
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
Continuous Delivery Workshop with Ansible x GitLab CI (3rd)
 
軟體組裝心得分享
軟體組裝心得分享軟體組裝心得分享
軟體組裝心得分享
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台
 
IoT開發平台NodeMCU
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU
 
Clonezilla tutorial.v7
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShop
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CI
 
Rootkit 101
Rootkit 101Rootkit 101
Rootkit 101
 

More from Wen Liao

GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例
Wen Liao
 
Testing in python 2.7.3
Testing in python 2.7.3Testing in python 2.7.3
Testing in python 2.7.3
Wen Liao
 

More from Wen Liao (16)

Notes on oracle solaris 11.3 linkers and libraries guide chapter one
Notes on oracle solaris 11.3 linkers  and libraries guide  chapter oneNotes on oracle solaris 11.3 linkers  and libraries guide  chapter one
Notes on oracle solaris 11.3 linkers and libraries guide chapter one
 
開放街圖 自助旅行的好幫手
開放街圖   自助旅行的好幫手開放街圖   自助旅行的好幫手
開放街圖 自助旅行的好幫手
 
GNU AS簡介
GNU AS簡介GNU AS簡介
GNU AS簡介
 
UPnP 1.0 簡介
UPnP 1.0 簡介UPnP 1.0 簡介
UPnP 1.0 簡介
 
故事:自由軟體和 Richard Stallman
故事:自由軟體和 Richard Stallman故事:自由軟體和 Richard Stallman
故事:自由軟體和 Richard Stallman
 
Hello world在那邊?背景說明
Hello world在那邊?背景說明Hello world在那邊?背景說明
Hello world在那邊?背景說明
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀
 
GNU ld的linker script簡介
GNU ld的linker script簡介GNU ld的linker script簡介
GNU ld的linker script簡介
 
Trace 程式碼之皮
Trace 程式碼之皮Trace 程式碼之皮
Trace 程式碼之皮
 
淺談Debian套件打包
淺談Debian套件打包淺談Debian套件打包
淺談Debian套件打包
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介
 
A Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard LibraryA Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
A Brief Introduction to Regular Expression with Python 2.7.3 Standard Library
 
GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例
 
Guide to GStreamer Application Development Manual: CH1 to CH10
Guide to GStreamer Application Development Manual: CH1 to CH10Guide to GStreamer Application Development Manual: CH1 to CH10
Guide to GStreamer Application Development Manual: CH1 to CH10
 
Testing in python 2.7.3
Testing in python 2.7.3Testing in python 2.7.3
Testing in python 2.7.3
 
從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理
 

Hello world 的一生