Correct unload of imported vars.

From level99procrastinator, just slightly adjusted.
Merge pull request #7055 from unknownbrackets/reloc-fix

Correct unload of imported vars