Program Behaviour Program Behaviour semantics .c .c .c source - - PowerPoint PPT Presentation
Program Behaviour Program Behaviour semantics .c .c .c source - - PowerPoint PPT Presentation
Program Behaviour Program Behaviour semantics .c .c .c source program code inputs Program Behaviour semantics .c .c .c source program code inputs Next Talk: other things Program Behaviour semantics .c .c .c source program
Program Behaviour
Program Behaviour
.c .c .c
source code semantics program inputs
Program Behaviour
.c .c .c
source code semantics program inputs
Next Talk:
- ther things
Program Behaviour
.c .c .c
source code semantics program inputs
Next Talk:
- ther things
This Talk: the linker
.c .c .c .c
.c .c .c .c .o .o
compile
.c .c .c .c .o .o
exe
compile link
.c .c .c .c .o .o
exe
.c
compile link concatenate
.c .c .c .c .o .o
exe exe
.c
compile compile link concatenate
.c .c .c .c .o .o
exe exe
.c
compile compile link concatenate
≠
Correctness can depend on how the program was linked
.c
.c
compile
.o
.c
compile
Sections
.o
.c
compile
Sections
.text
.o
.c
compile
Sections
.text .data
.o
.c
compile
Sections
.text .data
.o
.debug
.c
compile
Sections
.text .data
.o
.debug
.c
compile
Sections
.text .data
.o
.debug
X R
W
.data
.o
.debug .data
.o
.debug
.text .text
link
.data
.o
.debug
.text
.data
.o
.debug
.data
.text .text
.o
.debug
link
.data
.o
.debug
.text
.data
.o
.debug
.data
.text .text
.o
.debug
- Join sections together
- Resolve symbols
Executable 0x0000
Executable 0xb000
Executable 0xb400
Executable 0xc000
Executable 0xca00
Executable 0x0000 .text .text .data .data .debug .debug
Executable 0x0000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
Executable 0x0000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
Executable .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
Executable 0xb000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
.text
Executable 0xb000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
.text
Executable 0xb400 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
.text
Executable 0xb400 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
.text
Executable 0xd000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }
.text
.data
Executable 0xd000
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable 0xd000
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable 0xd000
text_start
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable 0xd000
text_start
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable 0xd400
.text
0xd000
text_start
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable 0xd400
.text
0xd000
text_start
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable
.text
0xd000
text_start
0xd400
text_end
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable
.text
0xd000
text_start
0xd400
text_end
.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)
Executable
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
.text : { text_start = . *(.text*) text_end = . }
Executable
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
extern char text_size[], text_start[], text_end[]; int main() { assert(&text_size == (char*)0x400); assert(&text_start == (char*)0xd000); }
Executable
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
Symbol Table foo bar ... text_start text_size 12 ... ??? ???
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
linker_syms.h char text_start[]; &text_start = 0xd000; char text_size[]; &text_size = 0x400;
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
linker_syms.h char text_start[]; &text_start = 0xd000; char text_size[]; &text_size = 0x400;
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }
linker_syms.h size_t text_start; text_start = 0xd000; size_t text_size; text_size = 0x400;
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *) text_start, (size_t) text_size); }
linker_syms.h size_t text_start; text_start = 0xd000; size_t text_size; text_size = 0x400;
extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *) text_start, (size_t) text_size); }
Symbol Table foo bar ... text_start text_size 12 ...
.ld
exe
OOPSLA'16
OOPSLA'16
.o
.ld
.o
exe
OOPSLA'16
.o
.ld
.o
exe
.ld
exe
text_start text_size 0xd 0xcSymbol Table
Four Functions
Four Functions addrS addrE : ident ⇀ ℕ symbS symbE : ident ⇀ ident
Four Functions addrS addrE : ident ⇀ ℕ
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
symbS symbE : ident ⇀ ident
Four Functions addrS addrE : ident ⇀ ℕ
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
symbS symbE : ident ⇀ ident
symbS = .text ↦ text_start symbE = .text ↦ text_end
Four Functions addrS addrE : ident ⇀ ℕ
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
symbS symbE : ident ⇀ ident
addrS = .text ↦ 0xd000 text_size ↦ 0x400 text_end ↦ 0xd400 text_start ↦ 0xd000
Four Functions addrS addrE : ident ⇀ ℕ
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
symbS symbE : ident ⇀ ident
addrE = .text ↦ 0xd400
Grammar
Grammar
MEMORY { } Memory Directives
Grammar
MEMORY { } SECTIONS { } Memory Directives Section Directives
Grammar
MEMORY { } SECTIONS { } Memory Directives Section Directives Global Assignments
Grammar
MEMORY { } SECTIONS { }
.text : { text_start = .; *(.text*) text_end = .; }
Grammar
MEMORY { } SECTIONS { }
text_size = SIZEOF(.text);
Grammar
MEMORY { } SECTIONS { }
rom : ORIGIN = 0x2000, LENTGH = 0x400;
Expressions
Expressions
Expressions
Expressions
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀
Interpretation addrS
MEMORY { } SECTIONS { }
symbS addrE symbE
⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀
.text
0x400 text_size 0xd000
text_start
0xd400
text_end
CAV'18
Implemented in CBMC
- Static analysers need to understand
program behaviour
- Linker scripts introduce information
unavailable to static analyser
- Solution: parse linker scripts, integrate
into static analysis