This is a rebased version https://reviews.llvm.org/D42176 which
is patch by Nicolas Wilson.
Addresses issue: https://github.com/WebAssembly/tool-conventions/issues/32,
and https://bugs.llvm.org/show_bug.cgi?id=38650
Previously, for each function/segment we iterated over every relocation
to find the relevant ones, which is an n^2 operation. Now, we just make
a single pass.