Skip to content

Commit 95a56b6

Browse files
committed
[MC][Mips] Add the required IMAGE_REL_MIPS_PAIR relocation after IMAGE_REL_MIPS_REFHI/IMAGE_REL_MIPS_SECRELHI
1 parent b02203d commit 95a56b6

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

llvm/lib/MC/WinCOFFObjectWriter.cpp

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -773,7 +773,10 @@ void WinCOFFWriter::assignFileOffsets(MCAssembler &Asm) {
773773

774774
for (auto &Relocation : Sec->Relocations) {
775775
assert(Relocation.Symb->getIndex() != -1);
776-
Relocation.Data.SymbolTableIndex = Relocation.Symb->getIndex();
776+
if (Header.Machine != COFF::IMAGE_FILE_MACHINE_R4000 ||
777+
Relocation.Data.Type != COFF::IMAGE_REL_MIPS_PAIR) {
778+
Relocation.Data.SymbolTableIndex = Relocation.Symb->getIndex();
779+
}
777780
}
778781
}
779782

@@ -967,8 +970,18 @@ void WinCOFFWriter::recordRelocation(MCAssembler &Asm,
967970
if (Fixup.getKind() == FK_SecRel_2)
968971
FixedValue = 0;
969972

970-
if (OWriter.TargetObjectWriter->recordRelocation(Fixup))
973+
if (OWriter.TargetObjectWriter->recordRelocation(Fixup)) {
971974
Sec->Relocations.push_back(Reloc);
975+
if (Header.Machine == COFF::IMAGE_FILE_MACHINE_R4000 &&
976+
(Reloc.Data.Type == COFF::IMAGE_REL_MIPS_REFHI ||
977+
Reloc.Data.Type == COFF::IMAGE_REL_MIPS_SECRELHI)) {
978+
// IMAGE_REL_MIPS_REFHI and IMAGE_REL_MIPS_SECRELHI *must*
979+
// be followed by IMAGE_REL_MIPS_PAIR
980+
auto RelocPair = Reloc;
981+
RelocPair.Data.Type = COFF::IMAGE_REL_MIPS_PAIR;
982+
Sec->Relocations.push_back(RelocPair);
983+
}
984+
}
972985
}
973986

974987
static std::time_t getTime() {

llvm/test/MC/Mips/coff-relocs.ll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ define i32 @foo_var() {
2323
; CHECK: - VirtualAddress: 32
2424
; CHECK: SymbolName: var
2525
; CHECK: Type: IMAGE_REL_MIPS_REFHI
26+
; CHECK: - VirtualAddress: 32
27+
; CHECK: SymbolName: .text
28+
; CHECK: Type: IMAGE_REL_MIPS_PAIR
2629
; CHECK: - VirtualAddress: 40
2730
; CHECK: SymbolName: var
2831
; CHECK: Type: IMAGE_REL_MIPS_REFLO

0 commit comments

Comments
 (0)