0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-25 23:14:13 +01:00

ircd::mods: Demangled imports.

This commit is contained in:
Jason Volk 2019-02-09 03:05:19 -08:00
parent 3fcb701b47
commit c5d993f7c5
4 changed files with 65 additions and 3 deletions

View file

@ -27,6 +27,9 @@ template<class T>
struct ircd::mods::import
:sym_ptr
{
string_view mangled_name;
std::string demangled_name;
std::string target_name;
std::string module_name;
std::string symbol_name;
@ -57,6 +60,18 @@ ircd::mods::import<T>::import(std::string module_name,
// "lazy" and will be loaded via miss on first use. This is useful in
// the general use-case of static construction.
}
,mangled_name
{
typeid(T).name()
}
,demangled_name
{
demangle(mangled_name)
}
,target_name{fmt::snstringf
{
1024, "%s(%s", symbol_name, split(demangled_name, "(").second
}}
,module_name
{
std::move(module_name)
@ -74,6 +89,14 @@ ircd::mods::import<T>::import(const mods::module &module,
{
module, symbol_name
}
,mangled_name
{
typeid(T).name()
}
,demangled_name
{
demangle(mangled_name)
}
,module_name
{
module.name()
@ -167,7 +190,12 @@ try
static_cast<sym_ptr &>(*this)
};
sp = { module, symbol_name };
const auto &symname
{
ircd::has(symbol_name, ':')? target_name : symbol_name
};
sp = { module, symname };
}
catch(const std::out_of_range &e)
{

View file

@ -31,6 +31,11 @@ namespace ircd::mapi
{
"IRCD_MODULE"
};
const char *const import_section_name
{
"ircd"
};
}
/// The magic number at the front of the header

View file

@ -77,6 +77,10 @@ try
{
mode
}
,mangles
{
mods::mangles(this->path, mapi::import_section_name)
}
,handle{[this]
{
// Can't interrupt this ctx during the dlopen() as long as exceptions
@ -575,7 +579,19 @@ ircd::mods::get<uint8_t>(mod &mod,
const string_view &sym)
try
{
return mod.handle.get<uint8_t>(std::string{sym});
const auto it
{
mod.mangles.find(sym)
};
std::string s
{
it == end(mod.mangles)?
std::string{sym}:
it->second
};
return mod.handle.get<uint8_t>(s);
}
catch(const std::exception &e)
{
@ -594,7 +610,19 @@ ircd::mods::get<const uint8_t>(const mod &mod,
const string_view &sym)
try
{
return mod.handle.get<const uint8_t>(std::string{sym});
const auto it
{
mod.mangles.find(sym)
};
std::string s
{
it == end(mod.mangles)?
std::string{sym}:
it->second
};
return mod.handle.get<const uint8_t>(s);
}
catch(const std::exception &e)
{

View file

@ -27,6 +27,7 @@ struct ircd::mods::mod
std::string path;
load_mode::type mode;
std::deque<mod *> children;
std::map<std::string, std::string> mangles;
boost::dll::shared_library handle;
const std::string _name;
const std::string _location;