Skip to content

Commit d9ce1d2

Browse files
MaskRayaaryanshukla
authored andcommitted
Revert "[llvm-objcopy] Remove empty SHT_GROUP sections (llvm#97141)"
This reverts commit 359c64f. This caused heap-use-after-free. See llvm#98106.
1 parent 7821b6b commit d9ce1d2

File tree

3 files changed

+2
-61
lines changed

3 files changed

+2
-61
lines changed

llvm/lib/ObjCopy/ELF/ELFObject.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,17 +2239,8 @@ Error Object::removeSections(
22392239
// Transfer removed sections into the Object RemovedSections container for use
22402240
// later.
22412241
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
2242-
// Now get rid of them altogether.
2242+
// Now finally get rid of them all together.
22432243
Sections.erase(Iter, std::end(Sections));
2244-
2245-
// Finally erase empty SHT_GROUP sections.
2246-
llvm::erase_if(Sections, [](const SecPtr &Sec) {
2247-
if (auto GroupSec = dyn_cast<GroupSection>(Sec.get()))
2248-
return GroupSec->getMembersCount() == 0;
2249-
2250-
return false;
2251-
});
2252-
22532244
return Error::success();
22542245
}
22552246

llvm/lib/ObjCopy/ELF/ELFObject.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -964,8 +964,6 @@ class GroupSection : public SectionBase {
964964
const DenseMap<SectionBase *, SectionBase *> &FromTo) override;
965965
void onRemove() override;
966966

967-
size_t getMembersCount() const { return GroupMembers.size(); }
968-
969967
static bool classof(const SectionBase *S) {
970968
return S->OriginalType == ELF::SHT_GROUP;
971969
}
Lines changed: 1 addition & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## This checks that the group section is shrunk when its member is removed.
22

3-
# RUN: yaml2obj --docnum=1 %s -o - \
3+
# RUN: yaml2obj %s -o - \
44
# RUN: | llvm-objcopy -R .foo - - \
55
# RUN: | obj2yaml - \
66
# RUN: | FileCheck %s
@@ -35,51 +35,3 @@ Symbols:
3535
- Name: foo_bar_grp
3636
Section: .group
3737
Binding: STB_GLOBAL
38-
39-
# RUN: yaml2obj --docnum=2 %s -o %t
40-
# RUN: llvm-objcopy --remove-section=.debug_macro %t
41-
# RUN: llvm-readelf --section-groups %t | FileCheck %s --check-prefix=GROUP-REMOVED
42-
43-
--- !ELF
44-
FileHeader:
45-
Class: ELFCLASS64
46-
Data: ELFDATA2LSB
47-
Type: ET_REL
48-
Machine: EM_X86_64
49-
Sections:
50-
- Name: .group
51-
Type: SHT_GROUP
52-
Info: foo_grp
53-
Members:
54-
- SectionOrType: GRP_COMDAT
55-
- SectionOrType: .debug_macro
56-
- Name: .debug_macro
57-
Type: SHT_PROGBITS
58-
Flags: [ SHF_GROUP ]
59-
Symbols:
60-
- Name: foo_grp
61-
Section: .group
62-
63-
# GROUP-REMOVED: There are no section groups in this file.
64-
65-
# RUN: yaml2obj --docnum=3 %s -o %t
66-
# RUN: llvm-objcopy --remove-section=.group %t
67-
# RUN: llvm-readelf --section-groups %t | FileCheck %s --check-prefix=EMPTY-GROUP-REMOVED
68-
69-
--- !ELF
70-
FileHeader:
71-
Class: ELFCLASS64
72-
Data: ELFDATA2LSB
73-
Type: ET_REL
74-
Machine: EM_X86_64
75-
Sections:
76-
- Name: .group
77-
Type: SHT_GROUP
78-
Info: foo_grp
79-
Members:
80-
- SectionOrType: GRP_COMDAT
81-
Symbols:
82-
- Name: foo_grp
83-
Section: .group
84-
85-
# EMPTY-GROUP-REMOVED: There are no section groups in this file.

0 commit comments

Comments
 (0)