1205407Srdivacky//===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
2205407Srdivacky//
3205407Srdivacky//                     The LLVM Compiler Infrastructure
4205407Srdivacky//
5205407Srdivacky// This file is distributed under the University of Illinois Open Source
6205407Srdivacky// License. See LICENSE.TXT for details.
7205407Srdivacky//
8205407Srdivacky//===----------------------------------------------------------------------===//
9205407Srdivacky
10218893Sdim#include "llvm/MC/MCAssembler.h"
11218893Sdim#include "llvm/MC/MCExpr.h"
12205407Srdivacky#include "llvm/MC/MCObjectWriter.h"
13218893Sdim#include "llvm/MC/MCSymbol.h"
14205407Srdivacky
15205407Srdivackyusing namespace llvm;
16205407Srdivacky
17205407SrdivackyMCObjectWriter::~MCObjectWriter() {
18205407Srdivacky}
19218893Sdim
20218893Sdimbool
21218893SdimMCObjectWriter::IsSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
22218893Sdim                                                   const MCSymbolRefExpr *A,
23218893Sdim                                                   const MCSymbolRefExpr *B,
24218893Sdim                                                   bool InSet) const {
25218893Sdim  // Modified symbol references cannot be resolved.
26218893Sdim  if (A->getKind() != MCSymbolRefExpr::VK_None ||
27218893Sdim      B->getKind() != MCSymbolRefExpr::VK_None)
28218893Sdim    return false;
29218893Sdim
30218893Sdim  const MCSymbol &SA = A->getSymbol();
31218893Sdim  const MCSymbol &SB = B->getSymbol();
32218893Sdim  if (SA.AliasedSymbol().isUndefined() || SB.AliasedSymbol().isUndefined())
33218893Sdim    return false;
34218893Sdim
35218893Sdim  const MCSymbolData &DataA = Asm.getSymbolData(SA);
36218893Sdim  const MCSymbolData &DataB = Asm.getSymbolData(SB);
37234353Sdim  if(!DataA.getFragment() || !DataB.getFragment())
38234353Sdim    return false;
39218893Sdim
40218893Sdim  return IsSymbolRefDifferenceFullyResolvedImpl(Asm, DataA,
41218893Sdim                                                *DataB.getFragment(),
42218893Sdim                                                InSet,
43218893Sdim                                                false);
44218893Sdim}
45218893Sdim
46218893Sdimbool
47218893SdimMCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
48218893Sdim                                                      const MCSymbolData &DataA,
49218893Sdim                                                      const MCFragment &FB,
50218893Sdim                                                      bool InSet,
51218893Sdim                                                      bool IsPCRel) const {
52218893Sdim  const MCSection &SecA = DataA.getSymbol().AliasedSymbol().getSection();
53218893Sdim  const MCSection &SecB = FB.getParent()->getSection();
54218893Sdim  // On ELF and COFF  A - B is absolute if A and B are in the same section.
55218893Sdim  return &SecA == &SecB;
56218893Sdim}
57