File indexing completed on 2026-05-10 08:44:19
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014 #ifndef LLVM_OBJECT_GOFFOBJECTFILE_H
0015 #define LLVM_OBJECT_GOFFOBJECTFILE_H
0016
0017 #include "llvm/ADT/DenseMap.h"
0018 #include "llvm/ADT/IndexedMap.h"
0019 #include "llvm/BinaryFormat/GOFF.h"
0020 #include "llvm/Object/ObjectFile.h"
0021 #include "llvm/Support/ConvertEBCDIC.h"
0022 #include "llvm/Support/Debug.h"
0023 #include "llvm/Support/raw_ostream.h"
0024 #include "llvm/TargetParser/SubtargetFeature.h"
0025 #include "llvm/TargetParser/Triple.h"
0026
0027 namespace llvm {
0028
0029 namespace object {
0030
0031 class GOFFObjectFile : public ObjectFile {
0032 friend class GOFFSymbolRef;
0033
0034 IndexedMap<const uint8_t *> EsdPtrs;
0035 SmallVector<const uint8_t *, 256> TextPtrs;
0036
0037 mutable DenseMap<uint32_t, std::pair<size_t, std::unique_ptr<char[]>>>
0038 EsdNamesCache;
0039
0040 typedef DataRefImpl SectionEntryImpl;
0041
0042
0043 SmallVector<SectionEntryImpl, 256> SectionList;
0044 mutable DenseMap<uint32_t, SmallVector<uint8_t>> SectionDataCache;
0045
0046 public:
0047 Expected<StringRef> getSymbolName(SymbolRef Symbol) const;
0048
0049 GOFFObjectFile(MemoryBufferRef Object, Error &Err);
0050 static inline bool classof(const Binary *V) { return V->isGOFF(); }
0051 section_iterator section_begin() const override;
0052 section_iterator section_end() const override;
0053
0054 uint8_t getBytesInAddress() const override { return 8; }
0055
0056 StringRef getFileFormatName() const override { return "GOFF-SystemZ"; }
0057
0058 Triple::ArchType getArch() const override { return Triple::systemz; }
0059
0060 Expected<SubtargetFeatures> getFeatures() const override { return SubtargetFeatures(); }
0061
0062 bool isRelocatableObject() const override { return true; }
0063
0064 void moveSymbolNext(DataRefImpl &Symb) const override;
0065 basic_symbol_iterator symbol_begin() const override;
0066 basic_symbol_iterator symbol_end() const override;
0067
0068 bool is64Bit() const override {
0069 return true;
0070 }
0071
0072 bool isSectionNoLoad(DataRefImpl Sec) const;
0073 bool isSectionReadOnlyData(DataRefImpl Sec) const;
0074 bool isSectionZeroInit(DataRefImpl Sec) const;
0075
0076 private:
0077
0078 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
0079 Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
0080 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
0081 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
0082 Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
0083 Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
0084 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
0085 uint64_t getSymbolSize(DataRefImpl Symb) const;
0086
0087 const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const;
0088 bool isSymbolUnresolved(DataRefImpl Symb) const;
0089 bool isSymbolIndirect(DataRefImpl Symb) const;
0090
0091
0092 void moveSectionNext(DataRefImpl &Sec) const override;
0093 virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const override;
0094 uint64_t getSectionAddress(DataRefImpl Sec) const override;
0095 uint64_t getSectionSize(DataRefImpl Sec) const override;
0096 virtual Expected<ArrayRef<uint8_t>>
0097 getSectionContents(DataRefImpl Sec) const override;
0098 uint64_t getSectionIndex(DataRefImpl Sec) const override { return Sec.d.a; }
0099 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
0100 bool isSectionCompressed(DataRefImpl Sec) const override { return false; }
0101 bool isSectionText(DataRefImpl Sec) const override;
0102 bool isSectionData(DataRefImpl Sec) const override;
0103 bool isSectionBSS(DataRefImpl Sec) const override { return false; }
0104 bool isSectionVirtual(DataRefImpl Sec) const override { return false; }
0105 relocation_iterator section_rel_begin(DataRefImpl Sec) const override {
0106 return relocation_iterator(RelocationRef(Sec, this));
0107 }
0108 relocation_iterator section_rel_end(DataRefImpl Sec) const override {
0109 return relocation_iterator(RelocationRef(Sec, this));
0110 }
0111
0112 const uint8_t *getSectionEdEsdRecord(DataRefImpl &Sec) const;
0113 const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const;
0114 const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const;
0115 const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const;
0116 uint32_t getSectionDefEsdId(DataRefImpl &Sec) const;
0117
0118
0119 void moveRelocationNext(DataRefImpl &Rel) const override {}
0120 uint64_t getRelocationOffset(DataRefImpl Rel) const override { return 0; }
0121 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override {
0122 DataRefImpl Temp;
0123 return basic_symbol_iterator(SymbolRef(Temp, this));
0124 }
0125 uint64_t getRelocationType(DataRefImpl Rel) const override { return 0; }
0126 void getRelocationTypeName(DataRefImpl Rel,
0127 SmallVectorImpl<char> &Result) const override {}
0128 };
0129
0130 class GOFFSymbolRef : public SymbolRef {
0131 public:
0132 GOFFSymbolRef(const SymbolRef &B) : SymbolRef(B) {
0133 assert(isa<GOFFObjectFile>(SymbolRef::getObject()));
0134 }
0135
0136 const GOFFObjectFile *getObject() const {
0137 return cast<GOFFObjectFile>(BasicSymbolRef::getObject());
0138 }
0139
0140 Expected<uint32_t> getSymbolGOFFFlags() const {
0141 return getObject()->getSymbolFlags(getRawDataRefImpl());
0142 }
0143
0144 Expected<SymbolRef::Type> getSymbolGOFFType() const {
0145 return getObject()->getSymbolType(getRawDataRefImpl());
0146 }
0147
0148 uint64_t getSize() const {
0149 return getObject()->getSymbolSize(getRawDataRefImpl());
0150 }
0151 };
0152
0153 }
0154
0155 }
0156
0157 #endif