blob: e90dea814796af8a6c3a62e604346e93740f0778 [file] [log] [blame]
Daniel Dunbar79e0e5a2010-03-19 10:43:15 +00001//===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
Daniel Dunbarf027abf2010-03-19 09:28:59 +00002//
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
Rafael Espindola0f8abeb2010-12-24 21:22:02 +000010#include "llvm/MC/MCAssembler.h"
Rafael Espindolab403e092010-12-18 06:27:54 +000011#include "llvm/MC/MCExpr.h"
Daniel Dunbarf027abf2010-03-19 09:28:59 +000012#include "llvm/MC/MCObjectWriter.h"
Rafael Espindolab403e092010-12-18 06:27:54 +000013#include "llvm/MC/MCSymbol.h"
Daniel Dunbarf027abf2010-03-19 09:28:59 +000014
15using namespace llvm;
16
17MCObjectWriter::~MCObjectWriter() {
18}
Kevin Enderbye46564a2010-09-30 16:52:03 +000019
Rafael Espindola59f90b22015-03-25 19:24:39 +000020bool MCObjectWriter::IsSymbolRefDifferenceFullyResolved(
21 const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
22 bool InSet) const {
Rafael Espindolab403e092010-12-18 06:27:54 +000023 // Modified symbol references cannot be resolved.
24 if (A->getKind() != MCSymbolRefExpr::VK_None ||
25 B->getKind() != MCSymbolRefExpr::VK_None)
26 return false;
27
28 const MCSymbol &SA = A->getSymbol();
29 const MCSymbol &SB = B->getSymbol();
Rafael Espindola972756b2015-04-06 16:10:05 +000030 if (SA.isUndefined() || SB.isUndefined())
Rafael Espindolab403e092010-12-18 06:27:54 +000031 return false;
32
Rafael Espindola0f8abeb2010-12-24 21:22:02 +000033 const MCSymbolData &DataA = Asm.getSymbolData(SA);
34 const MCSymbolData &DataB = Asm.getSymbolData(SB);
Kevin Enderbye1a12cf2012-01-31 23:02:57 +000035 if(!DataA.getFragment() || !DataB.getFragment())
36 return false;
Rafael Espindola0f8abeb2010-12-24 21:22:02 +000037
Rafael Espindola94a88d72015-04-06 15:27:57 +000038 return IsSymbolRefDifferenceFullyResolvedImpl(
Rafael Espindola35d61892015-04-17 21:15:17 +000039 Asm, DataA, *DataB.getFragment(), InSet, false);
Rafael Espindolab403e092010-12-18 06:27:54 +000040}
Rafael Espindola490d02a2011-02-16 03:25:55 +000041
Rafael Espindola94a88d72015-04-06 15:27:57 +000042bool MCObjectWriter::IsSymbolRefDifferenceFullyResolvedImpl(
Rafael Espindola35d61892015-04-17 21:15:17 +000043 const MCAssembler &Asm, const MCSymbolData &DataA, const MCFragment &FB,
44 bool InSet, bool IsPCRel) const {
Rafael Espindola972756b2015-04-06 16:10:05 +000045 const MCSection &SecA = DataA.getSymbol().getSection();
Rafael Espindola490d02a2011-02-16 03:25:55 +000046 const MCSection &SecB = FB.getParent()->getSection();
47 // On ELF and COFF A - B is absolute if A and B are in the same section.
48 return &SecA == &SecB;
49}
Rafael Espindolaf275ad82015-03-25 13:16:53 +000050
51bool MCObjectWriter::isWeak(const MCSymbolData &SD) const { return false; }