Implement LTO

The first commit was approved from another pull request, but I wanted to rebase LTO on top of it.

LTO is not turned on by default at all, and it's hidden behind a `-Z` flag. I have added a few small tests for it, however.