SlideShare una empresa de Scribd logo
1 de 33
1
Linker and Loader
2
Agenda
• What is Linker and Loader
• ELF Format
• Static Linker vs Dynamic Linker
• Run An Executable File
• Backup
3
What is Linker and Loader
A programming tool which
combines one or more
partial Object Files and libraries
into a (more) complete
executable object file.
4
Compile Process
5
ELF – Three Types
6
ELF – Format
7
ELF – Two Views
8
ELF – Two Views
9
ELF - Sections
10
• Allocator Space
• Resolve symbols
• Relocation symbols
• Create sections
Static Linker
Using ld in binutils
Printf.o
Strlen.o
Rand.o
foo.o
foo2.o
foo3.o
Static
Linker
Main.o
Main.o
Printf.o
Foo.o
Test executable
file
Run
process
Main.o
Printf.o
Foo.o
Test executable
file
11
Static Linker - Allocator Space
12
Static Linker – Resolve symbols
Scans input relocatable files from left to right as
on command line
• Maintains Set E of object files req to form
executable.
Set U of unresolved symbols
Set D of symbols defined in prev files.
• Update E,U and D while scanning input
relocatable files
• U must be empty at the end – contents of E used
to form executable
13
Static Linker - Relocation
A process of assigning
load addresses to
various parts of a
program and adjusting
the code and data in the
program to reflect the
assigned addresses
14
Static Linker – Relocation
.rel .text .symtab .strtab
Find and iterate .rel sections.
Every entry includes of
Typedef struct {
Elf32_Addr r_offset;
Elf32_Word r_info;
} Elf32_Rel
Find the address in .text
section by r_offset
Find the symbol index
in .symbol section by
r_info
Find the symbol type by
r_info
Got information about
the responding symbol
in .symbol sectioin
Compute the latest
address by symbol type
1
2
3
4
5
6
15
Static Linker – Linker script
Be passed to GNU ld to exercise greater control over the
linking process
16
ld –static crt1.o crti.o crtbeginT.o XXX.o –start-
group –lgcc –lgcc_eh –lc-end-group crtend.o crtn.o
Static Linker –Init/Finit Sections
Object Definition Owner Runtime
Crt1.o _start Glibc C、C++
Crti.o .init and .finit section Glibc C
Crtn.o .init and .finit section Glibc C
crtbeginT.o .init_array and .finit_array
section
Gcc C++
Crtend.o .init_array and .finit_array
section
Gcc C++
17
Static Linker –Init/Finit Sections
Crti.o
.init
.finit
a.o
.init
.finit
b.o
.init
.finit
Crtn.o
.init
.finit
A.out
.init
.finit
Linker
Contain the code
of beginning for
init function
Contain the code
of beginning for
finit function
Contain the code
of end for init
function
Contain code of to
init global variable
Contain code of to
de-init global
variable
Contain the code
of end for finit
function
Init function
FInit function
18
Static Linker –Init_array/Finit_array Sections
CRTBeginT.o
.init_array
.finit_array
a.o
.init_array
.finit_array
b.o(b.cpp)
.init_array
.finit_array
CrtEnd.o
.init_array
.finit_array
A.out
.init_array
.finit_array
Linker
Contain the code
of beginning for
init_array function
Contain the code
of beginning for
finit_array
function
Contain the code
of end for
init_array function
Contain pointer to
point global
constructor
Contain the code
of end for
finit_array
function
Pointer table
.text
Global constructor
Global de-
constructor
Contain pointer to
point global de-
constructor
pointer1
pointer2
pointer3
Number
Collect all pointers
who point global
constructor into
an array
19
Dynamic Linker
Printf.o
Strlen.o
Rand.o
Libc.so
foo.o
foo2.o
foo3.o
Libtest.so
Dynamic
Linker
Main.o
Main.o
Require
so
Test executable
file
Main.o
Require
so
Test executable file
Printf.o
Strlen.o
Rand.o
Libc.so
foo.o
foo2.o
foo3.o
Libtest.so
Run
process
20
Dynamic Linker - PIC
Position-independent
code (PIC) or position-
independent executable
(PIE) is a body of machine
code that, being placed
somewhere in the primary
memory,
Compile option: -fpic
Code section can be un-
modified when load into
memory so that it can be
shared in different process
21
Dynamic Linker - PLT
Stands for Procedure Linkage Table which is, put
simply, used to call external procedures/functions
whose address isn't known in the time of linking, and
is left to be resolved by the dynamic linker at run
time.
First Call Second Call
22
Dynamic Linker - PIE
Compile option: -fpie
23
• Implicit
Referred to as static load or load-time dynamic
linking.
• Explicit
Referred to as dynamic load or run-time
dynamic linking.
 Dlopen
 Dlsym
 Dlclose
Dynamic Linker – Two Mode
24
Dynamic Linker vs Static Linker
Dynamic Static
Memory usage Small Bigger
Storage usage Small Bigger
Performance Low (But with PLT, 5%
down)
Update easy Hard
Compatibility Hard No
25
• Implicit
Prelink
26
Run Executable File – Static Linker
• Fork
• Exec
• Kernel load executable file
• Run from the start entry of
executable
Run a executable file
Load and Map
executable file
(load_elf_bina
ry)
Do_execve
system call
Kernel
Read header of
executable file
Read other
headers of
executable file
NO
User space
__libc_init
Do_execve system call
finished
Return address is set to
entry of executable file
Fork process
New Process
If .interp is existing, read
the
ld.so(system/bin/linker)
Run the
executable file
from entry
point(_start)
main
exit
Running and quit
Init main
thread
Init globals
system_pro
perties_init
Call
preinit_arra
y and
init_array
Set
__cxa_atexi
t
27
Run Executable File – Dynamic Linker
• Fork
• Exec
• Kernel load executable file
• Kernel load ld.so
• Ld.so load the dependent so
• Relocation
• Run from the start entry of
executable
Run a executable file
who relies on other so
Load and Map
executable file
(load_elf_bina
ry)
Do_execve
system call
Kernel
Read header of
exe file
Got the path for
linker and map
it to get entry
point
Yes
User space
main
Return address is set to
entry of linker
Fork process
New Process
If .interp is existing, read the
ld.so(system/bin/linker)
Run the
executable file
from entry
point(_start)
exit
Running and quit
Do_execve system call
finished
_start ->
__linker_init t
Init main
thread
Init globals
call_constr
uctors(DT_I
NIT
DT_INIT_AR
RAY)
__libc_pr
einit
__libc_ini
t
prelink_ima
ge and
link_image
for linker
__linker_init_po
st_relocation
debuggerd
_init
Init globals
init_default
_namespac
e
__system_
properties_
init
Load
needed .So
one by one
28
Process Memory Map
29
Backup
30
• Gcc drivers the compile process.
• Glibc provide runtime/libc/libm/libthread …
• Binutils provides as/ar/ld
Relation Between Gcc, Glibc and Binutils
31
• GPL License
• 400K
• BinUtils
• Gcc
• Glibc
• Multi-thread
• LD(BinUtils)
• Loader
• System Call
Glibc vs Android Bionic
• APACHE License
• 200 K
• Ld
• Linker
• pThread
• System Call
32
• Linker
Ld under Linux
• Loader
/system/bin/linker
Linker and Loader in Android
33
Android Java loader
System.loadlibrary
Runtime.loadlibrary
Runtime.doLoad
JVM_NativeLoad
LoadNativeLibrary
dlopen
nativeLoad

Más contenido relacionado

La actualidad más candente

A hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file formatA hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file formatrety61
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about CYi-Hsiu Hsu
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)RuggedBoardGroup
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniqueAngel Boy
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewLinaro
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsAhmed El-Arabawy
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeAngel Boy
 

