SlideShare une entreprise Scribd logo
1  sur  69
Télécharger pour lire hors ligne
Something About
Dynamic Linking
Kai
ELFmemory
ELFmemory
ELF header
ELFmemory
ELF header
typedef struct
{
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff; /* offset of Program Header table*/
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize; /* the size of each entry */
Elf32_Half e_phnum; /* the number of entries */
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;

} Elf32_Ehdr;
ELFmemory
ELF header
typedef struct
{
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff; /* offset of Program Header table*/
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize; /* the size of each entry */
Elf32_Half e_phnum; /* the number of entries */
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;

} Elf32_Ehdr;
ELF Program
Header table
ELFmemory
ELF header
typedef struct
{
unsigned char e_ident[EI_NIDENT];
Elf32_Half e_type;
Elf32_Half e_machine;
Elf32_Word e_version;
Elf32_Addr e_entry;
Elf32_Off e_phoff; /* offset of Program Header table*/
Elf32_Off e_shoff;
Elf32_Word e_flags;
Elf32_Half e_ehsize;
Elf32_Half e_phentsize; /* the size of each entry */
Elf32_Half e_phnum; /* the number of entries */
Elf32_Half e_shentsize;
Elf32_Half e_shnum;
Elf32_Half e_shstrndx;

} Elf32_Ehdr;
ELF Program
Header table
ELFmemory
ELF header
ELF Program
Header table
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
segment in
memory
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
segment in
memory
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_LOAD */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
segment
segment in
memory
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_INTERP */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
/lib/ld-linux.so.2
segment in
memory
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_INTERP */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
/lib/ld-linux.so.2
segment in
memory
dynamic
linker
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_INTERP */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
/lib/ld-linux.so.2
segment in
memory
dynamic
linker
auxiliary
vector
stack
segment
ELFmemory
ELF header
ELF Program
Header table
typedef struct
{
Elf32_Word p_type; /* PT_INTERP */
Elf32_Off p_offset;
Elf32_Addr p_vaddr;
Elf32_Addr p_paddr;
Elf32_Word p_filesz;
Elf32_Word p_memsz;
Elf32_Word p_flags;
Elf32_Word p_align;

} Elf32_Phdr;
/lib/ld-linux.so.2
segment in
memory
dynamic
linker
auxiliary
vector
stack
entry
segment
Dynamic Linker
• Determine and load dependencies
• Relocate the application and all dependencies
• Initialise the application and dependencies in the
correct order
Types of Relocation
• Relative relocation
• Location which are known to be in the own object
• Not associated with a specific symbol
• Named relocation
• Based on symbols
• The reference of the definition is generally in a
different object than the definition
Symbol Lookup
• Traditional ELF Hash Table Handling
• GNU-style Hash Table Handling
1. Determine the hash value for the relocation name
2. For the object in the lookup scope,
A. Get the hash bucket using the hash value
B. Get the name offset of the symbol
C. Compare the symbol name with the relocation name
D. If the names match, we found the definition
E. If the names do not match, retry with next element in the
bucket
F. If there is no other element in the bucket, try next object.
3. If there is no other object in the lookup scope, the lookup failed
Traditional ELF Hash Table Handling
Traditional ELF Hash Table Handling
• If the scope contains more than one definition of the same
symbol, the algorithm simply picks up the first definition it finds.
• Use LD_PRELOAD to replace implementation
• LD_PRELOAD=./libfoo.so ./a.out
• The performance of each lookup depends on
• The length of the hash chains
• the number of symbols
• the choice of the hash table size
• The number of objects
/* sum.c */
#include <stdio.h>
int sum(int a, int b)
{
printf("sum is calledn");
return a + b;
}
/* sum_v2.c */
#include <stdio.h>
int base = 100;
int sum(int a, int b)
{
printf("sum (with base %d) is calledn", base);
return base + a + b;
}
LD_DEBUG=symbols LD_DEBUG_OUTPUT=debug.log LD_PRELOAD=./libsumv2.so ./a.out
LD_DEBUG=symbols LD_DEBUG_OUTPUT=debug.log ./a.out
1. Determine the hash value for the relocation name
2. For the object in the lookup scope,
A. Determine whether an entry with the given hash value is
presented (2-bit Bloom filter). If the filter indicates there is
no such definition, the next object is searched.
B. Determine the hash bucket
C. Get the entry from the chain array. Compare the value with
the hash value of the symbol. Ignore bit 0.
D. If the hash value matches, get the name offset.
E. Compare the symbol name with the relocation name
F. If the names match, we found the definition
G. If the names do not match and the value loaded from the
hash bucket does not have bit 0 set, retry with next element
in the bucket array
H. If bit 0 is set, there is no further entry in the hash chain, try
next object.
3. If there is no other object in the lookup scope, the lookup failed
GNU-style Hash Table Handling
Lookup Scope
• An ordered list of most loaded object
• global lookup scope
• executable
• all its dependencies in DT_NEEDED (added in breadth-first order)
• DT_SYMBOLIC: the object with the reference is added in front of the global lookup scope
• Only the object itself is added in front, not its dependencies
• local lookup scope
• DSO loaded dynamic using dlopen
• RTDL_GLOBAL: the loaded object and all the dependencies are added to the global
scope
• RTDL_DEEPBIND: search local lookup scope before global lookup scope
DT_SYMBOLIC
DT_SYMBOLIC
LD_DEBUG=symbols LD_PRELOAD=./libfoo_v2.so ./test_foo_sym
LD_DEBUG=symbols LD_PRELOAD=./libfoo_v2.so ./test_foo
DT_SYMBOLIC
/* foo.c */
void foo(void)
{
printf("foo in libfoo.son");
}
void libfoo(void)
{
printf("libfoo calls ");
foo();
}
/* foo_dyn.c */
void foo(void)
{
printf("foo in libfoo_dyn.son");
}
void libfoo(void)
{
printf("libfoo, dynamically loaded, calls ");
foo();
}
#include <stdio.h>
#include <dlfcn.h>
typedef void (*ptr)(void);
int main()
{
void *handle;
ptr foo_ptr;
libfoo();
handle = dlopen("libfoo_dyn.so", RTLD_LAZY);
foo_ptr = dlsym(handle, "libfoo");
foo_ptr();
dlclose(handle);
return 0;
}
No RTLD_DEEPBIND
#include <stdio.h>
#include <dlfcn.h>
typedef void (*ptr)(void);
int main()
{
void *handle;
ptr foo_ptr;
libfoo();
handle = dlopen("libfoo_dyn.so", RTLD_LAZY | RTLD_DEEPBIND);
foo_ptr = dlsym(handle, "libfoo");
foo_ptr();
dlclose(handle);
return 0;
}
/* foo_dyn.c */
void foo(void)
{
printf("foo in libfoon");
}
void bar(void)
{
printf("bar in libfoon");
}
void libfoo(void)
{
printf("libfoo, dynamically loaded, calls ");
foo();
}
/* bar_dyn.c */
void bar(void)
{
printf("bar in libbarn");
}
void libbar(void)
{
printf("libbar, dynamically loaded, calls ");
bar();
}
RTLD_GLOBAL
dlopen(“libfoo_dyn.so”, RTLD_LAZY | RTLD_GLOBAL)
GOT & PLT
movl $foo, %edi
call bar
movl $0, %eax
movq foo@GOTPCREL(%rip), %rax
movq %rax, %rdi
call bar@PLT
typedef void (*ptr)(void);
extern void foo(void);
extern void bar(ptr fn);
int libbar(void)
{
bar(foo);
return 0;
}
PIC
non-PIC
GOT & PLT
Disassembly of section .plt:
<_init+0x20>:
pushq 0x199a(%rip)
jmpq *0x199c(%rip)
nop
nop
nop
nop
. . .
<bar@plt>:
jmpq *0x198a(%rip)
pushq $0x2
jmpq 650 <_init+0x20>
call bar@PLT # dl-trampoline.S
<_dl_runtime_resolve>:
. . .
<bar>:
. . .
0
GOT
GOT & PLT
Disassembly of section .plt:
<_init+0x20>:
pushq 0x199a(%rip)
jmpq *0x199c(%rip)
nop
nop
nop
nop
. . .
<bar@plt>:
jmpq *0x198a(%rip)
pushq $0x2
jmpq 650 <_init+0x20>
call bar@PLT # dl-trampoline.S
<_dl_runtime_resolve>:
. . .
<bar>:
. . .
0
GOT
GOT & PLT
Disassembly of section .plt:
<_init+0x20>:
pushq 0x199a(%rip)
jmpq *0x199c(%rip)
nop
nop
nop
nop
. . .
<bar@plt>:
jmpq *0x198a(%rip)
pushq $0x2
jmpq 650 <_init+0x20>
call bar@PLT # dl-trampoline.S
<_dl_runtime_resolve>:
. . .
<bar>:
. . .
GOT
bar
GOT & PLT
Disassembly of section .plt:
<_init+0x20>:
pushq 0x199a(%rip)
jmpq *0x199c(%rip)
nop
nop
nop
nop
. . .
<bar@plt>:
jmpq *0x198a(%rip)
pushq $0x2
jmpq 650 <_init+0x20>
call bar@PLT # dl-trampoline.S
<_dl_runtime_resolve>:
. . .
<bar>:
. . .
GOT
GOT & PLT
Disassembly of section .plt:
<_init+0x20>:
pushq 0x199a(%rip)
jmpq *0x199c(%rip)
nop
nop
nop
nop
. . .
<bar@plt>:
jmpq *0x198a(%rip)
pushq $0x2
jmpq 650 <_init+0x20>
call bar@PLT # dl-trampoline.S
<_dl_runtime_resolve>:
. . .
<bar>:
. . .
GOT
bar
Data Definitions
• Common
• There can be more than one definition and they all get unified into one location.
• Unintialized
• It allows the linker to find multiple definitions and flag them as errors.
• Variables initialised with zero
• __attribute__ ((nocommon))
• -fno-common
• Initialised
• The initialisation value is stored in the file.
• It is always preferable to add variables as uninitialised or initialised with zero as
opposed to as initialised with a value other than zero.
• save disk space and eventually improve startup time.
Visibility
• default
• The symbol is exported and can be interposed.
• hidden
• while static restricts the visibility of a symbol to the file it is defined in, the hidden
attribute limits the visibility to the DSO the definition ends up in.
• the linker will not add hidden symbols to the dynamic symbol table.
• internal
• internal visibility is like hidden visibility, but with additional processor specific semantics.
• protected
• references to symbols defined in the same object are always satisfied locally, but the
symbols are still available outside the DSO.
Export Control
• Use static
• Define global visibility
• -fvisibility=hidden
• Define per-symbol visibility
• __attribute__ ((visibility (“hidden”)))
• #pragma GCC visibility push(hidden)
• Export Map
• -Wl,—version-script=symbol.map
• The linker is used only after the compiler already did its work and the
once generated code cannot be optimised significantly.
int last;
int next(void)
{
return ++last;
}
int foo(int scale)
{
return next() << scale;

}
Use Static
static
static int last;
static int next(void)
{
return ++last;
}
int foo(int scale)
{
return next() << scale;

}
Use Static
static
static
Define Visibility
gcc -fPIC -fvisibility=hidden -S test.c
int last;
int next(void)
{
return ++last;
}
int __attribute__ ((visibility (“default”)))
foo(int scale)
{
return next() << scale;

}
Export Map
{
global: foo;
local: *;
};
Export Map
Export Map
Export Map
Avoid Using Exported Symbols
• In some situations it might not be desirable to avoid exporting a symbol
but at the same time all local references should use the local definition.
• Wrapper functions
• Using aliases
• __attribute__ ((alias (“symbol”), visibility (“hidden”)))
• It is mandatory to create alias only of non-static functions and
variables.
• DT_SYMBOLIC
• all interfaces are affected
• the compiler does not get told about the use of local symbols
• lookup scope is changed
Wrapper Functions
static int last;
static int next_int (void) {
return ++last;
}
int next (void) { // wrapper function
return next_int ();
}
int index (int scale) {
return next_int () << scale;
}
Alias
int last;
extern __typeof (last) last_int // used in internal
__attribute ((alias (“last"), visibility (“hidden")));
int next (void) {
return ++last_int;
}
extern __typeof (next) next_int // used in internal
__attribute ((alias (“next"), visibility (“hidden")));
int index (int scale) {
return next_int () << scale;
}
Pointers v.s. Arrays
// the use of a variable is unnecessary.
char *str = “some string”;
// Here “str” is a name for a sequence of bytes.
// save one pointer variable in the non-sharable data segment
// save one relative relocation
char str[] = “some string”;
// compiler is able to move the string in read-only memory
const char str[] = “some string”;
Pointers v.s. Arrays
const char const *str = “some string”;
const char []str = “some string”;
Arrays of Data Pointers
// The total cost for this code is three words of data
// in writable memory and three relocations modifying
// this data in addition to the memory for the strings
// themselves.
static const char *msgs[] = {
[ERR1] = "message for err1",
[ERR2] = "message for err2",
[ERR3] = "message for err3"
};
const char *errstr (int nr) {
return msgs[nr];
}
// If the strings have different lengths it would mean
// wasting quite a bit of memory.
static const char msgs[][17] = {
[ERR1] = "message for err1",
[ERR2] = "message for err2",
[ERR3] = "message for err3"
};
Arrays of Data Pointers
// The cost of this code include three size_t words in
// read-only memory in addition to the memory for the strings.
static const char msgstr[] =
"message for err10"
"message for err20"
"message for err3”;
static const size_t msgidx[] = {
0,
sizeof ("message for err1"),
sizeof ("message for err1")
+ sizeof ("message for err2")
};
const char *errstr (int nr) {
return msgstr + msgidx[nr];
}
Security
• A changed GOT value might redirect a call to a function to an
arbitrary other place.
• -z relro linker option
• The linker is instructed to move the sections onto separate
memory page and emit a new program header entry
PT_GNU_RELRO.
• At runtime the dynamic linker can remove the write access to
those pages after it is done.
• -z now linker option
• Disable all lazy relocation at the expense of increased startup
costs.
Inter-Object File Relations
• By default the dynamic linker only looks into a few
directories to find DSOs.
• /lib
• /usr/lib
• Directories in /etc/ld.so.conf
• LD_LIBRARY_PATH environment variable
• rpath settings
Run Path
• Programmers could decide the path directly.
• The dynamic linker will use the value of the run path string when searching for dependencies of
the object.
• DT_RPATH (deprecated)
• Used before LD_LIBRARY_PATH
• It does not allow the user to overwrite the value.
• -rpath or -R linker option
• DT_RUNPATH
• Used after LD_LIBRARY_PATH
• --enable-new-dtags
• Empty path represents the current working directory.
• Dynamic string token
• $ORIGIN, $LIB, $PLATFORM
Reference
• How to Write Shared Libraries - Ulrich Drepper
• https://software.intel.com/sites/default/files/m/a/1/
e/dsohowto.pdf
• ELF Symbol Versioning
• https://www.akkadia.org/drepper/symbol-
versioning

