X-Git-Url: http://plrg.eecs.uci.edu/git/?a=blobdiff_plain;f=folly%2Fexperimental%2Fsymbolizer%2FElf-inl.h;h=e643dd2fc3c72fbcc51a1ec5bc26548e014bc9af;hb=f975d3c54800b7065985e5e548ce1d91fef4926c;hp=4bc644d5c691670ca9466d2ca7e1d1f94c24421b;hpb=5c77fedbef46995a71ffa268c9fcaf49efddd01b;p=folly.git diff --git a/folly/experimental/symbolizer/Elf-inl.h b/folly/experimental/symbolizer/Elf-inl.h index 4bc644d5..e643dd2f 100644 --- a/folly/experimental/symbolizer/Elf-inl.h +++ b/folly/experimental/symbolizer/Elf-inl.h @@ -1,5 +1,5 @@ /* - * Copyright 2013 Facebook, Inc. + * Copyright 2017 Facebook, Inc. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,7 +59,34 @@ const char* ElfFile::iterateStrings(const ElfW(Shdr)& stringTable, Fn fn) return ptr != end ? ptr : nullptr; } +template +const ElfW(Sym)* ElfFile::iterateSymbols(const ElfW(Shdr)& section, Fn fn) + const { + FOLLY_SAFE_CHECK(section.sh_entsize == sizeof(ElfW(Sym)), + "invalid entry size in symbol table"); + + const ElfW(Sym)* sym = &at(section.sh_offset); + const ElfW(Sym)* end = sym + (section.sh_size / section.sh_entsize); + + while (sym < end) { + if (fn(*sym)) { + return sym; + } + + ++sym; + } + + return nullptr; +} + +template +const ElfW(Sym)* ElfFile::iterateSymbolsWithType(const ElfW(Shdr)& section, + uint32_t type, Fn fn) const { + // N.B. st_info has the same representation on 32- and 64-bit platforms + return iterateSymbols(section, [&](const ElfW(Sym)& sym) -> bool { + return ELF32_ST_TYPE(sym.st_info) == type && fn(sym); + }); +} } // namespace symbolizer } // namespace folly -