From 8a6e9158fed893fed409fcafb69f6ed59bf54cfe Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Tue, 4 Jun 2019 03:18:03 -0700 Subject: [PATCH] ircd::mods::ldso: Add a DT_NEEDED iterator. --- include/ircd/mods/ldso.h | 2 ++ ircd/mods_ldso.cc | 27 +++++++++++++++++++++++++++ modules/console.cc | 27 +++++++++++++++++++++++++++ 3 files changed, 56 insertions(+) diff --git a/include/ircd/mods/ldso.h b/include/ircd/mods/ldso.h index 0bebd72bc..167852fb2 100644 --- a/include/ircd/mods/ldso.h +++ b/include/ircd/mods/ldso.h @@ -28,6 +28,7 @@ namespace ircd::mods::ldso IRCD_EXCEPTION(error, not_found); using link_closure = std::function; + using string_closure = std::function; using semantic_version = std::array; // Util @@ -52,4 +53,5 @@ namespace ircd::mods::ldso // Query link string_view string(const struct link_map &, const size_t &idx); + bool for_each_needed(const struct link_map &, const string_closure &); } diff --git a/ircd/mods_ldso.cc b/ircd/mods_ldso.cc index 0283501b4..2b768cbd6 100644 --- a/ircd/mods_ldso.cc +++ b/ircd/mods_ldso.cc @@ -21,6 +21,33 @@ // mods/ldso.h // +bool +ircd::mods::ldso::for_each_needed(const struct link_map &map, + const string_closure &closure) +{ + const char *strtab {nullptr}; + for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d) + if(d->d_tag == DT_STRTAB) + { + strtab = reinterpret_cast(d->d_un.d_ptr); + break; + } + + if(!strtab) + return true; + + for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d) + { + if(d->d_tag != DT_NEEDED) + continue; + + if(!closure(strtab + d->d_un.d_val)) + return false; + } + + return true; +} + ircd::string_view ircd::mods::ldso::string(const struct link_map &map, const size_t &idx) diff --git a/modules/console.cc b/modules/console.cc index ec88c7024..39ff71cac 100644 --- a/modules/console.cc +++ b/modules/console.cc @@ -1690,6 +1690,33 @@ console_cmd__mod__links(opt &out, const string_view &line) return true; } +bool +console_cmd__mod__needed(opt &out, const string_view &line) +{ + const params param{line, " ", + { + "name" + }}; + + const string_view name + { + param.at("name") + }; + + size_t i(0); + mods::ldso::for_each_needed(mods::ldso::get(name), [&out, &i] + (const string_view &name) + { + out << std::setw(2) << (i++) + << " " << name + << std::endl; + + return true; + }); + + return true; +} + // // ctx //