Contenu connexe

Tendances

Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Ahmed El-Arabawy
 
BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2 BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2 Linaro
 
Making a Headless Android Device
Making a Headless Android DeviceMaking a Headless Android Device
Making a Headless Android DevicePatricia Aas
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) Johnny Sung
 
Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Linaro
 
Introduction to the LLVM Compiler System
Introduction to the LLVM  Compiler SystemIntroduction to the LLVM  Compiler System
Introduction to the LLVM Compiler Systemzionsaint
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEELinaro
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modulesdibyajyotig
 

Tendances (20)

Embedded Android : System Development - Part I
Embedded Android : System Development - Part IEmbedded Android : System Development - Part I
Embedded Android : System Development - Part I
 
Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers Course 102: Lecture 25: Devices and Device Drivers
Course 102: Lecture 25: Devices and Device Drivers
 
BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2 BUD17-302: LLVM Internals #2
BUD17-302: LLVM Internals #2
 
Android Things : Building Embedded Devices
Android Things : Building Embedded DevicesAndroid Things : Building Embedded Devices
Android Things : Building Embedded Devices
 
Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)Embedded Android : System Development - Part III (Audio / Video HAL)
Embedded Android : System Development - Part III (Audio / Video HAL)
 
Java I/O
Java I/OJava I/O
Java I/O
 
