namespace folly {
namespace symbolizer {
+template <class Fn>
+const ElfPhdr* ElfFile::iterateProgramHeaders(Fn fn) const {
+ const ElfPhdr* ptr = &at<ElfPhdr>(elfHeader().e_phoff);
+ for (size_t i = 0; i < elfHeader().e_phnum; i++, ptr++) {
+ if (fn(*ptr)) {
+ return ptr;
+ }
+ }
+
+ return nullptr;
+}
+
template <class Fn>
const ElfShdr* ElfFile::iterateSections(Fn fn) const {
const ElfShdr* ptr = &at<ElfShdr>(elfHeader().e_shoff);
});
}
+template <class Fn>
+const ElfSym* ElfFile::iterateSymbolsWithTypes(
+ const ElfShdr& section,
+ std::initializer_list<uint32_t> types,
+ Fn fn) const {
+ // N.B. st_info has the same representation on 32- and 64-bit platforms
+ return iterateSymbols(section, [&](const ElfSym& sym) -> bool {
+ auto const elfType = ELF32_ST_TYPE(sym.st_info);
+ auto const it = std::find(types.begin(), types.end(), elfType);
+ return it != types.end() && fn(sym);
+ });
+}
+
} // namespace symbolizer
} // namespace folly