From 22d4d5c1c17978aef3726f32d74fe435e9c051e7 Mon Sep 17 00:00:00 2001 From: Sebastian Sumpf Date: Fri, 13 Dec 2019 14:01:38 +0100 Subject: [PATCH] ldso: update link map during respawn move binary to front of link map after respawn. This is required by GDB in order to load symbol files correctly. issue #3481 --- repos/base/src/lib/ldso/include/debug.h | 14 ++++++++++++++ repos/base/src/lib/ldso/main.cc | 8 ++++++++ 2 files changed, 22 insertions(+) diff --git a/repos/base/src/lib/ldso/include/debug.h b/repos/base/src/lib/ldso/include/debug.h index c59c793dc..451aad67d 100644 --- a/repos/base/src/lib/ldso/include/debug.h +++ b/repos/base/src/lib/ldso/include/debug.h @@ -134,6 +134,20 @@ struct Linker::Link_map first = map->next; } + static void make_first(Link_map *map) + { + remove(map); + + if (first) { + first->prev = map; + } + + map->prev = nullptr; + map->next = first; + first = map; + Debug::d()->map = map; + } + static void dump() { if (!verbose_link_map) diff --git a/repos/base/src/lib/ldso/main.cc b/repos/base/src/lib/ldso/main.cc index cca5a08bf..64ca09d5a 100644 --- a/repos/base/src/lib/ldso/main.cc +++ b/repos/base/src/lib/ldso/main.cc @@ -193,6 +193,11 @@ class Linker::Elf_object : public Object, private Fifo::Element Link_map::add(&_map); }; + void link_map_make_first() + { + Link_map::make_first(&_map); + } + void force_keep() { _keep = KEEP; } Link_map const &link_map() const override { return _map; } @@ -731,6 +736,9 @@ void *Dynamic_linker::_respawn(Env &env, char const *binary, char const *entry_n /* load new binary */ construct_at(binary_ptr, env, *heap(), config, name.string()); + /* move to front of link map */ + binary_ptr->link_map_make_first(); + try { return (void *)binary_ptr->lookup_symbol(entry_name); }