[llvm] 216b67e - AArch64: diagnose out of range relocation addends on MachO.
Tim Northover via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 27 05:01:30 PDT 2020
Author: Tim Northover
Date: 2020-07-27T13:01:22+01:00
New Revision: 216b67e2023315ff30c2802c911a8ae0c7640c30
URL: https://github.com/llvm/llvm-project/commit/216b67e2023315ff30c2802c911a8ae0c7640c30
DIFF: https://github.com/llvm/llvm-project/commit/216b67e2023315ff30c2802c911a8ae0c7640c30.diff
LOG: 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.
Added:
llvm/test/MC/AArch64/macho-addend-range.s
Modified:
llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
index b0f414bd27ed..012661edbbfd 100644
--- a/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
+++ b/llvm/lib/Target/AArch64/MCTargetDesc/AArch64MachObjectWriter.cpp
@@ -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;
diff --git a/llvm/test/MC/AArch64/macho-addend-range.s b/llvm/test/MC/AArch64/macho-addend-range.s
new file mode 100644
index 000000000000..fdcb9123c768
--- /dev/null
+++ b/llvm/test/MC/AArch64/macho-addend-range.s
@@ -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
More information about the llvm-commits
mailing list