Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:44:15

0001 //===- llvm/MC/MCWinCOFFObjectWriter.h - Win COFF Object Writer -*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLVM_MC_MCWINCOFFOBJECTWRITER_H
0010 #define LLVM_MC_MCWINCOFFOBJECTWRITER_H
0011 
0012 #include "llvm/MC/MCObjectWriter.h"
0013 #include <memory>
0014 
0015 namespace llvm {
0016 
0017 class MCAsmBackend;
0018 class MCContext;
0019 class MCFixup;
0020 class MCValue;
0021 class raw_pwrite_stream;
0022 
0023 class MCWinCOFFObjectTargetWriter : public MCObjectTargetWriter {
0024   virtual void anchor();
0025 
0026   const unsigned Machine;
0027 
0028 protected:
0029   MCWinCOFFObjectTargetWriter(unsigned Machine_);
0030 
0031 public:
0032   virtual ~MCWinCOFFObjectTargetWriter() = default;
0033 
0034   Triple::ObjectFormatType getFormat() const override { return Triple::COFF; }
0035   static bool classof(const MCObjectTargetWriter *W) {
0036     return W->getFormat() == Triple::COFF;
0037   }
0038 
0039   unsigned getMachine() const { return Machine; }
0040   virtual unsigned getRelocType(MCContext &Ctx, const MCValue &Target,
0041                                 const MCFixup &Fixup, bool IsCrossSection,
0042                                 const MCAsmBackend &MAB) const = 0;
0043   virtual bool recordRelocation(const MCFixup &) const { return true; }
0044 };
0045 
0046 class WinCOFFWriter;
0047 
0048 class WinCOFFObjectWriter final : public MCObjectWriter {
0049   friend class WinCOFFWriter;
0050 
0051   std::unique_ptr<MCWinCOFFObjectTargetWriter> TargetObjectWriter;
0052   std::unique_ptr<WinCOFFWriter> ObjWriter, DwoWriter;
0053   bool IncrementalLinkerCompatible = false;
0054 
0055 public:
0056   WinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
0057                       raw_pwrite_stream &OS);
0058   WinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
0059                       raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
0060 
0061   // MCObjectWriter interface implementation.
0062   void reset() override;
0063   void setIncrementalLinkerCompatible(bool Value) {
0064     IncrementalLinkerCompatible = Value;
0065   }
0066   void executePostLayoutBinding(MCAssembler &Asm) override;
0067   bool isSymbolRefDifferenceFullyResolvedImpl(const MCAssembler &Asm,
0068                                               const MCSymbol &SymA,
0069                                               const MCFragment &FB, bool InSet,
0070                                               bool IsPCRel) const override;
0071   void recordRelocation(MCAssembler &Asm, const MCFragment *Fragment,
0072                         const MCFixup &Fixup, MCValue Target,
0073                         uint64_t &FixedValue) override;
0074   uint64_t writeObject(MCAssembler &Asm) override;
0075   int getSectionNumber(const MCSection &Section) const;
0076 };
0077 
0078 /// Construct a new Win COFF writer instance.
0079 ///
0080 /// \param MOTW - The target specific WinCOFF writer subclass.
0081 /// \param OS - The stream to write to.
0082 /// \returns The constructed object writer.
0083 std::unique_ptr<MCObjectWriter>
0084 createWinCOFFObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
0085                           raw_pwrite_stream &OS);
0086 
0087 std::unique_ptr<MCObjectWriter>
0088 createWinCOFFDwoObjectWriter(std::unique_ptr<MCWinCOFFObjectTargetWriter> MOTW,
0089                              raw_pwrite_stream &OS, raw_pwrite_stream &DwoOS);
0090 } // end namespace llvm
0091 
0092 #endif // LLVM_MC_MCWINCOFFOBJECTWRITER_H