[lld-macho] Check address ranges when applying relocations
authorJez Ng <jezng@fb.com>
Fri, 12 Mar 2021 22:26:11 +0000 (17:26 -0500)
committerJez Ng <jezng@fb.com>
Fri, 12 Mar 2021 22:26:27 +0000 (17:26 -0500)
commitdc8bee92658e4ac2314aa2f59123078d49463219
treeee8916b68b3e6e118397365412421f492b2a1772
parent7b5ab956b1ffa16feabc537e057148530156a1c3
[lld-macho] Check address ranges when applying relocations

This diff required fixing `getEmbeddedAddend` to apply sign
extension to 32-bit values. We were previously passing around wrong
64-bit addend values that became "right" after being truncated back to
32-bit.

I've also made `getEmbeddedAddend` return a signed int, which is similar
to what LLD-ELF does for its `getImplicitAddend`.

`reportRangeError`, `checkUInt`, and `checkInt` are counterparts of similar
functions in LLD-ELF.

Reviewed By: #lld-macho, thakis

Differential Revision: https://reviews.llvm.org/D98387
lld/MachO/Arch/ARM64.cpp
lld/MachO/Arch/X86_64.cpp
lld/MachO/InputFiles.cpp
lld/MachO/Relocations.cpp
lld/MachO/Relocations.h
lld/MachO/Target.h
lld/test/MachO/invalid/range-check.s [new file with mode: 0644]