[llvm] 2abe53a - Revert "[llvm-objcopy] Remove empty SHT_GROUP sections (#97141)"
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 8 23:47:33 PDT 2024
Author: Fangrui Song
Date: 2024-07-08T23:47:28-07:00
New Revision: 2abe53a17f486a055a3715f19a37e3e91b4415fc
URL: https://github.com/llvm/llvm-project/commit/2abe53a17f486a055a3715f19a37e3e91b4415fc
DIFF: https://github.com/llvm/llvm-project/commit/2abe53a17f486a055a3715f19a37e3e91b4415fc.diff
LOG: Revert "[llvm-objcopy] Remove empty SHT_GROUP sections (#97141)"
This reverts commit 359c64f314ad568e78ee9a3723260286e3425c2d.
This caused heap-use-after-free. See #98106.
Added:
Modified:
llvm/lib/ObjCopy/ELF/ELFObject.cpp
llvm/lib/ObjCopy/ELF/ELFObject.h
llvm/test/tools/llvm-objcopy/ELF/remove-section-in-group.test
Removed:
################################################################################
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.cpp b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
index f9c5d2579be69..5e6d19b9bfa54 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.cpp
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.cpp
@@ -2239,17 +2239,8 @@ Error Object::removeSections(
// Transfer removed sections into the Object RemovedSections container for use
// later.
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
- // Now get rid of them altogether.
+ // Now finally get rid of them all together.
Sections.erase(Iter, std::end(Sections));
-
- // Finally erase empty SHT_GROUP sections.
- llvm::erase_if(Sections, [](const SecPtr &Sec) {
- if (auto GroupSec = dyn_cast<GroupSection>(Sec.get()))
- return GroupSec->getMembersCount() == 0;
-
- return false;
- });
-
return Error::success();
}
diff --git a/llvm/lib/ObjCopy/ELF/ELFObject.h b/llvm/lib/ObjCopy/ELF/ELFObject.h
index 2a9f337c3f323..e3c0e7abda16b 100644
--- a/llvm/lib/ObjCopy/ELF/ELFObject.h
+++ b/llvm/lib/ObjCopy/ELF/ELFObject.h
@@ -964,8 +964,6 @@ class GroupSection : public SectionBase {
const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
void onRemove() override;
- size_t getMembersCount() const { return GroupMembers.size(); }
-
static bool classof(const SectionBase *S) {
return S->OriginalType == ELF::SHT_GROUP;
}
diff --git a/llvm/test/tools/llvm-objcopy/ELF/remove-section-in-group.test b/llvm/test/tools/llvm-objcopy/ELF/remove-section-in-group.test
index ccc1ede0589c1..9e683b9f68c93 100644
--- a/llvm/test/tools/llvm-objcopy/ELF/remove-section-in-group.test
+++ b/llvm/test/tools/llvm-objcopy/ELF/remove-section-in-group.test
@@ -1,6 +1,6 @@
## This checks that the group section is shrunk when its member is removed.
-# RUN: yaml2obj --docnum=1 %s -o - \
+# RUN: yaml2obj %s -o - \
# RUN: | llvm-objcopy -R .foo - - \
# RUN: | obj2yaml - \
# RUN: | FileCheck %s
@@ -35,51 +35,3 @@ Symbols:
- Name: foo_bar_grp
Section: .group
Binding: STB_GLOBAL
-
-# RUN: yaml2obj --docnum=2 %s -o %t
-# RUN: llvm-objcopy --remove-section=.debug_macro %t
-# RUN: llvm-readelf --section-groups %t | FileCheck %s --check-prefix=GROUP-REMOVED
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
-Sections:
- - Name: .group
- Type: SHT_GROUP
- Info: foo_grp
- Members:
- - SectionOrType: GRP_COMDAT
- - SectionOrType: .debug_macro
- - Name: .debug_macro
- Type: SHT_PROGBITS
- Flags: [ SHF_GROUP ]
-Symbols:
- - Name: foo_grp
- Section: .group
-
-# GROUP-REMOVED: There are no section groups in this file.
-
-# RUN: yaml2obj --docnum=3 %s -o %t
-# RUN: llvm-objcopy --remove-section=.group %t
-# RUN: llvm-readelf --section-groups %t | FileCheck %s --check-prefix=EMPTY-GROUP-REMOVED
-
---- !ELF
-FileHeader:
- Class: ELFCLASS64
- Data: ELFDATA2LSB
- Type: ET_REL
- Machine: EM_X86_64
-Sections:
- - Name: .group
- Type: SHT_GROUP
- Info: foo_grp
- Members:
- - SectionOrType: GRP_COMDAT
-Symbols:
- - Name: foo_grp
- Section: .group
-
-# EMPTY-GROUP-REMOVED: There are no section groups in this file.
More information about the llvm-commits
mailing list