runtime.txt 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. "Dumb" runtime organization (revisit if inefficient)
  2. ====================================================
  3. Code is emitted into crates.
  4. We assume a loader that loads a crate at an arbitrary address.
  5. Every crate has a TOC.
  6. The TOC has a set of addresses-of-imported-values that are lazily
  7. resolved, and a set of addresses-of-crates-using-me that are informed
  8. when the crate is reloaded.
  9. One register is always dedicated to the current crate's TOC address.
  10. All intra-crate references are pc-relative if possible, or vector
  11. through fixed offsets in the crate TOC if impossible (for example,
  12. IA32 can only do pc-relative jumps; AMD64 permits general pc-relative
  13. operands).
  14. Thus any change to a file in a crate causes full relinking of the
  15. crate. An aggressive compiler can delay interprocedural optimizations
  16. to the point of crate linking, if it wants.
  17. All inter-crate procedure calls vector through the TOC.
  18. The TOC also contains a "relink" section that can be stripped. The
  19. relink section holds all the relocs in the crate, organized both by
  20. pointee (in order to re-run the relocs when the pointee is reloaded)
  21. and pointer (in order to update the reloc source when pointer is
  22. reloaded). When you reload a module into a relink-capable crate, the
  23. module is either rewritten in-place (if it fits) or mapped into a
  24. fresh location, then incrementally relinked.
  25. See L&L pg 171-172 for a description of the scheme. It's the AIX
  26. convention. It optimizes for the case of fast loading and execution
  27. for large blocks of code, at the expense of slower linking during
  28. development.
  29. Note that this is *not* how loaded ELF or PE code works (well, it's
  30. similar to PE). To interface with that code we will require stub
  31. routines.
  32. One register is also dedicated to top-of-stack. Frame base can be
  33. calculated implicitly from top-of-stack at every point; we don't
  34. support alloca() and we know every allocation size.
  35. Remaining register allocation is either linear-scan or
  36. usage-counting. Either way: *simple*.
  37. Procs consist of a control block and a stack. Each proc's stack is a
  38. linked list of stack pages. Each stack page is a power-of-two from a
  39. buddy allocator.
  40. Procs are grouped into single-threaded OS processes. OS processes
  41. communicate over unix domain sockets (or a win32 socket/pipe?), and
  42. can pass capabilities to one another over these channels via sendmsg()
  43. and SCM_RIGHTS (or DuplicateHandle in win32?).