La actualidad más candente (20)

Linux Programming
Linux ProgrammingLinux Programming
Linux Programming
 
Shell scripting
Shell scriptingShell scripting
Shell scripting
 
Linkers in compiler
Linkers in compilerLinkers in compiler
Linkers in compiler
 
A hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file formatA hands-on introduction to the ELF Object file format
A hands-on introduction to the ELF Object file format
 
Logging system of Android
Logging system of AndroidLogging system of Android
Logging system of Android
 
Linux basic commands
Linux basic commandsLinux basic commands
Linux basic commands
 
Understand more about C
Understand more about CUnderstand more about C
Understand more about C
 
loaders and linkers
 loaders and linkers loaders and linkers
loaders and linkers
 
Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)Embedded Linux BSP Training (Intro)
Embedded Linux BSP Training (Intro)
 
Kernel module in linux os.
Kernel module in linux os.Kernel module in linux os.
Kernel module in linux os.
 
Play with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit TechniquePlay with FILE Structure - Yet Another Binary Exploit Technique
Play with FILE Structure - Yet Another Binary Exploit Technique
 
HKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting ReviewHKG15-311: OP-TEE for Beginners and Porting Review
HKG15-311: OP-TEE for Beginners and Porting Review
 
Qemu Introduction
Qemu IntroductionQemu Introduction
Qemu Introduction
 
Course 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild CardsCourse 102: Lecture 4: Using Wild Cards
Course 102: Lecture 4: Using Wild Cards
 
Linux Internals - Part II
Linux Internals - Part IILinux Internals - Part II
Linux Internals - Part II
 
Linux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledgeLinux binary Exploitation - Basic knowledge
Linux binary Exploitation - Basic knowledge
 
Assembler
AssemblerAssembler
Assembler
 
Linux crontab
Linux crontabLinux crontab
Linux crontab
 
Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0Linux Internals - Interview essentials 4.0
Linux Internals - Interview essentials 4.0
 
Linux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell ScriptingLinux systems - Linux Commands and Shell Scripting
Linux systems - Linux Commands and Shell Scripting
 

Destacado

LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723Iftach Ian Amit
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friendAlexandre Moneger
 
Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)Varun Mahajan
 
Linker namespace upload
Linker namespace   uploadLinker namespace   upload
Linker namespace uploadBin Yang
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHackito Ergo Sum
 
Symbolic Debugging with DWARF
Symbolic Debugging with DWARFSymbolic Debugging with DWARF
Symbolic Debugging with DWARFSamy Bahra
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADDharmalingam Ganesan
 
DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data RepresentationWang Hsiangkai
 
Reversing & malware analysis training part 1 lab setup guide
Reversing & malware analysis training part 1   lab setup guideReversing & malware analysis training part 1   lab setup guide
Reversing & malware analysis training part 1 lab setup guidesecurityxploded
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and ExecutionChong-Kuan Chen
 
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)Ahmed El-Arabawy
 

Destacado (20)

Ch 4 linker loader
Ch 4 linker loaderCh 4 linker loader
Ch 4 linker loader
 
LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723
 
06 - ELF format, knowing your friend
06 - ELF format, knowing your friend06 - ELF format, knowing your friend
06 - ELF format, knowing your friend
 
Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)Program Structure in GNU/Linux (ELF Format)
Program Structure in GNU/Linux (ELF Format)
 
Linkers And Loaders
Linkers And LoadersLinkers And Loaders
Linkers And Loaders
 
Linkers
LinkersLinkers
Linkers
 
Loaders
LoadersLoaders
Loaders
 
Linker namespace upload
Linker namespace   uploadLinker namespace   upload
Linker namespace upload
 
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARFHES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
HES2011 - James Oakley and Sergey bratus-Exploiting-the-Hard-Working-DWARF
 
ELF 101
ELF 101ELF 101
ELF 101
 
Intro reverse engineering
Intro reverse engineeringIntro reverse engineering
Intro reverse engineering
 
