Fix linkage on OS X.

Unlike GNU ld, Apple's (BSD's?) doesn't allow linking common with defined
symbols, so we need an explicit "extern" to make accesses to initialized
arrays undefined.
Make the testsuite work on OS X.

Its sed lacks \d, and there's apparently no way to get the escape character,
so let's use perl instead.