Making a Headless Android Device
Making a Headless Android DeviceMaking a Headless Android Device
Making a Headless Android Device
 
ELF
ELFELF
ELF
 
U-Boot - An universal bootloader
U-Boot - An universal bootloader U-Boot - An universal bootloader
U-Boot - An universal bootloader
 
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang) [Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
[Golang] 以 Mobile App 工程師視角,帶你進入 Golang 的世界 (Introduction of GoLang)
 
C Programming - Refresher - Part II
C Programming - Refresher - Part II C Programming - Refresher - Part II
C Programming - Refresher - Part II
 
Linux Internals - Part I
Linux Internals - Part ILinux Internals - Part I
Linux Internals - Part I
 
Embedded C - Lecture 4
Embedded C - Lecture 4Embedded C - Lecture 4
Embedded C - Lecture 4
 
Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8Lcu14 107- op-tee on ar mv8
Lcu14 107- op-tee on ar mv8
 
Introduction to the LLVM Compiler System
Introduction to the LLVM  Compiler SystemIntroduction to the LLVM  Compiler System
Introduction to the LLVM Compiler System
 
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
 
SFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEESFO15-503: Secure storage in OP-TEE
SFO15-503: Secure storage in OP-TEE
 
Dotnet basics
Dotnet basicsDotnet basics
Dotnet basics
 
Embedded Android : System Development - Part III
Embedded Android : System Development - Part IIIEmbedded Android : System Development - Part III
Embedded Android : System Development - Part III
 
Introduction To Linux Kernel Modules
Introduction To Linux Kernel ModulesIntroduction To Linux Kernel Modules
Introduction To Linux Kernel Modules
 

En vedette

LLVM Register Allocation
LLVM Register AllocationLLVM Register Allocation
LLVM Register AllocationWang Hsiangkai
 
DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data RepresentationWang Hsiangkai
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)Wang Hsiangkai
 
LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723Iftach Ian Amit
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++Seok-joon Yun
 
Safer IoT using functional language
Safer IoT using functional languageSafer IoT using functional language
Safer IoT using functional languageKiwamu Okabe
 
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
 
SecureAssist Visual Studio Package 導入ガイド
SecureAssist Visual Studio Package 導入ガイドSecureAssist Visual Studio Package 導入ガイド
SecureAssist Visual Studio Package 導入ガイドAsterisk Research, Inc.
 
SecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドSecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドAsterisk Research, Inc.
 
SecureAssist Enterprise Portal 導入ガイド
SecureAssist Enterprise Portal 導入ガイドSecureAssist Enterprise Portal 導入ガイド
SecureAssist Enterprise Portal 導入ガイドAsterisk Research, Inc.
 
SecureAssist IntelliJ Plug-in 導入ガイド
SecureAssist IntelliJ Plug-in 導入ガイドSecureAssist IntelliJ Plug-in 導入ガイド
SecureAssist IntelliJ Plug-in 導入ガイドAsterisk Research, Inc.
 
SecureAssist Eclipse Plug-in 導入ガイド
SecureAssist Eclipse Plug-in 導入ガイドSecureAssist Eclipse Plug-in 導入ガイド
SecureAssist Eclipse Plug-in 導入ガイドAsterisk Research, Inc.
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol ResolutionKen Kawamoto
 
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
 

En vedette (20)

LLVM Register Allocation
LLVM Register AllocationLLVM Register Allocation
LLVM Register Allocation
 
Effective Modern C++
Effective Modern C++Effective Modern C++
Effective Modern C++
 
DWARF Data Representation
DWARF Data RepresentationDWARF Data Representation
DWARF Data Representation
 
LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)LLVM Register Allocation (2nd Version)
LLVM Register Allocation (2nd Version)
 
LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723LD_PRELOAD Exploitation - DC9723
LD_PRELOAD Exploitation - DC9723
 
Welcome to Modern C++
Welcome to Modern C++Welcome to Modern C++
Welcome to Modern C++
 
Safer IoT using functional language
Safer IoT using functional languageSafer IoT using functional language
Safer IoT using functional language
 
GCC GENERIC
GCC GENERICGCC GENERIC
GCC GENERIC
 
ELF 101
ELF 101ELF 101
ELF 101
 
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
 
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
 
SecureAssist Visual Studio Package 導入ガイド
SecureAssist Visual Studio Package 導入ガイドSecureAssist Visual Studio Package 導入ガイド
SecureAssist Visual Studio Package 導入ガイド
 
SecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイドSecureAssist Enterprise Portal APIガイド
SecureAssist Enterprise Portal APIガイド
 
SecureAssist Enterprise Portal 導入ガイド
SecureAssist Enterprise Portal 導入ガイドSecureAssist Enterprise Portal 導入ガイド
SecureAssist Enterprise Portal 導入ガイド
 
