diff --git a/lld/ELF/Arch/RISCV.cpp b/lld/ELF/Arch/RISCV.cpp --- a/lld/ELF/Arch/RISCV.cpp +++ b/lld/ELF/Arch/RISCV.cpp @@ -227,9 +227,16 @@ case R_RISCV_TPREL_LO12_S: return R_TLS; case R_RISCV_RELAX: - case R_RISCV_ALIGN: case R_RISCV_TPREL_ADD: return R_HINT; + case R_RISCV_ALIGN: + // Not just a hint; always padded to the worst-case number of NOPs, so may + // not currently be aligned, and without linker relaxation support we can't + // delete NOPs to realign. + error(getErrorLocation(loc) + + "relocation R_RISCV_ALIGN requires unimplemented linker relaxation" + "; recompile with -mno-relax"); + return R_NONE; default: return R_ABS; } @@ -420,7 +427,6 @@ write64le(loc, val - dtpOffset); break; - case R_RISCV_ALIGN: case R_RISCV_RELAX: return; // Ignored (for now) case R_RISCV_NONE: @@ -430,6 +436,8 @@ case R_RISCV_RELATIVE: case R_RISCV_COPY: case R_RISCV_JUMP_SLOT: + // Should have already given an error in getRelExpr + case R_RISCV_ALIGN: // GP-relative relocations are only produced after relaxation, which // we don't support for now case R_RISCV_GPREL_I: diff --git a/lld/test/ELF/riscv-reloc-align.s b/lld/test/ELF/riscv-reloc-align.s new file mode 100644 --- /dev/null +++ b/lld/test/ELF/riscv-reloc-align.s @@ -0,0 +1,12 @@ +# REQUIRES: riscv + +# RUN: llvm-mc -filetype=obj -triple=riscv32-unknown-elf -mattr=+relax %s -o %t.o +# RUN: not ld.lld %t.o -o %t 2>&1 | FileCheck %s + +# CHECK: relocation R_RISCV_ALIGN requires unimplemented linker relaxation + +.global _start +_start: + nop + .balign 8 + nop