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/raw_ostream.h"
24 #include "llvm/TargetParser/SubtargetFeature.h"
25 #include "llvm/TargetParser/Triple.h"
26 
27 namespace llvm {
28 
29 namespace object {
30 
31 class GOFFObjectFile : public ObjectFile {
32   IndexedMap<const uint8_t *> EsdPtrs; // Indexed by EsdId.
33 
34   mutable DenseMap<uint32_t, std::pair<size_t, std::unique_ptr<char[]>>>
35       EsdNamesCache;
36 
37   typedef DataRefImpl SectionEntryImpl;
38   // (EDID, 0)               code, r/o data section
39   // (EDID,PRID)             r/w data section
40   SmallVector<SectionEntryImpl, 256> SectionList;
41   mutable DenseMap<uint32_t, std::string> SectionDataCache;
42 
43 public:
44   Expected<StringRef> getSymbolName(SymbolRef Symbol) const;
45 
46   GOFFObjectFile(MemoryBufferRef Object, Error &Err);
classof(const Binary * V)47   static inline bool classof(const Binary *V) { return V->isGOFF(); }
48   section_iterator section_begin() const override;
49   section_iterator section_end() const override;
50 
getBytesInAddress()51   uint8_t getBytesInAddress() const override { return 8; }
52 
getFileFormatName()53   StringRef getFileFormatName() const override { return "GOFF-SystemZ"; }
54 
getArch()55   Triple::ArchType getArch() const override { return Triple::systemz; }
56 
getFeatures()57   Expected<SubtargetFeatures> getFeatures() const override { return SubtargetFeatures(); }
58 
isRelocatableObject()59   bool isRelocatableObject() const override { return true; }
60 
61   void moveSymbolNext(DataRefImpl &Symb) const override;
62   basic_symbol_iterator symbol_begin() const override;
63   basic_symbol_iterator symbol_end() const override;
64 
is64Bit()65   bool is64Bit() const override {
66     return true;
67   }
68 
69 private:
70   // SymbolRef.
71   Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
72   Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
73   uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
74   uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
75   Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
76   Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
77   Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
78 
79   const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const;
80   bool isSymbolUnresolved(DataRefImpl Symb) const;
81   bool isSymbolIndirect(DataRefImpl Symb) const;
82 
83   // SectionRef.
moveSectionNext(DataRefImpl & Sec)84   void moveSectionNext(DataRefImpl &Sec) const override {}
getSectionName(DataRefImpl Sec)85   virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const override {
86     return StringRef();
87   }
getSectionAddress(DataRefImpl Sec)88   uint64_t getSectionAddress(DataRefImpl Sec) const override { return 0; }
getSectionSize(DataRefImpl Sec)89   uint64_t getSectionSize(DataRefImpl Sec) const override { return 0; }
90   virtual Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec)91   getSectionContents(DataRefImpl Sec) const override {
92     return ArrayRef<uint8_t>();
93   }
getSectionIndex(DataRefImpl Sec)94   uint64_t getSectionIndex(DataRefImpl Sec) const override { return 0; }
getSectionAlignment(DataRefImpl Sec)95   uint64_t getSectionAlignment(DataRefImpl Sec) const override { return 0; }
isSectionCompressed(DataRefImpl Sec)96   bool isSectionCompressed(DataRefImpl Sec) const override { return false; }
isSectionText(DataRefImpl Sec)97   bool isSectionText(DataRefImpl Sec) const override { return false; }
isSectionData(DataRefImpl Sec)98   bool isSectionData(DataRefImpl Sec) const override { return false; }
isSectionBSS(DataRefImpl Sec)99   bool isSectionBSS(DataRefImpl Sec) const override { return false; }
isSectionVirtual(DataRefImpl Sec)100   bool isSectionVirtual(DataRefImpl Sec) const override { return false; }
section_rel_begin(DataRefImpl Sec)101   relocation_iterator section_rel_begin(DataRefImpl Sec) const override {
102     return relocation_iterator(RelocationRef(Sec, this));
103   }
section_rel_end(DataRefImpl Sec)104   relocation_iterator section_rel_end(DataRefImpl Sec) const override {
105     return relocation_iterator(RelocationRef(Sec, this));
106   }
107 
108   const uint8_t *getSectionEdEsdRecord(DataRefImpl &Sec) const;
109   const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const;
110   const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const;
111   const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const;
112 
113   // RelocationRef.
moveRelocationNext(DataRefImpl & Rel)114   void moveRelocationNext(DataRefImpl &Rel) const override {}
getRelocationOffset(DataRefImpl Rel)115   uint64_t getRelocationOffset(DataRefImpl Rel) const override { return 0; }
getRelocationSymbol(DataRefImpl Rel)116   symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override {
117     DataRefImpl Temp;
118     return basic_symbol_iterator(SymbolRef(Temp, this));
119   }
getRelocationType(DataRefImpl Rel)120   uint64_t getRelocationType(DataRefImpl Rel) const override { return 0; }
getRelocationTypeName(DataRefImpl Rel,SmallVectorImpl<char> & Result)121   void getRelocationTypeName(DataRefImpl Rel,
122                              SmallVectorImpl<char> &Result) const override {}
123 };
124 
125 } // namespace object
126 
127 } // namespace llvm
128 
129 #endif
130