News for hackers. Stuff that matters.
Re:Golang Package: plugin by pjmlp on Thursday September 22, 2016 @08:15AM (#12556251)
Because unloading, while possible is a pain to get right.

Hence why Java and .NET restrict it to Class Loaders/AppDomains.

Re:Golang Package: plugin by Someone on Thursday September 22, 2016 @03:04PM (#12559311)
For those who wonder why: some of the things you have to make sure of are if you want to implement this correctly:

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