1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
7 //===----------------------------------------------------------------------===//
9 #include "llvm/MC/MCObjectWriter.h"
10 #include "llvm/MC/MCExpr.h"
11 #include "llvm/MC/MCFragment.h"
12 #include "llvm/MC/MCSymbol.h"
19 MCObjectWriter::~MCObjectWriter() = default;
21 bool MCObjectWriter::isSymbolRefDifferenceFullyResolved(
22 const MCAssembler
&Asm
, const MCSymbolRefExpr
*A
, const MCSymbolRefExpr
*B
,
24 // Modified symbol references cannot be resolved.
25 if (A
->getKind() != MCSymbolRefExpr::VK_None
||
26 B
->getKind() != MCSymbolRefExpr::VK_None
)
29 const MCSymbol
&SA
= A
->getSymbol();
30 const MCSymbol
&SB
= B
->getSymbol();
31 if (SA
.isUndefined() || SB
.isUndefined())
34 if (!SA
.getFragment() || !SB
.getFragment())
37 return isSymbolRefDifferenceFullyResolvedImpl(Asm
, SA
, SB
, InSet
);
40 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
41 const MCAssembler
&Asm
, const MCSymbol
&A
, const MCSymbol
&B
,
43 return isSymbolRefDifferenceFullyResolvedImpl(Asm
, A
, *B
.getFragment(), InSet
,
47 bool MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl(
48 const MCAssembler
&Asm
, const MCSymbol
&SymA
, const MCFragment
&FB
,
49 bool InSet
, bool IsPCRel
) const {
50 const MCSection
&SecA
= SymA
.getSection();
51 const MCSection
&SecB
= *FB
.getParent();
52 // On ELF and COFF A - B is absolute if A and B are in the same section.
53 return &SecA
== &SecB
;