0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-11-25 08:12:37 +01:00

ircd::mods::ldso: Add strtab lookup convenience.

This commit is contained in:
Jason Volk 2020-05-02 16:22:21 -07:00
parent 747bc99987
commit 51cb09c31a
2 changed files with 21 additions and 10 deletions

View file

@ -55,6 +55,7 @@ namespace ircd::mods::ldso
struct link_map &get(const string_view &name);
// Query link
const char *strtab(const struct link_map &);
string_view string(const struct link_map &, const size_t &idx);
bool for_each_needed(const struct link_map &, const string_closure &);

View file

@ -99,16 +99,10 @@ ircd::string_view
ircd::mods::ldso::string(const struct link_map &map,
const size_t &idx)
{
const char *str {nullptr};
for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d)
if(d->d_tag == DT_STRTAB)
{
str = reinterpret_cast<const char *>(d->d_un.d_ptr);
break;
}
if(!str)
return {};
const char *str
{
strtab(map)
};
size_t i(1);
for(++str; *str && i < idx; str += strlen(str) + 1)
@ -120,6 +114,22 @@ ircd::mods::ldso::string(const struct link_map &map,
}
#endif
#if __has_include(<elf.h>)
const char *
ircd::mods::ldso::strtab(const struct link_map &map)
{
const char *str {nullptr};
for(auto d(map.l_ld); d->d_tag != DT_NULL; ++d)
if(d->d_tag == DT_STRTAB)
{
str = reinterpret_cast<const char *>(d->d_un.d_ptr);
break;
}
return str;
}
#endif
struct link_map &
ircd::mods::ldso::get(const string_view &name)
{