Symbolic Debugging with DWARF
Symbolic Debugging with DWARFSymbolic Debugging with DWARF
Symbolic Debugging with DWARF
 
Load-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOADLoad-time Hacking using LD_PRELOAD
Load-time Hacking using LD_PRELOAD
 
DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data Representation
 
The Internals of "Hello World" Program
The Internals of "Hello World" ProgramThe Internals of "Hello World" Program
The Internals of "Hello World" Program
 
Reversing & malware analysis training part 1 lab setup guide
Reversing & malware analysis training part 1   lab setup guideReversing & malware analysis training part 1   lab setup guide
Reversing & malware analysis training part 1 lab setup guide
 
Loader
LoaderLoader
Loader
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Sp chap2
Sp chap2Sp chap2
Sp chap2
 
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
Embedded Systems: Lecture 14: Introduction to GNU Toolchain (Binary Utilities)
 

Similar a Linker and loader upload

bh-europe-01-clowes
bh-europe-01-clowesbh-europe-01-clowes
bh-europe-01-clowesguest3e5046
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Ahmed El-Arabawy
 
Build process ppt.pptx
Build process ppt.pptxBuild process ppt.pptx
Build process ppt.pptxSHIVANISRECECE
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerGonçalo Gomes
 
An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization Vivek Pandya
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device DriverGary Yeh
 
Os7 2
Os7 2Os7 2
Os7 2issbp
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotoolsThierry Gayet
 
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...Linaro
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual DevelopGourav Kumar
 
Fl0ppy - CODEGATE 2016 CTF Preliminary
Fl0ppy - CODEGATE 2016 CTF PreliminaryFl0ppy - CODEGATE 2016 CTF Preliminary
Fl0ppy - CODEGATE 2016 CTF PreliminaryYOKARO-MON
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain艾鍗科技
 
Linux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsLinux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsQUONTRASOLUTIONS
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developersDmitry Guyvoronsky
 

Similar a Linker and loader upload (20)

bh-europe-01-clowes
bh-europe-01-clowesbh-europe-01-clowes
bh-europe-01-clowes
 
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
Embedded Systems: Lecture 13: Introduction to GNU Toolchain (Build Tools)
 
Build process ppt.pptx
Build process ppt.pptxBuild process ppt.pptx
Build process ppt.pptx
 
wk 4 -- linking.ppt
wk 4 -- linking.pptwk 4 -- linking.ppt
wk 4 -- linking.ppt
 
Whirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic LinkerWhirlwind tour of the Runtime Dynamic Linker
Whirlwind tour of the Runtime Dynamic Linker
 
An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization An Overview of LLVM Link Time Optimization
An Overview of LLVM Link Time Optimization
 
Intro To C++ - Class #21: Files
Intro To C++ - Class #21: FilesIntro To C++ - Class #21: Files
Intro To C++ - Class #21: Files
 
Linux Char Device Driver
Linux Char Device DriverLinux Char Device Driver
Linux Char Device Driver
 
Os7 2
Os7 2Os7 2
Os7 2
 
Introduction to c part 4
Introduction to c  part  4Introduction to c  part  4
Introduction to c part 4
 
GCC LTO
GCC LTOGCC LTO
GCC LTO
 
From gcc to the autotools
From gcc to the autotoolsFrom gcc to the autotools
From gcc to the autotools
 
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...
SFO15-406: ARM FDPIC toolset, kernel & libraries for Cortex-M & Cortex-R mmul...
 
Build process in ST Visual Develop
Build process in ST Visual DevelopBuild process in ST Visual Develop
Build process in ST Visual Develop
 
Fl0ppy - CODEGATE 2016 CTF Preliminary
Fl0ppy - CODEGATE 2016 CTF PreliminaryFl0ppy - CODEGATE 2016 CTF Preliminary
Fl0ppy - CODEGATE 2016 CTF Preliminary
 
