1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "llvm/MC/MCObjectWriter.h"
11 #include "llvm/MC/MCAssembler.h"
12 #include "llvm/MC/MCExpr.h"
13 #include "llvm/MC/MCFragment.h"
14 #include "llvm/MC/MCSymbol.h"
18 MCObjectWriter::~MCObjectWriter() = default;
20 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
21 const MCAssembler
&Asm
, const MCSymbolRefExpr
*A
, const MCSymbolRefExpr
*B
,
23 // Modified symbol references cannot be resolved.
24 if (A
->getKind() != MCSymbolRefExpr::VK_None
||
25 B
->getKind() != MCSymbolRefExpr::VK_None
)
28 const MCSymbol
&SA
= A
->getSymbol();
29 const MCSymbol
&SB
= B
->getSymbol();
30 if (SA
.isUndefined() || SB
.isUndefined())
33 if (!SA
.getFragment() || !SB
.getFragment())
36 return isSymbolRefDifferenceFullyResolvedImpl(Asm
, SA
, SB
, InSet
);
39 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
40 const MCAssembler
&Asm
, const MCSymbol
&A
, const MCSymbol
&B
,
42 return isSymbolRefDifferenceFullyResolvedImpl(Asm
, A
, *B
.getFragment(), InSet
,
46 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
47 const MCAssembler
&Asm
, const MCSymbol
&SymA
, const MCFragment
&FB
,
48 bool InSet
, bool IsPCRel
) const {
49 const MCSection
&SecA
= SymA
.getSection();
50 const MCSection
&SecB
= *FB
.getParent();
51 // On ELF and COFF A - B is absolute if A and B are in the same section.
52 return &SecA
== &SecB
;