[lld] [llvm] [MC, COFF] Change how we handle section symbols (PR #96459)

Alexis Engelke via llvm-commits llvm-commits at lists.llvm.org
Mon Jun 24 01:42:44 PDT 2024


================
@@ -322,27 +323,16 @@ static uint32_t getAlignment(const MCSectionCOFF &Sec) {
 void WinCOFFWriter::defineSection(const MCSectionCOFF &MCSec,
                                   const MCAsmLayout &Layout) {
   COFFSection *Section = createSection(MCSec.getName());
-  COFFSymbol *Symbol = createSymbol(MCSec.getName());
-  Section->Symbol = Symbol;
-  Symbol->Section = Section;
-  Symbol->Data.StorageClass = COFF::IMAGE_SYM_CLASS_STATIC;
-
-  // Create a COMDAT symbol if needed.
+  // Check whether the COMDAT symbol has been reused.
   if (MCSec.getSelection() != COFF::IMAGE_COMDAT_SELECT_ASSOCIATIVE) {
     if (const MCSymbol *S = MCSec.getCOMDATSymbol()) {
-      COFFSymbol *COMDATSymbol = GetOrCreateCOFFSymbol(S);
-      if (COMDATSymbol->Section)
-        report_fatal_error("two sections have the same comdat");
-      COMDATSymbol->Section = Section;
+      if (!ComdatSymSet.insert(S->getName()).second)
----------------
aengelke wrote:

getOrCreateSymbol should not create symbols with the same name. Couldn't we check this in getCOFFSection? Or store this in the symbol somehow? (I don't like the string map.)

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


More information about the llvm-commits mailing list