LLVM 24.0.0git
GOFFObjectFile.h
Go to the documentation of this file.
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"
23#include "llvm/Support/Debug.h"
27
28namespace llvm {
29
30namespace object {
31
32// RLD entry with all populated fields.
39
40// GOFFRelEntry::RelType is computed based on RLD fields at offset 1, 2, 4,
41// and 5.
42inline uint64_t getRldType(const uint8_t *Rld) {
43 return Rld[1] + (Rld[2] << 8) + (Rld[4] << 16) + (Rld[5] << 24);
44}
45
46// Getters for RLD fields based on GOFFRelEntry::RelType.
48 return static_cast<GOFF::RLDReferenceType>((RelType >> 4) & 0x0000000F);
49}
51 return static_cast<GOFF::RLDReferentType>((RelType) & 0x0000000F);
52}
54 return static_cast<GOFF::RLDAction>((RelType >> (8 + 1)) & 0x0000007F);
55}
57 return static_cast<GOFF::RLDFetchStore>((RelType >> 8) & 0x00000001);
58}
60 return static_cast<uint8_t>((RelType >> 16) & 0x000000FF);
61}
63 return static_cast<uint8_t>((RelType >> (24 + 5)) & 0x00000007);
64}
66 return static_cast<uint8_t>((RelType >> 24) & 0x00000007);
67}
68
70 friend class GOFFSymbolRef;
71
72 IndexedMap<const uint8_t *> EsdPtrs; // Indexed by EsdId.
75
77 EsdNamesCache;
78
79 typedef DataRefImpl SectionEntryImpl;
80 // (EDID, 0) code, r/o data section
81 // (EDID,PRID) r/w data section
83 mutable DenseMap<uint32_t, SmallVector<uint8_t>> SectionDataCache;
84
85 // Flattened data for all logical records (record type + continuous data
86 // without headers).
88
89 // Populate FlattenedData with all logical records.
90 Error createFlattenedData();
91
92 // Helper to get continuous data from a logical record (includes prefix +
93 // continuations) Returns the number of physical records consumed (including
94 // the initial record)
95 Expected<unsigned> getContinuousData(SmallVectorImpl<uint8_t> &CompleteData,
96 int DataIndex, uint16_t DataLength,
97 const uint8_t *Record) const;
98
99 void setRelocationData(const uint8_t *RldRecord);
100
101public:
102 // Get the flattened data structure
105 return FlattenedData;
106 }
107
108 Expected<StringRef> getSymbolName(SymbolRef Symbol) const;
109
110 // Returns the z/OS archive symbol attribute bits for a symbol:
111 // bit 2 (0x4): symbol is 64-bit
112 // bit 1 (0x2): symbol uses the XPLink calling convention
113 // bit 0 (0x1): symbol resides in a writable static area (WSA)
114 uint32_t getZOSSymbolArchiveAttributes(DataRefImpl Symb) const;
115
117 static inline bool classof(const Binary *V) { return V->isGOFF(); }
118 section_iterator section_begin() const override;
119 section_iterator section_end() const override;
120
121 uint8_t getBytesInAddress() const override { return 8; }
122
123 StringRef getFileFormatName() const override { return "GOFF-SystemZ"; }
124
125 Triple::ArchType getArch() const override { return Triple::systemz; }
126
128
129 bool isRelocatableObject() const override { return true; }
130
131 void moveSymbolNext(DataRefImpl &Symb) const override;
132 basic_symbol_iterator symbol_begin() const override;
133 basic_symbol_iterator symbol_end() const override;
134
135 bool is64Bit() const override {
136 return true;
137 }
138
139 bool isSectionNoLoad(DataRefImpl Sec) const;
140 bool isSectionReadOnlyData(DataRefImpl Sec) const;
141 bool isSectionZeroInit(DataRefImpl Sec) const;
142
143private:
144 // SymbolRef.
145 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
146 Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
147 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
148 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
149 Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
151 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
152 uint64_t getSymbolSize(DataRefImpl Symb) const;
153
154 const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const;
155 bool isSymbolUnresolved(DataRefImpl Symb) const;
156 bool isSymbolIndirect(DataRefImpl Symb) const;
157
158 // SectionRef.
159 void moveSectionNext(DataRefImpl &Sec) const override;
161 uint64_t getSectionAddress(DataRefImpl Sec) const override;
162 uint64_t getSectionSize(DataRefImpl Sec) const override;
164 getSectionContents(DataRefImpl Sec) const override;
165 uint64_t getSectionIndex(DataRefImpl Sec) const override { return Sec.d.a; }
166 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
167 bool isSectionCompressed(DataRefImpl Sec) const override { return false; }
168 bool isSectionText(DataRefImpl Sec) const override;
169 bool isSectionData(DataRefImpl Sec) const override;
170 bool isSectionBSS(DataRefImpl Sec) const override { return false; }
171 bool isSectionVirtual(DataRefImpl Sec) const override { return false; }
172 relocation_iterator section_rel_begin(DataRefImpl Sec) const override;
173 relocation_iterator section_rel_end(DataRefImpl Sec) const override;
174
175 const uint8_t *getSectionEdEsdRecord(DataRefImpl &Sec) const;
176 const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const;
177 const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const;
178 const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const;
179 uint32_t getSectionDefEsdId(DataRefImpl &Sec) const;
180
181 // RelocationRef.
182 void moveRelocationNext(DataRefImpl &Rel) const override;
183 uint64_t getRelocationOffset(DataRefImpl Rel) const override;
184 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override;
185 uint64_t getRelocationType(DataRefImpl Rel) const override;
186 void getRelocationTypeName(DataRefImpl Rel,
187 SmallVectorImpl<char> &Result) const override;
188};
189
190class GOFFSymbolRef : public SymbolRef {
191public:
195
199
201 return getObject()->getSymbolFlags(getRawDataRefImpl());
202 }
203
205 return getObject()->getSymbolType(getRawDataRefImpl());
206 }
207
209 return getObject()->getSymbolSize(getRawDataRefImpl());
210 }
211};
212
213} // namespace object
214
215} // namespace llvm
216
217#endif
assert(UImm &&(UImm !=~static_cast< T >(0)) &&"Invalid immediate!")
unsigned uint64_t
static GCRegistry::Add< OcamlGC > B("ocaml", "ocaml 3.10-compatible GC")
#define LLVM_ABI
Definition Compiler.h:215
This file provides utility functions for converting between EBCDIC-1047 and UTF-8.
This file defines the DenseMap class.
This file implements an indexed map.
static std::unique_ptr< PDBSymbol > getSymbolType(const PDBSymbol &Symbol)
Definition UDTLayout.cpp:34
Lightweight error class with error context and mandatory checking.
Definition Error.h:159
Tagged union holding either a T or a Error.
Definition Error.h:485
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
This is a 'vector' (really, a variable-sized array), optimized for the case when the array is small.
Represent a constant reference to a string, i.e.
Definition StringRef.h:56
Manages the enabling and disabling of subtarget specific features.
const SymbolicFile * getObject() const
DataRefImpl getRawDataRefImpl() const
Triple::ArchType getArch() const override
Expected< SubtargetFeatures > getFeatures() const override
uint8_t getBytesInAddress() const override
The number of bytes used to represent an address in this object file format.
GOFFObjectFile(MemoryBufferRef Object, Error &Err)
const SmallVector< std::pair< GOFF::RecordType, SmallVector< uint8_t > > > & getFlattenedData() const
static bool classof(const Binary *V)
bool is64Bit() const override
StringRef getFileFormatName() const override
bool isRelocatableObject() const override
True if this is a relocatable object (.o/.obj).
GOFFSymbolRef(const SymbolRef &B)
Expected< SymbolRef::Type > getSymbolGOFFType() const
Expected< uint32_t > getSymbolGOFFFlags() const
const GOFFObjectFile * getObject() const
ObjectFile(unsigned int Type, MemoryBufferRef Source)
Represents a GOFF physical record.
Definition GOFF.h:31
This is a value type class that represents a single symbol in the list of symbols in the object file.
Definition ObjectFile.h:170
const ObjectFile * getObject() const
Definition ObjectFile.h:493
RLDFetchStore
Definition GOFF.h:181
RLDReferenceType
Definition GOFF.h:160
RLDReferentType
Definition GOFF.h:169
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
uint8_t getRLDTargetLength(uint64_t RelType)
content_iterator< SectionRef > section_iterator
Definition ObjectFile.h:49
uint8_t getRLDBitLength(uint64_t RelType)
content_iterator< BasicSymbolRef > basic_symbol_iterator
uint64_t getRldType(const uint8_t *Rld)
GOFF::RLDReferentType getRLDReferentType(uint64_t RelType)
GOFF::RLDReferenceType getRLDReferenceType(uint64_t RelType)
uint8_t getRLDBitOffset(uint64_t RelType)
GOFF::RLDFetchStore getRLDFetchStore(uint64_t RelType)
GOFF::RLDAction getRLDAction(uint64_t RelType)
content_iterator< RelocationRef > relocation_iterator
Definition ObjectFile.h:79
This is an optimization pass for GlobalISel generic memory operations.
bool isa(const From &Val)
isa<X> - Return true if the parameter to the template is an instance of one of the template type argu...
Definition Casting.h:547
decltype(auto) cast(const From &Val)
cast<X> - Return the argument parameter cast to the specified type.
Definition Casting.h:559
struct llvm::object::DataRefImpl::@005117267142344013370254144343227032034000327225 d