[llvm-branch-commits] [llvm] [GOFF] Add writing of section symbols (PR #133799)

Ulrich Weigand via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Thu Apr 3 09:19:34 PDT 2025


================
@@ -239,6 +309,102 @@ class GOFFWriter {
 GOFFWriter::GOFFWriter(raw_pwrite_stream &OS, MCAssembler &Asm)
     : OS(OS), Asm(Asm) {}
 
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::SDAttr &Attr) {
+  return GOFFSymbol(Name, ++EsdIdCounter, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::EDAttr &Attr,
+                                        uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::LDAttr &Attr,
+                                        uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+GOFFSymbol GOFFWriter::createGOFFSymbol(StringRef Name, const GOFF::PRAttr &Attr,
+                                        uint32_t ParentEsdId) {
+  return GOFFSymbol(Name, ++EsdIdCounter, ParentEsdId, Attr);
+}
+
+void GOFFWriter::defineRootSymbol(const MCSectionGOFF *Text) {
+  // There is always a text section except for DWARF unit tests, so be lenient.
+  GOFFSymbol RootSD =
+      Text ? createGOFFSymbol(Text->getSDName(), Text->getSDAttributes())
+           : createGOFFSymbol("", GOFF::SDAttr{GOFF::ESD_TA_Unspecified,
+                                               GOFF::ESD_BSC_Unspecified});
+  writeSymbol(RootSD);
+  RootSDEsdId = RootSD.EsdId;
+}
+
+void GOFFWriter::defineSectionSymbols(const MCSectionGOFF &Section) {
+    uint32_t SDEsdId = RootSDEsdId;
+    if (!Section.usesRootSD()) {
+      GOFFSymbol SD =
+          createGOFFSymbol(Section.getSDName(), Section.getSDAttributes());
+      SDEsdId = SD.EsdId;
+      writeSymbol(SD);
+    }
+
+    GOFFSymbol ED = createGOFFSymbol(Section.getEDName(),
+                                     Section.getEDAttributes(), SDEsdId);
+    if ((!Section.hasLD() && !Section.hasPR()) || Section.hasLD()) {
+      ED.SectionLength = Asm.getSectionAddressSize(Section);
+    }
+    writeSymbol(ED);
+
+    if (Section.hasLD()) {
+      GOFFSymbol LD = createGOFFSymbol(Section.getLDorPRName(),
+                                       Section.getLDAttributes(), ED.EsdId);
+      if (Section.isText())
+        LD.ADAEsdId = ADAEsdId;
+      writeSymbol(LD);
+    }
+
+    if (Section.hasPR()) {
+      GOFFSymbol PR = createGOFFSymbol(Section.getLDorPRName(),
+                                       Section.getPRAttributes(), ED.EsdId);
+      PR.SectionLength = Asm.getSectionAddressSize(Section);
+      if (Section.getName() == ".ada") {
----------------
uweigand wrote:

I don't think this name will ever match with the latest code.   In any case, this is really not the proper place to put this kind of decision logic ... that should really be handled elsewhere (or more generically), I think.

https://github.com/llvm/llvm-project/pull/133799


More information about the llvm-branch-commits mailing list