Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions llvm/lib/ObjCopy/ELF/ELFObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -766,8 +766,14 @@ Error SymbolTableSection::removeSymbols(
function_ref<bool(const Symbol &)> ToRemove) {
Symbols.erase(
std::remove_if(std::begin(Symbols) + 1, std::end(Symbols),
[ToRemove](const SymPtr &Sym) { return ToRemove(*Sym); }),
std::end(Symbols));
[ToRemove](const SymPtr &Sym) {
if (ToRemove(*Sym)) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's no need for the braces here (see other comment about coding standards).

dbgs()<<"Symbols Removed:"<<Sym->Name<< "\n";
return true;
}
return false;
}));

auto PrevSize = Size;
Size = Symbols.size() * EntrySize;
if (Size < PrevSize)
Expand Down Expand Up @@ -2249,10 +2255,18 @@ Error Object::removeSections(

// Transfer removed sections into the Object RemovedSections container for use
// later.
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
// Now finally get rid of them all together.
Sections.erase(Iter, std::end(Sections));
return Error::success();
for(auto &KeepSec : make_range(std::begin(Sections) , Iter))
{

if (Error E = KeepSec->removeSectionReferences(
AllowBrokenLinks, [&RemoveSections](const SectionBase *Sec) {
return RemoveSections.find(Sec) != RemoveSections.end();
}))
std::move(Iter, Sections.end(), std::back_inserter(RemovedSections));
dbgs()<<"Sections Removed:"<<KeepSec->Name<<'\n';
Sections.erase(Iter, std::end(Sections));
return Error::success();
}
}

Error Object::replaceSections(
Expand Down
2 changes: 2 additions & 0 deletions llvm/tools/llvm-objcopy/CommonOpts.td
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ def regex

def version : Flag<["--"], "version">,
HelpText<"Print the version and exit.">;
def verbose : Flag<["--"], "verbose">,
HelpText<"Prints the removed symbols and sections">;
def V : Flag<["-"], "V">,
Alias<version>,
HelpText<"Alias for --version">;
Expand Down
Loading