Index: ELF/Target.cpp =================================================================== --- ELF/Target.cpp +++ ELF/Target.cpp @@ -1638,9 +1638,9 @@ uint64_t SA) { uint32_t Mask = 0xffffffff >> (32 - BSIZE); uint32_t Instr = read32(Loc); - if (SHIFT > 0) - checkAlignment<(1 << SHIFT)>(SA, Type); int64_t V = SA - P; + if (SHIFT > 0) + checkAlignment<(1 << SHIFT)>(V, Type); checkInt(V, Type); write32(Loc, (Instr & ~Mask) | ((V >> SHIFT) & Mask)); } Index: test/ELF/Inputs/mips-align-err.s =================================================================== --- /dev/null +++ test/ELF/Inputs/mips-align-err.s @@ -0,0 +1,2 @@ + .global _foo +_foo: Index: test/ELF/mips-align-err.s =================================================================== --- /dev/null +++ test/ELF/mips-align-err.s @@ -0,0 +1,12 @@ +# REQUIRES: mips +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux %s -o %t.o \ +# RUN: -mcpu=mips32r6 +# RUN: llvm-mc -filetype=obj -triple=mips-unknown-linux \ +# RUN: -mcpu=mips32r6 %S/Inputs/mips-align-err.s -o %t2.o +# RUN: not ld.lld %t.o %t2.o -o %t.exe 2>&1 | FileCheck %s +# CHECK: improper alignment for relocation R_MIPS_PC16 + + .globl __start +__start: +.zero 1 + beqc $5, $6, _foo # R_MIPS_PC16