1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===// 2 // 3 // The LLVM Compiler Infrastructure 4 // 5 // This file is distributed under the University of Illinois Open Source 6 // License. See LICENSE.TXT for details. 7 // 8 //===----------------------------------------------------------------------===// 9 10 #include "llvm/MC/MCAssembler.h" 11 #include "llvm/MC/MCExpr.h" 12 #include "llvm/MC/MCObjectWriter.h" 13 #include "llvm/MC/MCSymbol.h" 14 15 using namespace llvm; 16 17 MCObjectWriter::~MCObjectWriter() { 18 } 19 20 bool 21 MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, 22 const MCSymbolRefExpr *A, 23 const MCSymbolRefExpr *B, 24 bool InSet) const { 25 // Modified symbol references cannot be resolved. 26 if (A->getKind() != MCSymbolRefExpr::VK_None || 27 B->getKind() != MCSymbolRefExpr::VK_None) 28 return false; 29 30 const MCSymbol &SA = A->getSymbol(); 31 const MCSymbol &SB = B->getSymbol(); 32 if (SA.AliasedSymbol().isUndefined() || SB.AliasedSymbol().isUndefined()) 33 return false; 34 35 const MCSymbolData &DataA = Asm.getSymbolData(SA); 36 const MCSymbolData &DataB = Asm.getSymbolData(SB); 37 if(!DataA.getFragment() || !DataB.getFragment()) 38 return false; 39 40 return IsSymbolRefDifferenceFullyResolvedImpl(Asm, DataA, 41 *DataB.getFragment(), 42 InSet, 43 false); 44 } 45 46 bool 47 MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, 48 const MCSymbolData &DataA, 49 const MCFragment &FB, 50 bool InSet, 51 bool IsPCRel) const { 52 const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection(); 53 const MCSection &SecB = FB.getParent()->getSection(); 54 // On ELF and COFF A - B is absolute if A and B are in the same section. 55 return &SecA == &SecB; 56 } 57