[PATCH] D122236: [RISCV] Fix crash for initial section alignment with .option norvc
Luís Marques via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 22 09:07:46 PDT 2022
luismarques created this revision.
luismarques added reviewers: shiva0217, asb, jrtc27.
Herald added subscribers: s, VincentWu, luke957, StephenFan, vkmr, frasercrmck, evandro, apazos, sameer.abuasal, s.egerton, Jim, benna, psnobl, jocewei, PkmX, the_o, brucehoult, MartinMosbeck, rogfer01, edward-jones, zzheng, kito-cheng, niosHD, sabuasal, simoncook, johnrusso, rbar, hiraditya, arichardson.
Herald added a project: All.
luismarques requested review of this revision.
Herald added subscribers: llvm-commits, pcwang-thead, eopXD, MaskRay.
Herald added a project: LLVM.
The existing code wasn't getting the subtarget info from the fragment, so the current status of RVC would be ignored. This would cause a crash for the new test case when the target then reported it couldn't write the requested number of code alignment bytes.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D122236
Files:
llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
llvm/test/MC/RISCV/align.s
Index: llvm/test/MC/RISCV/align.s
===================================================================
--- llvm/test/MC/RISCV/align.s
+++ llvm/test/MC/RISCV/align.s
@@ -112,3 +112,11 @@
# C-EXT-RELAX-RELOC-NOT: R_RISCV_ALIGN
data2:
.word 9
+# Check that the initial alignment is properly handled when using .option to
+# disable the C extension. This used to crash.
+# C-EXT-RELAX-INST: <.text2>:
+# C-EXT-RELAX-INST-NEXT: add a0, a0, a1
+ .section .text2, "x"
+ .option norvc
+ .balign 4
+ add a0, a0, a1
Index: llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
===================================================================
--- llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
+++ llvm/lib/Target/RISCV/MCTargetDesc/RISCVAsmBackend.cpp
@@ -583,10 +583,11 @@
bool RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign(
const MCAlignFragment &AF, unsigned &Size) {
// Calculate Nops Size only when linker relaxation enabled.
- if (!STI.getFeatureBits()[RISCV::FeatureRelax])
+ const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+ if (!STI->getFeatureBits()[RISCV::FeatureRelax])
return false;
- bool HasStdExtC = STI.getFeatureBits()[RISCV::FeatureStdExtC];
+ bool HasStdExtC = STI->getFeatureBits()[RISCV::FeatureStdExtC];
unsigned MinNopLen = HasStdExtC ? 2 : 4;
if (AF.getAlignment() <= MinNopLen) {
@@ -606,7 +607,8 @@
const MCAsmLayout &Layout,
MCAlignFragment &AF) {
// Insert the fixup only when linker relaxation enabled.
- if (!STI.getFeatureBits()[RISCV::FeatureRelax])
+ const MCSubtargetInfo *STI = AF.getSubtargetInfo();
+ if (!STI->getFeatureBits()[RISCV::FeatureRelax])
return false;
// Calculate total Nops we need to insert. If there are none to insert
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D122236.417311.patch
Type: text/x-patch
Size: 1847 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220322/796f175f/attachment.bin>
More information about the llvm-commits
mailing list