Move getELFDynamicSymbolIterators to a public header.

llvm-svn: 202264
This commit is contained in:
Alexey Samsonov 2014-02-26 12:51:19 +00:00
parent 4ca51b9ace
commit 65056a39f3
2 changed files with 23 additions and 25 deletions

View File

@ -1015,6 +1015,25 @@ static inline error_code getELFRelocationAddend(const RelocationRef R,
llvm_unreachable("Object passed to getELFRelocationAddend() is not ELF");
}
static inline std::pair<symbol_iterator, symbol_iterator>
getELFDynamicSymbolIterators(SymbolicFile *Obj) {
if (const ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj))
return std::make_pair(ELF->dynamic_symbol_begin(),
ELF->dynamic_symbol_end());
if (const ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj))
return std::make_pair(ELF->dynamic_symbol_begin(),
ELF->dynamic_symbol_end());
if (const ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj))
return std::make_pair(ELF->dynamic_symbol_begin(),
ELF->dynamic_symbol_end());
if (const ELF64BEObjectFile *ELF = cast<ELF64BEObjectFile>(Obj))
return std::make_pair(ELF->dynamic_symbol_begin(),
ELF->dynamic_symbol_end());
llvm_unreachable(
"Object passed to getELFDynamicSymbolIterators() is not ELF");
}
/// This is a generic interface for retrieving GNU symbol version
/// information from an ELFObjectFile.
static inline error_code GetELFSymbolVersion(const ObjectFile *Obj,

View File

@ -462,30 +462,6 @@ static char getNMTypeChar(SymbolicFile *Obj, basic_symbol_iterator I) {
return Ret;
}
static void getDynamicSymbolIterators(SymbolicFile *Obj,
basic_symbol_iterator &Begin,
basic_symbol_iterator &End) {
if (ELF32LEObjectFile *ELF = dyn_cast<ELF32LEObjectFile>(Obj)) {
Begin = ELF->dynamic_symbol_begin();
End = ELF->dynamic_symbol_end();
return;
}
if (ELF64LEObjectFile *ELF = dyn_cast<ELF64LEObjectFile>(Obj)) {
Begin = ELF->dynamic_symbol_begin();
End = ELF->dynamic_symbol_end();
return;
}
if (ELF32BEObjectFile *ELF = dyn_cast<ELF32BEObjectFile>(Obj)) {
Begin = ELF->dynamic_symbol_begin();
End = ELF->dynamic_symbol_end();
return;
}
ELF64BEObjectFile *ELF = cast<ELF64BEObjectFile>(Obj);
Begin = ELF->dynamic_symbol_begin();
End = ELF->dynamic_symbol_end();
return;
}
static void dumpSymbolNamesFromObject(SymbolicFile *Obj) {
basic_symbol_iterator IBegin = Obj->symbol_begin();
basic_symbol_iterator IEnd = Obj->symbol_end();
@ -494,7 +470,10 @@ static void dumpSymbolNamesFromObject(SymbolicFile *Obj) {
error("File format has no dynamic symbol table", Obj->getFileName());
return;
}
getDynamicSymbolIterators(Obj, IBegin, IEnd);
std::pair<symbol_iterator, symbol_iterator> IDyn =
getELFDynamicSymbolIterators(Obj);
IBegin = IDyn.first;
IEnd = IDyn.second;
}
std::string NameBuffer;
raw_string_ostream OS(NameBuffer);