LLVM 20.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 /// List of declared file names
37 // XCOFF specific: Optional compiler version.
38 std::string CompilerVersion;
39 std::vector<const MCSymbol *> AddrsigSyms;
40 bool EmitAddrsigSection = false;
42
47 };
49
50 MCObjectWriter() = default;
51
52public:
53 MCObjectWriter(const MCObjectWriter &) = delete;
55 virtual ~MCObjectWriter();
56
57 /// lifetime management
58 virtual void reset();
59
60 /// \name High-Level API
61 /// @{
62
63 /// Perform any late binding of symbols (for example, to assign symbol
64 /// indices for use when generating relocations).
65 ///
66 /// This routine is called by the assembler after layout and relaxation is
67 /// complete.
69
70 /// Record a relocation entry.
71 ///
72 /// This routine is called by the assembler after layout and relaxation, and
73 /// post layout binding. The implementation is responsible for storing
74 /// information about the relocation so that it can be emitted during
75 /// writeObject().
76 virtual void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
78 uint64_t &FixedValue) = 0;
79
80 /// Check whether the difference (A - B) between two symbol references is
81 /// fully resolved.
82 ///
83 /// Clients are not required to answer precisely and may conservatively return
84 /// false, even when a difference is fully resolved.
86 const MCSymbolRefExpr *A,
87 const MCSymbolRefExpr *B,
88 bool InSet) const;
89
91 const MCSymbol &SymA,
92 const MCFragment &FB,
93 bool InSet,
94 bool IsPCRel) const;
95
97 return FileNames;
98 }
99 void addFileName(MCAssembler &Asm, StringRef FileName);
100 void setCompilerVersion(StringRef CompilerVers) {
101 CompilerVersion = CompilerVers;
102 }
103
104 /// Tell the object writer to emit an address-significance table during
105 /// writeObject(). If this function is not called, all symbols are treated as
106 /// address-significant.
108
110
111 /// Record the given symbol in the address-significance table to be written
112 /// diring writeObject().
113 void addAddrsigSymbol(const MCSymbol *Sym) { AddrsigSyms.push_back(Sym); }
114
115 std::vector<const MCSymbol *> &getAddrsigSyms() { return AddrsigSyms; }
117
118 // Mach-O specific: Whether .subsections_via_symbols is enabled.
121
122 /// Write the object file and returns the number of bytes written.
123 ///
124 /// This routine is called by the assembler after layout and relaxation is
125 /// complete, fixups have been evaluated and applied, and relocations
126 /// generated.
128
129 /// @}
130};
131
132/// Base class for classes that define behaviour that is specific to both the
133/// target and the object format.
135public:
136 virtual ~MCObjectTargetWriter() = default;
138};
139
140} // end namespace llvm
141
142#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")
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
MutableArrayRef< std::pair< std::string, size_t > > getFileNames()
MCObjectWriter & operator=(const MCObjectWriter &)=delete
SmallVector< CGProfileEntry, 0 > CGProfile
MCObjectWriter(const MCObjectWriter &)=delete
void setCompilerVersion(StringRef CompilerVers)
virtual ~MCObjectWriter()
virtual void executePostLayoutBinding(MCAssembler &Asm)
Perform any late binding of symbols (for example, to assign symbol indices for use when generating re...
bool getSubsectionsViaSymbols() const
void emitAddrsigSection()
Tell the object writer to emit an address-significance table during writeObject().
std::vector< const MCSymbol * > & getAddrsigSyms()
virtual void reset()
lifetime management
void addAddrsigSymbol(const MCSymbol *Sym)
Record the given symbol in the address-significance table to be written diring writeObject().
void setSubsectionsViaSymbols(bool Value)
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.
std::string CompilerVersion
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.
void addFileName(MCAssembler &Asm, StringRef FileName)
SmallVector< CGProfileEntry, 0 > & getCGProfile()
std::vector< const MCSymbol * > AddrsigSyms
SmallVector< std::pair< std::string, size_t >, 0 > FileNames
List of declared file names.
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
MutableArrayRef - Represent a mutable reference to an array (0 or more elements consecutively in memo...
Definition: ArrayRef.h:307
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Definition: SmallVector.h:1209
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Target - Wrapper for Target specific information.
ObjectFormatType
Definition: Triple.h:299
LLVM Value Representation.
Definition: Value.h:74
This is an optimization pass for GlobalISel generic memory operations.
Definition: AddressRanges.h:18