SecureAssist IntelliJ Plug-in 導入ガイド
SecureAssist IntelliJ Plug-in 導入ガイドSecureAssist IntelliJ Plug-in 導入ガイド
SecureAssist IntelliJ Plug-in 導入ガイド
 
SecureAssist Eclipse Plug-in 導入ガイド
SecureAssist Eclipse Plug-in 導入ガイドSecureAssist Eclipse Plug-in 導入ガイド
SecureAssist Eclipse Plug-in 導入ガイド
 
Runtime Symbol Resolution
Runtime Symbol ResolutionRuntime Symbol Resolution
Runtime Symbol Resolution
 
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)
 

Similaire à Something About Dynamic Linking

Php opcodes sep2008
Php opcodes sep2008Php opcodes sep2008
Php opcodes sep2008bengiuliano
 
Unit 4
Unit 4Unit 4
Unit 4siddr
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and ExecutionChong-Kuan Chen
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaPatrick Allaert
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvAnton Arhipov
 
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzerIn the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzerAlejandro Hernández
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstackThierry Gayet
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manualSami Said
 
Ekon bestof rtl_delphi
Ekon bestof rtl_delphiEkon bestof rtl_delphi
Ekon bestof rtl_delphiMax Kleiner
 
Reverse Engineering for exploit writers
Reverse Engineering for exploit writersReverse Engineering for exploit writers
Reverse Engineering for exploit writersamiable_indian
 
Jonathan - Reverse Engineering for exploit writers - ClubHack2008
Jonathan - Reverse Engineering for exploit writers - ClubHack2008Jonathan - Reverse Engineering for exploit writers - ClubHack2008
Jonathan - Reverse Engineering for exploit writers - ClubHack2008ClubHack
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for DummiesElizabeth Smith
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Spaceramanjosan
 

Similaire à Something About Dynamic Linking (20)

Php opcodes sep2008
Php opcodes sep2008Php opcodes sep2008
Php opcodes sep2008
 
Unit 4
Unit 4Unit 4
Unit 4
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Compilation and Execution
Compilation and ExecutionCompilation and Execution
Compilation and Execution
 
Create your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 VeronaCreate your own PHP extension, step by step - phpDay 2012 Verona
Create your own PHP extension, step by step - phpDay 2012 Verona
 
Java Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lvJava Bytecode Fundamentals - JUG.lv
Java Bytecode Fundamentals - JUG.lv
 
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzerIn the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
In the lands of corrupted elves - Breaking ELF software with Melkor fuzzer
 
Hooking signals and dumping the callstack
Hooking signals and dumping the callstackHooking signals and dumping the callstack
Hooking signals and dumping the callstack
 
Chado-XML
Chado-XMLChado-XML
Chado-XML
 
Lex tool manual
Lex tool manualLex tool manual
Lex tool manual
 
Php extensions
Php extensionsPhp extensions
Php extensions
 
Ekon bestof rtl_delphi
Ekon bestof rtl_delphiEkon bestof rtl_delphi
Ekon bestof rtl_delphi
 
Experimental dtrace
Experimental dtraceExperimental dtrace
Experimental dtrace
 
Reverse Engineering for exploit writers
Reverse Engineering for exploit writersReverse Engineering for exploit writers
Reverse Engineering for exploit writers
 
Jonathan - Reverse Engineering for exploit writers - ClubHack2008
Jonathan - Reverse Engineering for exploit writers - ClubHack2008Jonathan - Reverse Engineering for exploit writers - ClubHack2008
Jonathan - Reverse Engineering for exploit writers - ClubHack2008
 
Php Extensions for Dummies
Php Extensions for DummiesPhp Extensions for Dummies
Php Extensions for Dummies
 
CInputOutput.ppt
CInputOutput.pptCInputOutput.ppt
CInputOutput.ppt
 
Rpg Pointers And User Space
Rpg Pointers And User SpaceRpg Pointers And User Space
Rpg Pointers And User Space
 
C tutorial
C tutorialC tutorial
C tutorial
 
C tutorial
C tutorialC tutorial
C tutorial
 

Plus de Wang Hsiangkai

Plus de Wang Hsiangkai (8)

Debug Line Issues After Relaxation.
Debug Line Issues After Relaxation.Debug Line Issues After Relaxation.
Debug Line Issues After Relaxation.
 
Machine Trace Metrics
Machine Trace MetricsMachine Trace Metrics
Machine Trace Metrics
 
Instruction Combine in LLVM
Instruction Combine in LLVMInstruction Combine in LLVM
Instruction Combine in LLVM
 
GCC LTO
GCC LTOGCC LTO
GCC LTO
 
LTO plugin
LTO pluginLTO plugin
LTO plugin
 
Perf File Format
Perf File FormatPerf File Format
Perf File Format
 
Introduction to Perf
Introduction to PerfIntroduction to Perf
Introduction to Perf
 
SSA - PHI-functions Placements
SSA - PHI-functions PlacementsSSA - PHI-functions Placements
SSA - PHI-functions Placements
 

Dernier

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfjoe51371421
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Intelisync
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationkaushalgiri8080
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about usDynamic Netsoft
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptkotipi9215
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyFrank van der Linden
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...kellynguyen01
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...aditisharan08
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comFatema Valibhai
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxComplianceQuest1
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfkalichargn70th171
 

Dernier (20)

