diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp index a556d89c36400..485dd39a52df4 100644 --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -686,8 +686,14 @@ static bool relax(InputSection &sec) { const uint64_t align = PowerOf2Ceil(r.addend + 2); // All bytes beyond the alignment boundary should be removed. remove = nextLoc - ((loc + align - 1) & -align); - assert(static_cast(remove) >= 0 && - "R_RISCV_ALIGN needs expanding the content"); + // If we can't satisfy this alignment, we've found a bad input. + if (LLVM_UNLIKELY(static_cast(remove) < 0)) { + errorOrWarn(getErrorLocation((const uint8_t*)loc) + + "insufficient padding bytes for " + lld::toString(r.type) + + ": " + Twine(r.addend) + " bytes available " + "for requested alignment of " + Twine(align) + " bytes"); + remove = 0; + } break; } case R_RISCV_CALL: