LLVM  8.0.1
MCObjectWriter.h
Go to the documentation of this file.
1 //===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #ifndef LLVM_MC_MCOBJECTWRITER_H
11 #define LLVM_MC_MCOBJECTWRITER_H
12 
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/Endian.h"
19 #include <cassert>
20 #include <cstdint>
21 
22 namespace llvm {
23 
24 class MCAsmLayout;
25 class MCAssembler;
26 class MCFixup;
27 class MCFragment;
28 class MCSymbol;
29 class MCSymbolRefExpr;
30 class MCValue;
31 
32 /// Defines the object file and target independent interfaces used by the
33 /// assembler backend to write native file format object files.
34 ///
35 /// The object writer contains a few callbacks used by the assembler to allow
36 /// the object writer to modify the assembler data structures at appropriate
37 /// points. Once assembly is complete, the object writer is given the
38 /// MCAssembler instance, which contains all the symbol and section data which
39 /// should be emitted as part of writeObject().
41 protected:
42  MCObjectWriter() = default;
43 
44 public:
45  MCObjectWriter(const MCObjectWriter &) = delete;
46  MCObjectWriter &operator=(const MCObjectWriter &) = delete;
47  virtual ~MCObjectWriter();
48 
49  /// lifetime management
50  virtual void reset() {}
51 
52  /// \name High-Level API
53  /// @{
54 
55  /// Perform any late binding of symbols (for example, to assign symbol
56  /// indices for use when generating relocations).
57  ///
58  /// This routine is called by the assembler after layout and relaxation is
59  /// complete.
61  const MCAsmLayout &Layout) = 0;
62 
63  /// Record a relocation entry.
64  ///
65  /// This routine is called by the assembler after layout and relaxation, and
66  /// post layout binding. The implementation is responsible for storing
67  /// information about the relocation so that it can be emitted during
68  /// writeObject().
69  virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
70  const MCFragment *Fragment,
71  const MCFixup &Fixup, MCValue Target,
72  uint64_t &FixedValue) = 0;
73 
74  /// Check whether the difference (A - B) between two symbol references is
75  /// fully resolved.
76  ///
77  /// Clients are not required to answer precisely and may conservatively return
78  /// false, even when a difference is fully resolved.
80  const MCSymbolRefExpr *A,
81  const MCSymbolRefExpr *B,
82  bool InSet) const;
83 
85  const MCSymbol &A,
86  const MCSymbol &B,
87  bool InSet) const;
88 
90  const MCSymbol &SymA,
91  const MCFragment &FB,
92  bool InSet,
93  bool IsPCRel) const;
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.
98  virtual void emitAddrsigSection() {}
99 
100  /// Record the given symbol in the address-significance table to be written
101  /// diring writeObject().
102  virtual void addAddrsigSymbol(const MCSymbol *Sym) {}
103 
104  /// Write the object file and returns the number of bytes written.
105  ///
106  /// This routine is called by the assembler after layout and relaxation is
107  /// complete, fixups have been evaluated and applied, and relocations
108  /// generated.
109  virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
110 
111  /// @}
112 };
113 
114 /// Base class for classes that define behaviour that is specific to both the
115 /// target and the object format.
117 public:
118  virtual ~MCObjectTargetWriter() = default;
119  virtual Triple::ObjectFormatType getFormat() const = 0;
120 };
121 
122 } // end namespace llvm
123 
124 #endif // LLVM_MC_MCOBJECTWRITER_H
This class represents lattice values for constants.
Definition: AllocatorList.h:24
This represents an "assembler immediate".
Definition: MCValue.h:40
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:42
virtual void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
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...
Defines the object file and target independent interfaces used by the assembler backend to write nati...
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:74
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:29
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:166
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
virtual ~MCObjectWriter()
virtual void reset()
lifetime management
PowerPC TLS Dynamic Call Fixup
MCObjectWriter & operator=(const MCObjectWriter &)=delete
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
Target - Wrapper for Target specific information.
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.
Base class for classes that define behaviour that is specific to both the target and the object forma...
ObjectFormatType
Definition: Triple.h:216
virtual void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
MCObjectWriter()=default