[PATCH] D42421: [LLD][ELF] Make --fix-cortex-a53-843419 work on big endian hosts

Peter Smith via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Jan 23 07:25:47 PST 2018


peter.smith created this revision.
peter.smith added reviewers: ruiu, rafael.
Herald added subscribers: kristof.beyls, arichardson, javed.absar, emaste, aemerson.

The reinterpret cast to uint32_t to read the little-endian instructions will only work on a little endian system. Use ulittle32_t to always read little-endian (AArch64 instructions are always little endian).

Fixes PR36056: https://bugs.llvm.org/show_bug.cgi?id=36056

An alternative logically equivalent fix is to use read32le into a uint32_t but that is slightly more of a change to the structure of the code. I've uploaded to the PR a prototype fix under https://bugs.llvm.org/attachment.cgi?id=19727 and can use that if you prefer.

Found by Simon Dardis during release candidate testing on a Mips Big Endian system.


https://reviews.llvm.org/D42421

Files:
  ELF/AArch64ErrataFix.cpp


Index: ELF/AArch64ErrataFix.cpp
===================================================================
--- ELF/AArch64ErrataFix.cpp
+++ ELF/AArch64ErrataFix.cpp
@@ -47,6 +47,7 @@
 using namespace llvm;
 using namespace llvm::ELF;
 using namespace llvm::object;
+using namespace llvm::support;
 using namespace llvm::support::endian;
 
 using namespace lld;
@@ -357,14 +358,14 @@
 
   uint64_t PatchOff = 0;
   const uint8_t *Buf = IS->Data.begin();
-  const uint32_t *InstBuf = reinterpret_cast<const uint32_t *>(Buf + Off);
-  uint32_t Instr1 = *InstBuf++;
-  uint32_t Instr2 = *InstBuf++;
-  uint32_t Instr3 = *InstBuf++;
+  const ulittle32_t *InstBuf = reinterpret_cast<const ulittle32_t *>(Buf + Off);
+  ulittle32_t Instr1 = *InstBuf++;
+  ulittle32_t Instr2 = *InstBuf++;
+  ulittle32_t Instr3 = *InstBuf++;
   if (is843419ErratumSequence(Instr1, Instr2, Instr3)) {
     PatchOff = Off + 8;
   } else if (OptionalAllowed && !isBranch(Instr3)) {
-    uint32_t Instr4 = *InstBuf++;
+    ulittle32_t Instr4 = *InstBuf++;
     if (is843419ErratumSequence(Instr1, Instr2, Instr4))
       PatchOff = Off + 12;
   }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D42421.131068.patch
Type: text/x-patch
Size: 1112 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180123/bb67abf6/attachment.bin>


More information about the llvm-commits mailing list