[llvm-objcopy] Add --discard-all (-x) option
llvm-svn: 331400
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp
index 07b6036..93487dc 100644
--- a/llvm/tools/llvm-objcopy/Object.cpp
+++ b/llvm/tools/llvm-objcopy/Object.cpp
@@ -194,12 +194,7 @@
" cannot be removed because it is referenced by the symbol table " +
this->Name);
}
- auto Iter =
- std::remove_if(std::begin(Symbols), std::end(Symbols),
- [=](const SymPtr &Sym) { return Sym->DefinedIn == Sec; });
- Size -= (std::end(Symbols) - Iter) * this->EntrySize;
- Symbols.erase(Iter, std::end(Symbols));
- assignIndices();
+ removeSymbols([Sec](const Symbol &Sym) { return Sym.DefinedIn == Sec; });
}
void SymbolTableSection::updateSymbols(function_ref<void(Symbol &)> Callable) {
@@ -211,6 +206,15 @@
assignIndices();
}
+void SymbolTableSection::removeSymbols(function_ref<bool(Symbol &)> ToRemove) {
+ Symbols.erase(
+ std::remove_if(std::begin(Symbols), std::end(Symbols),
+ [ToRemove](const SymPtr &Sym) { return ToRemove(*Sym); }),
+ std::end(Symbols));
+ Size = Symbols.size() * EntrySize;
+ assignIndices();
+}
+
void SymbolTableSection::initialize(SectionTableRef SecTable) {
Size = 0;
setStrTab(SecTable.getSectionOfType<StringTableSection>(