Signed-off-by: Zhiting Zhu <zhiti...@cs.utexas.edu>
---
 core/elf.cc        | 14 ++++++++++++++
 include/osv/elf.hh |  1 +
 libc/dlfcn.cc      |  2 +-
 tests/tst-dlfcn.cc |  2 +-
 4 files changed, 17 insertions(+), 2 deletions(-)

diff --git a/core/elf.cc b/core/elf.cc
index 31777b92..882b4d49 100644
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -917,6 +917,20 @@ Elf64_Sym* object::lookup_symbol(const char* name)
     return sym;
 }
 
+symbol_module object::lookup_symbol_deep(const char* name)
+{
+    symbol_module sym = { lookup_symbol(name), this };
+    if (!sym.symbol) {
+        for (auto&& _obj : _needed) {
+            sym = _obj->lookup_symbol_deep(name);
+            if (sym.symbol) {
+                break;
+            }
+        }
+    }
+    return sym;
+}
+
 unsigned object::symtab_len()
 {
     if (dynamic_exists(DT_HASH)) {
diff --git a/include/osv/elf.hh b/include/osv/elf.hh
index 8e37aebb..ededb75a 100644
--- a/include/osv/elf.hh
+++ b/include/osv/elf.hh
@@ -341,6 +341,7 @@ public:
     void* base() const;
     void* end() const;
     Elf64_Sym* lookup_symbol(const char* name);
+    symbol_module lookup_symbol_deep(const char* name);
     void load_segments();
     void unload_segments();
     void fix_permissions();
diff --git a/libc/dlfcn.cc b/libc/dlfcn.cc
index 8cfb7b2a..1cad7ffd 100644
--- a/libc/dlfcn.cc
+++ b/libc/dlfcn.cc
@@ -74,7 +74,7 @@ void* dlsym(void* handle, const char* name)
         abort();
     } else {
         auto obj = *reinterpret_cast<std::shared_ptr<elf::object>*>(handle);
-        sym = { obj->lookup_symbol(name), obj.get() };
+        sym = obj->lookup_symbol_deep(name);
     }
     if (!sym.obj || !sym.symbol) {
         dlerror_fmt("dlsym: symbol %s not found", name);
diff --git a/tests/tst-dlfcn.cc b/tests/tst-dlfcn.cc
index d2c9f288..614a3d00 100644
--- a/tests/tst-dlfcn.cc
+++ b/tests/tst-dlfcn.cc
@@ -13,7 +13,7 @@
 namespace utf = boost::unit_test;
 
 const bool rtld_next = false;
-const bool deep_lookup = false;
+const bool deep_lookup = true;
 
 static bool called = false;
 extern "C" void DlSymTestFunction()
-- 
2.17.1

-- 
You received this message because you are subscribed to the Google Groups "OSv 
Development" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to osv-dev+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/osv-dev/20200107081540.11600-2-zhitingz%40cs.utexas.edu.

Reply via email to