LLVM  14.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 <cstdint>
14 
15 namespace llvm {
16 
17 class MCAsmLayout;
18 class MCAssembler;
19 class MCFixup;
20 class MCFragment;
21 class MCSymbol;
22 class MCSymbolRefExpr;
23 class MCValue;
24 
25 /// Defines the object file and target independent interfaces used by the
26 /// assembler backend to write native file format object files.
27 ///
28 /// The object writer contains a few callbacks used by the assembler to allow
29 /// the object writer to modify the assembler data structures at appropriate
30 /// points. Once assembly is complete, the object writer is given the
31 /// MCAssembler instance, which contains all the symbol and section data which
32 /// should be emitted as part of writeObject().
34 protected:
35  MCObjectWriter() = default;
36 
37 public:
38  MCObjectWriter(const MCObjectWriter &) = delete;
39  MCObjectWriter &operator=(const MCObjectWriter &) = delete;
40  virtual ~MCObjectWriter();
41 
42  /// lifetime management
43  virtual void reset() {}
44 
45  /// \name High-Level API
46  /// @{
47 
48  /// Perform any late binding of symbols (for example, to assign symbol
49  /// indices for use when generating relocations).
50  ///
51  /// This routine is called by the assembler after layout and relaxation is
52  /// complete.
54  const MCAsmLayout &Layout) = 0;
55 
56  /// Record a relocation entry.
57  ///
58  /// This routine is called by the assembler after layout and relaxation, and
59  /// post layout binding. The implementation is responsible for storing
60  /// information about the relocation so that it can be emitted during
61  /// writeObject().
62  virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
63  const MCFragment *Fragment,
64  const MCFixup &Fixup, MCValue Target,
65  uint64_t &FixedValue) = 0;
66 
67  /// Check whether the difference (A - B) between two symbol references is
68  /// fully resolved.
69  ///
70  /// Clients are not required to answer precisely and may conservatively return
71  /// false, even when a difference is fully resolved.
73  const MCSymbolRefExpr *A,
74  const MCSymbolRefExpr *B,
75  bool InSet) const;
76 
78  const MCSymbol &A,
79  const MCSymbol &B,
80  bool InSet) const;
81 
83  const MCSymbol &SymA,
84  const MCFragment &FB,
85  bool InSet,
86  bool IsPCRel) const;
87 
88  /// ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
89  virtual void markGnuAbi() {}
90 
91  /// Tell the object writer to emit an address-significance table during
92  /// writeObject(). If this function is not called, all symbols are treated as
93  /// address-significant.
94  virtual void emitAddrsigSection() {}
95 
96  /// Record the given symbol in the address-significance table to be written
97  /// diring writeObject().
98  virtual void addAddrsigSymbol(const MCSymbol *Sym) {}
99 
100  /// Write the object file and returns the number of bytes written.
101  ///
102  /// This routine is called by the assembler after layout and relaxation is
103  /// complete, fixups have been evaluated and applied, and relocations
104  /// generated.
105  virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
106 
107  /// @}
108 };
109 
110 /// Base class for classes that define behaviour that is specific to both the
111 /// target and the object format.
113 public:
114  virtual ~MCObjectTargetWriter() = default;
115  virtual Triple::ObjectFormatType getFormat() const = 0;
116 };
117 
118 } // end namespace llvm
119 
120 #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:89
llvm
This file implements support for optimizing divisions by a constant.
Definition: AllocatorList.h:23
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::~MCObjectWriter
virtual ~MCObjectWriter()
llvm::Target
Target - Wrapper for Target specific information.
Definition: TargetRegistry.h:137
llvm::MCObjectWriter::MCObjectWriter
MCObjectWriter()=default
llvm::MCFragment
Definition: MCFragment.h:31
llvm::MCObjectWriter::addAddrsigSymbol
virtual void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
Definition: MCObjectWriter.h:98
llvm::MCObjectTargetWriter
Base class for classes that define behaviour that is specific to both the target and the object forma...
Definition: MCObjectWriter.h:112
llvm::MCObjectWriter::operator=
MCObjectWriter & operator=(const MCObjectWriter &)=delete
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::MCAssembler
Definition: MCAssembler.h:60
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:33
llvm::MCObjectTargetWriter::~MCObjectTargetWriter
virtual ~MCObjectTargetWriter()=default
llvm::Triple::ObjectFormatType
ObjectFormatType
Definition: Triple.h:234
llvm::MCObjectTargetWriter::getFormat
virtual Triple::ObjectFormatType getFormat() const =0
llvm::MCObjectWriter::emitAddrsigSection
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
Definition: MCObjectWriter.h:94
llvm::MCObjectWriter::reset
virtual void reset()
lifetime management
Definition: MCObjectWriter.h:43
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:38
llvm::HexStyle::Asm
@ Asm
0ffh
Definition: MCInstPrinter.h:34
llvm::MCValue
This represents an "assembler immediate".
Definition: MCValue.h:37
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:19