[llvm] r218870 - Support padding unaligned data in .text.

Joerg Sonnenberger joerg at bec.de
Thu Oct 2 06:41:42 PDT 2014


Author: joerg
Date: Thu Oct  2 08:41:42 2014
New Revision: 218870

URL: http://llvm.org/viewvc/llvm-project?rev=218870&view=rev
Log:
Support padding unaligned data in .text.

Added:
    llvm/trunk/test/MC/Mips/unaligned-nops.s
Modified:
    llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp

Modified: llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp?rev=218870&r1=218869&r2=218870&view=diff
==============================================================================
--- llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp (original)
+++ llvm/trunk/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp Thu Oct  2 08:41:42 2014
@@ -367,7 +367,12 @@ bool MipsAsmBackend::writeNopData(uint64
   // Check for a less than instruction size number of bytes
   // FIXME: 16 bit instructions are not handled yet here.
   // We shouldn't be using a hard coded number for instruction size.
-  if (Count % 4) return false;
+
+  // If the count is not 4-byte aligned, we must be writing data into the text
+  // section (otherwise we have unaligned instructions, and thus have far
+  // bigger problems), so just write zeros instead.
+  for (uint64_t i = 0, e = Count % 4; i != e; ++i)
+    OW->Write8(0);
 
   uint64_t NumNops = Count / 4;
   for (uint64_t i = 0; i != NumNops; ++i)

Added: llvm/trunk/test/MC/Mips/unaligned-nops.s
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/MC/Mips/unaligned-nops.s?rev=218870&view=auto
==============================================================================
--- llvm/trunk/test/MC/Mips/unaligned-nops.s (added)
+++ llvm/trunk/test/MC/Mips/unaligned-nops.s Thu Oct  2 08:41:42 2014
@@ -0,0 +1,4 @@
+# RUN: llvm-mc -filetype=obj  -triple=mipsel %s -o %t
+.byte 1
+.p2align 2
+foo:





More information about the llvm-commits mailing list