program behaviour
play

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


  1. Program Behaviour

  2. Program Behaviour semantics .c .c .c source program code inputs

  3. Program Behaviour semantics .c .c .c source program code inputs Next Talk: other things

  4. Program Behaviour semantics .c .c .c source program code inputs Next Talk: This Talk: other things the linker

  5. .c .c .c .c

  6. .c .c .c .c compile .o .o

  7. .c .c .c .c compile .o .o link exe

  8. concatenate .c .c .c .c compile .c .o .o link exe

  9. concatenate .c .c .c .c compile .c .o .o compile link exe exe

  10. ≠ concatenate .c .c .c .c compile .c .o .o compile link exe exe

  11. Correctness can depend on how the program was linked

  12. .c

  13. compile .c .o

  14. Sections compile .c .o

  15. Sections .text compile .c .o

  16. Sections .text compile .c .data .o

  17. Sections .text compile .c .data .o .debug

  18. Sections .text compile .c .data .o .debug

  19. Sections .text compile .c .data .o .debug X R W

  20. .text .text .data .data .o .o .debug .debug

  21. .text .text .text .data .data .o .o .data .debug .debug .o link .debug

  22. .text .text .text .data .data .o .o .data .debug .debug .o link .debug - Join sections together - Resolve symbols

  23. Executable 0x0000

  24. Executable 0xb000

  25. Executable 0xb400

  26. Executable 0xc000

  27. Executable 0xca00

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

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

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

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

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

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

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

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

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

  37. .text : { Executable text_start = . *(.text*) text_end = . 0xd000 } text_size = SIZEOF(.text)

  38. .text : { Executable text_start = . *(.text*) text_end = . 0xd000 } text_size = SIZEOF(.text)

  39. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = SIZEOF(.text)

  40. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = SIZEOF(.text)

  41. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = .text SIZEOF(.text) 0xd400

  42. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = .text SIZEOF(.text) 0xd400

  43. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = .text SIZEOF(.text) text_end 0xd400

  44. .text : { Executable text_start = . *(.text*) text_end = . text_start } 0xd000 text_size = .text SIZEOF(.text) text_end 0xd400

  45. .text : { Executable text_start = . text_size *(.text*) 0x400 text_end = . text_start } 0xd000 .text text_end 0xd400

  46. extern char Executable text_size[], text_size text_start[], 0x400 text_end[]; text_start int main() { 0xd000 assert(&text_size .text == (char*)0x400); assert(&text_start text_end == (char*)0xd000); 0xd400 }

  47. extern char Executable text_size[], text_size text_start[], 0x400 text_end[]; text_start int main() { 0xd000 memcpy( .text buf, (void *)&text_start, (size_t)&text_size); text_end } 0xd400

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

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

  50. extern char Symbol Table text_size[], foo 12 text_start[], text_end[]; bar 0 int main() { ... ... text_start ??? memcpy( buf, text_size ??? (void *)&text_start, (size_t)&text_size); }

  51. extern char linker_syms.h text_size[], text_start[], char text_start[]; text_end[]; &text_start int main() { = 0xd000; memcpy( buf, char text_size[]; (void *)&text_start, (size_t)&text_size); &text_size = 0x400; }

  52. extern char linker_syms.h text_size[], text_start[], char text_start[]; text_end[]; &text_start int main() { = 0xd000; memcpy( buf, char text_size[]; (void *)&text_start, (size_t)&text_size); &text_size = 0x400; }

  53. extern char linker_syms.h text_size[], text_start[], size_t text_start; text_end[]; text_start int main() { = 0xd000; memcpy( buf, size_t text_size; (void *) text_start, (size_t) text_size); text_size = 0x400; }

  54. extern char linker_syms.h text_size[], text_start[], size_t text_start; text_end[]; text_start int main() { = 0xd000; memcpy( buf, size_t text_size; (void *) text_start, (size_t) text_size); text_size = 0x400; }

  55. Symbol Table foo 12 bar 0 .ld ... ... text_start text_size exe

  56. OOPSLA'16

  57. OOPSLA'16 .o .o .ld exe

  58. OOPSLA'16 .o .o .ld .ld exe Symbol Table exe text_start 0xd text_size 0xc

  59. Four Functions

  60. Four Functions addr S addr E : ident ⇀ ℕ symb S symb E : ident ⇀ ident

  61. Four Functions text_size addr S addr E 0x400 : ident ⇀ ℕ text_start 0xd000 symb S symb E : ident ⇀ ident .text text_end 0xd400

  62. Four Functions text_size addr S addr E 0x400 : ident ⇀ ℕ text_start 0xd000 symb S symb E : ident ⇀ ident .text symb S = .text ↦ text_start text_end 0xd400 symb E = .text ↦ text_end

  63. Four Functions text_size addr S addr E 0x400 : ident ⇀ ℕ text_start 0xd000 symb S symb E : ident ⇀ ident .text addr S = .text ↦ 0xd000 text_end text_size ↦ 0x400 0xd400 text_end ↦ 0xd400 text_start ↦ 0xd000

  64. Four Functions text_size addr S addr E 0x400 : ident ⇀ ℕ text_start 0xd000 symb S symb E : ident ⇀ ident .text text_end addr E = 0xd400 .text ↦ 0xd400

  65. Grammar

  66. Grammar MEMORY { Memory Directives }

  67. Grammar MEMORY { Memory Directives } SECTIONS { Section Directives }

  68. Grammar MEMORY { Memory Directives } SECTIONS { Section Directives } Global Assignments

  69. Grammar MEMORY { .text : { text_start = .; } *(.text*) text_end = .; SECTIONS { } }

  70. Grammar MEMORY { text_size = SIZEOF(.text); } SECTIONS { }

  71. Grammar MEMORY { rom : ORIGIN = } 0x2000, LENTGH = SECTIONS { 0x400; }

  72. Expressions

  73. Expressions

  74. Expressions

  75. Expressions

  76. Interpretation addr S MEMORY { symb S } SECTIONS { symb E } addr E

  77. Interpretation addr S ⇀ MEMORY { symb S } SECTIONS { symb E } addr E

  78. Interpretation addr S ⇀ MEMORY { symb S } SECTIONS { symb E } addr E

  79. Interpretation addr S ⇀ ⇀ MEMORY { symb S } SECTIONS { symb E } addr E

  80. Interpretation addr S ⇀ ⇀ MEMORY { symb S ⇀ } SECTIONS { symb E } addr E ⇀

  81. Interpretation addr S ⇀ ⇀ MEMORY { symb S ⇀ } SECTIONS { symb E } addr E ⇀

  82. Interpretation addr S ⇀ ⇀ MEMORY { symb S ⇀ } ⇀ SECTIONS { symb E ⇀ } addr E ⇀

  83. Interpretation addr S ⇀ ⇀ MEMORY { symb S ⇀ } ⇀ ⇀ SECTIONS { symb E ⇀ ⇀ } addr E ⇀ ⇀

  84. Interpretation addr S ⇀ ⇀ MEMORY { symb S ⇀ } ⇀ ⇀ SECTIONS { symb E ⇀ ⇀ } addr E ⇀ ⇀

  85. Interpretation addr S ⇀ ⇀ MEMORY { ⇀ symb S ⇀ } ⇀ ⇀ SECTIONS { symb E ⇀ ⇀ } addr E ⇀ ⇀

  86. Interpretation addr S ⇀ ⇀ MEMORY { ⇀ symb S ⇀ } ⇀ ⇀ SECTIONS { symb E ⇀ ⇀ } addr E ⇀ ⇀

  87. text_size 0x400 text_start 0xd000 .text text_end 0xd400

  88. CAV'18 Implemented in CBMC

  89. - Static analysers need to understand program behaviour - Linker scripts introduce information unavailable to static analyser - Solution: parse linker scripts, integrate into static analysis

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend