Initialize linker link_map for gdb directly
Remove unnecessary construction of soinfo when
initializing linker link_map for gdb.
Bug: http://b/27533895
Change-Id: Idf32cee56309aa9c9cf260efbd17a9deae9a756b
(cherry picked from commit 8d22dd53feddcc7a84e1cc481f171fd4dfe095a1)
diff --git a/linker/linker.cpp b/linker/linker.cpp
index 3c7637f..76d0168 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -283,14 +283,7 @@
static link_map* r_debug_tail = 0;
-static void insert_soinfo_into_debug_map(soinfo* info) {
- // Copy the necessary fields into the debug structure.
- link_map* map = &(info->link_map_head);
- map->l_addr = info->load_bias;
- // link_map l_name field is not const.
- map->l_name = const_cast<char*>(info->get_realpath());
- map->l_ld = info->dynamic;
-
+static void insert_link_map_into_debug_map(link_map* map) {
// Stick the new library at the end of the list.
// gdb tends to care more about libc than it does
// about leaf libraries, and ordering it this way
@@ -307,6 +300,17 @@
r_debug_tail = map;
}
+static void insert_soinfo_into_debug_map(soinfo* info) {
+ // Copy the necessary fields into the debug structure.
+ link_map* map = &(info->link_map_head);
+ map->l_addr = info->load_bias;
+ // link_map l_name field is not const.
+ map->l_name = const_cast<char*>(info->get_realpath());
+ map->l_ld = info->dynamic;
+
+ insert_link_map_into_debug_map(map);
+}
+
static void remove_soinfo_from_debug_map(soinfo* info) {
link_map* map = &(info->link_map_head);
@@ -4005,21 +4009,6 @@
#endif
}
-/*
- * This is linker soinfo for GDB. See details below.
- */
-#if defined(__LP64__)
-#define LINKER_PATH "/system/bin/linker64"
-#else
-#define LINKER_PATH "/system/bin/linker"
-#endif
-
-// This is done to avoid calling c-tor prematurely
-// because soinfo c-tor needs memory allocator
-// which might be initialized after global variables.
-static uint8_t linker_soinfo_for_gdb_buf[sizeof(soinfo)] __attribute__((aligned(8)));
-static soinfo* linker_soinfo_for_gdb = nullptr;
-
/* gdb expects the linker to be in the debug shared object list.
* Without this, gdb has trouble locating the linker's ".text"
* and ".plt" sections. Gdb could also potentially use this to
@@ -4028,10 +4017,15 @@
* be on the soinfo list.
*/
static void init_linker_info_for_gdb(ElfW(Addr) linker_base) {
- linker_soinfo_for_gdb = new (linker_soinfo_for_gdb_buf) soinfo(nullptr, LINKER_PATH,
- nullptr, 0, 0);
+ static link_map linker_link_map_for_gdb;
+#if defined(__LP64__)
+ static char kLinkerPath[] = "/system/bin/linker64";
+#else
+ static char kLinkerPath[] = "/system/bin/linker";
+#endif
- linker_soinfo_for_gdb->load_bias = linker_base;
+ linker_link_map_for_gdb.l_addr = linker_base;
+ linker_link_map_for_gdb.l_name = kLinkerPath;
/*
* Set the dynamic field in the link map otherwise gdb will complain with
@@ -4042,8 +4036,9 @@
ElfW(Ehdr)* elf_hdr = reinterpret_cast<ElfW(Ehdr)*>(linker_base);
ElfW(Phdr)* phdr = reinterpret_cast<ElfW(Phdr)*>(linker_base + elf_hdr->e_phoff);
phdr_table_get_dynamic_section(phdr, elf_hdr->e_phnum, linker_base,
- &linker_soinfo_for_gdb->dynamic, nullptr);
- insert_soinfo_into_debug_map(linker_soinfo_for_gdb);
+ &linker_link_map_for_gdb.l_ld, nullptr);
+
+ insert_link_map_into_debug_map(&linker_link_map_for_gdb);
}
static void init_default_namespace() {