forked from OSchip/llvm-project
AArch64: diagnose out of range relocation addends on MachO.
MachO only has 24-bit addends for most relocations, small enough that it can overflow in semi-reasonable functions and cause insidious bugs if compiled without assertions enabled. Switch it to an actual error instead. The condition isn't quite identical because ld64 treats the addend as a signed number.
This commit is contained in:
parent
13c9bbc28e
commit
216b67e202
|
@ -373,7 +373,11 @@ void AArch64MachObjectWriter::recordRelocation(
|
|||
Type == MachO::ARM64_RELOC_PAGE21 ||
|
||||
Type == MachO::ARM64_RELOC_PAGEOFF12) &&
|
||||
Value) {
|
||||
assert((Value & 0xff000000) == 0 && "Added relocation out of range!");
|
||||
if (!isInt<24>(Value)) {
|
||||
Asm.getContext().reportError(Fixup.getLoc(),
|
||||
"addend too big for relocation");
|
||||
return;
|
||||
}
|
||||
|
||||
MachO::any_relocation_info MRE;
|
||||
MRE.r_word0 = FixupOffset;
|
||||
|
|
|
@ -0,0 +1,14 @@
|
|||
// RUN: not llvm-mc -triple arm64-apple-ios -filetype=obj -o /dev/null %s 2>&1 | FileCheck %s
|
||||
.global _foo
|
||||
adrp x0, (_foo + 1)@PAGE
|
||||
adrp x0, (_foo - 1)@PAGE
|
||||
adrp x0, (_foo + 0x7fffff)@PAGE
|
||||
adrp x0, (_foo - 0x800000)@PAGE
|
||||
|
||||
// CHECK-NOT: error:
|
||||
// CHECK: error: addend too big for relocation
|
||||
// CHECK: adrp x0, (_foo + 0x800000)@PAGE
|
||||
// CHECK: error: addend too big for relocation
|
||||
// CHECK: adrp x0, (_foo - 0x800001)@PAGE
|
||||
adrp x0, (_foo + 0x800000)@PAGE
|
||||
adrp x0, (_foo - 0x800001)@PAGE
|
Loading…
Reference in New Issue