Revert "[SystemZ][z/OS] TXT records in the GOFF reader (#74526)"

This reverts commit 009f88fc0e.

Reverting PR due to test failure.
This commit is contained in:
Neumann Hon
2024-03-27 15:15:32 -04:00
parent c2bdbedf1c
commit aeb8628c21
4 changed files with 14 additions and 178 deletions

View File

@@ -73,26 +73,6 @@ protected:
}
};
class TXTRecord : public Record {
public:
/// \brief Maximum length of data; any more must go in continuation.
static const uint8_t TXTMaxDataLength = 56;
static Error getData(const uint8_t *Record, SmallString<256> &CompleteData);
static void getElementEsdId(const uint8_t *Record, uint32_t &EsdId) {
get<uint32_t>(Record, 4, EsdId);
}
static void getOffset(const uint8_t *Record, uint32_t &Offset) {
get<uint32_t>(Record, 12, Offset);
}
static void getDataLength(const uint8_t *Record, uint16_t &Length) {
get<uint16_t>(Record, 22, Length);
}
};
class HDRRecord : public Record {
public:
static Error getData(const uint8_t *Record, SmallString<256> &CompleteData);

View File

@@ -29,10 +29,7 @@ namespace llvm {
namespace object {
class GOFFObjectFile : public ObjectFile {
friend class GOFFSymbolRef;
IndexedMap<const uint8_t *> EsdPtrs; // Indexed by EsdId.
SmallVector<const uint8_t *, 256> TextPtrs;
mutable DenseMap<uint32_t, std::pair<size_t, std::unique_ptr<char[]>>>
EsdNamesCache;
@@ -41,7 +38,7 @@ class GOFFObjectFile : public ObjectFile {
// (EDID, 0) code, r/o data section
// (EDID,PRID) r/w data section
SmallVector<SectionEntryImpl, 256> SectionList;
mutable DenseMap<uint32_t, SmallVector<uint8_t>> SectionDataCache;
mutable DenseMap<uint32_t, std::string> SectionDataCache;
public:
Expected<StringRef> getSymbolName(SymbolRef Symbol) const;
@@ -69,10 +66,6 @@ public:
return true;
}
bool isSectionNoLoad(DataRefImpl Sec) const;
bool isSectionReadOnlyData(DataRefImpl Sec) const;
bool isSectionZeroInit(DataRefImpl Sec) const;
private:
// SymbolRef.
Expected<StringRef> getSymbolName(DataRefImpl Symb) const override;
@@ -82,24 +75,27 @@ private:
Expected<uint32_t> getSymbolFlags(DataRefImpl Symb) const override;
Expected<SymbolRef::Type> getSymbolType(DataRefImpl Symb) const override;
Expected<section_iterator> getSymbolSection(DataRefImpl Symb) const override;
uint64_t getSymbolSize(DataRefImpl Symb) const;
const uint8_t *getSymbolEsdRecord(DataRefImpl Symb) const;
bool isSymbolUnresolved(DataRefImpl Symb) const;
bool isSymbolIndirect(DataRefImpl Symb) const;
// SectionRef.
void moveSectionNext(DataRefImpl &Sec) const override;
virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const override;
uint64_t getSectionAddress(DataRefImpl Sec) const override;
uint64_t getSectionSize(DataRefImpl Sec) const override;
void moveSectionNext(DataRefImpl &Sec) const override {}
virtual Expected<StringRef> getSectionName(DataRefImpl Sec) const override {
return StringRef();
}
uint64_t getSectionAddress(DataRefImpl Sec) const override { return 0; }
uint64_t getSectionSize(DataRefImpl Sec) const override { return 0; }
virtual Expected<ArrayRef<uint8_t>>
getSectionContents(DataRefImpl Sec) const override;
uint64_t getSectionIndex(DataRefImpl Sec) const override { return Sec.d.a; }
uint64_t getSectionAlignment(DataRefImpl Sec) const override;
getSectionContents(DataRefImpl Sec) const override {
return ArrayRef<uint8_t>();
}
uint64_t getSectionIndex(DataRefImpl Sec) const override { return 0; }
uint64_t getSectionAlignment(DataRefImpl Sec) const override { return 0; }
bool isSectionCompressed(DataRefImpl Sec) const override { return false; }
bool isSectionText(DataRefImpl Sec) const override;
bool isSectionData(DataRefImpl Sec) const override;
bool isSectionText(DataRefImpl Sec) const override { return false; }
bool isSectionData(DataRefImpl Sec) const override { return false; }
bool isSectionBSS(DataRefImpl Sec) const override { return false; }
bool isSectionVirtual(DataRefImpl Sec) const override { return false; }
relocation_iterator section_rel_begin(DataRefImpl Sec) const override {
@@ -113,7 +109,6 @@ private:
const uint8_t *getSectionPrEsdRecord(DataRefImpl &Sec) const;
const uint8_t *getSectionEdEsdRecord(uint32_t SectionIndex) const;
const uint8_t *getSectionPrEsdRecord(uint32_t SectionIndex) const;
uint32_t getSectionDefEsdId(DataRefImpl &Sec) const;
// RelocationRef.
void moveRelocationNext(DataRefImpl &Rel) const override {}
@@ -127,29 +122,6 @@ private:
SmallVectorImpl<char> &Result) const override {}
};
class GOFFSymbolRef : public SymbolRef {
public:
GOFFSymbolRef(const SymbolRef &B) : SymbolRef(B) {
assert(isa<GOFFObjectFile>(SymbolRef::getObject()));
}
const GOFFObjectFile *getObject() const {
return cast<GOFFObjectFile>(BasicSymbolRef::getObject());
}
Expected<uint32_t> getSymbolGOFFFlags() const {
return getObject()->getSymbolFlags(getRawDataRefImpl());
}
Expected<SymbolRef::Type> getSymbolGOFFType() const {
return getObject()->getSymbolType(getRawDataRefImpl());
}
uint64_t getSize() const {
return getObject()->getSymbolSize(getRawDataRefImpl());
}
};
} // namespace object
} // namespace llvm

View File

@@ -168,11 +168,6 @@ GOFFObjectFile::GOFFObjectFile(MemoryBufferRef Object, Error &Err)
LLVM_DEBUG(dbgs() << " -- ESD " << EsdId << "\n");
break;
}
case GOFF::RT_TXT:
// Save TXT records.
TextPtrs.emplace_back(I);
LLVM_DEBUG(dbgs() << " -- TXT\n");
break;
case GOFF::RT_END:
LLVM_DEBUG(dbgs() << " -- END (GOFF record type) unhandled\n");
break;
@@ -369,13 +364,6 @@ GOFFObjectFile::getSymbolSection(DataRefImpl Symb) const {
std::to_string(SymEdId));
}
uint64_t GOFFObjectFile::getSymbolSize(DataRefImpl Symb) const {
const uint8_t *Record = getSymbolEsdRecord(Symb);
uint32_t Length;
ESDRecord::getLength(Record, Length);
return Length;
}
const uint8_t *GOFFObjectFile::getSectionEdEsdRecord(DataRefImpl &Sec) const {
SectionEntryImpl EsdIds = SectionList[Sec.d.a];
const uint8_t *EsdRecord = EsdPtrs[EsdIds.d.a];
@@ -636,13 +624,6 @@ Error ESDRecord::getData(const uint8_t *Record,
return getContinuousData(Record, DataSize, 72, CompleteData);
}
Error TXTRecord::getData(const uint8_t *Record,
SmallString<256> &CompleteData) {
uint16_t Length;
getDataLength(Record, Length);
return getContinuousData(Record, Length, 24, CompleteData);
}
Error ENDRecord::getData(const uint8_t *Record,
SmallString<256> &CompleteData) {
uint16_t Length = getNameLength(Record);

View File

@@ -502,100 +502,3 @@ TEST(GOFFObjectFileTest, InvalidERSymbolType) {
FailedWithMessage("ESD record 1 has unknown Executable type 0x03"));
}
}
TEST(GOFFObjectFileTest, TXTConstruct) {
char GOFFData[GOFF::RecordLength * 6] = {};
// HDR record.
GOFFData[0] = 0x03;
GOFFData[1] = 0xF0;
GOFFData[50] = 0x01;
// ESD record.
GOFFData[GOFF::RecordLength] = 0x03;
GOFFData[GOFF::RecordLength + 7] = 0x01; // ESDID.
GOFFData[GOFF::RecordLength + 71] = 0x05; // Size of symbol name.
GOFFData[GOFF::RecordLength + 72] = 0xa5; // Symbol name is v.
GOFFData[GOFF::RecordLength + 73] = 0x81; // Symbol name is a.
GOFFData[GOFF::RecordLength + 74] = 0x99; // Symbol name is r.
GOFFData[GOFF::RecordLength + 75] = 0x7b; // Symbol name is #.
GOFFData[GOFF::RecordLength + 76] = 0x83; // Symbol name is c.
// ESD record.
GOFFData[GOFF::RecordLength * 2] = 0x03;
GOFFData[GOFF::RecordLength * 2 + 3] = 0x01;
GOFFData[GOFF::RecordLength * 2 + 7] = 0x02; // ESDID.
GOFFData[GOFF::RecordLength * 2 + 11] = 0x01; // Parent ESDID.
GOFFData[GOFF::RecordLength * 2 + 27] = 0x08; // Length.
GOFFData[GOFF::RecordLength * 2 + 40] = 0x01; // Name Space ID.
GOFFData[GOFF::RecordLength * 2 + 41] = 0x80;
GOFFData[GOFF::RecordLength * 2 + 60] = 0x04; // Size of symbol name.
GOFFData[GOFF::RecordLength * 2 + 61] = 0x04; // Size of symbol name.
GOFFData[GOFF::RecordLength * 2 + 63] = 0x0a; // Size of symbol name.
GOFFData[GOFF::RecordLength * 2 + 66] = 0x03; // Size of symbol name.
GOFFData[GOFF::RecordLength * 2 + 71] = 0x08; // Size of symbol name.
GOFFData[GOFF::RecordLength * 2 + 72] = 0xc3; // Symbol name is c.
GOFFData[GOFF::RecordLength * 2 + 73] = 0x6d; // Symbol name is _.
GOFFData[GOFF::RecordLength * 2 + 74] = 0xc3; // Symbol name is c.
GOFFData[GOFF::RecordLength * 2 + 75] = 0xd6; // Symbol name is o.
GOFFData[GOFF::RecordLength * 2 + 76] = 0xc4; // Symbol name is D.
GOFFData[GOFF::RecordLength * 2 + 77] = 0xc5; // Symbol name is E.
GOFFData[GOFF::RecordLength * 2 + 78] = 0xf6; // Symbol name is 6.
GOFFData[GOFF::RecordLength * 2 + 79] = 0xf4; // Symbol name is 4.
// ESD record.
GOFFData[GOFF::RecordLength * 3] = 0x03;
GOFFData[GOFF::RecordLength * 3 + 3] = 0x02;
GOFFData[GOFF::RecordLength * 3 + 7] = 0x03; // ESDID.
GOFFData[GOFF::RecordLength * 3 + 11] = 0x02; // Parent ESDID.
GOFFData[GOFF::RecordLength * 3 + 71] = 0x05; // Size of symbol name.
GOFFData[GOFF::RecordLength * 3 + 72] = 0xa5; // Symbol name is v.
GOFFData[GOFF::RecordLength * 3 + 73] = 0x81; // Symbol name is a.
GOFFData[GOFF::RecordLength * 3 + 74] = 0x99; // Symbol name is r.
GOFFData[GOFF::RecordLength * 3 + 75] = 0x7b; // Symbol name is #.
GOFFData[GOFF::RecordLength * 3 + 76] = 0x83; // Symbol name is c.
// TXT record.
GOFFData[GOFF::RecordLength * 4] = 0x03;
GOFFData[GOFF::RecordLength * 4 + 1] = 0x10;
GOFFData[GOFF::RecordLength * 4 + 7] = 0x02;
GOFFData[GOFF::RecordLength * 4 + 23] = 0x08; // Data Length.
GOFFData[GOFF::RecordLength * 4 + 24] = 0x12;
GOFFData[GOFF::RecordLength * 4 + 25] = 0x34;
GOFFData[GOFF::RecordLength * 4 + 26] = 0x56;
GOFFData[GOFF::RecordLength * 4 + 27] = 0x78;
GOFFData[GOFF::RecordLength * 4 + 28] = 0x9a;
GOFFData[GOFF::RecordLength * 4 + 29] = 0xbc;
GOFFData[GOFF::RecordLength * 4 + 30] = 0xde;
GOFFData[GOFF::RecordLength * 4 + 31] = 0xf0;
// END record.
GOFFData[GOFF::RecordLength * 5] = 0x03;
GOFFData[GOFF::RecordLength * 5 + 1] = 0x40;
GOFFData[GOFF::RecordLength * 5 + 11] = 0x06;
StringRef Data(GOFFData, GOFF::RecordLength * 6);
Expected<std::unique_ptr<ObjectFile>> GOFFObjOrErr =
object::ObjectFile::createGOFFObjectFile(
MemoryBufferRef(Data, "dummyGOFF"));
ASSERT_THAT_EXPECTED(GOFFObjOrErr, Succeeded());
GOFFObjectFile *GOFFObj = dyn_cast<GOFFObjectFile>((*GOFFObjOrErr).get());
auto Symbols = GOFFObj->symbols();
ASSERT_EQ(std::distance(Symbols.begin(), Symbols.end()), 1);
SymbolRef Symbol = *Symbols.begin();
Expected<StringRef> SymbolNameOrErr = GOFFObj->getSymbolName(Symbol);
ASSERT_THAT_EXPECTED(SymbolNameOrErr, Succeeded());
StringRef SymbolName = SymbolNameOrErr.get();
EXPECT_EQ(SymbolName, "var#c");
auto Sections = GOFFObj->sections();
ASSERT_EQ(std::distance(Sections.begin(), Sections.end()), 1);
SectionRef Section = *Sections.begin();
Expected<StringRef> SectionContent = Section.getContents();
ASSERT_THAT_EXPECTED(SectionContent, Succeeded());
StringRef Contents = SectionContent.get();
EXPECT_EQ(Contents, "\x12\x34\x56\x78\x9a\xbc\xde\xf0");
}