diff --git a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp index 1c0a5ebdcfff..4df92d067ea6 100644 --- a/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp +++ b/llvm/lib/Target/Mips/MCTargetDesc/MipsELFObjectWriter.cpp @@ -70,7 +70,7 @@ unsigned MipsELFObjectWriter::GetRelocType(const MCValue &Target, switch (Kind) { case Mips::fixup_Mips_32: case FK_Data_4: - return ELF::R_MIPS_32; + return IsPCRel ? ELF::R_MIPS_PC32 : ELF::R_MIPS_32; case Mips::fixup_Mips_64: case FK_Data_8: return ELF::R_MIPS_64; diff --git a/llvm/test/MC/Mips/relocation.s b/llvm/test/MC/Mips/relocation.s new file mode 100644 index 000000000000..642b40960a65 --- /dev/null +++ b/llvm/test/MC/Mips/relocation.s @@ -0,0 +1,10 @@ +// RUN: llvm-mc -filetype=obj -triple mipsel-unknown-linux < %s | llvm-readobj -r | FileCheck %s + +// Test that we produce the correct relocation. +// FIXME: move more relocation only tests here. + + .long foo +// CHECK: R_MIPS_32 foo + + .long foo-. +// CHECK: R_MIPS_PC32 foo