mir icon indicating copy to clipboard operation
mir copied to clipboard

unloading modules

Open Itay2805 opened this issue 2 years ago • 5 comments

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...

Itay2805 avatar May 23 '22 18:05 Itay2805

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.

vnmakarov avatar May 24 '22 13:05 vnmakarov

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)

Itay2805 avatar Jun 04 '22 21:06 Itay2805

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.

vnmakarov avatar Jun 07 '22 14:06 vnmakarov

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?

Itay2805 avatar Jun 08 '22 08:06 Itay2805

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.

vnmakarov avatar Jun 08 '22 15:06 vnmakarov