Use size_t for array index.
Fix flaky elf/X86_64/dynlib-search.test.

Output to llvm::err() is not guaranteed to be thread-safe, so it needs
to be guarded with a lock.

Differential Revision: http://llvm-reviews.chandlerc.com/D1862