LLVM API Documentation

MCObjectWriter.cpp
Go to the documentation of this file.
00001 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
00002 //
00003 //                     The LLVM Compiler Infrastructure
00004 //
00005 // This file is distributed under the University of Illinois Open Source
00006 // License. See LICENSE.TXT for details.
00007 //
00008 //===----------------------------------------------------------------------===//
00009 
00010 #include "llvm/MC/MCAssembler.h"
00011 #include "llvm/MC/MCExpr.h"
00012 #include "llvm/MC/MCObjectWriter.h"
00013 #include "llvm/MC/MCSymbol.h"
00014 
00015 using namespace llvm;
00016 
00017 MCObjectWriter::~MCObjectWriter() {
00018 }
00019 
00020 bool
00021 MCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
00022                                                    const MCSymbolRefExpr *A,
00023                                                    const MCSymbolRefExpr *B,
00024                                                    bool InSet) const {
00025   // Modified symbol references cannot be resolved.
00026   if (A->getKind() != MCSymbolRefExpr::VK_None ||
00027       B->getKind() != MCSymbolRefExpr::VK_None)
00028     return false;
00029 
00030   const MCSymbol &SA = A->getSymbol();
00031   const MCSymbol &SB = B->getSymbol();
00032   if (SA.AliasedSymbol().isUndefined() || SB.AliasedSymbol().isUndefined())
00033     return false;
00034 
00035   const MCSymbolData &DataA = Asm.getSymbolData(SA);
00036   const MCSymbolData &DataB = Asm.getSymbolData(SB);
00037   if(!DataA.getFragment() || !DataB.getFragment())
00038     return false;
00039 
00040   return IsSymbolRefDifferenceFullyResolvedImpl(Asm, DataA,
00041                                                 *DataB.getFragment(),
00042                                                 InSet,
00043                                                 false);
00044 }
00045 
00046 bool
00047 MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
00048                                                       const MCSymbolData &DataA,
00049                                                       const MCFragment &FB,
00050                                                       bool InSet,
00051                                                       bool IsPCRel) const {
00052   const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection();
00053   const MCSection &SecB = FB.getParent()->getSection();
00054   // On ELF and COFF  A - B is absolute if A and B are in the same section.
00055   return &SecA == &SecB;
00056 }