Reapply r110396, with fixes to appease the Linux buildbot gods.