From f148a6d498e2636ef82b44e0d0aecd72209aca35 Mon Sep 17 00:00:00 2001 From: Joerg Sonnenberger Date: Thu, 2 Oct 2014 13:41:42 +0000 Subject: [PATCH] Support padding unaligned data in .text. llvm-svn: 218870 --- llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp | 7 ++++++- llvm/test/MC/Mips/unaligned-nops.s | 4 ++++ 2 files changed, 10 insertions(+), 1 deletion(-) create mode 100644 llvm/test/MC/Mips/unaligned-nops.s diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp index d8e6128cd54d..efeb54d91b89 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsAsmBackend.cpp @@ -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/llvm/test/MC/Mips/unaligned-nops.s b/llvm/test/MC/Mips/unaligned-nops.s new file mode 100644 index 000000000000..ebbbb40f4dc6 --- /dev/null +++ b/llvm/test/MC/Mips/unaligned-nops.s @@ -0,0 +1,4 @@ +# RUN: llvm-mc -filetype=obj -triple=mipsel %s -o %t +.byte 1 +.p2align 2 +foo: