[Not an expert but here's my understanding of what Joe is saying.]
- Library gets loaded -> it gets assigned some pages of the virtual address space.
- Library is used -> other pages now contain (direct) pointers into the pages for this library.
- Library is unloaded -> you have dangling pointers.
- Library is reloaded -> is gets assigned some pages of the virtual address space, which are likely different from the first time around.
- You or the runtime dereferences a dangling pointer while trying to reuse the library.
Put another way, this is another flavor of iterator invalidation (or use after free) where you move the object and if you have an iterator pointing into the space where the old object was present, then dereferencing that iterator is not appropriate. There are a few possible solutions:
- Don't move the object.
- Don't use interior iterators, use offsets.
- Don't maintain interior iterators across moves (or if you maintain them, don't use them which is basically the same thing).
Function calls for position-independent code use solution 2. -- which is maybe what you have in mind by the "refreshed" -- via the procedure linkage table (PLT), but that doesn't apply to arbitrary derived pointers, such as those created by the Swift runtime or your own code.