Fix #1084 and #1085 (miscellaneous issues with --modules=instantiate)

The following commits close the bugs #1084 and #1085, and add regression tests.