From 9209dfc9d54a9a96017332117a991e441a0848d5 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Tue, 11 May 2021 21:37:17 +0200 Subject: [PATCH] ldso: output loaded objects of 'Shared_object' interface When loading shared libraries via the 'Shared_object' interface display all additionaly loaded libraries in case 'ld_verbose' is configured. Up until now, only the loaded library was displayed. In order to determine if a dependend library had arlready been loaded prior to loading the 'Shared_object' the reference counter is used. fixes #4147 --- repos/base/src/lib/ldso/include/linker.h | 5 +++++ repos/base/src/lib/ldso/main.cc | 2 ++ repos/base/src/lib/ldso/shared_object.cc | 14 +++++++++----- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/repos/base/src/lib/ldso/include/linker.h b/repos/base/src/lib/ldso/include/linker.h index ea95c7c11c..05a2b5cc45 100644 --- a/repos/base/src/lib/ldso/include/linker.h +++ b/repos/base/src/lib/ldso/include/linker.h @@ -228,6 +228,11 @@ class Linker::Object : private Fifo::Element, virtual void load() = 0; virtual bool unload() { return false;} + /** + * Did this ELF require loading or was it present already + */ + virtual bool already_present() const { return false; } + /** * Next object in initialization list */ diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index 6a8d156c36..5006c3ef91 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -247,6 +247,8 @@ class Linker::Elf_object : public Object, private Fifo::Element void load() override { _ref_count++; } bool unload() override { return (_keep == DONT_KEEP) && !(--_ref_count); } + bool already_present() const override { return _ref_count > 1; } + bool keep() const override { return _keep == KEEP; } bool is_linker() const override { return false; } diff --git a/repos/base/src/lib/ldso/shared_object.cc b/repos/base/src/lib/ldso/shared_object.cc index 9ded9a2afc..2ec3c99583 100644 --- a/repos/base/src/lib/ldso/shared_object.cc +++ b/repos/base/src/lib/ldso/shared_object.cc @@ -59,16 +59,20 @@ Genode::Shared_object::Shared_object(Env &env, Allocator &md_alloc, try { Mutex::Guard guard(Linker::shared_object_mutex()); - _handle = new (md_alloc) + Root_object *root = new (md_alloc) Root_object(env, md_alloc, file ? file : binary_name(), bind == BIND_NOW ? Linker::BIND_NOW : Linker::BIND_LAZY, keep == KEEP ? Linker::KEEP : Linker::DONT_KEEP); + _handle = root; + /* print loaded object information */ - try { - if (Linker::verbose) - Linker::dump_link_map(to_root(_handle).first_dep()->obj()); - } catch (...) { } + if (Linker::verbose) { + root->deps().for_each([] (Linker::Dependency const &dep) { + if (dep.obj().already_present()) return; + Linker::dump_link_map(dep.obj()); + }); + } } catch(Linker::Not_found &symbol) { warning("LD: symbol not found: '", symbol, "'");