File tree Expand file tree Collapse file tree 3 files changed +42
-1
lines changed
test/tools/llvm-objcopy/ELF Expand file tree Collapse file tree 3 files changed +42
-1
lines changed Original file line number Diff line number Diff line change @@ -2206,8 +2206,16 @@ Error Object::removeSections(
2206
2206
// Transfer removed sections into the Object RemovedSections container for use
2207
2207
// later.
2208
2208
std::move (Iter, Sections.end (), std::back_inserter (RemovedSections));
2209
- // Now finally get rid of them all together.
2209
+ // Now get rid of them all together.
2210
2210
Sections.erase (Iter, std::end (Sections));
2211
+
2212
+ // Finally iterate over all sections and erase empty SHT_GROUP sections.
2213
+ for (auto Iter = Sections.begin (); Iter != Sections.end (); ++Iter) {
2214
+ if (auto GroupSec = dyn_cast<GroupSection>(Iter->get ())) {
2215
+ if (GroupSec->getMembersCount () == 0 )
2216
+ Sections.erase (Iter);
2217
+ }
2218
+ }
2211
2219
return Error::success ();
2212
2220
}
2213
2221
Original file line number Diff line number Diff line change @@ -963,6 +963,8 @@ class GroupSection : public SectionBase {
963
963
const DenseMap<SectionBase *, SectionBase *> &FromTo) override ;
964
964
void onRemove () override ;
965
965
966
+ size_t getMembersCount () { return GroupMembers.size (); }
967
+
966
968
static bool classof (const SectionBase *S) {
967
969
return S->OriginalType == ELF::SHT_GROUP;
968
970
}
Original file line number Diff line number Diff line change
1
+ # RUN: yaml2obj %s -o %t
2
+ # RUN: llvm-strip --strip-debug %t -o %t1
3
+ # RUN: llvm-readelf --section-groups %t1 | FileCheck %s
4
+ # RUN: llvm-strip --strip-unneeded %t -o %t2
5
+ # RUN: llvm-readelf --section-groups %t2 | FileCheck %s
6
+ # RUN: llvm-strip --remove-section=.debug_macro %t -o %t3
7
+ # RUN: llvm-readelf --section-groups %t3 | FileCheck %s
8
+ # RUN: llvm-strip --remove-section=.debug_* %t -o %t4
9
+ # RUN: llvm-readelf --section-groups %t4 | FileCheck %s
10
+
11
+ --- !ELF
12
+ FileHeader:
13
+ Class: ELFCLASS64
14
+ Data: ELFDATA2LSB
15
+ Type: ET_REL
16
+ Machine: EM_X86_64
17
+ Sections:
18
+ - Name: .group
19
+ Type: SHT_GROUP
20
+ Info: foo_grp
21
+ Members:
22
+ - SectionOrType: GRP_COMDAT
23
+ - SectionOrType: .debug_macro
24
+ - Name: .debug_macro
25
+ Type: SHT_PROGBITS
26
+ Flags: [ SHF_GROUP ]
27
+ Symbols:
28
+ - Name: foo_grp
29
+ Section: .group
30
+
31
+ # CHECK: There are no section groups in this file.
You can’t perform that action at this time.
0 commit comments