SlideShare a Scribd company logo
1 of 42
Download to read offline
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

Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~
Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~
Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~Yuichi Hasegawa
 
DockerCon EU 2015: Day 1 General Session
DockerCon EU 2015: Day 1 General SessionDockerCon EU 2015: Day 1 General Session
DockerCon EU 2015: Day 1 General SessionDocker, Inc.
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先Kazuho Oku
 
Software engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least onceSoftware engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least onceAlexey (Mr_Mig) Migutsky
 
ランサムウェアのおはなし
ランサムウェアのおはなしランサムウェアのおはなし
ランサムウェアのおはなしShiojiri Ohhara
 
PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報Masahiko Sawada
 
商用DBからPostgreSQLへ まず知っておいて欲しいまとめ
商用DBからPostgreSQLへ まず知っておいて欲しいまとめ商用DBからPostgreSQLへ まず知っておいて欲しいまとめ
商用DBからPostgreSQLへ まず知っておいて欲しいまとめKosuke Kida
 
第2章アーキテクチャ
第2章アーキテクチャ第2章アーキテクチャ
第2章アーキテクチャKenta Hattori
 
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...NTT DATA Technology & Innovation
 
Spring CloudとZipkinを利用した分散トレーシング
Spring CloudとZipkinを利用した分散トレーシングSpring CloudとZipkinを利用した分散トレーシング
Spring CloudとZipkinを利用した分散トレーシングRakuten Group, Inc.
 
GANMA!でDDDをやってみてから1年くらい経った
GANMA!でDDDをやってみてから1年くらい経ったGANMA!でDDDをやってみてから1年くらい経った
GANMA!でDDDをやってみてから1年くらい経ったYasuyuki Sugitani
 
PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選Tomoya Kawanishi
 
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)MicroAd, Inc.(Engineer)
 
NW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてNW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてkawarasho
 
Massive service basic
Massive service basicMassive service basic
Massive service basicDaeMyung Kang
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄SeongHyun Ahn
 
名は体を表していますか
名は体を表していますか名は体を表していますか
名は体を表していますかinfinite_loop
 
#dnstudy 01 ドメイン名の歴史
#dnstudy 01 ドメイン名の歴史#dnstudy 01 ドメイン名の歴史
#dnstudy 01 ドメイン名の歴史Takashi Takizawa
 

What's hot (20)

Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~
Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~
Application Re-Architecture Technology ~ StrutsからSpring MVCへ ~
 
DockerCon EU 2015: Day 1 General Session
DockerCon EU 2015: Day 1 General SessionDockerCon EU 2015: Day 1 General Session
DockerCon EU 2015: Day 1 General Session
 
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
ウェブを速くするためにDeNAがやっていること - HTTP/2と、さらにその先
 
Spring Framework勉強会
Spring  Framework勉強会Spring  Framework勉強会
Spring Framework勉強会
 
Software engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least onceSoftware engineering 101 - The basics you should hear about at least once
Software engineering 101 - The basics you should hear about at least once
 
ランサムウェアのおはなし
ランサムウェアのおはなしランサムウェアのおはなし
ランサムウェアのおはなし
 
PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報PostgreSQL 15 開発最新情報
PostgreSQL 15 開発最新情報
 
商用DBからPostgreSQLへ まず知っておいて欲しいまとめ
商用DBからPostgreSQLへ まず知っておいて欲しいまとめ商用DBからPostgreSQLへ まず知っておいて欲しいまとめ
商用DBからPostgreSQLへ まず知っておいて欲しいまとめ
 
第2章アーキテクチャ
第2章アーキテクチャ第2章アーキテクチャ
第2章アーキテクチャ
 
MySQL Binlog Events でストリーム処理してみた #MySQLUC15
MySQL Binlog Events でストリーム処理してみた #MySQLUC15MySQL Binlog Events でストリーム処理してみた #MySQLUC15
MySQL Binlog Events でストリーム処理してみた #MySQLUC15
 
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
今、改めて考えるPostgreSQLプラットフォーム - マルチクラウドとポータビリティ -(PostgreSQL Conference Japan 20...
 
Spring CloudとZipkinを利用した分散トレーシング
Spring CloudとZipkinを利用した分散トレーシングSpring CloudとZipkinを利用した分散トレーシング
Spring CloudとZipkinを利用した分散トレーシング
 
GANMA!でDDDをやってみてから1年くらい経った
GANMA!でDDDをやってみてから1年くらい経ったGANMA!でDDDをやってみてから1年くらい経った
GANMA!でDDDをやってみてから1年くらい経った
 
PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選PostgreSQL のイケてるテクニック7選
PostgreSQL のイケてるテクニック7選
 
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)
DDD&Scalaで作られたプロダクトはその後どうなったか?(Current state of products made with DDD & Scala)
 