(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
why an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdfwhy an Opensea Clone Script might be your perfect match.pdf
why an Opensea Clone Script might be your perfect match.pdf
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...Call Girls In Mukherjee Nagar 📱  9999965857  🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
Call Girls In Mukherjee Nagar 📱 9999965857 🤩 Delhi 🫦 HOT AND SEXY VVIP 🍎 SE...
 
Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)Introduction to Decentralized Applications (dApps)
Introduction to Decentralized Applications (dApps)
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
Project Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanationProject Based Learning (A.I).pptx detail explanation
Project Based Learning (A.I).pptx detail explanation
 
DNT_Corporate presentation know about us
DNT_Corporate presentation know about usDNT_Corporate presentation know about us
DNT_Corporate presentation know about us
 
chapter--4-software-project-planning.ppt
chapter--4-software-project-planning.pptchapter--4-software-project-planning.ppt
chapter--4-software-project-planning.ppt
 
Engage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The UglyEngage Usergroup 2024 - The Good The Bad_The Ugly
Engage Usergroup 2024 - The Good The Bad_The Ugly
 
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
Short Story: Unveiling the Reasoning Abilities of Large Language Models by Ke...
 
Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...Unit 1.1 Excite Part 1, class 9, cbse...
Unit 1.1 Excite Part 1, class 9, cbse...
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
HR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.comHR Software Buyers Guide in 2024 - HRSoftware.com
HR Software Buyers Guide in 2024 - HRSoftware.com
 
A Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docxA Secure and Reliable Document Management System is Essential.docx
A Secure and Reliable Document Management System is Essential.docx
 
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdfLearn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
Learn the Fundamentals of XCUITest Framework_ A Beginner's Guide.pdf
 

