LLVM 17.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
16namespace llvm {
17
18class MCAsmLayout;
19class MCAssembler;
20class MCFixup;
21class MCFragment;
22class MCSymbol;
23class MCSymbolRefExpr;
24class 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().
35protected:
36 std::vector<const MCSymbol *> AddrsigSyms;
37 bool EmitAddrsigSection = false;
38
39 MCObjectWriter() = default;
40
41public:
42 MCObjectWriter(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,
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 virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap,
109 unsigned LanguageCode, unsigned ReasonCode,
110 unsigned FunctionSize, bool hasDebug) {
111 report_fatal_error("addExceptionEntry is only supported on XCOFF targets");
112 }
113 /// Write the object file and returns the number of bytes written.
114 ///
115 /// This routine is called by the assembler after layout and relaxation is
116 /// complete, fixups have been evaluated and applied, and relocations
117 /// generated.
118 virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
119
120 /// @}
121};
122
123/// Base class for classes that define behaviour that is specific to both the
124/// target and the object format.
126public:
127 virtual ~MCObjectTargetWriter() = default;
129};
130
131} // end namespace llvm
132
133#endif // LLVM_MC_MCOBJECTWRITER_H
This header is deprecated in favour of llvm/TargetParser/Triple.h.
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
PowerPC TLS Dynamic Call Fixup
Encapsulates the layout of an assembly file at a particular point in time.
Definition: MCAsmLayout.h:28
Encode information on a single operation to perform on a byte sequence (e.g., an encoded instruction)...
Definition: MCFixup.h:71
Base class for classes that define behaviour that is specific to both the target and the object forma...
virtual Triple::ObjectFormatType getFormat() const =0
virtual ~MCObjectTargetWriter()=default
Defines the object file and target independent interfaces used by the assembler backend to write nati...
MCObjectWriter()=default
MCObjectWriter & operator=(const MCObjectWriter &)=delete
MCObjectWriter(const MCObjectWriter &)=delete
virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout)=0
Write the object file and returns the number of bytes written.
virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap, unsigned LanguageCode, unsigned ReasonCode, unsigned FunctionSize, bool hasDebug)
virtual ~MCObjectWriter()
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during 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...
std::vector< const MCSymbol * > & getAddrsigSyms()
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
virtual void reset()
lifetime management
virtual void markGnuAbi()
ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
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.
std::vector< const MCSymbol * > AddrsigSyms
virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:192
MCSymbol - Instances of this class represent a symbol name in the MC file, and MCSymbols are created ...
Definition: MCSymbol.h:41
This represents an "assembler immediate".
Definition: MCValue.h:36
Target - Wrapper for Target specific information.
ObjectFormatType
Definition: Triple.h:279
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18
void report_fatal_error(Error Err, bool gen_crash_diag=true)
Report a serious error, calling any installed error handler.
Definition: Error.cpp:145