[llvm] [z/OS][GOFF] Implement support for writing ESD + TXT records by the GOFFObjectWriter (PR #85851)
Ulrich Weigand via llvm-commits
llvm-commits at lists.llvm.org
Fri Mar 22 06:51:36 PDT 2024
================
@@ -259,6 +633,411 @@ void GOFFObjectWriter::writeHeader() {
OS.write_zeros(6); // Reserved
}
+void GOFFObjectWriter::writeSymbol(const GOFFSymbol &Symbol,
+ const MCAsmLayout &Layout) {
+ uint32_t Offset = 0;
+ uint32_t Length = 0;
+ GOFF::ESDNameSpaceId NameSpaceId = GOFF::ESD_NS_ProgramManagementBinder;
+ Flags SymbolFlags;
+ uint8_t FillByteValue = 0;
+
+ Flags BehavAttrs[10] = {};
+ auto setAmode = [&BehavAttrs](GOFF::ESDAmode Amode) {
+ BehavAttrs[0].set(0, 8, Amode);
+ };
+ auto setRmode = [&BehavAttrs](GOFF::ESDRmode Rmode) {
+ BehavAttrs[1].set(0, 8, Rmode);
+ };
+ auto setTextStyle = [&BehavAttrs](GOFF::ESDTextStyle Style) {
+ BehavAttrs[2].set(0, 4, Style);
+ };
+ auto setBindingAlgorithm =
+ [&BehavAttrs](GOFF::ESDBindingAlgorithm Algorithm) {
+ BehavAttrs[2].set(4, 4, Algorithm);
+ };
+ auto setTaskingBehavior =
+ [&BehavAttrs](GOFF::ESDTaskingBehavior TaskingBehavior) {
+ BehavAttrs[3].set(0, 3, TaskingBehavior);
+ };
+ auto setReadOnly = [&BehavAttrs](bool ReadOnly) {
+ BehavAttrs[3].set(4, 1, ReadOnly);
+ };
+ auto setExecutable = [&BehavAttrs](GOFF::ESDExecutable Executable) {
+ BehavAttrs[3].set(5, 3, Executable);
+ };
+ auto setDuplicateSeverity =
+ [&BehavAttrs](GOFF::ESDDuplicateSymbolSeverity DSS) {
+ BehavAttrs[4].set(2, 2, DSS);
+ };
+ auto setBindingStrength = [&BehavAttrs](GOFF::ESDBindingStrength Strength) {
+ BehavAttrs[4].set(4, 4, Strength);
+ };
+ auto setLoadingBehavior = [&BehavAttrs](GOFF::ESDLoadingBehavior Behavior) {
+ BehavAttrs[5].set(0, 2, Behavior);
+ };
+ auto setIndirectReference = [&BehavAttrs](bool Indirect) {
+ uint8_t Value = Indirect ? 1 : 0;
+ BehavAttrs[5].set(3, 1, Value);
+ };
+ auto setBindingScope = [&BehavAttrs](GOFF::ESDBindingScope Scope) {
+ BehavAttrs[5].set(4, 4, Scope);
+ };
+ auto setLinkageType = [&BehavAttrs](GOFF::ESDLinkageType Type) {
+ BehavAttrs[6].set(2, 1, Type);
+ };
+ auto setAlignment = [&BehavAttrs](GOFF::ESDAlignment Alignment) {
+ BehavAttrs[6].set(3, 5, Alignment);
+ };
+
+ uint32_t AdaEsdId = 0;
+ uint32_t SortPriority = 0;
+
+ switch (Symbol.SymbolType) {
+ case GOFF::ESD_ST_SectionDefinition: {
+ if (Symbol.isExecutable()) // Unspecified otherwise
+ setTaskingBehavior(GOFF::ESD_TA_Rent);
+ if (Symbol.BindingScope == GOFF::ESD_BSC_Section)
+ setBindingScope(Symbol.BindingScope);
+ } break;
+ case GOFF::ESD_ST_ElementDefinition: {
+ SymbolFlags.set(3, 1, Symbol.isRemovable()); // Removable
+ if (Symbol.isExecutable()) {
+ setExecutable(GOFF::ESD_EXE_CODE);
+ setReadOnly(true);
+ } else {
+ if (Symbol.isExecUnspecified())
+ setExecutable(GOFF::ESD_EXE_Unspecified);
+ else
+ setExecutable(GOFF::ESD_EXE_DATA);
+
+ if (Symbol.isForceRent() || Symbol.isReadOnly()) // TODO
+ setReadOnly(true);
+ }
+ Offset = 0; // TODO ED and SD are 1-1 for now
+ setAlignment(Symbol.Alignment);
+ SymbolFlags.set(0, 1, 1); // Fill-Byte Value Presence Flag
+ FillByteValue = 0;
+ SymbolFlags.set(1, 1, 0); // Mangled Flag TODO ?
+ setAmode(Symbol.Amode);
+ setRmode(Symbol.Rmode);
+ setTextStyle(Symbol.TextStyle);
+ setBindingAlgorithm(Symbol.BindAlgorithm);
+ setLoadingBehavior(Symbol.LoadBehavior);
+ SymbolFlags.set(5, 3, GOFF::ESD_RQ_0); // Reserved Qwords
+ if (Symbol.isForceRent())
+ setReadOnly(true);
+ NameSpaceId = Symbol.NameSpace;
+ Length = Symbol.SectionLength;
+ break;
+ }
+ case GOFF::ESD_ST_LabelDefinition: {
+ if (Symbol.isExecutable())
+ setExecutable(GOFF::ESD_EXE_CODE);
+ else
+ setExecutable(GOFF::ESD_EXE_DATA);
+ setBindingStrength(Symbol.BindingStrength);
+ setLinkageType(Symbol.Linkage);
+ SymbolFlags.set(2, 1, Symbol.Renamable); // Renamable;
+ setAmode(Symbol.Amode);
+ NameSpaceId = Symbol.NameSpace;
+ setBindingScope(Symbol.BindingScope);
+ AdaEsdId = Symbol.ADAEsdId;
+
+ // Only symbol that doesn't have an MC is the SectionLabelSymbol which
+ // implicitly has 0 offset into the parent SD!
+ if (auto *MCSym = Symbol.MCSym) {
+ uint64_t Ofs = Layout.getSymbolOffset(*MCSym);
----------------
uweigand wrote:
Why do we have to keep track of the MCSym pointer until here? Couldn't we have retrieved the Offset when creating the GOFFSymbol already?
https://github.com/llvm/llvm-project/pull/85851
More information about the llvm-commits
mailing list