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
33 friend class GOFFSymbolRef;
34
35 IndexedMap<const uint8_t *> EsdPtrs; // Indexed by EsdId.
37
39 EsdNamesCache;
40
41 typedef DataRefImpl SectionEntryImpl;
42 // (EDID, 0) code, r/o data section
43 // (EDID,PRID) r/w data section
45 mutable DenseMap<uint32_t, SmallVector<uint8_t>> SectionDataCache;
46
47 // Flattened data for all logical records (record type + continuous data
48 // without headers).
50
51 // Populate FlattenedData with all logical records.
52 Error createFlattenedData();
53
54 // Helper to get continuous data from a logical record (includes prefix +
55 // continuations) Returns the number of physical records consumed (including
56 // the initial record)
57 Expected<unsigned> getContinuousData(SmallVectorImpl<uint8_t> &CompleteData,
58 int DataIndex, uint16_t DataLength,
59 const uint8_t *Record) const;
60
61public:
62 // Get the flattened data structure
65 return FlattenedData;
66 }
67
68 Expected<StringRef> getSymbolName(SymbolRef Symbol) const;
69
70 // Returns the z/OS archive symbol attribute bits for a symbol:
71 // bit 2 (0x4): symbol is 64-bit
72 // bit 1 (0x2): symbol uses the XPLink calling convention
73 // bit 0 (0x1): symbol resides in a writable static area (WSA)
74 uint32_t getZOSSymbolArchiveAttributes(DataRefImpl Symb) const;
75
77 static inline bool classof(const Binary *V) { return V->isGOFF(); }
78 section_iterator section_begin() const override;
79 section_iterator section_end() const override;
80
81 uint8_t getBytesInAddress() const override { return 8; }
82
83 StringRef getFileFormatName() const override { return "GOFF-SystemZ"; }
84
85 Triple::ArchType getArch() const override { return Triple::systemz; }
86
88
89 bool isRelocatableObject() const override { return true; }
90
91 void moveSymbolNext(DataRefImpl &Symb) const override;
92 basic_symbol_iterator symbol_begin() const override;
93 basic_symbol_iterator symbol_end() const override;
94
95 bool is64Bit() const override {
96 return true;
97 }
98
99 bool isSectionNoLoad(DataRefImpl Sec) const;
100 bool isSectionReadOnlyData(DataRefImpl Sec) const;
101 bool isSectionZeroInit(DataRefImpl Sec) const;
102
103private:
104 // SymbolRef.
105 Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
106 Expected<uint64_t> getSymbolAddress(DataRefImpl Symb) const override;
107 uint64_t getSymbolValueImpl(DataRefImpl Symb) const override;
108 uint64_t getCommonSymbolSizeImpl(DataRefImpl Symb) const override;
109 Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
111 Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
112 uint64_t getSymbolSize(DataRefImpl Symb) const;
113
114 const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const;
115 bool isSymbolUnresolved(DataRefImpl Symb) const;
116 bool isSymbolIndirect(DataRefImpl Symb) const;
117
118 // SectionRef.
119 void moveSectionNext(DataRefImpl &Sec) const override;
121 uint64_t getSectionAddress(DataRefImpl Sec) const override;
122 uint64_t getSectionSize(DataRefImpl Sec) const override;
124 getSectionContents(DataRefImpl Sec) const override;
125 uint64_t getSectionIndex(DataRefImpl Sec) const override { return Sec.d.a; }
126 uint64_t getSectionAlignment(DataRefImpl Sec) const override;
127 bool isSectionCompressed(DataRefImpl Sec) const override { return false; }
128 bool isSectionText(DataRefImpl Sec) const override;
129 bool isSectionData(DataRefImpl Sec) const override;
130 bool isSectionBSS(DataRefImpl Sec) const override { return false; }
131 bool isSectionVirtual(DataRefImpl Sec) const override { return false; }
132 relocation_iterator section_rel_begin(DataRefImpl Sec) const override {
133 return relocation_iterator(RelocationRef(Sec, this));
134 }
135 relocation_iterator section_rel_end(DataRefImpl Sec) const override {
136 return relocation_iterator(RelocationRef(Sec, this));
137 }
138
139 const uint8_t *getSectionEdEsdRecord(DataRefImpl &Sec) const;
140 const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const;
141 const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const;
142 const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const;
143 uint32_t getSectionDefEsdId(DataRefImpl &Sec) const;
144
145 // RelocationRef.
146 void moveRelocationNext(DataRefImpl &Rel) const override {}
147 uint64_t getRelocationOffset(DataRefImpl Rel) const override { return 0; }
148 symbol_iterator getRelocationSymbol(DataRefImpl Rel) const override {
149 DataRefImpl Temp;
150 return basic_symbol_iterator(SymbolRef(Temp, this));
151 }
152 uint64_t getRelocationType(DataRefImpl Rel) const override { return 0; }
153 void getRelocationTypeName(DataRefImpl Rel,
154 SmallVectorImpl<char> &Result) const override {}
155};
156
157class GOFFSymbolRef : public SymbolRef {
158public:
162
166
168 return getObject()->getSymbolFlags(getRawDataRefImpl());
169 }
170
172 return getObject()->getSymbolType(getRawDataRefImpl());
173 }
174
176 return getObject()->getSymbolSize(getRawDataRefImpl());
177 }
178};
179
180} // namespace object
181
182} // namespace llvm
183
184#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
static constexpr const StringLiteral & getSectionName(DebugSectionKind SectionKind)
Return the name of the section.
content_iterator< SectionRef > section_iterator
Definition ObjectFile.h:49
content_iterator< BasicSymbolRef > basic_symbol_iterator
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