LLVM  10.0.0svn
MCObjectWriter.cpp
Go to the documentation of this file.
1 //===- lib/MC/MCObjectWriter.cpp - MCObjectWriter implementation ----------===//
2 //
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
6 //
7 //===----------------------------------------------------------------------===//
8 
10 #include "llvm/MC/MCAssembler.h"
11 #include "llvm/MC/MCExpr.h"
12 #include "llvm/MC/MCFragment.h"
13 #include "llvm/MC/MCSymbol.h"
14 
15 using namespace llvm;
16 
18 
20  const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B,
21  bool InSet) const {
22  // Modified symbol references cannot be resolved.
23  if (A->getKind() != MCSymbolRefExpr::VK_None ||
25  return false;
26 
27  const MCSymbol &SA = A->getSymbol();
28  const MCSymbol &SB = B->getSymbol();
29  if (SA.isUndefined() || SB.isUndefined())
30  return false;
31 
32  if (!SA.getFragment() || !SB.getFragment())
33  return false;
34 
35  return isSymbolRefDifferenceFullyResolvedImpl(Asm, SA, SB, InSet);
36 }
37 
39  const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B,
40  bool InSet) const {
41  return isSymbolRefDifferenceFullyResolvedImpl(Asm, A, *B.getFragment(), InSet,
42  false);
43 }
44 
46  const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB,
47  bool InSet, bool IsPCRel) const {
48  const MCSection &SecA = SymA.getSection();
49  const MCSection &SecB = *FB.getParent();
50  // On ELF and COFF A - B is absolute if A and B are in the same section.
51  return &SecA == &SecB;
52 }
Instances of this class represent a uniqued identifier for a section in the current translation unit...
Definition: MCSection.h:38
This class represents lattice values for constants.
Definition: AllocatorList.h:23
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
VariantKind getKind() const
Definition: MCExpr.h:342
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:169
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
virtual ~MCObjectWriter()
const MCSymbol & getSymbol() const
Definition: MCExpr.h:340
bool isUndefined(bool SetUsed=true) const
isUndefined - Check if this symbol undefined (i.e., implicitly defined).
Definition: MCSymbol.h:258
MCFragment * getFragment(bool SetUsed=true) const
Definition: MCSymbol.h:396
MCSection * getParent() const
Definition: MCFragment.h:98
MCSection & getSection() const
Get the section associated with a defined, non-absolute symbol.
Definition: MCSymbol.h:268
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, const MCSymbolRefExpr *A, const MCSymbolRefExpr *B, bool InSet) const
Check whether the difference (A - B) between two symbol references is fully resolved.