Fix handling of relocations with r_extern == 0.
If r_extern == 0 then r_symbolnum is an index of a section rather than a symbol index.
This diff is essentially an updated version of https://reviews.llvm.org/D71647 by @seiya,
the code has been slightly refactored, the test has been converted to YAML.
This change depends on https://reviews.llvm.org/D78898.
Test plan: make check-all