Beruflich Dokumente
Kultur Dokumente
Relocation
Performing section merge
Resolving all resolvable relocation
Replacing symbolic references with
actual addresses (binding)
MCLinker
MCLinker
Bitcode
Bitcode
Object
Object file
file
Archive
Archive
Bitcode
Bitcode
reader
reader
Object
Object
reader
reader
Archive
Archive
reader
reader
Symbol
Symboltable
table
MCLDFile
MCLDFile
MCLDFile
MCLDFile
MCLDFile
MCLDFile
Symbol
table
Symbol
Symboltable
table
Symbol
table
Symbol
Symboltable
table
Section a
Section b
Section
aaaaa
Section
Section
Section
Section
Section
a
Section
Section c
Section
bbbbb
Section
Section
Section
Section
Section
b
Section
Section
ccccc
Section
Section
Section
Section
Section
c
Section
Relocation
Relocation
Relocation
Relocation
Relocation
Relocation
Relocation
class
Relocation
Relocation
Data
http://code.google.com/p/mclinker
Symbol
Resolution
Output
Output
11/11/18
MCLinker
MCLDFile
symbol tables
sections
relocation entries
Linking operations on MCLDFile are efficient
http://code.google.com/p/mclinker
11/11/18
MCLinker
http://code.google.com/p/mclinker
11/11/18
MCLinker
Symbol Table 1
Dynamic
Symbol Table 2
Common
Non-Dynamic
Reference symbols
Common
Define symbols
MCLinker
Symbol in MCLinker
ELF
ELF Symbol
Symbol
st_name
st_name
st_info
st_info
st_shndx
st_shndx
st_value
st_value
st_size
st_size
st_other
st_other
http://code.google.com/p/mclinker
11/11/18
MachO
MachO Nlist
Nlist
n_un
n_un
n_type
n_type
n_desc
n_desc
n_sect
n_sect
n_value
n_value
COFF
COFF Symbol
Symbol
Name
Name
Type
Type
StorageClass
StorageClass
SectionNum
SectionNum
Value
Value
NumAux
NumAux
MCLinker
Symbol Resolution
Steps
is_dyn
type
bind
http://code.google.com/p/mclinker
11/11/18
MCLinker
Sections in MCLinker
MCLDFile reuses the definitions of sections in LLVM machine code (MC) layer
http://code.google.com/p/mclinker
11/11/18
MCLinker
TargetBackend additionally
provides target-dependent
relocation functions to improve
performance as needed
http://code.google.com/p/mclinker
11/11/18
LDRelocation
LDRelocation
symbol
symbol
offset
offset
addend
addend
howto
howto
type
type
right_shift
right_shift
size
size
bit_size
bit_size
pcrel
pcrel
bit_position
bit_position
overflow
overflow
target_callback
target_callback
src_mask
src_mask
dst_mask
dst_mask
pcrel_offset
pcrel_offset
MCLinker
Relocation = S + A P
S : the value of the symbol
A : the value of addend
P : the value derived from offset
Rn
Rd
Rotate
Immed 8
11100010010000010000111100111111
and
and
result high
Rn
Rd Rotate
Immed 8
11100010010000010000111111111111
~dst_mask
11111111111111111111111100000000
111000100100000100001111
final result
http://code.google.com/p/mclinker
sum
src_mask
11111111
final value of relocation ( offset + addend + symbol address )
11111111111111111111110000000100
and
dst_mask
11111111
result low
01000011
11100010010000010000111101000011
11/11/18
10
MCLinker
Average size of all members in libc.a is less than and closed to one page
However, LLVM MemoryBuffer uses memory mapped I/O only when the
request is larger than four pages
Policy
Advantage
Disadvantage
Dynamic Memory
No constraints on either the start Slow file copy
http://code.google.com/p/mclinker
11/11/18
11
malloc()
+ read()
address
or the requested
size
MCLinker
MemoryArea
MemorySpace
MemoryRegion
http://code.google.com/p/mclinker
11/11/18
12
MCLinker
LDObjectReader
LDObjectReader
MemoryRegion
MemoryRegion
MemoryRegion
MemoryArea
MemorySpace
MemorySpace
MemoryRegion
MemoryRegion
MemorySpace
MemorySpace
MemoryRegion
MemoryRegion
MemorySpace
MemorySpace
http://code.google.com/p/mclinker
11/11/18
mmap
mmap
dynamic
dynamicmemory
memory
13
MCLinker
LDObjectReader
LDObjectReader
MemoryRegion
3. Map a MemorySpace to
a MemoryRegion
MemoryArea MemorySpace
Request
RequestSize
Size<<Threshold
Threshold
Memory
MemoryPolicy
Policy
Using
Usingmemory
memorymapped
mappedI/O
I/O
Allocating
Allocatingdynamic
dynamicmemory
memory
Allocated
AllocatedMemorySpace
MemorySpaceSize
Size
Page
Pagealignment
alignment
As
Asrequested
requestedsize
size
Feature
Feature
Fast
Fastmemory
memoryread
readand
andwrite
write
Reducing
Reducingmemory
memoryfragments
fragments
http://code.google.com/p/mclinker
11/11/18
14
MCLinker