This recommits cc0b9647 which was reverted in d39d1a2f. I added a fix for an issue found when testing via distributed ThinLTO, and added a test case for that failure.