21#define DEBUG_TYPE "goff"
30 std::unique_ptr<GOFFObjectFile> Ret(
new GOFFObjectFile(Object, Err));
32 return std::move(Err);
33 return std::move(Ret);
43 "object file is not the right size. Must be a multiple "
44 "of 80 bytes, but is " +
45 std::to_string(Object.getBufferSize()) +
" bytes");
50 if (Object.getBufferSize() != 0) {
53 "object file must start with HDR record");
59 "object file must end with END record");
65 SectionList.emplace_back(DummySection);
67 uint8_t PrevRecordType = 0;
68 uint8_t PrevContinuationBits = 0;
72 bool IsContinuation =
I[1] & 0x02;
73 bool PrevWasContinued = PrevContinuationBits & 0x01;
78 if (PrevWasContinued && !IsContinuation) {
81 "record " + std::to_string(RecordNum) +
82 " is not a continuation record but the "
83 "preceding record is continued");
91 "record " + std::to_string(RecordNum) +
92 " is a continuation record that does not "
93 "match the type of the previous record");
96 if (!PrevWasContinued) {
98 "record " + std::to_string(RecordNum) +
99 " is a continuation record that is not "
100 "preceded by a continued record");
104 PrevContinuationBits =
I[1] & 0x03;
110 const uint8_t *
P =
I + J;
143 SectionList.emplace_back(Section);
150 Section.d.a = SymEdId;
152 SectionList.emplace_back(Section);
158 const uint8_t *SymEdRecord = EsdPtrs[SymEdId];
164 Section.d.a = SymEdId;
165 SectionList.emplace_back(Section);
181 PrevContinuationBits =
I[1] & 0x03;
185const uint8_t *GOFFObjectFile::getSymbolEsdRecord(
DataRefImpl Symb)
const {
186 const uint8_t *EsdRecord = EsdPtrs[Symb.
d.
a];
191 if (EsdNamesCache.
count(Symb.
d.
a)) {
192 auto &StrPtr = EsdNamesCache[Symb.
d.
a];
193 return StringRef(StrPtr.second.get(), StrPtr.first);
198 return std::move(Err);
203 size_t Size = SymbolNameConverted.
size();
204 auto StrPtr = std::make_pair(
Size, std::make_unique<
char[]>(
Size));
205 char *Buf = StrPtr.second.get();
206 memcpy(Buf, SymbolNameConverted.
data(),
Size);
207 EsdNamesCache[Symb.
d.
a] = std::move(StrPtr);
217 const uint8_t *EsdRecord = getSymbolEsdRecord(Symb);
224 const uint8_t *EsdRecord = getSymbolEsdRecord(Symb);
233bool GOFFObjectFile::isSymbolUnresolved(
DataRefImpl Symb)
const {
234 const uint8_t *
Record = getSymbolEsdRecord(Symb);
249bool GOFFObjectFile::isSymbolIndirect(
DataRefImpl Symb)
const {
250 const uint8_t *
Record = getSymbolEsdRecord(Symb);
258 if (isSymbolUnresolved(Symb))
261 const uint8_t *
Record = getSymbolEsdRecord(Symb);
286GOFFObjectFile::getSymbolType(
DataRefImpl Symb)
const {
287 const uint8_t *
Record = getSymbolEsdRecord(Symb);
301 "ESD record %" PRIu32
302 " has invalid symbol type 0x%02" PRIX8,
317 "ESD record %" PRIu32
318 " has unknown Executable type 0x%02X",
321 switch (Executable) {
335GOFFObjectFile::getSymbolSection(
DataRefImpl Symb)
const {
338 if (isSymbolUnresolved(Symb))
341 const uint8_t *SymEsdRecord = EsdPtrs[Symb.
d.
a];
344 const uint8_t *SymEdRecord = EsdPtrs[SymEdId];
346 for (
size_t I = 0,
E = SectionList.size();
I <
E; ++
I) {
348 const uint8_t *SectionPrRecord = getSectionPrEsdRecord(
I);
349 if (SectionPrRecord) {
350 Found = SymEsdRecord == SectionPrRecord;
352 const uint8_t *SectionEdRecord = getSectionEdEsdRecord(
I);
353 Found = SymEdRecord == SectionEdRecord;
362 "symbol with ESD id " + std::to_string(Symb.
d.
a) +
363 " refers to invalid section with ESD id " +
364 std::to_string(SymEdId));
367const uint8_t *GOFFObjectFile::getSectionEdEsdRecord(
DataRefImpl &Sec)
const {
368 SectionEntryImpl EsdIds = SectionList[Sec.
d.
a];
369 const uint8_t *EsdRecord = EsdPtrs[EsdIds.d.a];
373const uint8_t *GOFFObjectFile::getSectionPrEsdRecord(
DataRefImpl &Sec)
const {
374 SectionEntryImpl EsdIds = SectionList[Sec.
d.
a];
375 const uint8_t *EsdRecord =
nullptr;
377 EsdRecord = EsdPtrs[EsdIds.d.b];
382GOFFObjectFile::getSectionEdEsdRecord(
uint32_t SectionIndex)
const {
384 Sec.
d.
a = SectionIndex;
385 const uint8_t *EsdRecord = getSectionEdEsdRecord(Sec);
390GOFFObjectFile::getSectionPrEsdRecord(
uint32_t SectionIndex)
const {
392 Sec.
d.
a = SectionIndex;
393 const uint8_t *EsdRecord = getSectionPrEsdRecord(Sec);
399 moveSectionNext(Sec);
411 const uint8_t *EsdRecord = EsdPtrs[
I];
415 bool IgnoreSpecialGOFFSymbols =
true;
418 IgnoreSpecialGOFFSymbols;
446 DataLength -= SliceLength;
447 Slice += SliceLength;
450 for (; DataLength > 0;
458 "continued bit should not be set");
static GCRegistry::Add< CoreCLRGC > E("coreclr", "CoreCLR-compatible GC")
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
FunctionLoweringInfo::StatepointRelocationRecord RecordType
size_type count(const_arg_type_t< KeyT > Val) const
Return 1 if the specified key is in the map, 0 otherwise.
Helper for Errors used as out-parameters.
Lightweight error class with error context and mandatory checking.
static ErrorSuccess success()
Create a success value.
Tagged union holding either a T or a Error.
StorageT::size_type size() const
const char * getBufferEnd() const
SmallString - A SmallString is just a SmallVector with methods and accessors that make it work better...
void append(StringRef RHS)
Append from a StringRef.
pointer data()
Return a pointer to the vector's buffer, even if empty().
StringRef - Represent a constant reference to a string, i.e.
static Error getData(const uint8_t *Record, SmallString< 256 > &CompleteData)
static uint16_t getNameLength(const uint8_t *Record)
static void getIndirectReference(const uint8_t *Record, bool &Indirect)
static void getBindingStrength(const uint8_t *Record, GOFF::ESDBindingStrength &Strength)
static void getOffset(const uint8_t *Record, uint32_t &Offset)
static void getEsdId(const uint8_t *Record, uint32_t &EsdId)
static Error getData(const uint8_t *Record, SmallString< 256 > &CompleteData)
static void getLength(const uint8_t *Record, uint32_t &Length)
static void getParentEsdId(const uint8_t *Record, uint32_t &EsdId)
static void getSymbolType(const uint8_t *Record, GOFF::ESDSymbolType &SymbolType)
static uint16_t getNameLength(const uint8_t *Record)
static void getExecutable(const uint8_t *Record, GOFF::ESDExecutable &Executable)
static void getBindingScope(const uint8_t *Record, GOFF::ESDBindingScope &Scope)
section_iterator section_begin() const override
basic_symbol_iterator symbol_end() const override
GOFFObjectFile(MemoryBufferRef Object, Error &Err)
section_iterator section_end() const override
Expected< StringRef > getSymbolName(SymbolRef Symbol) const
void moveSymbolNext(DataRefImpl &Symb) const override
basic_symbol_iterator symbol_begin() const override
static Error getData(const uint8_t *Record, SmallString< 256 > &CompleteData)
static uint16_t getPropertyModuleLength(const uint8_t *Record)
This class is the base class for all object file types.
const uint8_t * base() const
static Expected< std::unique_ptr< ObjectFile > > createGOFFObjectFile(MemoryBufferRef Object)
Represents a GOFF physical record.
static bool isContinued(const uint8_t *Record)
static Error getContinuousData(const uint8_t *Record, uint16_t DataLength, int DataIndex, SmallString< 256 > &CompleteData)
static bool isContinuation(const uint8_t *Record)
This is a value type class that represents a single symbol in the list of symbols in the object file.
#define llvm_unreachable(msg)
Marks that the current location is not supposed to be reachable.
void convertToUTF8(StringRef Source, SmallVectorImpl< char > &Result)
constexpr uint8_t RecordPrefixLength
constexpr uint8_t PayloadLength
constexpr uint8_t RecordLength
@ ESD_ST_ElementDefinition
@ ESD_ST_SectionDefinition
@ ESD_ST_ExternalReference
content_iterator< SectionRef > section_iterator
content_iterator< BasicSymbolRef > basic_symbol_iterator
This is an optimization pass for GlobalISel generic memory operations.
Error createStringError(std::error_code EC, char const *Fmt, const Ts &... Vals)
Create formatted StringError object.
raw_ostream & dbgs()
dbgs() - This returns a reference to a raw_ostream for debugging messages.
format_object< Ts... > format(const char *Fmt, const Ts &... Vals)
These are helper functions used to produce formatted output.
Helper object to track which of three possible relocation mechanisms are used for a particular value ...
struct llvm::object::DataRefImpl::@351 d