1 //===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #ifndef LLVM_MC_MCOBJECTWRITER_H
11 #define LLVM_MC_MCOBJECTWRITER_H
13 #include "llvm/ADT/SmallVector.h"
14 #include "llvm/ADT/StringRef.h"
15 #include "llvm/ADT/Triple.h"
16 #include "llvm/Support/Endian.h"
17 #include "llvm/Support/EndianStream.h"
18 #include "llvm/Support/raw_ostream.h"
29 class MCSymbolRefExpr;
32 /// Defines the object file and target independent interfaces used by the
33 /// assembler backend to write native file format object files.
35 /// The object writer contains a few callbacks used by the assembler to allow
36 /// the object writer to modify the assembler data structures at appropriate
37 /// points. Once assembly is complete, the object writer is given the
38 /// MCAssembler instance, which contains all the symbol and section data which
39 /// should be emitted as part of writeObject().
40 class MCObjectWriter {
42 MCObjectWriter() = default;
45 MCObjectWriter(const MCObjectWriter &) = delete;
46 MCObjectWriter &operator=(const MCObjectWriter &) = delete;
47 virtual ~MCObjectWriter();
49 /// lifetime management
50 virtual void reset() {}
52 /// \name High-Level API
55 /// Perform any late binding of symbols (for example, to assign symbol
56 /// indices for use when generating relocations).
58 /// This routine is called by the assembler after layout and relaxation is
60 virtual void executePostLayoutBinding(MCAssembler &Asm,
61 const MCAsmLayout &Layout) = 0;
63 /// Record a relocation entry.
65 /// This routine is called by the assembler after layout and relaxation, and
66 /// post layout binding. The implementation is responsible for storing
67 /// information about the relocation so that it can be emitted during
69 virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
70 const MCFragment *Fragment,
71 const MCFixup &Fixup, MCValue Target,
72 uint64_t &FixedValue) = 0;
74 /// Check whether the difference (A - B) between two symbol references is
77 /// Clients are not required to answer precisely and may conservatively return
78 /// false, even when a difference is fully resolved.
79 bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
80 const MCSymbolRefExpr *A,
81 const MCSymbolRefExpr *B,
84 virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
89 virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
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.
98 virtual void emitAddrsigSection() {}
100 /// Record the given symbol in the address-significance table to be written
101 /// diring writeObject().
102 virtual void addAddrsigSymbol(const MCSymbol *Sym) {}
104 /// Write the object file and returns the number of bytes written.
106 /// This routine is called by the assembler after layout and relaxation is
107 /// complete, fixups have been evaluated and applied, and relocations
109 virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
114 /// Base class for classes that define behaviour that is specific to both the
115 /// target and the object format.
116 class MCObjectTargetWriter {
118 virtual ~MCObjectTargetWriter() = default;
119 virtual Triple::ObjectFormatType getFormat() const = 0;
122 } // end namespace llvm
124 #endif // LLVM_MC_MCOBJECTWRITER_H