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