1321369Sdim//===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===// 2205407Srdivacky// 3353358Sdim// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4353358Sdim// See https://llvm.org/LICENSE.txt for license information. 5353358Sdim// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6205407Srdivacky// 7205407Srdivacky//===----------------------------------------------------------------------===// 8205407Srdivacky 9205407Srdivacky#ifndef LLVM_MC_MCOBJECTWRITER_H 10205407Srdivacky#define LLVM_MC_MCOBJECTWRITER_H 11205407Srdivacky 12249423Sdim#include "llvm/ADT/SmallVector.h" 13321369Sdim#include "llvm/ADT/StringRef.h" 14341825Sdim#include "llvm/ADT/Triple.h" 15321369Sdim#include "llvm/Support/Endian.h" 16288943Sdim#include "llvm/Support/EndianStream.h" 17249423Sdim#include "llvm/Support/raw_ostream.h" 18205407Srdivacky#include <cassert> 19321369Sdim#include <cstdint> 20205407Srdivacky 21205407Srdivackynamespace llvm { 22321369Sdim 23206083Srdivackyclass MCAsmLayout; 24205407Srdivackyclass MCAssembler; 25208599Srdivackyclass MCFixup; 26206083Srdivackyclass MCFragment; 27309124Sdimclass MCSymbol; 28218893Sdimclass MCSymbolRefExpr; 29205407Srdivackyclass MCValue; 30205407Srdivacky 31288943Sdim/// Defines the object file and target independent interfaces used by the 32288943Sdim/// assembler backend to write native file format object files. 33205407Srdivacky/// 34205407Srdivacky/// The object writer contains a few callbacks used by the assembler to allow 35205407Srdivacky/// the object writer to modify the assembler data structures at appropriate 36205407Srdivacky/// points. Once assembly is complete, the object writer is given the 37205407Srdivacky/// MCAssembler instance, which contains all the symbol and section data which 38288943Sdim/// should be emitted as part of writeObject(). 39205407Srdivackyclass MCObjectWriter { 40205407Srdivackyprotected: 41341825Sdim MCObjectWriter() = default; 42205407Srdivacky 43205407Srdivackypublic: 44321369Sdim MCObjectWriter(const MCObjectWriter &) = delete; 45321369Sdim MCObjectWriter &operator=(const MCObjectWriter &) = delete; 46205407Srdivacky virtual ~MCObjectWriter(); 47205407Srdivacky 48249423Sdim /// lifetime management 49288943Sdim virtual void reset() {} 50249423Sdim 51288943Sdim /// \name High-Level API 52205407Srdivacky /// @{ 53205407Srdivacky 54288943Sdim /// Perform any late binding of symbols (for example, to assign symbol 55249423Sdim /// indices for use when generating relocations). 56205407Srdivacky /// 57205407Srdivacky /// This routine is called by the assembler after layout and relaxation is 58205407Srdivacky /// complete. 59288943Sdim virtual void executePostLayoutBinding(MCAssembler &Asm, 60218893Sdim const MCAsmLayout &Layout) = 0; 61205407Srdivacky 62288943Sdim /// Record a relocation entry. 63205407Srdivacky /// 64205407Srdivacky /// This routine is called by the assembler after layout and relaxation, and 65205407Srdivacky /// post layout binding. The implementation is responsible for storing 66205407Srdivacky /// information about the relocation so that it can be emitted during 67288943Sdim /// writeObject(). 68288943Sdim virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout, 69206083Srdivacky const MCFragment *Fragment, 70208599Srdivacky const MCFixup &Fixup, MCValue Target, 71321369Sdim uint64_t &FixedValue) = 0; 72205407Srdivacky 73288943Sdim /// Check whether the difference (A - B) between two symbol references is 74288943Sdim /// fully resolved. 75218893Sdim /// 76218893Sdim /// Clients are not required to answer precisely and may conservatively return 77218893Sdim /// false, even when a difference is fully resolved. 78288943Sdim bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm, 79288943Sdim const MCSymbolRefExpr *A, 80288943Sdim const MCSymbolRefExpr *B, 81288943Sdim bool InSet) const; 82218893Sdim 83288943Sdim virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, 84296417Sdim const MCSymbol &A, 85296417Sdim const MCSymbol &B, 86296417Sdim bool InSet) const; 87296417Sdim 88296417Sdim virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm, 89288943Sdim const MCSymbol &SymA, 90288943Sdim const MCFragment &FB, 91288943Sdim bool InSet, 92288943Sdim bool IsPCRel) const; 93218893Sdim 94341825Sdim /// Tell the object writer to emit an address-significance table during 95341825Sdim /// writeObject(). If this function is not called, all symbols are treated as 96341825Sdim /// address-significant. 97341825Sdim virtual void emitAddrsigSection() {} 98341825Sdim 99341825Sdim /// Record the given symbol in the address-significance table to be written 100341825Sdim /// diring writeObject(). 101341825Sdim virtual void addAddrsigSymbol(const MCSymbol *Sym) {} 102341825Sdim 103341825Sdim /// Write the object file and returns the number of bytes written. 104205407Srdivacky /// 105205407Srdivacky /// This routine is called by the assembler after layout and relaxation is 106208599Srdivacky /// complete, fixups have been evaluated and applied, and relocations 107205407Srdivacky /// generated. 108341825Sdim virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0; 109205407Srdivacky 110205407Srdivacky /// @} 111341825Sdim}; 112205407Srdivacky 113341825Sdim/// Base class for classes that define behaviour that is specific to both the 114341825Sdim/// target and the object format. 115341825Sdimclass MCObjectTargetWriter { 116341825Sdimpublic: 117341825Sdim virtual ~MCObjectTargetWriter() = default; 118341825Sdim virtual Triple::ObjectFormatType getFormat() const = 0; 119205407Srdivacky}; 120205407Srdivacky 121321369Sdim} // end namespace llvm 122205407Srdivacky 123321369Sdim#endif // LLVM_MC_MCOBJECTWRITER_H 124