[llvm] [SystemZ][z/OS] yaml2obj GOFF symbols (PR #75971)
Yusra Syeda via llvm-commits
llvm-commits at lists.llvm.org
Tue Apr 9 08:23:31 PDT 2024
https://github.com/ysyeda updated https://github.com/llvm/llvm-project/pull/75971
>From 36be16704a9fd2be6fbb9e79bf5a9f830cfe642e Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 19 Dec 2023 16:29:40 -0500
Subject: [PATCH 01/11] add sections & symbols
---
llvm/include/llvm/BinaryFormat/GOFF.h | 6 +
llvm/include/llvm/ObjectYAML/GOFFYAML.h | 143 +++++++++++++
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 106 +++++++++-
llvm/lib/ObjectYAML/GOFFYAML.cpp | 254 ++++++++++++++++++++++++
4 files changed, 508 insertions(+), 1 deletion(-)
diff --git a/llvm/include/llvm/BinaryFormat/GOFF.h b/llvm/include/llvm/BinaryFormat/GOFF.h
index 443bcfc9479a8b..be6850216dbe2a 100644
--- a/llvm/include/llvm/BinaryFormat/GOFF.h
+++ b/llvm/include/llvm/BinaryFormat/GOFF.h
@@ -157,6 +157,12 @@ enum ESDAlignment : uint8_t {
ESD_ALIGN_4Kpage = 12,
};
+enum TXTRecordStyle : uint8_t {
+ TXT_RS_Byte = 0,
+ TXT_RS_Structured = 1,
+ TXT_RS_Unstructured = 2,
+};
+
enum ENDEntryPointRequest : uint8_t {
END_EPR_None = 0,
END_EPR_EsdidOffset = 1,
diff --git a/llvm/include/llvm/ObjectYAML/GOFFYAML.h b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
index f9bf45e95bd3a4..c17b4b605e258e 100644
--- a/llvm/include/llvm/ObjectYAML/GOFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
@@ -21,10 +21,120 @@
namespace llvm {
+namespace GOFF {
+
+enum ESDFlags {
+ ESD_FillByteValuePresent = 1 << 7,
+ ESD_SymbolDisplayFlag = 1 << 6,
+ ESD_SymbolRenamingFlag = 1 << 5,
+ ESD_RemovableClass = 1 << 4
+};
+
+enum {
+ ESD_Mask_ERST = 0x07,
+ ESD_Mask_RQW = 0x07,
+ ESD_Mask_TextStyle = 0xf0,
+ ESD_Mask_BindingAlgorithm = 0x0f,
+};
+
+enum ESDBAFlags {
+ ESD_BA_Movable = 0x01,
+ ESD_BA_ReadOnly = 0x2,
+ ESD_BA_NoPrime = 0x4,
+ ESD_BA_COMMON = 0x8,
+ ESD_BA_Indirect = 0x10,
+};
+} // end namespace GOFF
+
// The structure of the yaml files is not an exact 1:1 match to GOFF. In order
// to use yaml::IO, we use these structures which are closer to the source.
namespace GOFFYAML {
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDSYMBOLTYPE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDNAMESPACEID)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDFlags)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDAMODE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDRMODE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDTEXTSTYLE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDBINDINGALGORITHM)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDTASKINGBEHAVIOR)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDEXECUTABLE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDLINKAGETYPE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDBINDINGSTRENGTH)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDLOADINGBEHAVIOR)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDBINDINGSCOPE)
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_ESDALIGNMENT)
+LLVM_YAML_STRONG_TYPEDEF(uint64_t, GOFF_BAFLAGS)
+
+LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_TEXTRECORDSTYLE)
+
+struct RecordBase {
+ enum RecordBaseKind { RBK_Symbol, RBK_Section };
+
+private:
+ const RecordBaseKind Kind;
+
+protected:
+ RecordBase(RecordBaseKind Kind) : Kind(Kind) {}
+
+public:
+ RecordBaseKind getKind() const { return Kind; }
+};
+typedef std::unique_ptr<RecordBase> RecordPtr;
+
+struct Section : public RecordBase {
+ Section() : RecordBase(RBK_Section) {}
+
+ StringRef SymbolName;
+ uint32_t SymbolID;
+ uint32_t Offset;
+ uint32_t TrueLength;
+ uint16_t TextEncoding;
+ uint16_t DataLength;
+ GOFF_TEXTRECORDSTYLE TextStyle;
+
+ std::optional<yaml::BinaryRef> Data;
+
+ static bool classof(const RecordBase *Rec) {
+ return Rec->getKind() == RBK_Section;
+ }
+};
+
+struct Symbol : public RecordBase {
+ Symbol() : RecordBase(RBK_Symbol) {}
+
+ StringRef Name;
+ GOFF_ESDSYMBOLTYPE Type;
+ uint32_t ID;
+ uint32_t OwnerID;
+ uint32_t Address;
+ uint32_t Length;
+ uint32_t ExtAttrID;
+ uint32_t ExtAttrOffset;
+ GOFF_ESDNAMESPACEID NameSpace;
+ GOFF_ESDFlags Flags;
+ uint8_t FillByteValue;
+ uint32_t PSectID;
+ uint32_t Priority;
+ std::optional<llvm::yaml::Hex64> Signature;
+ GOFF_ESDAMODE Amode;
+ GOFF_ESDRMODE Rmode;
+ GOFF_ESDTEXTSTYLE TextStyle;
+ GOFF_ESDBINDINGALGORITHM BindingAlgorithm;
+ GOFF_ESDTASKINGBEHAVIOR TaskingBehavior;
+ GOFF_ESDEXECUTABLE Executable;
+ GOFF_ESDLINKAGETYPE LinkageType;
+ GOFF_ESDBINDINGSTRENGTH BindingStrength;
+ GOFF_ESDLOADINGBEHAVIOR LoadingBehavior;
+ GOFF_ESDBINDINGSCOPE BindingScope;
+ GOFF_ESDALIGNMENT Alignment;
+ GOFF_BAFLAGS BAFlags;
+
+ static bool classof(const RecordBase *Rec) {
+ return Rec->getKind() == RBK_Symbol;
+ }
+};
+
struct FileHeader {
uint32_t TargetEnvironment = 0;
uint32_t TargetOperatingSystem = 0;
@@ -38,12 +148,45 @@ struct FileHeader {
struct Object {
FileHeader Header;
+ std::vector<RecordPtr> Records;
Object();
};
} // end namespace GOFFYAML
} // end namespace llvm
+LLVM_YAML_IS_SEQUENCE_VECTOR(GOFFYAML::RecordPtr)
+
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDSYMBOLTYPE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDNAMESPACEID)
+LLVM_YAML_DECLARE_BITSET_TRAITS(GOFFYAML::GOFF_ESDFlags)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDAMODE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDRMODE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDTEXTSTYLE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDBINDINGALGORITHM)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDTASKINGBEHAVIOR)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDEXECUTABLE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDLINKAGETYPE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDBINDINGSTRENGTH)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDLOADINGBEHAVIOR)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDBINDINGSCOPE)
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_ESDALIGNMENT)
+LLVM_YAML_DECLARE_BITSET_TRAITS(GOFFYAML::GOFF_BAFLAGS)
+
+LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_TEXTRECORDSTYLE)
+
+LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Section)
+LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Symbol)
LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::FileHeader)
LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Object)
+namespace llvm {
+namespace yaml {
+
+template <> struct CustomMappingTraits<GOFFYAML::RecordPtr> {
+ static void inputOne(IO &IO, StringRef Key, GOFFYAML::RecordPtr &Elem);
+ static void output(IO &IO, GOFFYAML::RecordPtr &Elem);
+};
+
+} // end namespace yaml
+} // end namespace llvm
#endif // LLVM_OBJECTYAML_GOFFYAML_H
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 345904407e1d24..e7db0736993444 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -22,6 +22,8 @@ using namespace llvm;
namespace {
+static const uint8_t TXTMaxDataLength = 56;
+
// Common flag values on records.
enum {
// Flag: This record is continued.
@@ -60,6 +62,11 @@ raw_ostream &operator<<(raw_ostream &OS, const ZerosImpl &Z) {
ZerosImpl zeros(const size_t NumBytes) { return ZerosImpl{NumBytes}; }
+raw_ostream &operator<<(raw_ostream &OS, const yaml::BinaryRef &Data) {
+ Data.writeAsBinary(OS);
+ return OS;
+}
+
// The GOFFOstream is responsible to write the data into the fixed physical
// records of the format. A user of this class announces the start of a new
// logical record and the size of its payload. While writing the payload, the
@@ -175,6 +182,8 @@ class GOFFOstream : public raw_ostream {
class GOFFState {
void writeHeader(GOFFYAML::FileHeader &FileHdr);
void writeEnd();
+ void writeSymbol(GOFFYAML::Symbol Sym);
+ void writeSection(GOFFYAML::Section Sec);
void reportError(const Twine &Msg) {
ErrHandler(Msg);
@@ -183,7 +192,7 @@ class GOFFState {
GOFFState(raw_ostream &OS, GOFFYAML::Object &Doc,
yaml::ErrorHandler ErrHandler)
- : GW(OS), Doc(Doc), ErrHandler(ErrHandler), HasError(false) {}
+ : GW(OS), Doc(Doc), ErrHandler(ErrHandler), SymbolID(0), HasError(false) {}
~GOFFState() { GW.finalize(); }
@@ -197,6 +206,7 @@ class GOFFState {
GOFFOstream GW;
GOFFYAML::Object &Doc;
yaml::ErrorHandler ErrHandler;
+ uint16_t SymbolID;
bool HasError;
};
@@ -245,6 +255,90 @@ void GOFFState::writeHeader(GOFFYAML::FileHeader &FileHdr) {
}
}
+void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
+ if (Sym.ID != SymbolID + 1)
+ reportError("symbol IDs not monotonic " + Sym.Name);
+ else
+ ++SymbolID;
+ if (Sym.OwnerID >= SymbolID)
+ reportError("owner ID not defined " + Sym.Name);
+ SmallString<80> SymName;
+ if (std::error_code EC = ConverterEBCDIC::convertToEBCDIC(Sym.Name, SymName))
+ reportError("conversion error on " + Sym.Name);
+ size_t SymLength = SymName.size();
+ if (SymLength > GOFF::MaxDataLength)
+ reportError("symbol name is too long: " + Twine(SymLength));
+
+ GW.makeNewRecord(GOFF::RT_ESD, 69 + SymLength);
+ GW << binaryBe(Sym.Type) // Symbol type
+ << binaryBe(Sym.ID) // ESDID
+ << binaryBe(Sym.OwnerID) // Owner ESDID
+ << binaryBe(uint32_t(0)) // Reserved
+ << binaryBe(Sym.Address) // Offset/Address
+ << binaryBe(uint32_t(0)) // Reserved
+ << binaryBe(Sym.Length) // Length
+ << binaryBe(Sym.ExtAttrID) // Extended attributes
+ << binaryBe(Sym.ExtAttrOffset) // Extended attributes data offset
+ << binaryBe(uint32_t(0)) // Reserved
+ << binaryBe(Sym.NameSpace) // Namespace ID
+ << binaryBe(Sym.Flags) // Flags
+ << binaryBe(Sym.FillByteValue) // Fill byte value
+ << binaryBe(uint8_t(0)) // Reserved
+ << binaryBe(Sym.PSectID) // PSECT ID
+ << binaryBe(Sym.Priority); // Priority
+ if (Sym.Signature)
+ GW << *Sym.Signature; // Signature
+ else
+ GW << zeros(8);
+#define BIT(E, N) (Sym.BAFlags & GOFF::E ? 1 << (7 - N) : 0)
+ GW << binaryBe(Sym.Amode) // Behavioral attributes - Amode
+ << binaryBe(Sym.Rmode) // Behavioral attributes - Rmode
+ << binaryBe(uint8_t(Sym.TextStyle << 4 | Sym.BindingAlgorithm))
+ << binaryBe(uint8_t(Sym.TaskingBehavior << 5 | BIT(ESD_BA_Movable, 3) |
+ BIT(ESD_BA_ReadOnly, 4) | Sym.Executable))
+ << binaryBe(uint8_t(BIT(ESD_BA_NoPrime, 1) | Sym.BindingStrength))
+ << binaryBe(uint8_t(Sym.LoadingBehavior << 6 | BIT(ESD_BA_COMMON, 2) |
+ BIT(ESD_BA_Indirect, 3) | Sym.BindingScope))
+ << binaryBe(uint8_t(Sym.LinkageType << 5 | Sym.Alignment))
+ << zeros(3) // Behavioral attributes - Reserved
+ << binaryBe(static_cast<uint16_t>(SymLength)) // Name length
+ << SymName.str();
+#undef BIT
+}
+
+void GOFFState::writeSection(GOFFYAML::Section Sec) {
+ if (Sec.SymbolID == 0 || Sec.SymbolID > SymbolID)
+ reportError("section symbol not defined: " + Twine(Sec.SymbolID));
+
+ size_t Size = 0;
+ if (Sec.Data) {
+ Size = Sec.Data->binary_size();
+ if (Size > GOFF::MaxDataLength) {
+ reportError("section content is too long: " + Twine(Size));
+ return;
+ }
+ if (Sec.DataLength && Sec.DataLength != Size) {
+ reportError("Section content length " + Twine(Size) +
+ " does not match data length " + Twine(Sec.DataLength));
+ return;
+ }
+ } else
+ Size = Sec.DataLength;
+
+ GW.makeNewRecord(GOFF::RT_TXT, GOFF::PayloadLength - TXTMaxDataLength + Size);
+ GW << binaryBe(Sec.TextStyle) // Text Record Style
+ << binaryBe(Sec.SymbolID) // Element ESDID
+ << binaryBe(uint32_t(0)) // Reserved
+ << binaryBe(Sec.Offset) // Offset
+ << binaryBe(Sec.TrueLength) // Text Field True Length
+ << binaryBe(Sec.TextEncoding) // Text Encoding
+ << binaryBe(static_cast<uint16_t>(Size)); // Data Length
+ if (Sec.Data)
+ GW << *Sec.Data; // Data
+ else
+ GW << zeros(Size);
+}
+
void GOFFState::writeEnd() {
GW.makeNewRecord(GOFF::RT_END, GOFF::PayloadLength);
GW << binaryBe(uint8_t(0)) // No entry point
@@ -259,6 +353,16 @@ bool GOFFState::writeObject() {
writeHeader(Doc.Header);
if (HasError)
return false;
+ // Iterate over all records.
+ for (auto &Rec : Doc.Records) {
+ if (auto *Sec = dyn_cast<GOFFYAML::Section>(Rec.get())) {
+ writeSection(*Sec);
+ } else if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get())) {
+ writeSymbol(*Sym);
+ } else {
+ reportError("Unknown record type");
+ }
+ }
writeEnd();
return true;
}
diff --git a/llvm/lib/ObjectYAML/GOFFYAML.cpp b/llvm/lib/ObjectYAML/GOFFYAML.cpp
index ae857980a521b0..4d10c8352219cf 100644
--- a/llvm/lib/ObjectYAML/GOFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/GOFFYAML.cpp
@@ -23,6 +23,235 @@ Object::Object() {}
namespace yaml {
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDSYMBOLTYPE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDSYMBOLTYPE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_ST_SectionDefinition);
+ ECase(ESD_ST_ElementDefinition);
+ ECase(ESD_ST_LabelDefinition);
+ ECase(ESD_ST_PartReference);
+ ECase(ESD_ST_ExternalReference);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDNAMESPACEID>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDNAMESPACEID &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_NS_ProgramManagementBinder);
+ ECase(ESD_NS_NormalName);
+ ECase(ESD_NS_PseudoRegister);
+ ECase(ESD_NS_Parts);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarBitSetTraits<GOFFYAML::GOFF_ESDFlags>::bitset(
+ IO &IO, GOFFYAML::GOFF_ESDFlags &Value) {
+#define BCase(X) IO.bitSetCase(Value, #X, GOFF::X)
+#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, GOFF::X, GOFF::M)
+ BCase(ESD_FillByteValuePresent);
+ BCase(ESD_SymbolDisplayFlag);
+ BCase(ESD_SymbolRenamingFlag);
+ BCase(ESD_RemovableClass);
+ BCaseMask(ESD_RQ_0, ESD_Mask_RQW);
+ BCaseMask(ESD_RQ_1, ESD_Mask_RQW);
+ BCaseMask(ESD_RQ_2, ESD_Mask_RQW);
+ BCaseMask(ESD_RQ_3, ESD_Mask_RQW);
+#undef BCase
+#undef BCaseMask
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_TEXTRECORDSTYLE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_TEXTRECORDSTYLE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(TXT_RS_Byte);
+ ECase(TXT_RS_Structured);
+ ECase(TXT_RS_Unstructured);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDAMODE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDAMODE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_AMODE_None);
+ ECase(ESD_AMODE_24);
+ ECase(ESD_AMODE_31);
+ ECase(ESD_AMODE_ANY);
+ ECase(ESD_AMODE_64);
+ ECase(ESD_AMODE_MIN);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDRMODE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDRMODE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_RMODE_None);
+ ECase(ESD_RMODE_24);
+ ECase(ESD_RMODE_31);
+ ECase(ESD_RMODE_64);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDTEXTSTYLE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDTEXTSTYLE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_TS_ByteOriented);
+ ECase(ESD_TS_Structured);
+ ECase(ESD_TS_Unstructured);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGALGORITHM>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDBINDINGALGORITHM &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_BA_Concatenate);
+ ECase(ESD_BA_Merge);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDTASKINGBEHAVIOR>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDTASKINGBEHAVIOR &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_TA_Unspecified);
+ ECase(ESD_TA_NonReus);
+ ECase(ESD_TA_Reus);
+ ECase(ESD_TA_Rent);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDEXECUTABLE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDEXECUTABLE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_EXE_Unspecified);
+ ECase(ESD_EXE_DATA);
+ ECase(ESD_EXE_CODE);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDLINKAGETYPE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDLINKAGETYPE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_LT_OS);
+ ECase(ESD_LT_XPLink);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGSTRENGTH>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDBINDINGSTRENGTH &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_BST_Strong);
+ ECase(ESD_BST_Weak);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDLOADINGBEHAVIOR>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDLOADINGBEHAVIOR &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_LB_Initial);
+ ECase(ESD_LB_Deferred);
+ ECase(ESD_LB_NoLoad);
+ ECase(ESD_LB_Reserved);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGSCOPE>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDBINDINGSCOPE &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_BSC_Unspecified);
+ ECase(ESD_BSC_Section);
+ ECase(ESD_BSC_Module);
+ ECase(ESD_BSC_Library);
+ ECase(ESD_BSC_ImportExport);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDALIGNMENT>::enumeration(
+ IO &IO, GOFFYAML::GOFF_ESDALIGNMENT &Value) {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+ ECase(ESD_ALIGN_Byte);
+ ECase(ESD_ALIGN_Halfword);
+ ECase(ESD_ALIGN_Fullword);
+ ECase(ESD_ALIGN_Doubleword);
+ ECase(ESD_ALIGN_Quadword);
+ ECase(ESD_ALIGN_32byte);
+ ECase(ESD_ALIGN_64byte);
+ ECase(ESD_ALIGN_128byte);
+ ECase(ESD_ALIGN_256byte);
+ ECase(ESD_ALIGN_512byte);
+ ECase(ESD_ALIGN_1024byte);
+ ECase(ESD_ALIGN_2Kpage);
+ ECase(ESD_ALIGN_4Kpage);
+#undef ECase
+ IO.enumFallback<Hex8>(Value);
+}
+
+void ScalarBitSetTraits<GOFFYAML::GOFF_BAFLAGS>::bitset(
+ IO &IO, GOFFYAML::GOFF_BAFLAGS &Value) {
+#define BCase(X) IO.bitSetCase(Value, #X, GOFF::X)
+#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, GOFF::X, GOFF::M)
+ BCase(ESD_BA_Movable);
+ BCase(ESD_BA_ReadOnly);
+ BCase(ESD_BA_NoPrime);
+ BCase(ESD_BA_COMMON);
+ BCase(ESD_BA_Indirect);
+#undef BCase
+#undef BCaseMask
+}
+
+void MappingTraits<GOFFYAML::Section>::mapping(IO &IO, GOFFYAML::Section &Sec) {
+ IO.mapRequired("SymbolName", Sec.SymbolName);
+ IO.mapRequired("SymbolID", Sec.SymbolID);
+ IO.mapOptional("Offset", Sec.Offset, 0);
+ IO.mapOptional("TrueLength", Sec.TrueLength, 0);
+ IO.mapOptional("TextEncoding", Sec.TextEncoding, 0);
+ IO.mapOptional("DataLength", Sec.DataLength, 0);
+ IO.mapOptional("TextStyle", Sec.TextStyle, GOFF::TXT_RS_Byte);
+ IO.mapOptional("Data", Sec.Data);
+}
+
+void MappingTraits<GOFFYAML::Symbol>::mapping(IO &IO, GOFFYAML::Symbol &Sym) {
+ IO.mapRequired("Name", Sym.Name);
+ IO.mapRequired("Type", Sym.Type);
+ IO.mapRequired("ID", Sym.ID);
+ IO.mapOptional("OwnerID", Sym.OwnerID, 0);
+ IO.mapOptional("Address", Sym.Address, 0);
+ IO.mapOptional("Length", Sym.Length, 0);
+ IO.mapOptional("ExtAttrID", Sym.ExtAttrID, 0);
+ IO.mapOptional("ExtAttrOffset", Sym.ExtAttrOffset, 0);
+ IO.mapRequired("NameSpace", Sym.NameSpace);
+ IO.mapOptional("Flags", Sym.Flags, GOFFYAML::GOFF_ESDFlags(0));
+ IO.mapOptional("FillByteValue", Sym.FillByteValue, 0);
+ IO.mapOptional("PSectID", Sym.PSectID, 0);
+ IO.mapOptional("Priority", Sym.Priority, 0);
+ IO.mapOptional("Signature", Sym.Signature);
+ IO.mapOptional("Amode", Sym.Amode, GOFF::ESD_AMODE_None);
+ IO.mapOptional("Rmode", Sym.Rmode, GOFF::ESD_RMODE_None);
+ IO.mapOptional("TextStyle", Sym.TextStyle, GOFF::ESD_TS_ByteOriented);
+ IO.mapOptional("BindingAlgorithm", Sym.BindingAlgorithm,
+ GOFF::ESD_BA_Concatenate);
+ IO.mapOptional("TaskingBehavior", Sym.TaskingBehavior,
+ GOFF::ESD_TA_Unspecified);
+ IO.mapOptional("Executable", Sym.Executable, GOFF::ESD_EXE_Unspecified);
+ IO.mapOptional("LinkageType", Sym.LinkageType, GOFF::ESD_LT_OS);
+ IO.mapOptional("BindingStrength", Sym.BindingStrength, GOFF::ESD_BST_Strong);
+ IO.mapOptional("LoadingBehavior", Sym.LoadingBehavior, GOFF::ESD_LB_Initial);
+ IO.mapOptional("BindingScope", Sym.BindingScope, GOFF::ESD_BSC_Unspecified);
+ IO.mapOptional("Alignment", Sym.Alignment, GOFF::ESD_ALIGN_Byte);
+ IO.mapOptional("BAFlags", Sym.BAFlags, 0);
+}
+
void MappingTraits<GOFFYAML::FileHeader>::mapping(
IO &IO, GOFFYAML::FileHeader &FileHdr) {
IO.mapOptional("TargetEnvironment", FileHdr.TargetEnvironment, 0);
@@ -37,9 +266,34 @@ void MappingTraits<GOFFYAML::FileHeader>::mapping(
FileHdr.TargetSoftwareEnvironment);
}
+void CustomMappingTraits<GOFFYAML::RecordPtr>::inputOne(
+ IO &IO, StringRef Key, GOFFYAML::RecordPtr &Elem) {
+ if (Key == "Section") {
+ GOFFYAML::Section Sec;
+ IO.mapRequired("Section", Sec);
+ Elem = std::make_unique<GOFFYAML::Section>(std::move(Sec));
+ } else if (Key == "Symbol") {
+ GOFFYAML::Symbol Sym;
+ IO.mapRequired("Symbol", Sym);
+ Elem = std::make_unique<GOFFYAML::Symbol>(std::move(Sym));
+ }
+}
+
+void CustomMappingTraits<GOFFYAML::RecordPtr>::output(
+ IO &IO, GOFFYAML::RecordPtr &Elem) {
+ if (auto *Sec = dyn_cast<GOFFYAML::Section>(Elem.get())) {
+ IO.mapRequired("Section", *Sec);
+ } else if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Elem.get())) {
+ IO.mapRequired("Symbol", *Sym);
+ } else {
+ IO.setError("Unknown record type");
+ }
+}
+
void MappingTraits<GOFFYAML::Object>::mapping(IO &IO, GOFFYAML::Object &Obj) {
IO.mapTag("!GOFF", true);
IO.mapRequired("FileHeader", Obj.Header);
+ IO.mapRequired("Records", Obj.Records);
}
} // namespace yaml
>From ae601e2e653b4c030a802c2baa67f9b385905309 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 19 Dec 2023 16:39:47 -0500
Subject: [PATCH 02/11] add tests
---
.../tools/yaml2obj/GOFF/GOFF-TXTSection.yaml | 49 ++++++++++
llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml | 59 ++++++++++++
.../tools/yaml2obj/GOFF/GOFF-header-end.yaml | 1 +
.../yaml2obj/GOFF/GOFF-header-settings.yaml | 3 +-
.../tools/yaml2obj/GOFF/GOFF-longSymbol.yaml | 91 +++++++++++++++++++
.../tools/yaml2obj/GOFF/GOFF-oneSymb.yaml | 40 ++++++++
6 files changed, 242 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
create mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml
create mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
create mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
new file mode 100644
index 00000000000000..3336c452bcaefd
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
@@ -0,0 +1,49 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+ - Symbol:
+ Name: 'var#c'
+ Type: ESD_ST_SectionDefinition
+ ID: 1
+ NameSpace: ESD_NS_ProgramManagementBinder
+ - Symbol:
+ Name: C_CODE64
+ Type: ESD_ST_ElementDefinition
+ ID: 2
+ OwnerID: 1
+ Length: 8
+ NameSpace: ESD_NS_NormalName
+ Flags: [ ESD_FillByteValuePresent ]
+ FillByteValue: 0
+ Amode: ESD_AMODE_64
+ Rmode: ESD_RMODE_64
+ Executable: ESD_EXE_CODE
+ Alignment: ESD_ALIGN_Doubleword
+ BAFlags: [ ESD_BA_ReadOnly ]
+ - Symbol:
+ Name: 'var#c'
+ Type: ESD_ST_LabelDefinition
+ ID: 3
+ OwnerID: 2
+ NameSpace: ESD_NS_ProgramManagementBinder
+# TXT Records' byte 1, bits 0-3 should be 0001.
+# Byte 3, bits 4-7 represent Text Record Style, with 0000
+# for byte-oriented data.
+# Note: DataLength field is 8, so despite Data field being a
+# string of length greater than 8, there are only 8 bytes of
+# data represented.
+# CHECK: 03 10 00 00 00 00 00 02 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 08 12 34 56 78 9a bc de f0
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ - Section:
+ SymbolName: C_CODE64
+ SymbolID: 2
+ TextStyle: TXT_RS_Byte
+ DataLength: 8
+ Data: "123456789ABCDEF0"
+...
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml
new file mode 100644
index 00000000000000..1395bb1fdf2641
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml
@@ -0,0 +1,59 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+# Bytes 80-159
+# CHECK: 03 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 04 88 89 7b c3 00 00 00 00
+ - Symbol:
+ Name: 'hi#C'
+ Type: ESD_ST_SectionDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ NameSpace: ESD_NS_ProgramManagementBinder
+# Bytes 160-239
+# CHECK: 03 00 00 01 00 00 00 02 00 00 00 01 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
+# CHECK: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
+ - Symbol:
+ Name: 'C_WSA64'
+ Type: ESD_ST_ElementDefinition
+ ID: 2
+ OwnerID: 1
+ NameSpace: ESD_NS_Parts
+ Flags: [ ESD_FillByteValuePresent, ESD_RQ_1 ]
+ FillByteValue: 0
+ Amode: ESD_AMODE_64
+ Rmode: ESD_RMODE_64
+ BindingAlgorithm: ESD_BA_Merge
+ Executable: ESD_EXE_DATA
+ LoadingBehavior: ESD_LB_Deferred
+ Alignment: ESD_ALIGN_Doubleword
+# Bytes 240-319
+# CHECK: 03 00 00 03 00 00 00 03 00 00 00 02 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+# CHECK: 00 01 24 00 00 00 00 04 88 89 7b e2 00 00 00 00
+ - Symbol:
+ Name: 'hi#S'
+ Type: ESD_ST_PartReference
+ ID: 3
+ OwnerID: 2
+ Address: 0
+ Length: 2
+ NameSpace: ESD_NS_Parts
+ LinkageType: ESD_LT_XPLink
+ Alignment: ESD_ALIGN_Quadword
+ BindingScope: ESD_BSC_Section
+ Executable: ESD_EXE_DATA
+
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml
index a5e99c2da2c491..3c11b2b9b4d3ff 100644
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml
@@ -18,3 +18,4 @@
--- !GOFF
FileHeader:
ArchitectureLevel: 1
+Records:
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml
index 1971c407199fbe..77833ffbf346d1 100644
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml
@@ -23,4 +23,5 @@ FileHeader:
LanguageProductIdentifier: ""
ArchitectureLevel: 1
InternalCCSID: 0
- TargetSoftwareEnvironment: 0
+ TargetSoftwareEnvironment: 0
+Records:
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
new file mode 100644
index 00000000000000..308deea9117e16
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
@@ -0,0 +1,91 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+# Bytes 80-159
+# Bits 06-07 of Byte 2 should be set to 01 to indicate that this
+# is an "initial record" and it will be continued on the subsequent
+# record.
+# CHECK: 03 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 39 88 89 a3 88 89 a2 89 a2
+# Bytes 160-239
+# Bits 06-07 of Byte 2 are set to 10 to indicate that this is
+# a continuation record, and it is not continued on the next
+# record.
+# CHECK: 03 02 00 81 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
+# CHECK: a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
+# CHECK: a5 85 99 a8 93 96 95 87 a2 a8 94 82 96 93 95 81
+# CHECK: 94 85 7b c3 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ - Symbol:
+ Name: 'hithisisaveryveryveryveryveryveryveryverylongsymbolname#C'
+ Type: ESD_ST_SectionDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ NameSpace: ESD_NS_ProgramManagementBinder
+# CHECK: 03 00 00 01 00 00 00 02 00 00 00 01 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
+# CHECK: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
+ - Symbol:
+ Name: 'C_WSA64'
+ Type: ESD_ST_ElementDefinition
+ ID: 2
+ OwnerID: 1
+ NameSpace: ESD_NS_Parts
+ Flags: [ ESD_FillByteValuePresent, ESD_RQ_1 ]
+ FillByteValue: 0
+ Amode: ESD_AMODE_64
+ Rmode: ESD_RMODE_64
+ BindingAlgorithm: ESD_BA_Merge
+ Executable: ESD_EXE_DATA
+ LoadingBehavior: ESD_LB_Deferred
+ Alignment: ESD_ALIGN_Doubleword
+# Symbol spanning 4 records. First record's second byte
+# ends in 01 indicating that it is continued.
+# CHECK: 03 01 00 03 00 00 00 03 00 00 00 01 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+# CHECK: 00 00 02 00 00 00 00 cf 93 96 95 87 a2 a8 94 82
+# Second record's second byte ends in 11 indicating that it
+# is continued, and it itself is a continuation.
+# CHECK: 03 03 00 96 93 95 96 a3 a2 88 96 99 a3 a3 88 89
+# CHECK: a2 89 a2 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# Third record's second byte ends in 11 indicating that it
+# is continued, and it itself is a continuation.
+# CHECK: 03 03 00 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK: 99 a8 a5 85 99 a8 93 96 95 87 89 95 86 81 83 a3
+# CHECK: a3 88 89 a2 89 a2 85 a5 85 95 93 96 95 87 85 99
+# Fourth record's second byte ends in 10 indicating that it
+# is not continued, but the record itself is a continuation.
+# CHECK: 03 02 00 a3 88 81 95 a3 88 85 97 99 85 a5 89 96
+# CHECK: a4 a2 a2 a8 94 82 96 93 a6 88 89 83 88 a6 81 a2
+# CHECK: 98 a4 89 a3 85 93 96 95 87 81 93 99 85 81 84 a8
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+ - Symbol:
+ Name: 'longsymbolnotshortthisisveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylonginfactthisisevenlongerthantheprevioussymbolwhichwasquitelongalready'
+ Type: ESD_ST_PartReference
+ ID: 3
+ OwnerID: 1
+ Address: 0
+ Length: 4
+ NameSpace: ESD_NS_Parts
+ Alignment: ESD_ALIGN_Fullword
+ Executable: ESD_EXE_DATA
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
new file mode 100644
index 00000000000000..c565cba6dc7874
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
@@ -0,0 +1,40 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+# Verify that GOFF Header is correct.
+# CHECK: 03 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+# Verify that the symbol is written correctly.
+# CHECK: 03 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
+
+# Verify GOFF Module end.
+# CHECK: 03 40 00 00 00 00 00 00 00 00 00 03 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+ - Symbol:
+ Name: 'x'
+ Type: ESD_ST_ElementDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ NameSpace: ESD_NS_NormalName
+ Flags: []
+ FillByteValue: 0
+
>From e53969c0b2ab23ec443a4b6bc16b70e4d68bf4a8 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 19 Dec 2023 16:45:36 -0500
Subject: [PATCH 03/11] fix formtting
---
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index e7db0736993444..85612ec584c311 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -192,7 +192,8 @@ class GOFFState {
GOFFState(raw_ostream &OS, GOFFYAML::Object &Doc,
yaml::ErrorHandler ErrHandler)
- : GW(OS), Doc(Doc), ErrHandler(ErrHandler), SymbolID(0), HasError(false) {}
+ : GW(OS), Doc(Doc), ErrHandler(ErrHandler), SymbolID(0), HasError(false) {
+ }
~GOFFState() { GW.finalize(); }
>From 22c968e7e327b2d68b1215391d1b21a692abc305 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 2 Jan 2024 14:40:41 -0500
Subject: [PATCH 04/11] remove section related code
---
llvm/include/llvm/ObjectYAML/GOFFYAML.h | 21 +-------
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 45 +----------------
llvm/lib/ObjectYAML/GOFFYAML.cpp | 21 +-------
.../tools/yaml2obj/GOFF/GOFF-TXTSection.yaml | 49 -------------------
4 files changed, 4 insertions(+), 132 deletions(-)
delete mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
diff --git a/llvm/include/llvm/ObjectYAML/GOFFYAML.h b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
index c17b4b605e258e..542864e66b618e 100644
--- a/llvm/include/llvm/ObjectYAML/GOFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
@@ -69,7 +69,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint64_t, GOFF_BAFLAGS)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_TEXTRECORDSTYLE)
struct RecordBase {
- enum RecordBaseKind { RBK_Symbol, RBK_Section };
+ enum RecordBaseKind { RBK_Symbol};
private:
const RecordBaseKind Kind;
@@ -82,24 +82,6 @@ struct RecordBase {
};
typedef std::unique_ptr<RecordBase> RecordPtr;
-struct Section : public RecordBase {
- Section() : RecordBase(RBK_Section) {}
-
- StringRef SymbolName;
- uint32_t SymbolID;
- uint32_t Offset;
- uint32_t TrueLength;
- uint16_t TextEncoding;
- uint16_t DataLength;
- GOFF_TEXTRECORDSTYLE TextStyle;
-
- std::optional<yaml::BinaryRef> Data;
-
- static bool classof(const RecordBase *Rec) {
- return Rec->getKind() == RBK_Section;
- }
-};
-
struct Symbol : public RecordBase {
Symbol() : RecordBase(RBK_Symbol) {}
@@ -174,7 +156,6 @@ LLVM_YAML_DECLARE_BITSET_TRAITS(GOFFYAML::GOFF_BAFLAGS)
LLVM_YAML_DECLARE_ENUM_TRAITS(GOFFYAML::GOFF_TEXTRECORDSTYLE)
-LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Section)
LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Symbol)
LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::FileHeader)
LLVM_YAML_DECLARE_MAPPING_TRAITS(GOFFYAML::Object)
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 85612ec584c311..33cff0e5147fb2 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -22,8 +22,6 @@ using namespace llvm;
namespace {
-static const uint8_t TXTMaxDataLength = 56;
-
// Common flag values on records.
enum {
// Flag: This record is continued.
@@ -62,11 +60,6 @@ raw_ostream &operator<<(raw_ostream &OS, const ZerosImpl &Z) {
ZerosImpl zeros(const size_t NumBytes) { return ZerosImpl{NumBytes}; }
-raw_ostream &operator<<(raw_ostream &OS, const yaml::BinaryRef &Data) {
- Data.writeAsBinary(OS);
- return OS;
-}
-
// The GOFFOstream is responsible to write the data into the fixed physical
// records of the format. A user of this class announces the start of a new
// logical record and the size of its payload. While writing the payload, the
@@ -183,7 +176,6 @@ class GOFFState {
void writeHeader(GOFFYAML::FileHeader &FileHdr);
void writeEnd();
void writeSymbol(GOFFYAML::Symbol Sym);
- void writeSection(GOFFYAML::Section Sec);
void reportError(const Twine &Msg) {
ErrHandler(Msg);
@@ -307,39 +299,6 @@ void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
#undef BIT
}
-void GOFFState::writeSection(GOFFYAML::Section Sec) {
- if (Sec.SymbolID == 0 || Sec.SymbolID > SymbolID)
- reportError("section symbol not defined: " + Twine(Sec.SymbolID));
-
- size_t Size = 0;
- if (Sec.Data) {
- Size = Sec.Data->binary_size();
- if (Size > GOFF::MaxDataLength) {
- reportError("section content is too long: " + Twine(Size));
- return;
- }
- if (Sec.DataLength && Sec.DataLength != Size) {
- reportError("Section content length " + Twine(Size) +
- " does not match data length " + Twine(Sec.DataLength));
- return;
- }
- } else
- Size = Sec.DataLength;
-
- GW.makeNewRecord(GOFF::RT_TXT, GOFF::PayloadLength - TXTMaxDataLength + Size);
- GW << binaryBe(Sec.TextStyle) // Text Record Style
- << binaryBe(Sec.SymbolID) // Element ESDID
- << binaryBe(uint32_t(0)) // Reserved
- << binaryBe(Sec.Offset) // Offset
- << binaryBe(Sec.TrueLength) // Text Field True Length
- << binaryBe(Sec.TextEncoding) // Text Encoding
- << binaryBe(static_cast<uint16_t>(Size)); // Data Length
- if (Sec.Data)
- GW << *Sec.Data; // Data
- else
- GW << zeros(Size);
-}
-
void GOFFState::writeEnd() {
GW.makeNewRecord(GOFF::RT_END, GOFF::PayloadLength);
GW << binaryBe(uint8_t(0)) // No entry point
@@ -356,9 +315,7 @@ bool GOFFState::writeObject() {
return false;
// Iterate over all records.
for (auto &Rec : Doc.Records) {
- if (auto *Sec = dyn_cast<GOFFYAML::Section>(Rec.get())) {
- writeSection(*Sec);
- } else if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get())) {
+ if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get())) {
writeSymbol(*Sym);
} else {
reportError("Unknown record type");
diff --git a/llvm/lib/ObjectYAML/GOFFYAML.cpp b/llvm/lib/ObjectYAML/GOFFYAML.cpp
index 4d10c8352219cf..ba54e07a07447d 100644
--- a/llvm/lib/ObjectYAML/GOFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/GOFFYAML.cpp
@@ -210,17 +210,6 @@ void ScalarBitSetTraits<GOFFYAML::GOFF_BAFLAGS>::bitset(
#undef BCaseMask
}
-void MappingTraits<GOFFYAML::Section>::mapping(IO &IO, GOFFYAML::Section &Sec) {
- IO.mapRequired("SymbolName", Sec.SymbolName);
- IO.mapRequired("SymbolID", Sec.SymbolID);
- IO.mapOptional("Offset", Sec.Offset, 0);
- IO.mapOptional("TrueLength", Sec.TrueLength, 0);
- IO.mapOptional("TextEncoding", Sec.TextEncoding, 0);
- IO.mapOptional("DataLength", Sec.DataLength, 0);
- IO.mapOptional("TextStyle", Sec.TextStyle, GOFF::TXT_RS_Byte);
- IO.mapOptional("Data", Sec.Data);
-}
-
void MappingTraits<GOFFYAML::Symbol>::mapping(IO &IO, GOFFYAML::Symbol &Sym) {
IO.mapRequired("Name", Sym.Name);
IO.mapRequired("Type", Sym.Type);
@@ -268,11 +257,7 @@ void MappingTraits<GOFFYAML::FileHeader>::mapping(
void CustomMappingTraits<GOFFYAML::RecordPtr>::inputOne(
IO &IO, StringRef Key, GOFFYAML::RecordPtr &Elem) {
- if (Key == "Section") {
- GOFFYAML::Section Sec;
- IO.mapRequired("Section", Sec);
- Elem = std::make_unique<GOFFYAML::Section>(std::move(Sec));
- } else if (Key == "Symbol") {
+ if (Key == "Symbol") {
GOFFYAML::Symbol Sym;
IO.mapRequired("Symbol", Sym);
Elem = std::make_unique<GOFFYAML::Symbol>(std::move(Sym));
@@ -281,9 +266,7 @@ void CustomMappingTraits<GOFFYAML::RecordPtr>::inputOne(
void CustomMappingTraits<GOFFYAML::RecordPtr>::output(
IO &IO, GOFFYAML::RecordPtr &Elem) {
- if (auto *Sec = dyn_cast<GOFFYAML::Section>(Elem.get())) {
- IO.mapRequired("Section", *Sec);
- } else if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Elem.get())) {
+ if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Elem.get())) {
IO.mapRequired("Symbol", *Sym);
} else {
IO.setError("Unknown record type");
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
deleted file mode 100644
index 3336c452bcaefd..00000000000000
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-TXTSection.yaml
+++ /dev/null
@@ -1,49 +0,0 @@
-# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
-
---- !GOFF
-FileHeader:
- ArchitectureLevel: 1
-Records:
- - Symbol:
- Name: 'var#c'
- Type: ESD_ST_SectionDefinition
- ID: 1
- NameSpace: ESD_NS_ProgramManagementBinder
- - Symbol:
- Name: C_CODE64
- Type: ESD_ST_ElementDefinition
- ID: 2
- OwnerID: 1
- Length: 8
- NameSpace: ESD_NS_NormalName
- Flags: [ ESD_FillByteValuePresent ]
- FillByteValue: 0
- Amode: ESD_AMODE_64
- Rmode: ESD_RMODE_64
- Executable: ESD_EXE_CODE
- Alignment: ESD_ALIGN_Doubleword
- BAFlags: [ ESD_BA_ReadOnly ]
- - Symbol:
- Name: 'var#c'
- Type: ESD_ST_LabelDefinition
- ID: 3
- OwnerID: 2
- NameSpace: ESD_NS_ProgramManagementBinder
-# TXT Records' byte 1, bits 0-3 should be 0001.
-# Byte 3, bits 4-7 represent Text Record Style, with 0000
-# for byte-oriented data.
-# Note: DataLength field is 8, so despite Data field being a
-# string of length greater than 8, there are only 8 bytes of
-# data represented.
-# CHECK: 03 10 00 00 00 00 00 02 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 08 12 34 56 78 9a bc de f0
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- - Section:
- SymbolName: C_CODE64
- SymbolID: 2
- TextStyle: TXT_RS_Byte
- DataLength: 8
- Data: "123456789ABCDEF0"
-...
>From 25a8034f27a90c0e2179c85a20a68010bcc0d7e1 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Thu, 18 Jan 2024 16:20:29 -0500
Subject: [PATCH 05/11] address comments
---
llvm/include/llvm/ObjectYAML/GOFFYAML.h | 7 +-
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 18 ++--
.../tools/yaml2obj/GOFF/GOFF-longSymbol.yaml | 91 -------------------
.../tools/yaml2obj/GOFF/GOFF-oneSymb.yaml | 40 --------
.../GOFF/{GOFF-basic.yaml => basic.yaml} | 27 +++---
.../{GOFF-header-end.yaml => header-end.yaml} | 0
...der-settings.yaml => header-settings.yaml} | 0
.../test/tools/yaml2obj/GOFF/long-symbol.yaml | 90 ++++++++++++++++++
.../{GOFF-no-header.yaml => no-header.yaml} | 0
llvm/test/tools/yaml2obj/GOFF/one-symbol.yaml | 37 ++++++++
10 files changed, 152 insertions(+), 158 deletions(-)
delete mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
delete mode 100644 llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
rename llvm/test/tools/yaml2obj/GOFF/{GOFF-basic.yaml => basic.yaml} (66%)
rename llvm/test/tools/yaml2obj/GOFF/{GOFF-header-end.yaml => header-end.yaml} (100%)
rename llvm/test/tools/yaml2obj/GOFF/{GOFF-header-settings.yaml => header-settings.yaml} (100%)
create mode 100644 llvm/test/tools/yaml2obj/GOFF/long-symbol.yaml
rename llvm/test/tools/yaml2obj/GOFF/{GOFF-no-header.yaml => no-header.yaml} (100%)
create mode 100644 llvm/test/tools/yaml2obj/GOFF/one-symbol.yaml
diff --git a/llvm/include/llvm/ObjectYAML/GOFFYAML.h b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
index 542864e66b618e..402f2b5d10f4c9 100644
--- a/llvm/include/llvm/ObjectYAML/GOFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
@@ -20,7 +20,6 @@
#include <vector>
namespace llvm {
-
namespace GOFF {
enum ESDFlags {
@@ -44,6 +43,7 @@ enum ESDBAFlags {
ESD_BA_COMMON = 0x8,
ESD_BA_Indirect = 0x10,
};
+
} // end namespace GOFF
// The structure of the yaml files is not an exact 1:1 match to GOFF. In order
@@ -69,7 +69,7 @@ LLVM_YAML_STRONG_TYPEDEF(uint64_t, GOFF_BAFLAGS)
LLVM_YAML_STRONG_TYPEDEF(uint8_t, GOFF_TEXTRECORDSTYLE)
struct RecordBase {
- enum RecordBaseKind { RBK_Symbol};
+ enum RecordBaseKind { RBK_Symbol };
private:
const RecordBaseKind Kind;
@@ -80,7 +80,8 @@ struct RecordBase {
public:
RecordBaseKind getKind() const { return Kind; }
};
-typedef std::unique_ptr<RecordBase> RecordPtr;
+
+using RecordPtr = std::unique_ptr<RecordBase>;
struct Symbol : public RecordBase {
Symbol() : RecordBase(RBK_Symbol) {}
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 33cff0e5147fb2..f7833765b77875 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -258,11 +258,11 @@ void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
SmallString<80> SymName;
if (std::error_code EC = ConverterEBCDIC::convertToEBCDIC(Sym.Name, SymName))
reportError("conversion error on " + Sym.Name);
- size_t SymLength = SymName.size();
- if (SymLength > GOFF::MaxDataLength)
- reportError("symbol name is too long: " + Twine(SymLength));
+ size_t SymNameLength = SymName.size();
+ if (SymNameLength > GOFF::MaxDataLength)
+ reportError("symbol name is too long: " + Twine(SymNameLength));
- GW.makeNewRecord(GOFF::RT_ESD, 69 + SymLength);
+ GW.makeNewRecord(GOFF::RT_ESD, 69 + SymNameLength);
GW << binaryBe(Sym.Type) // Symbol type
<< binaryBe(Sym.ID) // ESDID
<< binaryBe(Sym.OwnerID) // Owner ESDID
@@ -294,7 +294,7 @@ void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
BIT(ESD_BA_Indirect, 3) | Sym.BindingScope))
<< binaryBe(uint8_t(Sym.LinkageType << 5 | Sym.Alignment))
<< zeros(3) // Behavioral attributes - Reserved
- << binaryBe(static_cast<uint16_t>(SymLength)) // Name length
+ << binaryBe(static_cast<uint16_t>(SymNameLength)) // Name length
<< SymName.str();
#undef BIT
}
@@ -314,13 +314,11 @@ bool GOFFState::writeObject() {
if (HasError)
return false;
// Iterate over all records.
- for (auto &Rec : Doc.Records) {
- if (auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get())) {
+ for (const std::unique_ptr<llvm::GOFFYAML::RecordBase> &Rec : Doc.Records)
+ if (const auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get()))
writeSymbol(*Sym);
- } else {
+ else
reportError("Unknown record type");
- }
- }
writeEnd();
return true;
}
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
deleted file mode 100644
index 308deea9117e16..00000000000000
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-longSymbol.yaml
+++ /dev/null
@@ -1,91 +0,0 @@
-# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
-
-
---- !GOFF
-FileHeader:
- ArchitectureLevel: 1
-Records:
-# Bytes 80-159
-# Bits 06-07 of Byte 2 should be set to 01 to indicate that this
-# is an "initial record" and it will be continued on the subsequent
-# record.
-# CHECK: 03 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 39 88 89 a3 88 89 a2 89 a2
-# Bytes 160-239
-# Bits 06-07 of Byte 2 are set to 10 to indicate that this is
-# a continuation record, and it is not continued on the next
-# record.
-# CHECK: 03 02 00 81 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
-# CHECK: a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
-# CHECK: a5 85 99 a8 93 96 95 87 a2 a8 94 82 96 93 95 81
-# CHECK: 94 85 7b c3 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
- - Symbol:
- Name: 'hithisisaveryveryveryveryveryveryveryverylongsymbolname#C'
- Type: ESD_ST_SectionDefinition
- ID: 1
- OwnerID: 0
- Address: 0
- Length: 0
- NameSpace: ESD_NS_ProgramManagementBinder
-# CHECK: 03 00 00 01 00 00 00 02 00 00 00 01 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
-# CHECK: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
- - Symbol:
- Name: 'C_WSA64'
- Type: ESD_ST_ElementDefinition
- ID: 2
- OwnerID: 1
- NameSpace: ESD_NS_Parts
- Flags: [ ESD_FillByteValuePresent, ESD_RQ_1 ]
- FillByteValue: 0
- Amode: ESD_AMODE_64
- Rmode: ESD_RMODE_64
- BindingAlgorithm: ESD_BA_Merge
- Executable: ESD_EXE_DATA
- LoadingBehavior: ESD_LB_Deferred
- Alignment: ESD_ALIGN_Doubleword
-# Symbol spanning 4 records. First record's second byte
-# ends in 01 indicating that it is continued.
-# CHECK: 03 01 00 03 00 00 00 03 00 00 00 01 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
-# CHECK: 00 00 02 00 00 00 00 cf 93 96 95 87 a2 a8 94 82
-# Second record's second byte ends in 11 indicating that it
-# is continued, and it itself is a continuation.
-# CHECK: 03 03 00 96 93 95 96 a3 a2 88 96 99 a3 a3 88 89
-# CHECK: a2 89 a2 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
-# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
-# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
-# CHECK: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
-# Third record's second byte ends in 11 indicating that it
-# is continued, and it itself is a continuation.
-# CHECK: 03 03 00 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
-# CHECK: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
-# CHECK: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
-# CHECK: 99 a8 a5 85 99 a8 93 96 95 87 89 95 86 81 83 a3
-# CHECK: a3 88 89 a2 89 a2 85 a5 85 95 93 96 95 87 85 99
-# Fourth record's second byte ends in 10 indicating that it
-# is not continued, but the record itself is a continuation.
-# CHECK: 03 02 00 a3 88 81 95 a3 88 85 97 99 85 a5 89 96
-# CHECK: a4 a2 a2 a8 94 82 96 93 a6 88 89 83 88 a6 81 a2
-# CHECK: 98 a4 89 a3 85 93 96 95 87 81 93 99 85 81 84 a8
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-
- - Symbol:
- Name: 'longsymbolnotshortthisisveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylonginfactthisisevenlongerthantheprevioussymbolwhichwasquitelongalready'
- Type: ESD_ST_PartReference
- ID: 3
- OwnerID: 1
- Address: 0
- Length: 4
- NameSpace: ESD_NS_Parts
- Alignment: ESD_ALIGN_Fullword
- Executable: ESD_EXE_DATA
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml b/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
deleted file mode 100644
index c565cba6dc7874..00000000000000
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-oneSymb.yaml
+++ /dev/null
@@ -1,40 +0,0 @@
-# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
-
-# Verify that GOFF Header is correct.
-# CHECK: 03 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-
-# Verify that the symbol is written correctly.
-# CHECK: 03 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
-
-# Verify GOFF Module end.
-# CHECK: 03 40 00 00 00 00 00 00 00 00 00 03 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-
-
-
---- !GOFF
-FileHeader:
- ArchitectureLevel: 1
-Records:
- - Symbol:
- Name: 'x'
- Type: ESD_ST_ElementDefinition
- ID: 1
- OwnerID: 0
- Address: 0
- Length: 0
- NameSpace: ESD_NS_NormalName
- Flags: []
- FillByteValue: 0
-
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml b/llvm/test/tools/yaml2obj/GOFF/basic.yaml
similarity index 66%
rename from llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml
rename to llvm/test/tools/yaml2obj/GOFF/basic.yaml
index 1395bb1fdf2641..4b2b8cba48039e 100644
--- a/llvm/test/tools/yaml2obj/GOFF/GOFF-basic.yaml
+++ b/llvm/test/tools/yaml2obj/GOFF/basic.yaml
@@ -4,12 +4,12 @@
FileHeader:
ArchitectureLevel: 1
Records:
-# Bytes 80-159
+## Bytes 80-159
# CHECK: 03 00 00 00 00 00 00 01 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 04 88 89 7b c3 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 04 88 89 7b c3 00 00 00 00
- Symbol:
Name: 'hi#C'
Type: ESD_ST_SectionDefinition
@@ -20,10 +20,10 @@ Records:
NameSpace: ESD_NS_ProgramManagementBinder
# Bytes 160-239
# CHECK: 03 00 00 01 00 00 00 02 00 00 00 01 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
-# CHECK: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
+# CHECK-NEXT: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
- Symbol:
Name: 'C_WSA64'
Type: ESD_ST_ElementDefinition
@@ -40,10 +40,10 @@ Records:
Alignment: ESD_ALIGN_Doubleword
# Bytes 240-319
# CHECK: 03 00 00 03 00 00 00 03 00 00 00 02 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
-# CHECK: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
-# CHECK: 00 01 24 00 00 00 00 04 88 89 7b e2 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+# CHECK-NEXT: 00 01 24 00 00 00 00 04 88 89 7b e2 00 00 00 00
- Symbol:
Name: 'hi#S'
Type: ESD_ST_PartReference
@@ -56,4 +56,3 @@ Records:
Alignment: ESD_ALIGN_Quadword
BindingScope: ESD_BSC_Section
Executable: ESD_EXE_DATA
-
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml b/llvm/test/tools/yaml2obj/GOFF/header-end.yaml
similarity index 100%
rename from llvm/test/tools/yaml2obj/GOFF/GOFF-header-end.yaml
rename to llvm/test/tools/yaml2obj/GOFF/header-end.yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml b/llvm/test/tools/yaml2obj/GOFF/header-settings.yaml
similarity index 100%
rename from llvm/test/tools/yaml2obj/GOFF/GOFF-header-settings.yaml
rename to llvm/test/tools/yaml2obj/GOFF/header-settings.yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/long-symbol.yaml b/llvm/test/tools/yaml2obj/GOFF/long-symbol.yaml
new file mode 100644
index 00000000000000..8639c5cfe14fb7
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/long-symbol.yaml
@@ -0,0 +1,90 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+## Bytes 80-159
+## Bits 06-07 of Byte 2 should be set to 01 to indicate that this
+## is an "initial record" and it will be continued in the subsequent
+## record.
+# CHECK: 03 01 00 00 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 39 88 89 a3 88 89 a2 89 a2
+## Bytes 160-239
+## Bits 06-07 of Byte 2 are set to 10 to indicate that this is
+## a continuation record, and it is not continued in the next
+## record.
+# CHECK-NEXT: 03 02 00 81 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
+# CHECK-NEXT: a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8
+# CHECK-NEXT: a5 85 99 a8 93 96 95 87 a2 a8 94 82 96 93 95 81
+# CHECK-NEXT: 94 85 7b c3 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+ - Symbol:
+ Name: 'hithisisaveryveryveryveryveryveryveryverylongsymbolname#C'
+ Type: ESD_ST_SectionDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ NameSpace: ESD_NS_ProgramManagementBinder
+# CHECK-NEXT: 03 00 00 01 00 00 00 02 00 00 00 01 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 03 81 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 04 04 01 01
+# CHECK-NEXT: 00 40 03 00 00 00 00 07 c3 6d e6 e2 c1 f6 f4 00
+ - Symbol:
+ Name: 'C_WSA64'
+ Type: ESD_ST_ElementDefinition
+ ID: 2
+ OwnerID: 1
+ NameSpace: ESD_NS_Parts
+ Flags: [ ESD_FillByteValuePresent, ESD_RQ_1 ]
+ FillByteValue: 0
+ Amode: ESD_AMODE_64
+ Rmode: ESD_RMODE_64
+ BindingAlgorithm: ESD_BA_Merge
+ Executable: ESD_EXE_DATA
+ LoadingBehavior: ESD_LB_Deferred
+ Alignment: ESD_ALIGN_Doubleword
+## Symbol spanning 4 records. First record's second byte
+## ends in 01 indicating that it is continued.
+# CHECK-NEXT: 03 01 00 03 00 00 00 03 00 00 00 01 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 03 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 01
+# CHECK-NEXT: 00 00 02 00 00 00 00 cf 93 96 95 87 a2 a8 94 82
+## Second record's second byte ends in 11 indicating that it
+## is continued, and it itself is a continuation.
+# CHECK-NEXT: 03 03 00 96 93 95 96 a3 a2 88 96 99 a3 a3 88 89
+# CHECK-NEXT: a2 89 a2 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK-NEXT: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK-NEXT: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+# CHECK-NEXT: 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5
+## Third record's second byte ends in 11 indicating that it
+## is continued, and it itself is a continuation.
+# CHECK-NEXT: 03 03 00 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK-NEXT: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK-NEXT: 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85 99 a8 a5 85
+# CHECK-NEXT: 99 a8 a5 85 99 a8 93 96 95 87 89 95 86 81 83 a3
+# CHECK-NEXT: a3 88 89 a2 89 a2 85 a5 85 95 93 96 95 87 85 99
+## Fourth record's second byte ends in 10 indicating that it
+## is not continued, but the record itself is a continuation.
+# CHECK-NEXT: 03 02 00 a3 88 81 95 a3 88 85 97 99 85 a5 89 96
+# CHECK-NEXT: a4 a2 a2 a8 94 82 96 93 a6 88 89 83 88 a6 81 a2
+# CHECK-NEXT: 98 a4 89 a3 85 93 96 95 87 81 93 99 85 81 84 a8
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+ - Symbol:
+ Name: 'longsymbolnotshortthisisveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryveryverylonginfactthisisevenlongerthantheprevioussymbolwhichwasquitelongalready'
+ Type: ESD_ST_PartReference
+ ID: 3
+ OwnerID: 1
+ Address: 0
+ Length: 4
+ NameSpace: ESD_NS_Parts
+ Alignment: ESD_ALIGN_Fullword
+ Executable: ESD_EXE_DATA
diff --git a/llvm/test/tools/yaml2obj/GOFF/GOFF-no-header.yaml b/llvm/test/tools/yaml2obj/GOFF/no-header.yaml
similarity index 100%
rename from llvm/test/tools/yaml2obj/GOFF/GOFF-no-header.yaml
rename to llvm/test/tools/yaml2obj/GOFF/no-header.yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/one-symbol.yaml b/llvm/test/tools/yaml2obj/GOFF/one-symbol.yaml
new file mode 100644
index 00000000000000..b414b253209084
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/one-symbol.yaml
@@ -0,0 +1,37 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+## Verify that GOFF Header is correct.
+# CHECK: 03 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+## Verify that the symbol is written correctly.
+# CHECK-NEXT: 03 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
+
+## Verify GOFF Module end.
+# CHECK-NEXT: 03 40 00 00 00 00 00 00 00 00 00 03 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+ - Symbol:
+ Name: 'x'
+ Type: ESD_ST_ElementDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ NameSpace: ESD_NS_NormalName
+ Flags: []
+ FillByteValue: 0
>From 2ce0e3b366a05f2ac3b5de53a90b72c42f7fb021 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 12 Mar 2024 15:32:59 -0400
Subject: [PATCH 06/11] remove std::option for Signature
---
llvm/include/llvm/ObjectYAML/GOFFYAML.h | 3 ++-
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 4 ++--
llvm/lib/ObjectYAML/GOFFYAML.cpp | 2 +-
3 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/llvm/include/llvm/ObjectYAML/GOFFYAML.h b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
index 402f2b5d10f4c9..cc88def3aea4a0 100644
--- a/llvm/include/llvm/ObjectYAML/GOFFYAML.h
+++ b/llvm/include/llvm/ObjectYAML/GOFFYAML.h
@@ -99,7 +99,7 @@ struct Symbol : public RecordBase {
uint8_t FillByteValue;
uint32_t PSectID;
uint32_t Priority;
- std::optional<llvm::yaml::Hex64> Signature;
+ llvm::yaml::Hex64 Signature;
GOFF_ESDAMODE Amode;
GOFF_ESDRMODE Rmode;
GOFF_ESDTEXTSTYLE TextStyle;
@@ -134,6 +134,7 @@ struct Object {
std::vector<RecordPtr> Records;
Object();
};
+
} // end namespace GOFFYAML
} // end namespace llvm
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index f7833765b77875..a2e8f53fc65c46 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -280,7 +280,7 @@ void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
<< binaryBe(Sym.PSectID) // PSECT ID
<< binaryBe(Sym.Priority); // Priority
if (Sym.Signature)
- GW << *Sym.Signature; // Signature
+ GW << Sym.Signature; // Signature
else
GW << zeros(8);
#define BIT(E, N) (Sym.BAFlags & GOFF::E ? 1 << (7 - N) : 0)
@@ -318,7 +318,7 @@ bool GOFFState::writeObject() {
if (const auto *Sym = dyn_cast<GOFFYAML::Symbol>(Rec.get()))
writeSymbol(*Sym);
else
- reportError("Unknown record type");
+ reportError("unknown record type");
writeEnd();
return true;
}
diff --git a/llvm/lib/ObjectYAML/GOFFYAML.cpp b/llvm/lib/ObjectYAML/GOFFYAML.cpp
index ba54e07a07447d..df8be5f8af9b29 100644
--- a/llvm/lib/ObjectYAML/GOFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/GOFFYAML.cpp
@@ -224,7 +224,7 @@ void MappingTraits<GOFFYAML::Symbol>::mapping(IO &IO, GOFFYAML::Symbol &Sym) {
IO.mapOptional("FillByteValue", Sym.FillByteValue, 0);
IO.mapOptional("PSectID", Sym.PSectID, 0);
IO.mapOptional("Priority", Sym.Priority, 0);
- IO.mapOptional("Signature", Sym.Signature);
+ IO.mapOptional("Signature", Sym.Signature, 0);
IO.mapOptional("Amode", Sym.Amode, GOFF::ESD_AMODE_None);
IO.mapOptional("Rmode", Sym.Rmode, GOFF::ESD_RMODE_None);
IO.mapOptional("TextStyle", Sym.TextStyle, GOFF::ESD_TS_ByteOriented);
>From ddca5576b84a07dba539f21ec547506ddb6c14d3 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Thu, 14 Mar 2024 16:33:28 -0400
Subject: [PATCH 07/11] remove checks
---
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 9 +--------
1 file changed, 1 insertion(+), 8 deletions(-)
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index a2e8f53fc65c46..340e6c7ebf54ed 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -184,7 +184,7 @@ class GOFFState {
GOFFState(raw_ostream &OS, GOFFYAML::Object &Doc,
yaml::ErrorHandler ErrHandler)
- : GW(OS), Doc(Doc), ErrHandler(ErrHandler), SymbolID(0), HasError(false) {
+ : GW(OS), Doc(Doc), ErrHandler(ErrHandler), HasError(false) {
}
~GOFFState() { GW.finalize(); }
@@ -199,7 +199,6 @@ class GOFFState {
GOFFOstream GW;
GOFFYAML::Object &Doc;
yaml::ErrorHandler ErrHandler;
- uint16_t SymbolID;
bool HasError;
};
@@ -249,12 +248,6 @@ void GOFFState::writeHeader(GOFFYAML::FileHeader &FileHdr) {
}
void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
- if (Sym.ID != SymbolID + 1)
- reportError("symbol IDs not monotonic " + Sym.Name);
- else
- ++SymbolID;
- if (Sym.OwnerID >= SymbolID)
- reportError("owner ID not defined " + Sym.Name);
SmallString<80> SymName;
if (std::error_code EC = ConverterEBCDIC::convertToEBCDIC(Sym.Name, SymName))
reportError("conversion error on " + Sym.Name);
>From c92c5c240773b36e846ba632acdecf71ba5e5ff2 Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Fri, 15 Mar 2024 14:32:46 -0400
Subject: [PATCH 08/11] more comments
---
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 3 +--
llvm/lib/ObjectYAML/GOFFYAML.cpp | 42 +++++------------------------
2 files changed, 7 insertions(+), 38 deletions(-)
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 340e6c7ebf54ed..542a1f0f5f3209 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -184,8 +184,7 @@ class GOFFState {
GOFFState(raw_ostream &OS, GOFFYAML::Object &Doc,
yaml::ErrorHandler ErrHandler)
- : GW(OS), Doc(Doc), ErrHandler(ErrHandler), HasError(false) {
- }
+ : GW(OS), Doc(Doc), ErrHandler(ErrHandler), HasError(false) {}
~GOFFState() { GW.finalize(); }
diff --git a/llvm/lib/ObjectYAML/GOFFYAML.cpp b/llvm/lib/ObjectYAML/GOFFYAML.cpp
index df8be5f8af9b29..c4c7e25423b9fc 100644
--- a/llvm/lib/ObjectYAML/GOFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/GOFFYAML.cpp
@@ -23,33 +23,30 @@ Object::Object() {}
namespace yaml {
+#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
+#define BCase(X) IO.bitSetCase(Value, #X, GOFF::X)
+#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, GOFF::X, GOFF::M)
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDSYMBOLTYPE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDSYMBOLTYPE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_ST_SectionDefinition);
ECase(ESD_ST_ElementDefinition);
ECase(ESD_ST_LabelDefinition);
ECase(ESD_ST_PartReference);
ECase(ESD_ST_ExternalReference);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDNAMESPACEID>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDNAMESPACEID &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_NS_ProgramManagementBinder);
ECase(ESD_NS_NormalName);
ECase(ESD_NS_PseudoRegister);
ECase(ESD_NS_Parts);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarBitSetTraits<GOFFYAML::GOFF_ESDFlags>::bitset(
IO &IO, GOFFYAML::GOFF_ESDFlags &Value) {
-#define BCase(X) IO.bitSetCase(Value, #X, GOFF::X)
-#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, GOFF::X, GOFF::M)
BCase(ESD_FillByteValuePresent);
BCase(ESD_SymbolDisplayFlag);
BCase(ESD_SymbolRenamingFlag);
@@ -58,128 +55,103 @@ void ScalarBitSetTraits<GOFFYAML::GOFF_ESDFlags>::bitset(
BCaseMask(ESD_RQ_1, ESD_Mask_RQW);
BCaseMask(ESD_RQ_2, ESD_Mask_RQW);
BCaseMask(ESD_RQ_3, ESD_Mask_RQW);
-#undef BCase
-#undef BCaseMask
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_TEXTRECORDSTYLE>::enumeration(
IO &IO, GOFFYAML::GOFF_TEXTRECORDSTYLE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(TXT_RS_Byte);
ECase(TXT_RS_Structured);
ECase(TXT_RS_Unstructured);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDAMODE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDAMODE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_AMODE_None);
ECase(ESD_AMODE_24);
ECase(ESD_AMODE_31);
ECase(ESD_AMODE_ANY);
ECase(ESD_AMODE_64);
ECase(ESD_AMODE_MIN);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDRMODE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDRMODE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_RMODE_None);
ECase(ESD_RMODE_24);
ECase(ESD_RMODE_31);
ECase(ESD_RMODE_64);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDTEXTSTYLE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDTEXTSTYLE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_TS_ByteOriented);
ECase(ESD_TS_Structured);
ECase(ESD_TS_Unstructured);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGALGORITHM>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDBINDINGALGORITHM &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_BA_Concatenate);
ECase(ESD_BA_Merge);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDTASKINGBEHAVIOR>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDTASKINGBEHAVIOR &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_TA_Unspecified);
ECase(ESD_TA_NonReus);
ECase(ESD_TA_Reus);
ECase(ESD_TA_Rent);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDEXECUTABLE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDEXECUTABLE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_EXE_Unspecified);
ECase(ESD_EXE_DATA);
ECase(ESD_EXE_CODE);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDLINKAGETYPE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDLINKAGETYPE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_LT_OS);
ECase(ESD_LT_XPLink);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGSTRENGTH>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDBINDINGSTRENGTH &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_BST_Strong);
ECase(ESD_BST_Weak);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDLOADINGBEHAVIOR>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDLOADINGBEHAVIOR &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_LB_Initial);
ECase(ESD_LB_Deferred);
ECase(ESD_LB_NoLoad);
ECase(ESD_LB_Reserved);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDBINDINGSCOPE>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDBINDINGSCOPE &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_BSC_Unspecified);
ECase(ESD_BSC_Section);
ECase(ESD_BSC_Module);
ECase(ESD_BSC_Library);
ECase(ESD_BSC_ImportExport);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDALIGNMENT>::enumeration(
IO &IO, GOFFYAML::GOFF_ESDALIGNMENT &Value) {
-#define ECase(X) IO.enumCase(Value, #X, GOFF::X)
ECase(ESD_ALIGN_Byte);
ECase(ESD_ALIGN_Halfword);
ECase(ESD_ALIGN_Fullword);
@@ -193,27 +165,25 @@ void ScalarEnumerationTraits<GOFFYAML::GOFF_ESDALIGNMENT>::enumeration(
ECase(ESD_ALIGN_1024byte);
ECase(ESD_ALIGN_2Kpage);
ECase(ESD_ALIGN_4Kpage);
-#undef ECase
IO.enumFallback<Hex8>(Value);
}
void ScalarBitSetTraits<GOFFYAML::GOFF_BAFLAGS>::bitset(
IO &IO, GOFFYAML::GOFF_BAFLAGS &Value) {
-#define BCase(X) IO.bitSetCase(Value, #X, GOFF::X)
-#define BCaseMask(X, M) IO.maskedBitSetCase(Value, #X, GOFF::X, GOFF::M)
BCase(ESD_BA_Movable);
BCase(ESD_BA_ReadOnly);
BCase(ESD_BA_NoPrime);
BCase(ESD_BA_COMMON);
BCase(ESD_BA_Indirect);
+}
#undef BCase
#undef BCaseMask
-}
+#undef ECase
void MappingTraits<GOFFYAML::Symbol>::mapping(IO &IO, GOFFYAML::Symbol &Sym) {
IO.mapRequired("Name", Sym.Name);
IO.mapRequired("Type", Sym.Type);
- IO.mapRequired("ID", Sym.ID);
+ IO.mapOptional("ID", Sym.ID);
IO.mapOptional("OwnerID", Sym.OwnerID, 0);
IO.mapOptional("Address", Sym.Address, 0);
IO.mapOptional("Length", Sym.Length, 0);
>From 263bef65d8c1db6c950dfaed70f38d962bca5b0b Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Fri, 15 Mar 2024 15:51:57 -0400
Subject: [PATCH 09/11] add maxdatalength to message, define NameLengthOffset
---
llvm/lib/ObjectYAML/GOFFEmitter.cpp | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/llvm/lib/ObjectYAML/GOFFEmitter.cpp b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
index 542a1f0f5f3209..8b539bf7b15c94 100644
--- a/llvm/lib/ObjectYAML/GOFFEmitter.cpp
+++ b/llvm/lib/ObjectYAML/GOFFEmitter.cpp
@@ -252,9 +252,11 @@ void GOFFState::writeSymbol(GOFFYAML::Symbol Sym) {
reportError("conversion error on " + Sym.Name);
size_t SymNameLength = SymName.size();
if (SymNameLength > GOFF::MaxDataLength)
- reportError("symbol name is too long: " + Twine(SymNameLength));
+ reportError("symbol name is too long: " + Twine(SymNameLength) +
+ ". Max length is: " + Twine(GOFF::MaxDataLength));
- GW.makeNewRecord(GOFF::RT_ESD, 69 + SymNameLength);
+ unsigned NameLengthOffset = 69;
+ GW.makeNewRecord(GOFF::RT_ESD, NameLengthOffset + SymNameLength);
GW << binaryBe(Sym.Type) // Symbol type
<< binaryBe(Sym.ID) // ESDID
<< binaryBe(Sym.OwnerID) // Owner ESDID
>From 85251f6c477da73b7bf43713450e0b25b46b7eaf Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Thu, 4 Apr 2024 16:28:56 -0400
Subject: [PATCH 10/11] remove Records label if there are none
---
llvm/lib/ObjectYAML/GOFFYAML.cpp | 2 +-
llvm/test/tools/yaml2obj/GOFF/header-end.yaml | 1 -
llvm/test/tools/yaml2obj/GOFF/header-settings.yaml | 1 -
3 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/lib/ObjectYAML/GOFFYAML.cpp b/llvm/lib/ObjectYAML/GOFFYAML.cpp
index c4c7e25423b9fc..476dc662201940 100644
--- a/llvm/lib/ObjectYAML/GOFFYAML.cpp
+++ b/llvm/lib/ObjectYAML/GOFFYAML.cpp
@@ -246,7 +246,7 @@ void CustomMappingTraits<GOFFYAML::RecordPtr>::output(
void MappingTraits<GOFFYAML::Object>::mapping(IO &IO, GOFFYAML::Object &Obj) {
IO.mapTag("!GOFF", true);
IO.mapRequired("FileHeader", Obj.Header);
- IO.mapRequired("Records", Obj.Records);
+ IO.mapOptional("Records", Obj.Records);
}
} // namespace yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/header-end.yaml b/llvm/test/tools/yaml2obj/GOFF/header-end.yaml
index 3c11b2b9b4d3ff..a5e99c2da2c491 100644
--- a/llvm/test/tools/yaml2obj/GOFF/header-end.yaml
+++ b/llvm/test/tools/yaml2obj/GOFF/header-end.yaml
@@ -18,4 +18,3 @@
--- !GOFF
FileHeader:
ArchitectureLevel: 1
-Records:
diff --git a/llvm/test/tools/yaml2obj/GOFF/header-settings.yaml b/llvm/test/tools/yaml2obj/GOFF/header-settings.yaml
index 77833ffbf346d1..e7495b24527d3d 100644
--- a/llvm/test/tools/yaml2obj/GOFF/header-settings.yaml
+++ b/llvm/test/tools/yaml2obj/GOFF/header-settings.yaml
@@ -24,4 +24,3 @@ FileHeader:
ArchitectureLevel: 1
InternalCCSID: 0
TargetSoftwareEnvironment: 0
-Records:
>From 975462fc6671dc7af33d9ffec61ce32886d5112f Mon Sep 17 00:00:00 2001
From: Yusra Syeda <yusra.syeda at ibm.com>
Date: Tue, 9 Apr 2024 11:23:11 -0400
Subject: [PATCH 11/11] add more testing
---
.../yaml2obj/GOFF/symbol-all-fields.yaml | 54 +++++++++++++++++++
.../tools/yaml2obj/GOFF/symbol-required.yaml | 31 +++++++++++
2 files changed, 85 insertions(+)
create mode 100644 llvm/test/tools/yaml2obj/GOFF/symbol-all-fields.yaml
create mode 100644 llvm/test/tools/yaml2obj/GOFF/symbol-required.yaml
diff --git a/llvm/test/tools/yaml2obj/GOFF/symbol-all-fields.yaml b/llvm/test/tools/yaml2obj/GOFF/symbol-all-fields.yaml
new file mode 100644
index 00000000000000..1111eea8852037
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/symbol-all-fields.yaml
@@ -0,0 +1,54 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+## Verify that GOFF Header is correct.
+# CHECK: 03 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+## Verify that the symbol is written correctly.
+# CHECK-NEXT: 03 00 00 01 00 00 00 01 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
+
+## Verify GOFF Module end.
+# CHECK-NEXT: 03 40 00 00 00 00 00 00 00 00 00 03 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+ - Symbol:
+ Name: 'x'
+ Type: ESD_ST_ElementDefinition
+ ID: 1
+ OwnerID: 0
+ Address: 0
+ Length: 0
+ ExtAttrID: 0
+ ExtAttrOffset: 0
+ NameSpace: ESD_NS_NormalName
+ Flags: []
+ FillByteValue: 0
+ PSectID: 0
+ Priority: 0
+ Signature: 0
+ Amode: 0
+ Rmode: 0
+ TextStyle: 0
+ BindingAlgorithm: 0
+ TaskingBehavior: 0
+ Executable: 0
+ LinkageType: 0
+ BindingStrength: 0
+ LoadingBehavior: 0
+ BindingScope: 0
+ Alignment: 0
+ BAFlags: []
diff --git a/llvm/test/tools/yaml2obj/GOFF/symbol-required.yaml b/llvm/test/tools/yaml2obj/GOFF/symbol-required.yaml
new file mode 100644
index 00000000000000..e4f8012a3a5f17
--- /dev/null
+++ b/llvm/test/tools/yaml2obj/GOFF/symbol-required.yaml
@@ -0,0 +1,31 @@
+# RUN: yaml2obj %s | od -v -An -tx1 | FileCheck --ignore-case %s
+
+## Verify that GOFF Header is correct.
+# CHECK: 03 f0 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+## Verify that the symbol is written correctly.
+# CHECK-NEXT: 03 00 00 01 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 01 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 01 a7 00 00 00 00 00 00 00
+
+## Verify GOFF Module end.
+# CHECK-NEXT: 03 40 00 00 00 00 00 00 00 00 00 03 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+# CHECK-NEXT: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
+
+--- !GOFF
+FileHeader:
+ ArchitectureLevel: 1
+Records:
+ - Symbol:
+ Name: 'x'
+ Type: ESD_ST_ElementDefinition
+ NameSpace: ESD_NS_NormalName
More information about the llvm-commits
mailing list