diff --git a/llvm/lib/MC/ELFObjectWriter.cpp b/llvm/lib/MC/ELFObjectWriter.cpp --- a/llvm/lib/MC/ELFObjectWriter.cpp +++ b/llvm/lib/MC/ELFObjectWriter.cpp @@ -1381,6 +1381,16 @@ if (TargetObjectWriter->getEMachine() == ELF::EM_386 && Type == ELF::R_386_GOTOFF) return true; + + // Work around an issue in MIPS relocation handling: both R_MIPS_HI16 and + // R_MIPS_LO16 are considered as absolute relocations (the type is R_ABS). + // When we calculate R_MIPS_HI16's addend we find a paired R_MIPS_LO16, + // generate a combined addend and return the correct symbol value from the + // InputSectionBase::getRelocTargetVA. For R_MIPS_LO16 we do not do that + // and use its addend as is. + if (TargetObjectWriter->getEMachine() == ELF::EM_MIPS && + !hasRelocationAddend()) + return true; } // Most TLS relocations use a got, so they need the symbol. Even those that