LLVM 19.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/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 /// ELF only, override the default ABIVersion in the ELF header.
96 virtual void setOverrideABIVersion(uint8_t ABIVersion) {}
97
98 /// Tell the object writer to emit an address-significance table during
99 /// writeObject(). If this function is not called, all symbols are treated as
100 /// address-significant.
102
104
105 /// Record the given symbol in the address-significance table to be written
106 /// diring writeObject().
107 void addAddrsigSymbol(const MCSymbol *Sym) { AddrsigSyms.push_back(Sym); }
108
109 std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
110
111 virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap,
112 unsigned LanguageCode, unsigned ReasonCode,
113 unsigned FunctionSize, bool hasDebug) {
114 report_fatal_error("addExceptionEntry is only supported on XCOFF targets");
115 }
117 report_fatal_error("addCInfoSymEntry is only supported on XCOFF targets");
118 }
119 /// Write the object file and returns the number of bytes written.
120 ///
121 /// This routine is called by the assembler after layout and relaxation is
122 /// complete, fixups have been evaluated and applied, and relocations
123 /// generated.
124 virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
125
126 /// @}
127};
128
129/// Base class for classes that define behaviour that is specific to both the
130/// target and the object format.
132public:
133 virtual ~MCObjectTargetWriter() = default;
135};
136
137} // end namespace llvm
138
139#endif // LLVM_MC_MCOBJECTWRITER_H
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
static GCRegistry::Add< ErlangGC > A("erlang", "erlang-compatible garbage collector")
std::string Name
Symbol * Sym
Definition: ELF_riscv.cpp:479
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()
virtual void addCInfoSymEntry(StringRef Name, StringRef Metadata)
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.
virtual void setOverrideABIVersion(uint8_t ABIVersion)
ELF only, override the default ABIVersion in the ELF header.
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:40
This represents an "assembler immediate".
Definition: MCValue.h:36
Root of the metadata hierarchy.
Definition: Metadata.h:62
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
ObjectFormatType
Definition: Triple.h:285
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:156