Skip to content

Handle top-level Addr# literals in the bytecode compiler

Alexis King requested to merge tweag/ghc:addr-literals-in-bytecode into master

This MR fixes #22376 (closed) by changing the way the bytecode compiler, linker, and loader handle top-level Addr# literals. It does not address #22400 in any way, so these literals continue to leak memory, but things are not any worse than the status quo.

The strategy for handling top-level Addr# bindings is outlined in Note [Generating code for top-level string literal bindings] in GHC.StgToByteCode. The design I eventually went with is quite naïve: it just adds another constructor to the BCONPtr type containing a Name, which must refer to top-level Addr# binding. The memory for the bindings is still allocated in the same way, and the linker just bakes the address into the compiled BCO in the same way the bytecode compiler handles local Addr# bindings. I am not entirely satisfied with this, as it makes no progress at all towards #22400, but my original approach (which involved support to allow the Addr# bindings to be freed when a BCO is unloaded) ended up being much more invasive than I had hoped, so I’ve decided to just implement the simple patch for now.

Merge request reports