MCObjectWriter.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- llvm/MC/MCObjectWriter.h - Object File Writer Interface --*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. #ifndef LLVM_MC_MCOBJECTWRITER_H
  14. #define LLVM_MC_MCOBJECTWRITER_H
  15. #include "llvm/ADT/Triple.h"
  16. #include <cstdint>
  17. namespace llvm {
  18. class MCAsmLayout;
  19. class MCAssembler;
  20. class MCFixup;
  21. class MCFragment;
  22. class MCSymbol;
  23. class MCSymbolRefExpr;
  24. class MCValue;
  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().
  33. class MCObjectWriter {
  34. protected:
  35. MCObjectWriter() = default;
  36. public:
  37. MCObjectWriter(const MCObjectWriter &) = delete;
  38. MCObjectWriter &operator=(const MCObjectWriter &) = delete;
  39. virtual ~MCObjectWriter();
  40. /// lifetime management
  41. virtual void reset() {}
  42. /// \name High-Level API
  43. /// @{
  44. /// Perform any late binding of symbols (for example, to assign symbol
  45. /// indices for use when generating relocations).
  46. ///
  47. /// This routine is called by the assembler after layout and relaxation is
  48. /// complete.
  49. virtual void executePostLayoutBinding(MCAssembler &Asm,
  50. const MCAsmLayout &Layout) = 0;
  51. /// Record a relocation entry.
  52. ///
  53. /// This routine is called by the assembler after layout and relaxation, and
  54. /// post layout binding. The implementation is responsible for storing
  55. /// information about the relocation so that it can be emitted during
  56. /// writeObject().
  57. virtual void recordRelocation(MCAssembler &Asm, const MCAsmLayout &Layout,
  58. const MCFragment *Fragment,
  59. const MCFixup &Fixup, MCValue Target,
  60. uint64_t &FixedValue) = 0;
  61. /// Check whether the difference (A - B) between two symbol references is
  62. /// fully resolved.
  63. ///
  64. /// Clients are not required to answer precisely and may conservatively return
  65. /// false, even when a difference is fully resolved.
  66. bool isSymbolRefDifferenceFullyResolved(const MCAssembler &Asm,
  67. const MCSymbolRefExpr *A,
  68. const MCSymbolRefExpr *B,
  69. bool InSet) const;
  70. virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
  71. const MCSymbol &A,
  72. const MCSymbol &B,
  73. bool InSet) const;
  74. virtual bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
  75. const MCSymbol &SymA,
  76. const MCFragment &FB,
  77. bool InSet,
  78. bool IsPCRel) const;
  79. /// ELF only. Mark that we have seen GNU ABI usage (e.g. SHF_GNU_RETAIN).
  80. virtual void markGnuAbi() {}
  81. /// Tell the object writer to emit an address-significance table during
  82. /// writeObject(). If this function is not called, all symbols are treated as
  83. /// address-significant.
  84. virtual void emitAddrsigSection() {}
  85. /// Record the given symbol in the address-significance table to be written
  86. /// diring writeObject().
  87. virtual void addAddrsigSymbol(const MCSymbol *Sym) {}
  88. /// Write the object file and returns the number of bytes written.
  89. ///
  90. /// This routine is called by the assembler after layout and relaxation is
  91. /// complete, fixups have been evaluated and applied, and relocations
  92. /// generated.
  93. virtual uint64_t writeObject(MCAssembler &Asm, const MCAsmLayout &Layout) = 0;
  94. /// @}
  95. };
  96. /// Base class for classes that define behaviour that is specific to both the
  97. /// target and the object format.
  98. class MCObjectTargetWriter {
  99. public:
  100. virtual ~MCObjectTargetWriter() = default;
  101. virtual Triple::ObjectFormatType getFormat() const = 0;
  102. };
  103. } // end namespace llvm
  104. #endif // LLVM_MC_MCOBJECTWRITER_H
  105. #ifdef __GNUC__
  106. #pragma GCC diagnostic pop
  107. #endif