Git uptospeed
Git uptospeedGit uptospeed
Git uptospeed
 
嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain嵌入式Linux課程-GNU Toolchain
嵌入式Linux課程-GNU Toolchain
 
assem.ppt
assem.pptassem.ppt
assem.ppt
 
Linux operating system by Quontra Solutions
Linux operating system by Quontra SolutionsLinux operating system by Quontra Solutions
Linux operating system by Quontra Solutions
 
Introduction to Git for developers
Introduction to Git for developersIntroduction to Git for developers
Introduction to Git for developers
 

Más de Bin Yang

Introduction of android treble
Introduction of android trebleIntroduction of android treble
Introduction of android trebleBin Yang
 
Introduction of Android Architecture
Introduction of Android ArchitectureIntroduction of Android Architecture
Introduction of Android ArchitectureBin Yang
 
New features in android m upload
New features in android m   uploadNew features in android m   upload
New features in android m uploadBin Yang
 
Android ressource and overlay upload
Android ressource and overlay   uploadAndroid ressource and overlay   upload
Android ressource and overlay uploadBin Yang
 
Android secuirty permission - upload
Android secuirty   permission - uploadAndroid secuirty   permission - upload
Android secuirty permission - uploadBin Yang
 
Update from android kk to android l
Update from android kk to android lUpdate from android kk to android l
Update from android kk to android lBin Yang
 
Google IO 2014 overview
Google IO 2014 overviewGoogle IO 2014 overview
Google IO 2014 overviewBin Yang
 

Más de Bin Yang (7)

Introduction of android treble
Introduction of android trebleIntroduction of android treble
Introduction of android treble
 
Introduction of Android Architecture
Introduction of Android ArchitectureIntroduction of Android Architecture
Introduction of Android Architecture
 
New features in android m upload
New features in android m   uploadNew features in android m   upload
New features in android m upload
 
Android ressource and overlay upload
Android ressource and overlay   uploadAndroid ressource and overlay   upload
Android ressource and overlay upload
 
Android secuirty permission - upload
Android secuirty   permission - uploadAndroid secuirty   permission - upload
Android secuirty permission - upload
 
Update from android kk to android l
Update from android kk to android lUpdate from android kk to android l
Update from android kk to android l
 
Google IO 2014 overview
Google IO 2014 overviewGoogle IO 2014 overview
Google IO 2014 overview
 

Último

The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...ranjana rawat
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performancesivaprakash250
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSrknatarajan
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...roncy bisnoi
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...Call Girls in Nagpur High Profile
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdfSuman Jyoti
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)simmis5
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...Call Girls in Nagpur High Profile
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTbhaskargani46
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfJiananWang21
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringmulugeta48
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLManishPatel169454
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdfankushspencer015
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Call Girls in Nagpur High Profile
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdfKamal Acharya
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingrknatarajan
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spaintimesproduction05
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlysanyuktamishra911
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduitsrknatarajan
 

Último (20)

Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024Water Industry Process Automation & Control Monthly - April 2024
Water Industry Process Automation & Control Monthly - April 2024
 
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
The Most Attractive Pune Call Girls Budhwar Peth 8250192130 Will You Miss Thi...
 
UNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its PerformanceUNIT - IV - Air Compressors and its Performance
UNIT - IV - Air Compressors and its Performance
 
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICSUNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
UNIT-IFLUID PROPERTIES & FLOW CHARACTERISTICS
 
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
Call Girls Pimpri Chinchwad Call Me 7737669865 Budget Friendly No Advance Boo...
 
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...Booking open Available Pune Call Girls Pargaon  6297143586 Call Hot Indian Gi...
Booking open Available Pune Call Girls Pargaon 6297143586 Call Hot Indian Gi...
 
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank  Design by Working Stress - IS Method.pdfIntze Overhead Water Tank  Design by Working Stress - IS Method.pdf
Intze Overhead Water Tank Design by Working Stress - IS Method.pdf
 
Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)Java Programming :Event Handling(Types of Events)
Java Programming :Event Handling(Types of Events)
 
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...Booking open Available Pune Call Girls Koregaon Park  6297143586 Call Hot Ind...
Booking open Available Pune Call Girls Koregaon Park 6297143586 Call Hot Ind...
 
Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
chapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineeringchapter 5.pptx: drainage and irrigation engineering
chapter 5.pptx: drainage and irrigation engineering
 
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELLPVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
PVC VS. FIBERGLASS (FRP) GRAVITY SEWER - UNI BELL
 