Something About Dynamic Linking

  • 4. ELFmemory ELF header typedef struct { unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; /* offset of Program Header table*/ Elf32_Off e_shoff; Elf32_Word e_flags; Elf32_Half e_ehsize; Elf32_Half e_phentsize; /* the size of each entry */ Elf32_Half e_phnum; /* the number of entries */ Elf32_Half e_shentsize; Elf32_Half e_shnum; Elf32_Half e_shstrndx;
 } Elf32_Ehdr;
  • 5. ELFmemory ELF header typedef struct { unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; /* offset of Program Header table*/ Elf32_Off e_shoff; Elf32_Word e_flags; Elf32_Half e_ehsize; Elf32_Half e_phentsize; /* the size of each entry */ Elf32_Half e_phnum; /* the number of entries */ Elf32_Half e_shentsize; Elf32_Half e_shnum; Elf32_Half e_shstrndx;
 } Elf32_Ehdr; ELF Program Header table
  • 6. ELFmemory ELF header typedef struct { unsigned char e_ident[EI_NIDENT]; Elf32_Half e_type; Elf32_Half e_machine; Elf32_Word e_version; Elf32_Addr e_entry; Elf32_Off e_phoff; /* offset of Program Header table*/ Elf32_Off e_shoff; Elf32_Word e_flags; Elf32_Half e_ehsize; Elf32_Half e_phentsize; /* the size of each entry */ Elf32_Half e_phnum; /* the number of entries */ Elf32_Half e_shentsize; Elf32_Half e_shnum; Elf32_Half e_shstrndx;
 } Elf32_Ehdr; ELF Program Header table
  • 8. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr;
  • 9. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment
  • 10. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment
  • 11. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment
  • 12. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment
  • 13. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment segment in memory
  • 14. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment segment in memory
  • 15. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_LOAD */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; segment segment in memory
  • 16. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_INTERP */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; /lib/ld-linux.so.2 segment in memory segment
  • 17. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_INTERP */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; /lib/ld-linux.so.2 segment in memory dynamic linker segment
  • 18. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_INTERP */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; /lib/ld-linux.so.2 segment in memory dynamic linker auxiliary vector stack segment
  • 19. ELFmemory ELF header ELF Program Header table typedef struct { Elf32_Word p_type; /* PT_INTERP */ Elf32_Off p_offset; Elf32_Addr p_vaddr; Elf32_Addr p_paddr; Elf32_Word p_filesz; Elf32_Word p_memsz; Elf32_Word p_flags; Elf32_Word p_align;
 } Elf32_Phdr; /lib/ld-linux.so.2 segment in memory dynamic linker auxiliary vector stack entry segment
  • 20. Dynamic Linker • Determine and load dependencies • Relocate the application and all dependencies • Initialise the application and dependencies in the correct order
  • 21. Types of Relocation • Relative relocation • Location which are known to be in the own object • Not associated with a specific symbol • Named relocation • Based on symbols • The reference of the definition is generally in a different object than the definition
  • 22. Symbol Lookup • Traditional ELF Hash Table Handling • GNU-style Hash Table Handling
  • 23. 1. Determine the hash value for the relocation name 2. For the object in the lookup scope, A. Get the hash bucket using the hash value B. Get the name offset of the symbol C. Compare the symbol name with the relocation name D. If the names match, we found the definition E. If the names do not match, retry with next element in the bucket F. If there is no other element in the bucket, try next object. 3. If there is no other object in the lookup scope, the lookup failed Traditional ELF Hash Table Handling
  • 24. Traditional ELF Hash Table Handling • If the scope contains more than one definition of the same symbol, the algorithm simply picks up the first definition it finds. • Use LD_PRELOAD to replace implementation • LD_PRELOAD=./libfoo.so ./a.out • The performance of each lookup depends on • The length of the hash chains • the number of symbols • the choice of the hash table size • The number of objects
  • 25. /* sum.c */ #include <stdio.h> int sum(int a, int b) { printf("sum is calledn"); return a + b; } /* sum_v2.c */ #include <stdio.h> int base = 100; int sum(int a, int b) { printf("sum (with base %d) is calledn", base); return base + a + b; }
  • 26.
  • 27. LD_DEBUG=symbols LD_DEBUG_OUTPUT=debug.log LD_PRELOAD=./libsumv2.so ./a.out LD_DEBUG=symbols LD_DEBUG_OUTPUT=debug.log ./a.out
  • 28. 1. Determine the hash value for the relocation name 2. For the object in the lookup scope, A. Determine whether an entry with the given hash value is presented (2-bit Bloom filter). If the filter indicates there is no such definition, the next object is searched. B. Determine the hash bucket C. Get the entry from the chain array. Compare the value with the hash value of the symbol. Ignore bit 0. D. If the hash value matches, get the name offset. E. Compare the symbol name with the relocation name F. If the names match, we found the definition G. If the names do not match and the value loaded from the hash bucket does not have bit 0 set, retry with next element in the bucket array H. If bit 0 is set, there is no further entry in the hash chain, try next object. 3. If there is no other object in the lookup scope, the lookup failed GNU-style Hash Table Handling
  • 29.
  • 30. Lookup Scope • An ordered list of most loaded object • global lookup scope • executable • all its dependencies in DT_NEEDED (added in breadth-first order) • DT_SYMBOLIC: the object with the reference is added in front of the global lookup scope • Only the object itself is added in front, not its dependencies • local lookup scope • DSO loaded dynamic using dlopen • RTDL_GLOBAL: the loaded object and all the dependencies are added to the global scope • RTDL_DEEPBIND: search local lookup scope before global lookup scope
  • 35. /* foo.c */ void foo(void) { printf("foo in libfoo.son"); } void libfoo(void) { printf("libfoo calls "); foo(); } /* foo_dyn.c */ void foo(void) { printf("foo in libfoo_dyn.son"); } void libfoo(void) { printf("libfoo, dynamically loaded, calls "); foo(); }
  • 36. #include <stdio.h> #include <dlfcn.h> typedef void (*ptr)(void); int main() { void *handle; ptr foo_ptr; libfoo(); handle = dlopen("libfoo_dyn.so", RTLD_LAZY); foo_ptr = dlsym(handle, "libfoo"); foo_ptr(); dlclose(handle); return 0; }
  • 38. #include <stdio.h> #include <dlfcn.h> typedef void (*ptr)(void); int main() { void *handle; ptr foo_ptr; libfoo(); handle = dlopen("libfoo_dyn.so", RTLD_LAZY | RTLD_DEEPBIND); foo_ptr = dlsym(handle, "libfoo"); foo_ptr(); dlclose(handle); return 0; }
  • 39. /* foo_dyn.c */ void foo(void) { printf("foo in libfoon"); } void bar(void) { printf("bar in libfoon"); } void libfoo(void) { printf("libfoo, dynamically loaded, calls "); foo(); }
  • 40. /* bar_dyn.c */ void bar(void) { printf("bar in libbarn"); } void libbar(void) { printf("libbar, dynamically loaded, calls "); bar(); }
  • 42. GOT & PLT movl $foo, %edi call bar movl $0, %eax movq foo@GOTPCREL(%rip), %rax movq %rax, %rdi call bar@PLT typedef void (*ptr)(void); extern void foo(void); extern void bar(ptr fn); int libbar(void) { bar(foo); return 0; } PIC non-PIC
  • 43. GOT & PLT Disassembly of section .plt: <_init+0x20>: pushq 0x199a(%rip) jmpq *0x199c(%rip) nop nop nop nop . . . <bar@plt>: jmpq *0x198a(%rip) pushq $0x2 jmpq 650 <_init+0x20> call bar@PLT # dl-trampoline.S <_dl_runtime_resolve>: . . . <bar>: . . . 0 GOT
  • 44. GOT & PLT Disassembly of section .plt: <_init+0x20>: pushq 0x199a(%rip) jmpq *0x199c(%rip) nop nop nop nop . . . <bar@plt>: jmpq *0x198a(%rip) pushq $0x2 jmpq 650 <_init+0x20> call bar@PLT # dl-trampoline.S <_dl_runtime_resolve>: . . . <bar>: . . . 0 GOT
  • 45. GOT & PLT Disassembly of section .plt: <_init+0x20>: pushq 0x199a(%rip) jmpq *0x199c(%rip) nop nop nop nop . . . <bar@plt>: jmpq *0x198a(%rip) pushq $0x2 jmpq 650 <_init+0x20> call bar@PLT # dl-trampoline.S <_dl_runtime_resolve>: . . . <bar>: . . . GOT bar
  • 46. GOT & PLT Disassembly of section .plt: <_init+0x20>: pushq 0x199a(%rip) jmpq *0x199c(%rip) nop nop nop nop . . . <bar@plt>: jmpq *0x198a(%rip) pushq $0x2 jmpq 650 <_init+0x20> call bar@PLT # dl-trampoline.S <_dl_runtime_resolve>: . . . <bar>: . . . GOT
  • 47. GOT & PLT Disassembly of section .plt: <_init+0x20>: pushq 0x199a(%rip) jmpq *0x199c(%rip) nop nop nop nop . . . <bar@plt>: jmpq *0x198a(%rip) pushq $0x2 jmpq 650 <_init+0x20> call bar@PLT # dl-trampoline.S <_dl_runtime_resolve>: . . . <bar>: . . . GOT bar
  • 48. Data Definitions • Common • There can be more than one definition and they all get unified into one location. • Unintialized • It allows the linker to find multiple definitions and flag them as errors. • Variables initialised with zero • __attribute__ ((nocommon)) • -fno-common • Initialised • The initialisation value is stored in the file. • It is always preferable to add variables as uninitialised or initialised with zero as opposed to as initialised with a value other than zero. • save disk space and eventually improve startup time.
  • 49. Visibility • default • The symbol is exported and can be interposed. • hidden • while static restricts the visibility of a symbol to the file it is defined in, the hidden attribute limits the visibility to the DSO the definition ends up in. • the linker will not add hidden symbols to the dynamic symbol table. • internal • internal visibility is like hidden visibility, but with additional processor specific semantics. • protected • references to symbols defined in the same object are always satisfied locally, but the symbols are still available outside the DSO.
  • 50. Export Control • Use static • Define global visibility • -fvisibility=hidden • Define per-symbol visibility • __attribute__ ((visibility (“hidden”))) • #pragma GCC visibility push(hidden) • Export Map • -Wl,—version-script=symbol.map • The linker is used only after the compiler already did its work and the once generated code cannot be optimised significantly.
  • 51. int last; int next(void) { return ++last; } int foo(int scale) { return next() << scale;
 } Use Static static static int last; static int next(void) { return ++last; } int foo(int scale) { return next() << scale;
 }
  • 53. Define Visibility gcc -fPIC -fvisibility=hidden -S test.c int last; int next(void) { return ++last; } int __attribute__ ((visibility (“default”))) foo(int scale) { return next() << scale;
 }
  • 58. Avoid Using Exported Symbols • In some situations it might not be desirable to avoid exporting a symbol but at the same time all local references should use the local definition. • Wrapper functions • Using aliases • __attribute__ ((alias (“symbol”), visibility (“hidden”))) • It is mandatory to create alias only of non-static functions and variables. • DT_SYMBOLIC • all interfaces are affected • the compiler does not get told about the use of local symbols • lookup scope is changed
  • 59. Wrapper Functions static int last; static int next_int (void) { return ++last; } int next (void) { // wrapper function return next_int (); } int index (int scale) { return next_int () << scale; }
  • 60. Alias int last; extern __typeof (last) last_int // used in internal __attribute ((alias (“last"), visibility (“hidden"))); int next (void) { return ++last_int; } extern __typeof (next) next_int // used in internal __attribute ((alias (“next"), visibility (“hidden"))); int index (int scale) { return next_int () << scale; }
  • 61.
  • 62. Pointers v.s. Arrays // the use of a variable is unnecessary. char *str = “some string”; // Here “str” is a name for a sequence of bytes. // save one pointer variable in the non-sharable data segment // save one relative relocation char str[] = “some string”; // compiler is able to move the string in read-only memory const char str[] = “some string”;
  • 63. Pointers v.s. Arrays const char const *str = “some string”; const char []str = “some string”;
  • 64. Arrays of Data Pointers // The total cost for this code is three words of data // in writable memory and three relocations modifying // this data in addition to the memory for the strings // themselves. static const char *msgs[] = { [ERR1] = "message for err1", [ERR2] = "message for err2", [ERR3] = "message for err3" }; const char *errstr (int nr) { return msgs[nr]; } // If the strings have different lengths it would mean // wasting quite a bit of memory. static const char msgs[][17] = { [ERR1] = "message for err1", [ERR2] = "message for err2", [ERR3] = "message for err3" };
  • 65. Arrays of Data Pointers // The cost of this code include three size_t words in // read-only memory in addition to the memory for the strings. static const char msgstr[] = "message for err10" "message for err20" "message for err3”; static const size_t msgidx[] = { 0, sizeof ("message for err1"), sizeof ("message for err1") + sizeof ("message for err2") }; const char *errstr (int nr) { return msgstr + msgidx[nr]; }
  • 66. Security • A changed GOT value might redirect a call to a function to an arbitrary other place. • -z relro linker option • The linker is instructed to move the sections onto separate memory page and emit a new program header entry PT_GNU_RELRO. • At runtime the dynamic linker can remove the write access to those pages after it is done. • -z now linker option • Disable all lazy relocation at the expense of increased startup costs.
  • 67. Inter-Object File Relations • By default the dynamic linker only looks into a few directories to find DSOs. • /lib • /usr/lib • Directories in /etc/ld.so.conf • LD_LIBRARY_PATH environment variable • rpath settings
  • 68. Run Path • Programmers could decide the path directly. • The dynamic linker will use the value of the run path string when searching for dependencies of the object. • DT_RPATH (deprecated) • Used before LD_LIBRARY_PATH • It does not allow the user to overwrite the value. • -rpath or -R linker option • DT_RUNPATH • Used after LD_LIBRARY_PATH • --enable-new-dtags • Empty path represents the current working directory. • Dynamic string token • $ORIGIN, $LIB, $PLATFORM
  • 69. Reference • How to Write Shared Libraries - Ulrich Drepper • https://software.intel.com/sites/default/files/m/a/1/ e/dsohowto.pdf • ELF Symbol Versioning • https://www.akkadia.org/drepper/symbol- versioning