Skip to content

Commit 718edfe

Browse files
committed
[ELFObject] Added dbgs() statement in removeSections()
This patch adds dbgs() statement inside removeSections() and removeSymbol() function to print the removed sections and symbols. Fixes: #123041
1 parent 79685b5 commit 718edfe

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)
@@ -2249,10 +2255,18 @@ Error Object::removeSections(
22492255

22502256
// Transfer removed sections into the Object RemovedSections container for use
22512257
// later.
2252-
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
2253-
// Now finally get rid of them all together.
2254-
Sections.erase(Iter, std::end(Sections));
2255-
return Error::success();
2258+
for(auto &KeepSec : make_range(std::begin(Sections) , Iter))
2259+
{
2260+
2261+
if (Error E = KeepSec->removeSectionReferences(
2262+
AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
2263+
return RemoveSections.find(Sec) != RemoveSections.end();
2264+
}))
2265+
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
2266+
dbgs()<<"Sections Removed:"<<KeepSec->Name<<'\n';
2267+
Sections.erase(Iter, std::end(Sections));
2268+
return Error::success();
2269+
}
22562270
}
22572271

22582272
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)