AKTU Computer Networks notes --- Unit 3.pdf
AKTU Computer Networks notes ---  Unit 3.pdfAKTU Computer Networks notes ---  Unit 3.pdf
AKTU Computer Networks notes --- Unit 3.pdf
 
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...Top Rated  Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
Top Rated Pune Call Girls Budhwar Peth ⟟ 6297143586 ⟟ Call Me For Genuine Se...
 
University management System project report..pdf
University management System project report..pdfUniversity management System project report..pdf
University management System project report..pdf
 
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and workingUNIT-V FMM.HYDRAULIC TURBINE - Construction and working
UNIT-V FMM.HYDRAULIC TURBINE - Construction and working
 
Vivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design SpainVivazz, Mieres Social Housing Design Spain
Vivazz, Mieres Social Housing Design Spain
 
KubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghlyKubeKraft presentation @CloudNativeHooghly
KubeKraft presentation @CloudNativeHooghly
 
UNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular ConduitsUNIT-II FMM-Flow Through Circular Conduits
UNIT-II FMM-Flow Through Circular Conduits
 

Linker and loader upload

  • 2. 2 Agenda • What is Linker and Loader • ELF Format • Static Linker vs Dynamic Linker • Run An Executable File • Backup
  • 3. 3 What is Linker and Loader A programming tool which combines one or more partial Object Files and libraries into a (more) complete executable object file.
  • 10. 10 • Allocator Space • Resolve symbols • Relocation symbols • Create sections Static Linker Using ld in binutils Printf.o Strlen.o Rand.o foo.o foo2.o foo3.o Static Linker Main.o Main.o Printf.o Foo.o Test executable file Run process Main.o Printf.o Foo.o Test executable file
  • 11. 11 Static Linker - Allocator Space
  • 12. 12 Static Linker – Resolve symbols Scans input relocatable files from left to right as on command line • Maintains Set E of object files req to form executable. Set U of unresolved symbols Set D of symbols defined in prev files. • Update E,U and D while scanning input relocatable files • U must be empty at the end – contents of E used to form executable
  • 13. 13 Static Linker - Relocation A process of assigning load addresses to various parts of a program and adjusting the code and data in the program to reflect the assigned addresses
  • 14. 14 Static Linker – Relocation .rel .text .symtab .strtab Find and iterate .rel sections. Every entry includes of Typedef struct { Elf32_Addr r_offset; Elf32_Word r_info; } Elf32_Rel Find the address in .text section by r_offset Find the symbol index in .symbol section by r_info Find the symbol type by r_info Got information about the responding symbol in .symbol sectioin Compute the latest address by symbol type 1 2 3 4 5 6
  • 15. 15 Static Linker – Linker script Be passed to GNU ld to exercise greater control over the linking process
  • 16. 16 ld –static crt1.o crti.o crtbeginT.o XXX.o –start- group –lgcc –lgcc_eh –lc-end-group crtend.o crtn.o Static Linker –Init/Finit Sections Object Definition Owner Runtime Crt1.o _start Glibc C、C++ Crti.o .init and .finit section Glibc C Crtn.o .init and .finit section Glibc C crtbeginT.o .init_array and .finit_array section Gcc C++ Crtend.o .init_array and .finit_array section Gcc C++
  • 17. 17 Static Linker –Init/Finit Sections Crti.o .init .finit a.o .init .finit b.o .init .finit Crtn.o .init .finit A.out .init .finit Linker Contain the code of beginning for init function Contain the code of beginning for finit function Contain the code of end for init function Contain code of to init global variable Contain code of to de-init global variable Contain the code of end for finit function Init function FInit function
  • 18. 18 Static Linker –Init_array/Finit_array Sections CRTBeginT.o .init_array .finit_array a.o .init_array .finit_array b.o(b.cpp) .init_array .finit_array CrtEnd.o .init_array .finit_array A.out .init_array .finit_array Linker Contain the code of beginning for init_array function Contain the code of beginning for finit_array function Contain the code of end for init_array function Contain pointer to point global constructor Contain the code of end for finit_array function Pointer table .text Global constructor Global de- constructor Contain pointer to point global de- constructor pointer1 pointer2 pointer3 Number Collect all pointers who point global constructor into an array
  • 20. 20 Dynamic Linker - PIC Position-independent code (PIC) or position- independent executable (PIE) is a body of machine code that, being placed somewhere in the primary memory, Compile option: -fpic Code section can be un- modified when load into memory so that it can be shared in different process
  • 21. 21 Dynamic Linker - PLT Stands for Procedure Linkage Table which is, put simply, used to call external procedures/functions whose address isn't known in the time of linking, and is left to be resolved by the dynamic linker at run time. First Call Second Call
  • 22. 22 Dynamic Linker - PIE Compile option: -fpie
  • 23. 23 • Implicit Referred to as static load or load-time dynamic linking. • Explicit Referred to as dynamic load or run-time dynamic linking.  Dlopen  Dlsym  Dlclose Dynamic Linker – Two Mode
  • 24. 24 Dynamic Linker vs Static Linker Dynamic Static Memory usage Small Bigger Storage usage Small Bigger Performance Low (But with PLT, 5% down) Update easy Hard Compatibility Hard No
  • 26. 26 Run Executable File – Static Linker • Fork • Exec • Kernel load executable file • Run from the start entry of executable Run a executable file Load and Map executable file (load_elf_bina ry) Do_execve system call Kernel Read header of executable file Read other headers of executable file NO User space __libc_init Do_execve system call finished Return address is set to entry of executable file Fork process New Process If .interp is existing, read the ld.so(system/bin/linker) Run the executable file from entry point(_start) main exit Running and quit Init main thread Init globals system_pro perties_init Call preinit_arra y and init_array Set __cxa_atexi t
  • 27. 27 Run Executable File – Dynamic Linker • Fork • Exec • Kernel load executable file • Kernel load ld.so • Ld.so load the dependent so • Relocation • Run from the start entry of executable Run a executable file who relies on other so Load and Map executable file (load_elf_bina ry) Do_execve system call Kernel Read header of exe file Got the path for linker and map it to get entry point Yes User space main Return address is set to entry of linker Fork process New Process If .interp is existing, read the ld.so(system/bin/linker) Run the executable file from entry point(_start) exit Running and quit Do_execve system call finished _start -> __linker_init t Init main thread Init globals call_constr uctors(DT_I NIT DT_INIT_AR RAY) __libc_pr einit __libc_ini t prelink_ima ge and link_image for linker __linker_init_po st_relocation debuggerd _init Init globals init_default _namespac e __system_ properties_ init Load needed .So one by one
  • 30. 30 • Gcc drivers the compile process. • Glibc provide runtime/libc/libm/libthread … • Binutils provides as/ar/ld Relation Between Gcc, Glibc and Binutils
  • 31. 31 • GPL License • 400K • BinUtils • Gcc • Glibc • Multi-thread • LD(BinUtils) • Loader • System Call Glibc vs Android Bionic • APACHE License • 200 K • Ld • Linker • pThread • System Call
  • 32. 32 • Linker Ld under Linux • Loader /system/bin/linker Linker and Loader in Android