[llvm] r347922 - Produce an error on non-encodable offsets for darwin ARM scattered relocations.
Jonas Devlieghere via llvm-commits
llvm-commits at lists.llvm.org
Thu Nov 29 13:58:23 PST 2018
Author: jdevlieghere
Date: Thu Nov 29 13:58:23 2018
New Revision: 347922
URL: http://llvm.org/viewvc/llvm-project?rev=347922&view=rev
Log:
Produce an error on non-encodable offsets for darwin ARM scattered relocations.
Scattered ARM relocations for Mach-O's only have 24 bits available to
encode the offset. This is not checked but just truncated and can result
in corrupt binaries after linking because the relocations are applied to
the wrong offset. This patch will check and error out in those
situations instead of emitting a wrong relocation.
Patch by: Sander Bogaert (dzn)
Differential revision: https://reviews.llvm.org/D54776
Added:
llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-offset-scattered.s
Modified:
llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
Modified: llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp?rev=347922&r1=347921&r2=347922&view=diff
==============================================================================
--- llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp (original)
+++ llvm/trunk/lib/Target/ARM/MCTargetDesc/ARMMachObjectWriter.cpp Thu Nov 29 13:58:23 2018
@@ -22,6 +22,8 @@
#include "llvm/MC/MCSection.h"
#include "llvm/MC/MCValue.h"
#include "llvm/Support/ErrorHandling.h"
+#include "llvm/Support/ScopedPrinter.h"
+
using namespace llvm;
namespace {
@@ -144,6 +146,15 @@ RecordARMScatteredHalfRelocation(MachObj
MCValue Target,
uint64_t &FixedValue) {
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+
+ if (FixupOffset & 0xff000000) {
+ Asm.getContext().reportError(Fixup.getLoc(),
+ "can not encode offset '0x" +
+ to_hexString(FixupOffset) +
+ "' in resulting scattered relocation.");
+ return;
+ }
+
unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
unsigned Type = MachO::ARM_RELOC_HALF;
@@ -250,6 +261,15 @@ void ARMMachObjectWriter::RecordARMScatt
unsigned Log2Size,
uint64_t &FixedValue) {
uint32_t FixupOffset = Layout.getFragmentOffset(Fragment)+Fixup.getOffset();
+
+ if (FixupOffset & 0xff000000) {
+ Asm.getContext().reportError(Fixup.getLoc(),
+ "can not encode offset '0x" +
+ to_hexString(FixupOffset) +
+ "' in resulting scattered relocation.");
+ return;
+ }
+
unsigned IsPCRel = Writer->isFixupKindPCRel(Asm, Fixup.getKind());
// See <reloc.h>.
Added: llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-offset-scattered.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-offset-scattered.s?rev=347922&view=auto
==============================================================================
--- llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-offset-scattered.s (added)
+++ llvm/trunk/test/MC/MachO/ARM/bad-darwin-ARM-offset-scattered.s Thu Nov 29 13:58:23 2018
@@ -0,0 +1,15 @@
+@ RUN: not llvm-mc -n -triple armv7-apple-darwin10 %s -filetype=obj -o - 2> %t.err > %t
+@ RUN: FileCheck --check-prefix=CHECK-ERROR < %t.err %s
+
+.text
+.space 0x1029eb8
+
+fn:
+ movw r0, :lower16:(fn2-L1)
+ andeq r0, r0, r0
+L1:
+ andeq r0, r0, r0
+
+fn2:
+
+@ CHECK-ERROR: error: can not encode offset '0x1029EB8' in resulting scattered relocation.
More information about the llvm-commits
mailing list