Support padding unaligned data in .text.
authorJoerg Sonnenberger <joerg@bec.de>
Thu, 2 Oct 2014 13:41:42 +0000 (13:41 +0000)
committerJoerg Sonnenberger <joerg@bec.de>
Thu, 2 Oct 2014 13:41:42 +0000 (13:41 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@218870 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp
test/MC/Mips/unaligned-nops.s [new file with mode: 0644]

index d8e6128cd54d5477bd6164c4537a2375d11d8b0f..efeb54d91b89f355cad91fe878bb4d5357287596 100644 (file)
@@ -367,7 +367,12 @@ bool MipsAsmBackend::writeNopData(uint64_t Count, MCObjectWriter *OW) const {
   // 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)
diff --git a/test/MC/Mips/unaligned-nops.s b/test/MC/Mips/unaligned-nops.s
new file mode 100644 (file)
index 0000000..ebbbb40
--- /dev/null
@@ -0,0 +1,4 @@
+# RUN: llvm-mc -filetype=obj  -triple=mipsel %s -o %t
+.byte 1
+.p2align 2
+foo: