1 //===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
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
7 //===----------------------------------------------------------------------===//
9 #ifndef LLVM_MC_MCOBJECTWRITER_H
10 #define LLVM_MC_MCOBJECTWRITER_H
12 #include "llvm/ADT/SmallVector.h"
13 #include "llvm/ADT/StringRef.h"
14 #include "llvm/ADT/Triple.h"
15 #include "llvm/Support/Endian.h"
16 #include "llvm/Support/EndianStream.h"
17 #include "llvm/Support/raw_ostream.h"
28 class MCSymbolRefExpr
;
31 /// Defines the object file and target independent interfaces used by the
32 /// assembler backend to write native file format object files.
34 /// The object writer contains a few callbacks used by the assembler to allow
35 /// the object writer to modify the assembler data structures at appropriate
36 /// points. Once assembly is complete, the object writer is given the
37 /// MCAssembler instance, which contains all the symbol and section data which
38 /// should be emitted as part of writeObject().
39 class MCObjectWriter
{
41 MCObjectWriter() = default;
44 MCObjectWriter(const MCObjectWriter
&) = delete;
45 MCObjectWriter
&operator=(const MCObjectWriter
&) = delete;
46 virtual ~MCObjectWriter();
48 /// lifetime management
49 virtual void reset() {}
51 /// \name High-Level API
54 /// Perform any late binding of symbols (for example, to assign symbol
55 /// indices for use when generating relocations).
57 /// This routine is called by the assembler after layout and relaxation is
59 virtual void executePostLayoutBinding(MCAssembler
&Asm
,
60 const MCAsmLayout
&Layout
) = 0;
62 /// Record a relocation entry.
64 /// This routine is called by the assembler after layout and relaxation, and
65 /// post layout binding. The implementation is responsible for storing
66 /// information about the relocation so that it can be emitted during
68 virtual void recordRelocation(MCAssembler
&Asm
, const MCAsmLayout
&Layout
,
69 const MCFragment
*Fragment
,
70 const MCFixup
&Fixup
, MCValue Target
,
71 uint64_t &FixedValue
) = 0;
73 /// Check whether the difference (A - B) between two symbol references is
76 /// Clients are not required to answer precisely and may conservatively return
77 /// false, even when a difference is fully resolved.
78 bool isSymbolRefDifferenceFullyResolved(const MCAssembler
&Asm
,
79 const MCSymbolRefExpr
*A
,
80 const MCSymbolRefExpr
*B
,
83 virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler
&Asm
,
88 virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler
&Asm
,
94 /// Tell the object writer to emit an address-significance table during
95 /// writeObject(). If this function is not called, all symbols are treated as
96 /// address-significant.
97 virtual void emitAddrsigSection() {}
99 /// Record the given symbol in the address-significance table to be written
100 /// diring writeObject().
101 virtual void addAddrsigSymbol(const MCSymbol
*Sym
) {}
103 /// Write the object file and returns the number of bytes written.
105 /// This routine is called by the assembler after layout and relaxation is
106 /// complete, fixups have been evaluated and applied, and relocations
108 virtual uint64_t writeObject(MCAssembler
&Asm
, const MCAsmLayout
&Layout
) = 0;
113 /// Base class for classes that define behaviour that is specific to both the
114 /// target and the object format.
115 class MCObjectTargetWriter
{
117 virtual ~MCObjectTargetWriter() = default;
118 virtual Triple::ObjectFormatType
getFormat() const = 0;
121 } // end namespace llvm
123 #endif // LLVM_MC_MCOBJECTWRITER_H