SlideShare ist ein Scribd-Unternehmen logo
1 von 9
Downloaden Sie, um offline zu lesen
Notes on Oracle Solaris 11.3 Linkers
and Libraries Guide: Chapter one
Wen Liao
Oracle is registered trademarks of Oracle and/or its affiliates.
Outlines
● 使用Link-Editor 以及 Runtime Linker
○ Ch 1 ~ 4
● 參考手冊Quick Reference
○ Ch 5
● 進階主題
○ Ch 6 ~ Ch 12
● ELF ABI
○ Ch 13 ~ Ch 15
● 附錄
○ System V Release 4 (Version 1) Mapfiles
Chapter One
● 簡介Link Editors
Link editor 輸出檔案
輸入檔案
Linker editor
Object 1
Object 2
Object n
...
連連看 Object
輸出 Object 分類
● Dynamic executable
○ 由ld.so 載入並執行
● Shared object
○ 和Dynamic executable 最主要的差別是動態在入時才會被指定 Virtual address
○ 因為多個process可以共享shared object,所以產生shared object需要考慮
■ 相容性(版本)
■ 效能
■ 共享的程度
● Position-independent executable (PIE)
○ Shared object 特例,gcc說只能link成exectable,可透過-fPIE 產生
● Relocatable object (*.o)
File1.o (Relocatable object)
程式碼(機械碼):
foo()
{...
有初始值的資料:
int g_var = 0xdeadbeef;
沒有初始值的資料:
int g_var_1;
Main.o (Relocatable object)
程式碼(機械碼):
bar()
{
...
main()
{...
有初始值的資料:
int g_var_m = 0xdeadbeef;
沒有初始值的資料:
int g_var_2;
Linker editor
Main (Dynamic Executable,由
ld.so 載入並執行)
程式碼(機械碼):
foo()
{
...
bar()
{
…
main()
{
...
有初始值的資料:
int g_var = 0xdeadbeef;
int g_var_m = 0xdeadbeef;
沒有初始值的資料:
int g_var_1;
int g_var_2;
Runtime linking
● 透過runtime linker (ld.so) 載入並執行
dynamic executable
● Dynamic executable 可以runtime 載入
shared object(s)
○ 重點: ABI (Application binary interface)
○ 在linker editor產生dynamic executable時會把一些資
訊存入
■ Dependency
處理Shared object 方式
● Compile time
○ Linker editor將相依的shared object紀錄在輸出的結
果(shared object或是 dynamic executable)
● Runtime
○ Runtime linker載入相關shared object以形成Process
環境變數 (man ld.so)
● LD_LIBRARY_PATH
○ Shared object search path
● LD_PRELOAD
○ 最先載入的shared object,可用來trace/hook 函數
● LD_DEBUG
○ 顯示runtime linker行為
● LD_PROFILE
○ Profile shard object行為

Weitere ähnliche Inhalte

Mehr von 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
 
軟體組裝心得分享
軟體組裝心得分享軟體組裝心得分享
軟體組裝心得分享Wen Liao
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command lineWen Liao
 

Mehr von Wen Liao (10)

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
 
從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理從組裝軟體中談談軟體發展管理
從組裝軟體中談談軟體發展管理
 
軟體組裝心得分享
軟體組裝心得分享軟體組裝心得分享
軟體組裝心得分享
 
Introduce to Linux command line
Introduce to Linux command lineIntroduce to Linux command line
Introduce to Linux command line
 

Notes on oracle solaris 11.3 linkers and libraries guide chapter one

  • 1. Notes on Oracle Solaris 11.3 Linkers and Libraries Guide: Chapter one Wen Liao Oracle is registered trademarks of Oracle and/or its affiliates.
  • 2. Outlines ● 使用Link-Editor 以及 Runtime Linker ○ Ch 1 ~ 4 ● 參考手冊Quick Reference ○ Ch 5 ● 進階主題 ○ Ch 6 ~ Ch 12 ● ELF ABI ○ Ch 13 ~ Ch 15 ● 附錄 ○ System V Release 4 (Version 1) Mapfiles
  • 4. Link editor 輸出檔案 輸入檔案 Linker editor Object 1 Object 2 Object n ... 連連看 Object
  • 5. 輸出 Object 分類 ● Dynamic executable ○ 由ld.so 載入並執行 ● Shared object ○ 和Dynamic executable 最主要的差別是動態在入時才會被指定 Virtual address ○ 因為多個process可以共享shared object,所以產生shared object需要考慮 ■ 相容性(版本) ■ 效能 ■ 共享的程度 ● Position-independent executable (PIE) ○ Shared object 特例,gcc說只能link成exectable,可透過-fPIE 產生 ● Relocatable object (*.o)
  • 6. File1.o (Relocatable object) 程式碼(機械碼): foo() {... 有初始值的資料: int g_var = 0xdeadbeef; 沒有初始值的資料: int g_var_1; Main.o (Relocatable object) 程式碼(機械碼): bar() { ... main() {... 有初始值的資料: int g_var_m = 0xdeadbeef; 沒有初始值的資料: int g_var_2; Linker editor Main (Dynamic Executable,由 ld.so 載入並執行) 程式碼(機械碼): foo() { ... bar() { … main() { ... 有初始值的資料: int g_var = 0xdeadbeef; int g_var_m = 0xdeadbeef; 沒有初始值的資料: int g_var_1; int g_var_2;
  • 7. Runtime linking ● 透過runtime linker (ld.so) 載入並執行 dynamic executable ● Dynamic executable 可以runtime 載入 shared object(s) ○ 重點: ABI (Application binary interface) ○ 在linker editor產生dynamic executable時會把一些資 訊存入 ■ Dependency
  • 8. 處理Shared object 方式 ● Compile time ○ Linker editor將相依的shared object紀錄在輸出的結 果(shared object或是 dynamic executable) ● Runtime ○ Runtime linker載入相關shared object以形成Process
  • 9. 環境變數 (man ld.so) ● LD_LIBRARY_PATH ○ Shared object search path ● LD_PRELOAD ○ 最先載入的shared object,可用來trace/hook 函數 ● LD_DEBUG ○ 顯示runtime linker行為 ● LD_PROFILE ○ Profile shard object行為