From 11afad01054344b02f6288259d0fff05ab23f9e4 Mon Sep 17 00:00:00 2001 From: Rafael Espindola Date: Thu, 25 Jun 2015 14:39:35 +0000 Subject: [PATCH] Modernize getELFDynamicSymbolIterators. * Have it return a iterator_range. * Remove the global function. * Rename to getDynamicSymbolIterators. llvm-svn: 240644 --- llvm/include/llvm/Object/ELFObjectFile.h | 17 +++++------------ llvm/tools/llvm-nm/llvm-nm.cpp | 10 +++++----- llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp | 7 +++---- 3 files changed, 13 insertions(+), 21 deletions(-) diff --git a/llvm/include/llvm/Object/ELFObjectFile.h b/llvm/include/llvm/Object/ELFObjectFile.h index d8e1c16..8ecfa71 100644 --- a/llvm/include/llvm/Object/ELFObjectFile.h +++ b/llvm/include/llvm/Object/ELFObjectFile.h @@ -46,8 +46,7 @@ public: // and addend or not. virtual bool hasRelocationAddend(DataRefImpl Rel) const = 0; - virtual std::pair - getELFDynamicSymbolIterators() const = 0; + virtual symbol_iterator_range getDynamicSymbolIterators() const = 0; virtual uint64_t getSectionFlags(SectionRef Sec) const = 0; virtual uint32_t getSectionType(SectionRef Sec) const = 0; @@ -237,8 +236,7 @@ public: ELFT::Is64Bits); } - std::pair - getELFDynamicSymbolIterators() const override; + symbol_iterator_range getDynamicSymbolIterators() const override; bool isRelocatableObject() const override; }; @@ -855,20 +853,15 @@ unsigned ELFObjectFile::getArch() const { } template -std::pair -ELFObjectFile::getELFDynamicSymbolIterators() const { - return std::make_pair(dynamic_symbol_begin(), dynamic_symbol_end()); +ObjectFile::symbol_iterator_range +ELFObjectFile::getDynamicSymbolIterators() const { + return make_range(dynamic_symbol_begin(), dynamic_symbol_end()); } template bool ELFObjectFile::isRelocatableObject() const { return EF.getHeader()->e_type == ELF::ET_REL; } -inline std::pair -getELFDynamicSymbolIterators(const SymbolicFile *Obj) { - return cast(Obj)->getELFDynamicSymbolIterators(); -} - } } diff --git a/llvm/tools/llvm-nm/llvm-nm.cpp b/llvm/tools/llvm-nm/llvm-nm.cpp index b96d152..15dbc8c 100644 --- a/llvm/tools/llvm-nm/llvm-nm.cpp +++ b/llvm/tools/llvm-nm/llvm-nm.cpp @@ -890,14 +890,14 @@ static void dumpSymbolNamesFromObject(SymbolicFile &Obj, bool printName, basic_symbol_iterator IBegin = Obj.symbol_begin(); basic_symbol_iterator IEnd = Obj.symbol_end(); if (DynamicSyms) { - if (!Obj.isELF()) { + const auto *E = dyn_cast(&Obj); + if (!E) { error("File format has no dynamic symbol table", Obj.getFileName()); return; } - std::pair IDyn = - getELFDynamicSymbolIterators(&Obj); - IBegin = IDyn.first; - IEnd = IDyn.second; + auto IDyn = E->getDynamicSymbolIterators(); + IBegin = IDyn.begin(); + IEnd = IDyn.end(); } std::string NameBuffer; raw_string_ostream OS(NameBuffer); diff --git a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp index b6af342..eaf0d08 100644 --- a/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp +++ b/llvm/tools/llvm-symbolizer/LLVMSymbolize.cpp @@ -77,10 +77,9 @@ ModuleInfo::ModuleInfo(ObjectFile *Obj, DIContext *DICtx) bool NoSymbolTable = (Module->symbol_begin() == Module->symbol_end()); if (NoSymbolTable && Module->isELF()) { // Fallback to dynamic symbol table, if regular symbol table is stripped. - std::pair IDyn = - getELFDynamicSymbolIterators(Module); - for (symbol_iterator si = IDyn.first, se = IDyn.second; si != se; ++si) { - addSymbol(*si, OpdExtractor.get(), OpdAddress); + auto IDyn = cast(Module)->getDynamicSymbolIterators(); + for (SymbolRef Sym : IDyn) { + addSymbol(Sym, OpdExtractor.get(), OpdAddress); } } } -- 2.7.4