From: Rafael Espindola Date: Thu, 22 Jun 2017 20:27:33 +0000 (+0000) Subject: Simplify WinCOFFObjectWriter::recordRelocation. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=7eb15c6d33b28b7f3d7b5643cd83449c0b486bb9;p=llvm Simplify WinCOFFObjectWriter::recordRelocation. It looks like that when this code was written recordRelocation could be called with A-B where A and B are in the same section. The expression evaluation logic these days makes sure those are folded, so some of this code was dead. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@306053 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/MC/WinCOFFObjectWriter.cpp b/lib/MC/WinCOFFObjectWriter.cpp index 53dee3e8b9f..ec1fa0801a0 100644 --- a/lib/MC/WinCOFFObjectWriter.cpp +++ b/lib/MC/WinCOFFObjectWriter.cpp @@ -735,7 +735,6 @@ void WinCOFFObjectWriter::recordRelocation( COFFSection *Sec = SectionMap[MCSec]; const MCSymbolRefExpr *SymB = Target.getSymB(); - bool CrossSection = false; if (SymB) { const MCSymbol *B = &SymB->getSymbol(); @@ -755,20 +754,12 @@ void WinCOFFObjectWriter::recordRelocation( return; } - CrossSection = &A.getSection() != &B->getSection(); + assert(&A.getSection() != &B->getSection() && + "This doesn't need a relocation"); // Offset of the symbol in the section int64_t OffsetOfB = Layout.getSymbolOffset(*B); - // In the case where we have SymbA and SymB, we just need to store the delta - // between the two symbols. Update FixedValue to account for the delta, and - // skip recording the relocation. - if (!CrossSection) { - int64_t OffsetOfA = Layout.getSymbolOffset(A); - FixedValue = (OffsetOfA - OffsetOfB) + Target.getConstant(); - return; - } - // Offset of the relocation in the section int64_t OffsetOfRelocation = Layout.getFragmentOffset(Fragment) + Fixup.getOffset(); @@ -784,7 +775,7 @@ void WinCOFFObjectWriter::recordRelocation( Reloc.Data.VirtualAddress = Layout.getFragmentOffset(Fragment); // Turn relocations for temporary symbols into section relocations. - if (A.isTemporary() || CrossSection) { + if (A.isTemporary() || SymB) { MCSection *TargetSection = &A.getSection(); assert( SectionMap.find(TargetSection) != SectionMap.end() && @@ -801,8 +792,8 @@ void WinCOFFObjectWriter::recordRelocation( ++Reloc.Symb->Relocations; Reloc.Data.VirtualAddress += Fixup.getOffset(); - Reloc.Data.Type = TargetObjectWriter->getRelocType( - Target, Fixup, CrossSection, Asm.getBackend()); + Reloc.Data.Type = + TargetObjectWriter->getRelocType(Target, Fixup, SymB, Asm.getBackend()); // FIXME: Can anyone explain what this does other than adjust for the size // of the offset?