roc/linker
2021-09-14 13:30:19 +02:00
..
src recurse on lambda set in wasm backend 2021-09-14 13:30:19 +02:00
tests/fib Fix issue with offsets and update some printing 2021-08-28 14:57:52 -07:00
Cargo.toml Change package versions back to default 2021-09-03 20:00:48 -07:00
README.md Add TODO discussing merging with main compiler 2021-09-08 15:52:42 -07:00

The Roc Surgical Linker

This linker has the goal of being extremely slim lined and fast. It is focused on the scope of only linking platforms to Roc applications. This restriction enables ignoring most of linking.

General Overview

This linker is run in 2 phases: preprocessing and surigical linking.

Platform Preprocessor

  1. Dynamically link the platform to a dummy Roc application dynamic library
  2. Create metadata related to Roc dynamically linked functions
    • Symbols that need to be redefined
    • Call locations that need to be modified for each symbol
    • Locations of special roc functions (roc_alloc, roc_dealloc, builtins, etc)
  3. Modify the main executable to no longer be dynamically link
    • Delete dependency on dynamic library
    • Remove symbols from the dynamic table (maybe add them to the regular table?)
    • Delete GOT and PLT entries
    • Remove relocations from the dynamic table
    • Add extra header information about new text and data section at end of file

Surgical Linker

  1. Build off of preprocessed platform
  2. Append text and data of application, dealing with app relocations
  3. Surgically update all call locations in the platform
  4. Surgically update call information in the application (also dealing with other relocations for builtins)

TODO for merging with compiler flow

  1. Add new compiler flag to hide this all behind.
  2. Get compiler to generate dummy shared libraries with Roc exported symbols defined.
  3. Modify host linking to generate dynamic executable that links against the dummy lib.
  4. Call the preprocessor on the dynamic executable host.
  5. Call the surgical linker on the emitted roc object file and the preprocessed host.
  6. Enjoy!
  7. Extract preprocessing generation to run earlier, maybe in parallel with the main compiler until we have full precompiled hosts.
  8. Maybe add a roc command to generate the dummy lib to be used by platform authors.