mir
mir copied to clipboard
unloading modules
It would be very useful to have the ability to unload a module and relink.
I am not sure if it is possible to just remove the module from the item list in the mir context...
Currently you can load and link module containing exported functions with the same names. All references linked to previous functions will be redirected to new functions as all calls are done through thunks. For exported bss/data, it will not work. I did not implement analogous thing (thunks for data) for them as this considerably decrease the generated code performance in general case.
Removing thunks could improve performance but would require binary patching already generated code. Possibility of patching binary code would disable some optimizations and require adding a lot of machine-dependent code for each target.
what I am mainly looking at is the ability to remove a module that was already linked, freeing all the resources it is taking (data and code pages)
It can be done. The biggest challenge for this is to implement some kind of allocator with freeing space or GC of generated code. I am going to work on this as I see I'll need this too. It will be needed for me too when I implement more active re-jitting for my own MIR based JIT. Although I cannot say when it will be done.
Currently you can load and link module containing exported functions with the same names. All references linked to previous functions will be redirected to new functions as all calls are done through thunks.
what if I add module A (using MIR_change_module_ctx
) with exported function FUNC, and then add module B with exported function FUNC, would the function get overidden as you described it? Also is it possible to use MIR_change_module_ctx
to move a module to another context that already has that module name? will it just merge them?
what if I add module A (using
MIR_change_module_ctx
) with exported function FUNC, and then add module B with exported function FUNC, would the function get overidden as you described it? Yes but only in context where B is added.
Also is it possible to use
MIR_change_module_ctx
to move a module to another context that already has that module name? will it just merge them?
Yes, you can move such module. Module names can be considered as comments (or as just base file names). There is no module merge. Simply you will have 2 different modules with the same name in the context.