Execuation Explained
Overview
https://www.youtube.com/watch?v=Ss2e6JauS0Y
https://www.slideshare.net/AngelBoy1/execution-50215114 (recommended)
keyword: dynamic linker, rellocation, PIC, GOT, PLT
Preliminary
Unix Process Memory Layout
https://www.geeksforgeeks.org/memory-layout-of-c-program/
keyword: section, segment, variable, allocation.
Build Process
CS61C:https://drive.google.com/file/d/1Gg1pKejSDy_dUPWdwQ1zuquI0RW8UKUu/view?pli=1
Linker
Memory Mapping
Dynamic linking - Code sharing
https://bottomupcs.com/ch09s03.html
https://github.com/jserv/min-dl
https://hackmd.io/@RinHizakura/S1tNA0RZv
keyword: virtual memory, shared library
Elf specification
ELF Document:
https://www.cs.cmu.edu/afs/cs/academic/class/15213-f00/docs/elf.pdf
ELF explained:
https://www.youtube.com/watch?v=nC1U1LJQL8o
Linker & Loader:
https://www.cs.cornell.edu/courses/cs3410/2013sp/lecture/15-linkers2-w.pdf
Lazy binding - Startup time reduction
https://stackoverflow.com/questions/63745016/why-use-lazy-binding-for-position-independent-code-function-calls
https://rafaelchen.wordpress.com/2017/09/25/pwn%e7%9a%84%e4%bf%ae%e7%85%89%e4%b9%8b%e8%b7%af-lazy-binding/#more-1244
Position Independent Code
https://docs.oracle.com/cd/E26505_01/html/E26506/glmqp.html
https://bottomupcs.com/ch09s02.html#dynamic_linker_s2
In an executable file, the code and data segment is given a specified base address in virtual memory. The executable code is not shared, and each executable gets its own fresh address space. This means that the compiler knows exactly where the data section will be, and can reference it directly.
Consequently all libraries must be produced with code that can execute no matter where it is put into memory, known as position independent code (or PIC for short). Note that the data section is still a fixed offset from the code section; but to actually find the address of data the offset needs to be added to the load address.
.got - Runtime symbol resolve
https://bottomupcs.com/ch09s03.html
_start - The entry point of the program
1 | 0000000000001050 <_start>: |
__libc_start_main - Initialization funtion
https://hammertux.github.io/libc-start
https://bottomupcs.com/ch08s08.html#startup
Signature of __libc_start_main.
1 | int __libc_start_main(int (*main)(int, char *[], char *[]), int argc, char *argv[], void (*init)(void), void (*fini)(void), void (*rtld_fini)(void), void *stack_end) { |
keyword: __libc_start_main, .init, .fini, __do_global_ctors_aux
Appendix
Stack allocation padding and alignment - Performance
https://stackoverflow.com/questions/1061818/stack-allocation-padding-and-alignment
keyword: cache block size, data structure alignment, performance.
__Attribute__
In C, __attribute__ is a keyword-like syntax extension that allows you to provide additional information or directives to the compiler about various attributes of a function, variable, or type.
1 | void __attribute__((constructor)) program_init(void) { |