llvm.org GIT mirror llvm / c052b64
[RISCV] Avoid overflow when determining number of nops for code align RISCVAsmBackend::shouldInsertExtraNopBytesForCodeAlign() assumed that the align specified would be greater than or equal to the minimum nop length, but that is not always the case - for example if a user specifies ".align 0" in assembly. Differential Revision: https://reviews.llvm.org/D63274 Patch by Edward Jones. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@366176 91177308-0d34-0410-b5e6-96231b3b80d8 Alex Bradbury 3 months ago
2 changed file(s) with 13 addition(s) and 2 deletion(s). Raw diff Collapse all Expand all
312312 bool HasStdExtC = STI.getFeatureBits()[RISCV::FeatureStdExtC];
313313 unsigned MinNopLen = HasStdExtC ? 2 : 4;
314314
315 Size = AF.getAlignment() - MinNopLen;
316 return true;
315 if (AF.getAlignment() <= MinNopLen) {
316 return false;
317 } else {
318 Size = AF.getAlignment() - MinNopLen;
319 return true;
320 }
317321 }
318322
319323 // We need to insert R_RISCV_ALIGN relocation type to indicate the
8989 ret
9090 # NORELAX-RELOC-NOT: R_RISCV
9191 # C-EXT-NORELAX-RELOC-NOT: R_RISCV
92 # Code alignment of a byte size less than the size of a nop must be treated
93 # as no alignment. This used to trigger a fatal error with relaxation enabled
94 # as the calculation to emit the worst-case sequence of nops would overflow.
95 .p2align 1
96 add a0, a0, a1
97 .p2align 0
98 add a0, a0, a1
9299 # We only need to insert R_RISCV_ALIGN for code section
93100 # when the linker relaxation enabled.
94101 .data