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 MCAssembler;
19class MCFixup;
20class MCFragment;
21class MCSymbol;
22class MCSymbolRefExpr;
23class 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().
34protected:
35 std::vector<const MCSymbol *> AddrsigSyms;
36 bool EmitAddrsigSection = false;
37
38 MCObjectWriter() = default;
39
40public:
41 MCObjectWriter(const MCObjectWriter &) = delete;
43 virtual ~MCObjectWriter();
44
45 /// lifetime management
46 virtual void reset() {}
47
48 /// \name High-Level API
49 /// @{
50
51 /// Perform any late binding of symbols (for example, to assign symbol
52 /// indices for use when generating relocations).
53 ///
54 /// This routine is called by the assembler after layout and relaxation is
55 /// complete.
57
58 /// Record a relocation entry.
59 ///
60 /// This routine is called by the assembler after layout and relaxation, and
61 /// post layout binding. The implementation is responsible for storing
62 /// information about the relocation so that it can be emitted during
63 /// writeObject().
64 virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
66 uint64_t &FixedValue) = 0;
67
68 /// Check whether the difference (A - B) between two symbol references is
69 /// fully resolved.
70 ///
71 /// Clients are not required to answer precisely and may conservatively return
72 /// false, even when a difference is fully resolved.
74 const MCSymbolRefExpr *A,
75 const MCSymbolRefExpr *B,
76 bool InSet) const;
77
79 const MCSymbol &SymA,
80 const MCFragment &FB,
81 bool InSet,
82 bool IsPCRel) const;
83
84 /// ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
85 virtual void markGnuAbi() {}
86
87 /// ELF only, override the default ABIVersion in the ELF header.
88 virtual void setOverrideABIVersion(uint8_t ABIVersion) {}
89
90 /// Tell the object writer to emit an address-significance table during
91 /// writeObject(). If this function is not called, all symbols are treated as
92 /// address-significant.
94
96
97 /// Record the given symbol in the address-significance table to be written
98 /// diring writeObject().
99 void addAddrsigSymbol(const MCSymbol *Sym) { AddrsigSyms.push_back(Sym); }
100
101 std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
102
103 virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap,
104 unsigned LanguageCode, unsigned ReasonCode,
105 unsigned FunctionSize, bool hasDebug) {
106 report_fatal_error("addExceptionEntry is only supported on XCOFF targets");
107 }
109 report_fatal_error("addCInfoSymEntry is only supported on XCOFF targets");
110 }
111 /// Write the object file and returns the number of bytes written.
112 ///
113 /// This routine is called by the assembler after layout and relaxation is
114 /// complete, fixups have been evaluated and applied, and relocations
115 /// generated.
117
118 /// @}
119};
120
121/// Base class for classes that define behaviour that is specific to both the
122/// target and the object format.
124public:
125 virtual ~MCObjectTargetWriter() = default;
127};
128
129} // end namespace llvm
130
131#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
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...
virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, const MCSymbol &SymA, const MCFragment &FB, bool InSet, bool IsPCRel) const
MCObjectWriter()=default
MCObjectWriter & operator=(const MCObjectWriter &)=delete
MCObjectWriter(const MCObjectWriter &)=delete
virtual void addExceptionEntry(const MCSymbol *Symbol, const MCSymbol *Trap, unsigned LanguageCode, unsigned ReasonCode, unsigned FunctionSize, bool hasDebug)
virtual ~MCObjectWriter()
virtual void executePostLayoutBinding(MCAssembler &Asm)
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
virtual void addCInfoSymEntry(StringRef Name, StringRef Metadata)
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
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 uint64_t writeObject(MCAssembler &Asm)=0
Write the object file and returns the number of bytes written.
virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment, const MCFixup &Fixup, MCValue Target, uint64_t &FixedValue)=0
Record a relocation entry.
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
Represent a reference to a symbol from inside an expression.
Definition: MCExpr.h:188
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
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:297
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:167