Program Behaviour Program Behaviour semantics .c .c .c source - - PowerPoint PPT Presentation

program behaviour
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1
slide-2
SLIDE 2

Program Behaviour

slide-3
SLIDE 3

Program Behaviour

.c .c .c

source code semantics program inputs

slide-4
SLIDE 4

Program Behaviour

.c .c .c

source code semantics program inputs

Next Talk:

  • ther things
slide-5
SLIDE 5

Program Behaviour

.c .c .c

source code semantics program inputs

Next Talk:

  • ther things

This Talk: the linker

slide-6
SLIDE 6

.c .c .c .c

slide-7
SLIDE 7

.c .c .c .c .o .o

compile

slide-8
SLIDE 8

.c .c .c .c .o .o

exe

compile link

slide-9
SLIDE 9

.c .c .c .c .o .o

exe

.c

compile link concatenate

slide-10
SLIDE 10

.c .c .c .c .o .o

exe exe

.c

compile compile link concatenate

slide-11
SLIDE 11

.c .c .c .c .o .o

exe exe

.c

compile compile link concatenate

slide-12
SLIDE 12

Correctness can depend on how the program was linked

slide-13
SLIDE 13

.c

slide-14
SLIDE 14

.c

compile

.o

slide-15
SLIDE 15

.c

compile

Sections

.o

slide-16
SLIDE 16

.c

compile

Sections

.text

.o

slide-17
SLIDE 17

.c

compile

Sections

.text .data

.o

slide-18
SLIDE 18

.c

compile

Sections

.text .data

.o

.debug

slide-19
SLIDE 19

.c

compile

Sections

.text .data

.o

.debug

slide-20
SLIDE 20

.c

compile

Sections

.text .data

.o

.debug

X R

W

slide-21
SLIDE 21

.data

.o

.debug .data

.o

.debug

.text .text

slide-22
SLIDE 22

link

.data

.o

.debug

.text

.data

.o

.debug

.data

.text .text

.o

.debug

slide-23
SLIDE 23

link

.data

.o

.debug

.text

.data

.o

.debug

.data

.text .text

.o

.debug

  • Join sections together
  • Resolve symbols
slide-24
SLIDE 24

Executable 0x0000

slide-25
SLIDE 25

Executable 0xb000

slide-26
SLIDE 26

Executable 0xb400

slide-27
SLIDE 27

Executable 0xc000

slide-28
SLIDE 28

Executable 0xca00

slide-29
SLIDE 29

Executable 0x0000 .text .text .data .data .debug .debug

slide-30
SLIDE 30

Executable 0x0000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

slide-31
SLIDE 31

Executable 0x0000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

slide-32
SLIDE 32

Executable .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

slide-33
SLIDE 33

Executable 0xb000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

.text

slide-34
SLIDE 34

Executable 0xb000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

.text

slide-35
SLIDE 35

Executable 0xb400 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

.text

slide-36
SLIDE 36

Executable 0xb400 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

.text

slide-37
SLIDE 37

Executable 0xd000 .text .text .data .data .debug .debug .text : { *(.text*) } . = . + 0x400 .data : { *(.data*) }

.text

.data

slide-38
SLIDE 38

Executable 0xd000

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-39
SLIDE 39

Executable 0xd000

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-40
SLIDE 40

Executable 0xd000

text_start

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-41
SLIDE 41

Executable 0xd000

text_start

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-42
SLIDE 42

Executable 0xd400

.text

0xd000

text_start

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-43
SLIDE 43

Executable 0xd400

.text

0xd000

text_start

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-44
SLIDE 44

Executable

.text

0xd000

text_start

0xd400

text_end

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-45
SLIDE 45

Executable

.text

0xd000

text_start

0xd400

text_end

.text : { text_start = . *(.text*) text_end = . } text_size = SIZEOF(.text)

slide-46
SLIDE 46

Executable

.text

0x400 text_size 0xd000

text_start

0xd400

text_end

.text : { text_start = . *(.text*) text_end = . }

slide-47
SLIDE 47

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); }

slide-48
SLIDE 48

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); }

slide-49
SLIDE 49

extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }

slide-50
SLIDE 50

extern char text_size[], text_start[], text_end[]; int main() { memcpy( buf, (void *)&text_start, (size_t)&text_size); }

slide-51
SLIDE 51

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); }

slide-52
SLIDE 52

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); }

slide-53
SLIDE 53

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); }

slide-54
SLIDE 54

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); }

slide-55
SLIDE 55

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); }

slide-56
SLIDE 56

Symbol Table foo bar ... text_start text_size 12 ...

.ld

exe

slide-57
SLIDE 57

OOPSLA'16

slide-58
SLIDE 58

OOPSLA'16

.o

.ld

.o

exe

slide-59
SLIDE 59

OOPSLA'16

.o

.ld

.o

exe

.ld

exe

text_start text_size 0xd 0xc

Symbol Table

slide-60
SLIDE 60

Four Functions

slide-61
SLIDE 61

Four Functions addrS addrE : ident ⇀ ℕ symbS symbE : ident ⇀ ident

slide-62
SLIDE 62

Four Functions addrS addrE : ident ⇀ ℕ

.text

0x400 text_size 0xd000

text_start

0xd400

text_end

symbS symbE : ident ⇀ ident

slide-63
SLIDE 63

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

slide-64
SLIDE 64

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

slide-65
SLIDE 65

Four Functions addrS addrE : ident ⇀ ℕ

.text

0x400 text_size 0xd000

text_start

0xd400

text_end

symbS symbE : ident ⇀ ident

addrE = .text ↦ 0xd400

slide-66
SLIDE 66

Grammar

slide-67
SLIDE 67

Grammar

MEMORY { } Memory Directives

slide-68
SLIDE 68

Grammar

MEMORY { } SECTIONS { } Memory Directives Section Directives

slide-69
SLIDE 69

Grammar

MEMORY { } SECTIONS { } Memory Directives Section Directives Global Assignments

slide-70
SLIDE 70

Grammar

MEMORY { } SECTIONS { }

.text : { text_start = .; *(.text*) text_end = .; }

slide-71
SLIDE 71

Grammar

MEMORY { } SECTIONS { }

text_size = SIZEOF(.text);

slide-72
SLIDE 72

Grammar

MEMORY { } SECTIONS { }

rom : ORIGIN = 0x2000, LENTGH = 0x400;

slide-73
SLIDE 73

Expressions

slide-74
SLIDE 74

Expressions

slide-75
SLIDE 75

Expressions

slide-76
SLIDE 76

Expressions

slide-77
SLIDE 77

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

slide-78
SLIDE 78

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

slide-79
SLIDE 79

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

slide-80
SLIDE 80

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀

slide-81
SLIDE 81

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀

slide-82
SLIDE 82

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀

slide-83
SLIDE 83

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀ ⇀ ⇀

slide-84
SLIDE 84

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀

slide-85
SLIDE 85

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀

slide-86
SLIDE 86

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀

slide-87
SLIDE 87

Interpretation addrS

MEMORY { } SECTIONS { }

symbS addrE symbE

⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀ ⇀

slide-88
SLIDE 88
slide-89
SLIDE 89
slide-90
SLIDE 90

.text

0x400 text_size 0xd000

text_start

0xd400

text_end

slide-91
SLIDE 91

CAV'18

Implemented in CBMC

slide-92
SLIDE 92
  • Static analysers need to understand

program behaviour

  • Linker scripts introduce information

unavailable to static analyser

  • Solution: parse linker scripts, integrate

into static analysis