[lld] [LLD][COFF] Ensure .bss is merged at the end of a section. (PR #137677)

Martin Storsjö via llvm-commits llvm-commits at lists.llvm.org
Mon Apr 28 14:19:12 PDT 2025


================
@@ -1594,28 +1619,13 @@ void Writer::mergeSections() {
   }
 
   for (auto &p : ctx.config.merge) {
-    StringRef toName = p.second;
-    if (p.first == toName)
-      continue;
-    StringSet<> names;
-    while (true) {
-      if (!names.insert(toName).second)
-        Fatal(ctx) << "/merge: cycle found for section '" << p.first << "'";
-      auto i = ctx.config.merge.find(toName);
-      if (i == ctx.config.merge.end())
-        break;
-      toName = i->second;
-    }
-    OutputSection *from = findSection(p.first);
-    OutputSection *to = findSection(toName);
-    if (!from)
-      continue;
-    if (!to) {
-      from->name = toName;
-      continue;
-    }
-    to->merge(from);
+    if (p.first != ".bss")
+      mergeSection(p);
   }
+
----------------
mstorsjo wrote:

I think this could use a comment here, explaining why we do this.

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


More information about the llvm-commits mailing list