Module loading is something that can be added to a language later, but I suspect safe module unloading is something that has to go in from day one to ever work right. Even in languages that support it (Erlang) it's got a tricky list of caveats to keep track of that strike me as fairly essential to the problem, rather than accidental (in the Fred Brooks sense of the terms).
Hence why Java and .NET restrict it to Class Loaders/AppDomains.
- no thread is running code in the plugin.
- no thread has a return address on the stack somewhere in the plugin.
- no variable stores a pointer pointing into the plugin (This includes objects whose destructor is implemented in the plugin)
- no signal handler points into the plugin.
- no kernel thread is reading the plug-ins memory.
In addition there are race conditions to take care of (e.g. thread T unloads a plugin that thread U is loading)
With a 64 bit address space, I guess you can get around most if not all problems by mapping the memory that was mapped to the plugin as "can't read, can't write, can't execute", so that you crash hard if somebody tries to access it, but if you do that, you can just as well keep the code around.
Go is garbage-collected, so it likely already has a lot of the logic to do this, but even then, combining the functionality to get a robust implementation of plugin unloading is a lot of work.
Why not?