|
27 | 27 | #include <sys/utsname.h> |
28 | 28 | #include <osv/demangle.hh> |
29 | 29 | #include <boost/version.hpp> |
| 30 | +#include <deque> |
30 | 31 |
|
31 | 32 | #include "arch.hh" |
32 | 33 |
|
@@ -950,6 +951,22 @@ Elf64_Sym* object::lookup_symbol(const char* name, bool self_lookup) |
950 | 951 | return sym; |
951 | 952 | } |
952 | 953 |
|
| 954 | +symbol_module object::lookup_symbol_deep(const char* name) |
| 955 | +{ |
| 956 | + symbol_module sym = { lookup_symbol(name, false), this }; |
| 957 | + if (!sym.symbol) { |
| 958 | + auto deps = this->collect_dependencies_bfs(); |
| 959 | + for (auto&& _obj : deps) { |
| 960 | + auto symbol = _obj->lookup_symbol(name, false); |
| 961 | + if (symbol) { |
| 962 | + sym = { symbol, _obj }; |
| 963 | + break; |
| 964 | + } |
| 965 | + } |
| 966 | + } |
| 967 | + return sym; |
| 968 | +} |
| 969 | + |
953 | 970 | unsigned object::symtab_len() |
954 | 971 | { |
955 | 972 | if (dynamic_exists(DT_HASH)) { |
@@ -1089,6 +1106,28 @@ void object::collect_dependencies(std::unordered_set<elf::object*>& ds) |
1089 | 1106 | } |
1090 | 1107 | } |
1091 | 1108 |
|
| 1109 | +std::deque<elf::object*> object::collect_dependencies_bfs() |
| 1110 | +{ |
| 1111 | + std::unordered_set<object*> deps_set; |
| 1112 | + std::deque<object*> operate_queue; |
| 1113 | + std::deque<object*> deps; |
| 1114 | + operate_queue.push_back(this); |
| 1115 | + deps_set.insert(this); |
| 1116 | + |
| 1117 | + while (!operate_queue.empty()) { |
| 1118 | + object* obj = operate_queue.front(); |
| 1119 | + operate_queue.pop_front(); |
| 1120 | + deps.push_back(obj); |
| 1121 | + for (auto&& d : obj->_needed) { |
| 1122 | + if (!deps_set.count(d.get())) { |
| 1123 | + deps_set.insert(d.get()); |
| 1124 | + operate_queue.push_back(d.get()); |
| 1125 | + } |
| 1126 | + } |
| 1127 | + } |
| 1128 | + return deps; |
| 1129 | +} |
| 1130 | + |
1092 | 1131 | std::string object::soname() |
1093 | 1132 | { |
1094 | 1133 | return dynamic_exists(DT_SONAME) ? dynamic_str(DT_SONAME) : std::string(); |
|
0 commit comments