NW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用についてNW遅延環境(Paas)でのPostgreSQLの利用について
NW遅延環境(Paas)でのPostgreSQLの利用について
 
Massive service basic
Massive service basicMassive service basic
Massive service basic
 
파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄파이썬 데이터베이스 연결 2탄
파이썬 데이터베이스 연결 2탄
 
名は体を表していますか
名は体を表していますか名は体を表していますか
名は体を表していますか
 
#dnstudy 01 ドメイン名の歴史
#dnstudy 01 ドメイン名の歴史#dnstudy 01 ドメイン名の歴史
#dnstudy 01 ドメイン名の歴史
 

Similar to Hello world 的一生

Hcsm lect-20120913
Hcsm lect-20120913Hcsm lect-20120913
Hcsm lect-20120913lusecheng
 
運用 Docker 整合 Laravel 提升團隊開發效率
運用 Docker 整合 Laravel 提升團隊開發效率運用 Docker 整合 Laravel 提升團隊開發效率
運用 Docker 整合 Laravel 提升團隊開發效率Bo-Yi Wu
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command lineWen Liao
 
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 CIChu-Siang Lai
 
Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Docker 基礎介紹與實戰
Docker 基礎介紹與實戰Bo-Yi Wu
 
Cygwin intro
Cygwin introCygwin intro
Cygwin introcri fan
 
Cygwin intro
Cygwin introCygwin intro
Cygwin introcri fan
 
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)Chu-Siang Lai
 
容器與 Gitlab CI 應用
容器與 Gitlab CI 應用容器與 Gitlab CI 應用
容器與 Gitlab CI 應用Philip Zheng
 
2010 08-14 web-sitei18n
2010 08-14 web-sitei18n2010 08-14 web-sitei18n
2010 08-14 web-sitei18ntsunghaolee
 
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)Chu-Siang Lai
 
軟體組裝心得分享
軟體組裝心得分享軟體組裝心得分享
軟體組裝心得分享Wen Liao
 
用 Drone 打造 輕量級容器持續交付平台
用 Drone 打造輕量級容器持續交付平台用 Drone 打造輕量級容器持續交付平台
用 Drone 打造 輕量級容器持續交付平台Bo-Yi Wu
 
IoT開發平台NodeMCU
IoT開發平台NodeMCUIoT開發平台NodeMCU
IoT開發平台NodeMCU承翰 蔡
 
Clonezilla tutorial.v7
Clonezilla tutorial.v7Clonezilla tutorial.v7
Clonezilla tutorial.v7hs1250
 
Docker容器微服務 x WorkShop
Docker容器微服務 x WorkShopDocker容器微服務 x WorkShop
Docker容器微服務 x WorkShopPhilip Zheng
 
Jenkins x GitLab CI
Jenkins x GitLab CIJenkins x GitLab CI
Jenkins x GitLab CIYihsuan Chen
 

Similar to Hello world 的一生 (20)

from Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Worksfrom Source to Binary: How GNU Toolchain Works
from Source to Binary: How GNU Toolchain Works
 
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
 

More from Wen Liao

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 oneWen Liao
 
開放街圖 自助旅行的好幫手
開放街圖   自助旅行的好幫手開放街圖   自助旅行的好幫手
開放街圖 自助旅行的好幫手Wen Liao
 
GNU AS簡介
GNU AS簡介GNU AS簡介
GNU AS簡介Wen Liao
 
UPnP 1.0 簡介
UPnP 1.0 簡介UPnP 1.0 簡介
UPnP 1.0 簡介Wen Liao
 
故事:自由軟體和 Richard Stallman
故事:自由軟體和 Richard Stallman故事:自由軟體和 Richard Stallman
故事:自由軟體和 Richard StallmanWen Liao
 
Hello world在那邊?背景說明
Hello world在那邊?背景說明Hello world在那邊?背景說明
Hello world在那邊?背景說明Wen Liao
 
A successful git branching model 導讀
A successful git branching model 導讀A successful git branching model 導讀
A successful git branching model 導讀Wen Liao
 
GNU ld的linker script簡介
GNU ld的linker script簡介GNU ld的linker script簡介
GNU ld的linker script簡介Wen Liao
 
Trace 程式碼之皮
Trace 程式碼之皮Trace 程式碼之皮
Trace 程式碼之皮Wen Liao
 
淺談Debian套件打包
淺談Debian套件打包淺談Debian套件打包
淺談Debian套件打包Wen Liao
 
GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介GNU Make, Autotools, CMake 簡介
GNU Make, Autotools, CMake 簡介Wen Liao
 
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 LibraryWen Liao
 
GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例GNU gettext簡介 - 以C語言為範例
GNU gettext簡介 - 以C語言為範例Wen Liao
 
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 CH10Wen Liao
 
Testing in python 2.7.3
Testing in python 2.7.3Testing in python 2.7.3
Testing in python 2.7.3Wen Liao
 
從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理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 的一生