dlsym function doesn't seem to lookup symbol deep enough. This
patch fixes test_dlsym_from_sofile_with_preload and
dlsym_with_dependencies

Signed-off-by: Waldemar Kozaczuk <jwkozac...@gmail.com>
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 73834b19..26a25c43 100644
--- a/core/elf.cc
+++ b/core/elf.cc
@@ -950,6 +950,20 @@ Elf64_Sym* object::lookup_symbol(const char* name, bool 
self_lookup)
     return sym;
 }
 
+symbol_module object::lookup_symbol_deep(const char* name)
+{
+    symbol_module sym = { lookup_symbol(name, false), 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 1dac6c08..8cd7b37a 100644
--- a/include/osv/elf.hh
+++ b/include/osv/elf.hh
@@ -347,6 +347,7 @@ public:
     void* base() const;
     void* end() const;
     Elf64_Sym* lookup_symbol(const char* name, bool self_lookup);
+    symbol_module lookup_symbol_deep(const char* name);
     void load_segments();
     void process_headers();
     void unload_segments();
diff --git a/libc/dlfcn.cc b/libc/dlfcn.cc
index 346cf195..e3a4a577 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, false), 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 5258256a..6d91fb93 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/20200115173946.76109-1-zhitingz%40cs.utexas.edu.

Reply via email to