dynamic loading

This still lacks thorough testing so there are likely some bugs but it supports
almost all dynamic loading scenarios, including loading shared libraries in different threads.

depends on #587, #589, #590, #591 and #592