1*06c3fb27SDimitry Andric //===- GOFFObjectFile.h - GOFF object file implementation -------*- C++ -*-===// 2*06c3fb27SDimitry Andric // 3*06c3fb27SDimitry Andric // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. 4*06c3fb27SDimitry Andric // See https://llvm.org/LICENSE.txt for license information. 5*06c3fb27SDimitry Andric // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception 6*06c3fb27SDimitry Andric // 7*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 8*06c3fb27SDimitry Andric // 9*06c3fb27SDimitry Andric // This file declares the GOFFObjectFile class. 10*06c3fb27SDimitry Andric // Record classes and derivatives are also declared and implemented. 11*06c3fb27SDimitry Andric // 12*06c3fb27SDimitry Andric //===----------------------------------------------------------------------===// 13*06c3fb27SDimitry Andric 14*06c3fb27SDimitry Andric #ifndef LLVM_OBJECT_GOFFOBJECTFILE_H 15*06c3fb27SDimitry Andric #define LLVM_OBJECT_GOFFOBJECTFILE_H 16*06c3fb27SDimitry Andric 17*06c3fb27SDimitry Andric #include "llvm/ADT/DenseMap.h" 18*06c3fb27SDimitry Andric #include "llvm/ADT/IndexedMap.h" 19*06c3fb27SDimitry Andric #include "llvm/BinaryFormat/GOFF.h" 20*06c3fb27SDimitry Andric #include "llvm/Object/ObjectFile.h" 21*06c3fb27SDimitry Andric #include "llvm/Support/ConvertEBCDIC.h" 22*06c3fb27SDimitry Andric #include "llvm/Support/Debug.h" 23*06c3fb27SDimitry Andric #include "llvm/Support/Endian.h" 24*06c3fb27SDimitry Andric #include "llvm/Support/raw_ostream.h" 25*06c3fb27SDimitry Andric #include "llvm/TargetParser/SubtargetFeature.h" 26*06c3fb27SDimitry Andric #include "llvm/TargetParser/Triple.h" 27*06c3fb27SDimitry Andric 28*06c3fb27SDimitry Andric namespace llvm { 29*06c3fb27SDimitry Andric 30*06c3fb27SDimitry Andric namespace object { 31*06c3fb27SDimitry Andric 32*06c3fb27SDimitry Andric class GOFFObjectFile : public ObjectFile { 33*06c3fb27SDimitry Andric IndexedMap<const uint8_t *> EsdPtrs; // Indexed by EsdId. 34*06c3fb27SDimitry Andric 35*06c3fb27SDimitry Andric mutable DenseMap<uint32_t, std::pair<size_t, std::unique_ptr<char[]>>> 36*06c3fb27SDimitry Andric EsdNamesCache; 37*06c3fb27SDimitry Andric 38*06c3fb27SDimitry Andric typedef DataRefImpl SectionEntryImpl; 39*06c3fb27SDimitry Andric // (EDID, 0) code, r/o data section 40*06c3fb27SDimitry Andric // (EDID,PRID) r/w data section 41*06c3fb27SDimitry Andric SmallVector<SectionEntryImpl, 256> SectionList; 42*06c3fb27SDimitry Andric mutable DenseMap<uint32_t, std::string> SectionDataCache; 43*06c3fb27SDimitry Andric 44*06c3fb27SDimitry Andric public: 45*06c3fb27SDimitry Andric Expected<StringRef> getSymbolName(SymbolRef Symbol) const; 46*06c3fb27SDimitry Andric 47*06c3fb27SDimitry Andric GOFFObjectFile(MemoryBufferRef Object, Error &Err); 48*06c3fb27SDimitry Andric static inline bool classof(const Binary *V) { return V->isGOFF(); } 49*06c3fb27SDimitry Andric section_iterator section_begin() const override; 50*06c3fb27SDimitry Andric section_iterator section_end() const override; 51*06c3fb27SDimitry Andric 52*06c3fb27SDimitry Andric uint8_t getBytesInAddress() const override { return 8; } 53*06c3fb27SDimitry Andric 54*06c3fb27SDimitry Andric StringRef getFileFormatName() const override { return "GOFF-SystemZ"; } 55*06c3fb27SDimitry Andric 56*06c3fb27SDimitry Andric Triple::ArchType getArch() const override { return Triple::systemz; } 57*06c3fb27SDimitry Andric 58*06c3fb27SDimitry Andric Expected<SubtargetFeatures> getFeatures() const override { return SubtargetFeatures(); } 59*06c3fb27SDimitry Andric 60*06c3fb27SDimitry Andric bool isRelocatableObject() const override { return true; } 61*06c3fb27SDimitry Andric 62*06c3fb27SDimitry Andric void moveSymbolNext(DataRefImpl &Symb) const override; 63*06c3fb27SDimitry Andric basic_symbol_iterator symbol_begin() const override; 64*06c3fb27SDimitry Andric basic_symbol_iterator symbol_end() const override; 65*06c3fb27SDimitry Andric 66*06c3fb27SDimitry Andric bool is64Bit() const override { 67*06c3fb27SDimitry Andric return true; 68*06c3fb27SDimitry Andric } 69*06c3fb27SDimitry Andric 70*06c3fb27SDimitry Andric private: 71*06c3fb27SDimitry Andric // SymbolRef. 72*06c3fb27SDimitry Andric Expected<StringRef> getSymbolName(DataRefImpl Symb) const override; 73*06c3fb27SDimitry Andric Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override; 74*06c3fb27SDimitry Andric uint64_t getSymbolValueImpl(DataRefImpl Symb) const override; 75*06c3fb27SDimitry Andric uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override; 76*06c3fb27SDimitry Andric Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override; 77*06c3fb27SDimitry Andric Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override; 78*06c3fb27SDimitry Andric Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override; 79*06c3fb27SDimitry Andric 80*06c3fb27SDimitry Andric const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const; 81*06c3fb27SDimitry Andric bool isSymbolUnresolved(DataRefImpl Symb) const; 82*06c3fb27SDimitry Andric bool isSymbolIndirect(DataRefImpl Symb) const; 83*06c3fb27SDimitry Andric 84*06c3fb27SDimitry Andric // SectionRef. 85*06c3fb27SDimitry Andric void moveSectionNext(DataRefImpl &Sec) const override {} 86*06c3fb27SDimitry Andric virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const override { 87*06c3fb27SDimitry Andric return StringRef(); 88*06c3fb27SDimitry Andric } 89*06c3fb27SDimitry Andric uint64_t getSectionAddress(DataRefImpl Sec) const override { return 0; } 90*06c3fb27SDimitry Andric uint64_t getSectionSize(DataRefImpl Sec) const override { return 0; } 91*06c3fb27SDimitry Andric virtual Expected<ArrayRef<uint8_t>> 92*06c3fb27SDimitry Andric getSectionContents(DataRefImpl Sec) const override { 93*06c3fb27SDimitry Andric return ArrayRef<uint8_t>(); 94*06c3fb27SDimitry Andric } 95*06c3fb27SDimitry Andric uint64_t getSectionIndex(DataRefImpl Sec) const override { return 0; } 96*06c3fb27SDimitry Andric uint64_t getSectionAlignment(DataRefImpl Sec) const override { return 0; } 97*06c3fb27SDimitry Andric bool isSectionCompressed(DataRefImpl Sec) const override { return false; } 98*06c3fb27SDimitry Andric bool isSectionText(DataRefImpl Sec) const override { return false; } 99*06c3fb27SDimitry Andric bool isSectionData(DataRefImpl Sec) const override { return false; } 100*06c3fb27SDimitry Andric bool isSectionBSS(DataRefImpl Sec) const override { return false; } 101*06c3fb27SDimitry Andric bool isSectionVirtual(DataRefImpl Sec) const override { return false; } 102*06c3fb27SDimitry Andric relocation_iterator section_rel_begin(DataRefImpl Sec) const override { 103*06c3fb27SDimitry Andric return relocation_iterator(RelocationRef(Sec, this)); 104*06c3fb27SDimitry Andric } 105*06c3fb27SDimitry Andric relocation_iterator section_rel_end(DataRefImpl Sec) const override { 106*06c3fb27SDimitry Andric return relocation_iterator(RelocationRef(Sec, this)); 107*06c3fb27SDimitry Andric } 108*06c3fb27SDimitry Andric 109*06c3fb27SDimitry Andric const uint8_t *getSectionEdEsdRecord(DataRefImpl &Sec) const; 110*06c3fb27SDimitry Andric const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const; 111*06c3fb27SDimitry Andric const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const; 112*06c3fb27SDimitry Andric const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const; 113*06c3fb27SDimitry Andric 114*06c3fb27SDimitry Andric // RelocationRef. 115*06c3fb27SDimitry Andric void moveRelocationNext(DataRefImpl &Rel) const override {} 116*06c3fb27SDimitry Andric uint64_t getRelocationOffset(DataRefImpl Rel) const override { return 0; } 117*06c3fb27SDimitry Andric symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override { 118*06c3fb27SDimitry Andric DataRefImpl Temp; 119*06c3fb27SDimitry Andric return basic_symbol_iterator(SymbolRef(Temp, this)); 120*06c3fb27SDimitry Andric } 121*06c3fb27SDimitry Andric uint64_t getRelocationType(DataRefImpl Rel) const override { return 0; } 122*06c3fb27SDimitry Andric void getRelocationTypeName(DataRefImpl Rel, 123*06c3fb27SDimitry Andric SmallVectorImpl<char> &Result) const override {} 124*06c3fb27SDimitry Andric }; 125*06c3fb27SDimitry Andric 126*06c3fb27SDimitry Andric } // namespace object 127*06c3fb27SDimitry Andric 128*06c3fb27SDimitry Andric } // namespace llvm 129*06c3fb27SDimitry Andric 130*06c3fb27SDimitry Andric #endif 131