Skip to content

Commit 14dce11

Browse files
committed
[ELFObject.cpp]Added dbgs() statement in removeSections()
I have added the dbgs() function inside removeSections() function to print the removed sections and symbols. Fixes: #123041
1 parent 9ae6faf commit 14dce11

File tree

2 files changed

+22
-6
lines changed

2 files changed

+22
-6
lines changed

llvm/lib/ObjCopy/ELF/ELFObject.cpp

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -766,8 +766,14 @@ Error SymbolTableSection::removeSymbols(
766766
function_ref<bool(const Symbol &)> ToRemove) {
767767
Symbols.erase(
768768
std::remove_if(std::begin(Symbols) + 1, std::end(Symbols),
769-
[ToRemove](const SymPtr &Sym) { return ToRemove(*Sym); }),
770-
std::end(Symbols));
769+
[ToRemove](const SymPtr &Sym) {
770+
if (ToRemove(*Sym)) {
771+
dbgs()<<"Symbols Removed:"<<Sym->Name<< "\n";
772+
return true;
773+
}
774+
return false;
775+
}));
776+
771777
auto PrevSize = Size;
772778
Size = Symbols.size() * EntrySize;
773779
if (Size < PrevSize)
@@ -2240,10 +2246,18 @@ Error Object::removeSections(
22402246

22412247
// Transfer removed sections into the Object RemovedSections container for use
22422248
// later.
2243-
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
2244-
// Now finally get rid of them all together.
2245-
Sections.erase(Iter, std::end(Sections));
2246-
return Error::success();
2249+
for(auto &KeepSec : make_range(std::begin(Sections) , Iter))
2250+
{
2251+
2252+
if (Error E = KeepSec->removeSectionReferences(
2253+
AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
2254+
return RemoveSections.find(Sec) != RemoveSections.end();
2255+
}))
2256+
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
2257+
dbgs()<<"Sections Removed:"<<KeepSec->Name<<'\n';
2258+
Sections.erase(Iter, std::end(Sections));
2259+
return Error::success();
2260+
}
22472261
}
22482262

22492263
Error Object::replaceSections(

llvm/tools/llvm-objcopy/CommonOpts.td

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,8 @@ def regex
117117

118118
def version : Flag<["--"], "version">,
119119
HelpText<"Print the version and exit.">;
120+
def verbose : Flag<["--"], "verbose">,
121+
HelpText<"Prints the removed symbols and sections">;
120122
def V : Flag<["-"], "V">,
121123
Alias<version>,
122124
HelpText<"Alias for --version">;

0 commit comments

Comments
 (0)