[llvm] [llvm-strip] Remove empty SHT_GROUP sections. (PR #97141)

Dmitriy Chestnykh via llvm-commits llvm-commits at lists.llvm.org
Fri Jul 5 21:52:26 PDT 2024


================
@@ -2206,8 +2206,15 @@ Error Object::removeSections(
   // Transfer removed sections into the Object RemovedSections container for use
   // later.
   std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
-  // Now finally get rid of them all together.
+  // Now get rid of them altogether.
   Sections.erase(Iter, std::end(Sections));
+
+  // Finally iterate over all sections and erase empty SHT_GROUP sections.
+  for (auto Iter = Sections.begin(); Iter != Sections.end(); ++Iter)
+    if (auto GroupSec = dyn_cast<GroupSection>(Iter->get()))
+      if (GroupSec->getMembersCount() == 0)
+        Sections.erase(Iter);
----------------
chestnykh wrote:

Fixed, thanks!

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


More information about the llvm-commits mailing list