summaryrefslogtreecommitdiffstats
path: root/llvm/tools/llvm-objcopy/Object.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'llvm/tools/llvm-objcopy/Object.cpp')
-rw-r--r--llvm/tools/llvm-objcopy/Object.cpp19
1 files changed, 19 insertions, 0 deletions
diff --git a/llvm/tools/llvm-objcopy/Object.cpp b/llvm/tools/llvm-objcopy/Object.cpp
index 9e82448187e..a0708ed59b4 100644
--- a/llvm/tools/llvm-objcopy/Object.cpp
+++ b/llvm/tools/llvm-objcopy/Object.cpp
@@ -175,6 +175,25 @@ void SymbolTableSection::removeSectionReferences(const SectionBase *Sec) {
Symbols.erase(Iter, std::end(Symbols));
}
+void SymbolTableSection::localize(
+ std::function<bool(const Symbol &)> ToLocalize) {
+ for (const auto &Sym : Symbols) {
+ if (ToLocalize(*Sym))
+ Sym->Binding = STB_LOCAL;
+ }
+
+ // Now that the local symbols aren't grouped at the start we have to reorder
+ // the symbols to respect this property.
+ std::stable_partition(
+ std::begin(Symbols), std::end(Symbols),
+ [](const SymPtr &Sym) { return Sym->Binding == STB_LOCAL; });
+
+ // Lastly we fix the symbol indexes.
+ uint32_t Index = 0;
+ for (auto &Sym : Symbols)
+ Sym->Index = Index++;
+}
+
void SymbolTableSection::initialize(SectionTableRef SecTable) {
Size = 0;
setStrTab(SecTable.getSectionOfType<StringTableSection>(
OpenPOWER on IntegriCloud