LLVM  15.0.0git
MCObjectWriter.h
Go to the documentation of this file.
1 //===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
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 
9 #ifndef LLVM_MC_MCOBJECTWRITER_H
10 #define LLVM_MC_MCOBJECTWRITER_H
11 
12 #include "llvm/ADT/Triple.h"
13 #include "llvm/MC/MCSymbol.h"
14 #include <cstdint>
15 
16 namespace llvm {
17 
18 class MCAsmLayout;
19 class MCAssembler;
20 class MCFixup;
21 class MCFragment;
22 class MCSymbol;
23 class MCSymbolRefExpr;
24 class MCValue;
25 
26 /// Defines the object file and target independent interfaces used by the
27 /// assembler backend to write native file format object files.
28 ///
29 /// The object writer contains a few callbacks used by the assembler to allow
30 /// the object writer to modify the assembler data structures at appropriate
31 /// points. Once assembly is complete, the object writer is given the
32 /// MCAssembler instance, which contains all the symbol and section data which
33 /// should be emitted as part of writeObject().
35 protected:
36  std::vector<const MCSymbol *> AddrsigSyms;
37  bool EmitAddrsigSection = false;
38 
39  MCObjectWriter() = default;
40 
41 public:
42  MCObjectWriter(const MCObjectWriter &) = delete;
43  MCObjectWriter &operator=(const MCObjectWriter &) = delete;
44  virtual ~MCObjectWriter();
45 
46  /// lifetime management
47  virtual void reset() {}
48 
49  /// \name High-Level API
50  /// @{
51 
52  /// Perform any late binding of symbols (for example, to assign symbol
53  /// indices for use when generating relocations).
54  ///
55  /// This routine is called by the assembler after layout and relaxation is
56  /// complete.
58  const MCAsmLayout &Layout) = 0;
59 
60  /// Record a relocation entry.
61  ///
62  /// This routine is called by the assembler after layout and relaxation, and
63  /// post layout binding. The implementation is responsible for storing
64  /// information about the relocation so that it can be emitted during
65  /// writeObject().
66  virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
67  const MCFragment *Fragment,
68  const MCFixup &Fixup, MCValue Target,
69  uint64_t &FixedValue) = 0;
70 
71  /// Check whether the difference (A - B) between two symbol references is
72  /// fully resolved.
73  ///
74  /// Clients are not required to answer precisely and may conservatively return
75  /// false, even when a difference is fully resolved.
77  const MCSymbolRefExpr *A,
78  const MCSymbolRefExpr *B,
79  bool InSet) const;
80 
82  const MCSymbol &A,
83  const MCSymbol &B,
84  bool InSet) const;
85 
87  const MCSymbol &SymA,
88  const MCFragment &FB,
89  bool InSet,
90  bool IsPCRel) const;
91 
92  /// ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
93  virtual void markGnuAbi() {}
94 
95  /// Tell the object writer to emit an address-significance table during
96  /// writeObject(). If this function is not called, all symbols are treated as
97  /// address-significant.
99 
101 
102  /// Record the given symbol in the address-significance table to be written
103  /// diring writeObject().
104  void addAddrsigSymbol(const MCSymbol *Sym) { AddrsigSyms.push_back(Sym); }
105 
106  std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
107 
108  /// Write the object file and returns the number of bytes written.
109  ///
110  /// This routine is called by the assembler after layout and relaxation is
111  /// complete, fixups have been evaluated and applied, and relocations
112  /// generated.
113  virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
114 
115  /// @}
116 };
117 
118 /// Base class for classes that define behaviour that is specific to both the
119 /// target and the object format.
121 public:
122  virtual ~MCObjectTargetWriter() = default;
123  virtual Triple::ObjectFormatType getFormat() const = 0;
124 };
125 
126 } // end namespace llvm
127 
128 #endif // LLVM_MC_MCOBJECTWRITER_H
llvm::MCObjectWriter::markGnuAbi
virtual void markGnuAbi()
ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
Definition: MCObjectWriter.h:93
llvm
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:17
llvm::MCSymbol
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
llvm::MCObjectWriter::EmitAddrsigSection
bool EmitAddrsigSection
Definition: MCObjectWriter.h:37
llvm::MCObjectWriter::~MCObjectWriter
virtual ~MCObjectWriter()
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:145
llvm::MCObjectWriter::getAddrsigSyms
std::vector< const MCSymbol * > & getAddrsigSyms()
Definition: MCObjectWriter.h:106
llvm::MCObjectWriter::MCObjectWriter
MCObjectWriter()=default
llvm::MCObjectWriter::AddrsigSyms
std::vector< const MCSymbol * > AddrsigSyms
Definition: MCObjectWriter.h:36
llvm::MCObjectWriter::addAddrsigSymbol
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
Definition: MCObjectWriter.h:104
llvm::MCFragment
Definition: MCFragment.h:30
llvm::MCObjectTargetWriter
Base class for classes that define behaviour that is specific to both the target and the object forma...
Definition: MCObjectWriter.h:120
llvm::MCObjectWriter::operator=
MCObjectWriter & operator=(const MCObjectWriter &)=delete
MCSymbol.h
B
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
llvm::MCObjectWriter::recordRelocation
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
llvm::MCObjectWriter::emitAddrsigSection
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
Definition: MCObjectWriter.h:98
llvm::MCAssembler
Definition: MCAssembler.h:73
uint64_t
llvm::MCSymbolRefExpr
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
Triple.h
llvm::MCObjectWriter
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Definition: MCObjectWriter.h:34
llvm::MCObjectTargetWriter::~MCObjectTargetWriter
virtual ~MCObjectTargetWriter()=default
llvm::Triple::ObjectFormatType
ObjectFormatType
Definition: Triple.h:269
llvm::MCObjectTargetWriter::getFormat
virtual Triple::ObjectFormatType getFormat() const =0
llvm::MCObjectWriter::reset
virtual void reset()
lifetime management
Definition: MCObjectWriter.h:47
llvm::MCAsmLayout
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
llvm::MCObjectWriter::executePostLayoutBinding
virtual void executePostLayoutBinding(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
llvm::MCObjectWriter::writeObject
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolvedImpl
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &A, const MCSymbol &B, bool InSet) const
Definition: MCObjectWriter.cpp:40
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:36
llvm::MCObjectWriter::getEmitAddrsigSection
bool getEmitAddrsigSection()
Definition: MCObjectWriter.h:100
llvm::MCFixup
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
llvm::ISD::MCSymbol
@ MCSymbol
Definition: ISDOpcodes.h:172
llvm::MCObjectWriter::isSymbolRefDifferenceFullyResolved
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.
Definition: MCObjectWriter.cpp:21