[PATCH] D132482: RISCV: permit unaligned nop-slide padding emission
Saleem Abdulrasool via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Aug 23 10:50:08 PDT 2022
compnerd updated this revision to Diff 454894.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D132482/new/
https://reviews.llvm.org/D132482
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/test/MC/RISCV/nop-slide.s
Index: llvm/test/MC/RISCV/nop-slide.s
===================================================================
--- /dev/null
+++ llvm/test/MC/RISCV/nop-slide.s
@@ -0,0 +1,12 @@
+# RUN: llvm-mc -triple riscv64 -filetype obj -o - %s | llvm-objdump -d - | FileCheck %s
+
+ .balign 4
+ .byte 0
+
+ .balign 4
+ auipc a0, 0
+
+# CHECK: 0000000000000000 <.text>:
+# CHECK-NEXT: 0: 00 00 <unknown>
+# CHECK-NEXT: 2: 00 00 <unknown>
+# CHECK-NEXT: 4: 17 05 00 00 auipc a0, 0
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -354,20 +354,21 @@
bool RISCVAsmBackend::writeNopData(raw_ostream &OS, uint64_t Count,
const MCSubtargetInfo *STI) const {
- bool HasStdExtC = STI->getFeatureBits()[RISCV::FeatureStdExtC];
- unsigned MinNopLen = HasStdExtC ? 2 : 4;
-
- if ((Count % MinNopLen) != 0)
- return false;
-
// The canonical nop on RISC-V is addi x0, x0, 0.
for (; Count >= 4; Count -= 4)
OS.write("\x13\0\0\0", 4);
// The canonical nop on RVC is c.nop.
- if (Count && HasStdExtC)
- OS.write("\x01\0", 2);
-
+ if (STI->getFeatureBits()[RISCV::FeatureStdExtC])
+ for (; Count >= 2; Count -= 2)
+ OS.write("\x01\0", 2);
+
+ // If the count is not 4-byte aligned (or 2-byte under the C extensions), 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. This also may occur for non-standard data sections which are not
+ // declared and thus get detected as text rather than data.
+ OS.write_zeros(Count);
return true;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132482.454894.patch
Type: text/x-patch
Size: 1822 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220823/f6e406cb/attachment.bin>
More information about the llvm-commits
mailing list