[PATCH] D70652: [X86][MC] no error diagnostic for out-of-range jrcxz/jecxz/jcxz
Alexey Lapshin via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Sun Nov 24 22:18:07 PST 2019
avl created this revision.
avl added reviewers: craig.topper, RKSimon, spatel.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.
This is the fix for PR24072:
X86 instructions jrcxz/jecxz/jcxz performs short jumps if rcx/ecx/cx register is 0
The maximum relative offset for a forward short jump is 127 Bytes (0x7F).
The maximum relative offset for a backward short jump is 128 Bytes (0x80).
Gnu assembler warns when the distance of the jump exceeds the maximum but llvm-as does not.
The fix for that problem was already presented for review : D36991 <https://reviews.llvm.org/D36991>
The llvm codebase changed since August of 2017, thus it does not pass
current check-all testing. I limited it for only PCRel fixups and to
not check not-resolved symbols.
https://reviews.llvm.org/D70652
Files:
llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
llvm/test/MC/MachO/reloc.s
llvm/test/MC/X86/x86-jcxz-loop-fixup.s
Index: llvm/test/MC/X86/x86-jcxz-loop-fixup.s
===================================================================
--- /dev/null
+++ llvm/test/MC/X86/x86-jcxz-loop-fixup.s
@@ -0,0 +1,26 @@
+# RUN: not llvm-mc -filetype=obj -triple=x86_64-linux-gnu %s 2>&1 | FileCheck %s
+
+ .balign 128
+label00:
+// CHECK: value of 253 is too large for field of 1 byte.
+ jecxz label01
+// CHECK: value of 251 is too large for field of 1 byte.
+ jrcxz label01
+// CHECK: value of 249 is too large for field of 1 byte.
+ loop label01
+// CHECK: value of 247 is too large for field of 1 byte.
+ loope label01
+// CHECK: value of 245 is too large for field of 1 byte.
+ loopne label01
+ .balign 256
+label01:
+// CHECK: value of -259 is too large for field of 1 byte.
+ jecxz label00
+// CHECK: value of -261 is too large for field of 1 byte.
+ jrcxz label00
+// CHECK: value of -263 is too large for field of 1 byte.
+ loop label00
+// CHECK: value of -265 is too large for field of 1 byte.
+ loope label00
+// CHECK: value of -267 is too large for field of 1 byte.
+ loopne label00
Index: llvm/test/MC/MachO/reloc.s
===================================================================
--- llvm/test/MC/MachO/reloc.s
+++ llvm/test/MC/MachO/reloc.s
@@ -37,7 +37,7 @@
.text
_f0:
L1:
- jmp 0xbabecafe
+ jmp 0x7abecafe
jmp L0
jmp L1
ret
Index: llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
===================================================================
--- llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
+++ llvm/lib/Target/X86/MCTargetDesc/X86AsmBackend.cpp
@@ -12,11 +12,14 @@
#include "llvm/BinaryFormat/ELF.h"
#include "llvm/BinaryFormat/MachO.h"
#include "llvm/MC/MCAsmBackend.h"
+#include "llvm/MC/MCAssembler.h"
+#include "llvm/MC/MCContext.h"
#include "llvm/MC/MCDwarf.h"
#include "llvm/MC/MCELFObjectWriter.h"
#include "llvm/MC/MCExpr.h"
#include "llvm/MC/MCFixupKindInfo.h"
#include "llvm/MC/MCInst.h"
+#include "llvm/MC/MCValue.h"
#include "llvm/MC/MCMachObjectWriter.h"
#include "llvm/MC/MCObjectWriter.h"
#include "llvm/MC/MCRegisterInfo.h"
@@ -114,12 +117,24 @@
assert(Fixup.getOffset() + Size <= Data.size() && "Invalid fixup offset!");
- // Check that uppper bits are either all zeros or all ones.
- // Specifically ignore overflow/underflow as long as the leakage is
- // limited to the lower bits. This is to remain compatible with
- // other assemblers.
- assert((Size == 0 || isIntN(Size * 8 + 1, Value)) &&
- "Value does not fit in the Fixup field");
+ int64_t SignedValue = static_cast<int64_t>(Value);
+ if ((Target.isAbsolute() || IsResolved)
+ && getFixupKindInfo(Fixup.getKind()).Flags &
+ MCFixupKindInfo::FKF_IsPCRel) {
+ // check that PC relative fixup fits into the fixup size.
+ if (Size > 0 && !isIntN(Size * 8, SignedValue))
+ Asm.getContext().reportError(
+ Fixup.getLoc(), "value of " + Twine(SignedValue) +
+ " is too large for field of " + Twine(Size) +
+ ((Size == 1) ? " byte." : " bytes."));
+ } else {
+ // Check that uppper bits are either all zeros or all ones.
+ // Specifically ignore overflow/underflow as long as the leakage is
+ // limited to the lower bits. This is to remain compatible with
+ // other assemblers.
+ assert((Size == 0 || isIntN(Size * 8 + 1, SignedValue)) &&
+ "Value does not fit in the Fixup field");
+ }
for (unsigned i = 0; i != Size; ++i)
Data[Fixup.getOffset() + i] = uint8_t(Value >> (i * 8));
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D70652.230834.patch
Type: text/x-patch
Size: 3666 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191125/c021b5d0/attachment.bin>
More information about the llvm-commits
mailing list