Fix gdb could not get shared library list issue

Get dynamic flags from phdr table's correct entry rather the first
entry, so that the following DT_DEBUG entry can be set.

Also fix the undefined reference to LoadTask::deleter issue under gcc
-O0 option.

Bug: 17524778

(cherry picked from commit e93be99da0614ff38cbf8b2bb0624ff1dc79b8d0)

Change-Id: I347792dab25c7b19c3fc690e03d20899ce1e26e0
diff --git a/linker/linker.cpp b/linker/linker.cpp
index acbb1b0..1befaa6 100644
--- a/linker/linker.cpp
+++ b/linker/linker.cpp
@@ -666,6 +666,8 @@
   DISALLOW_IMPLICIT_CONSTRUCTORS(LoadTask);
 };
 
+LoadTask::deleter_t LoadTask::deleter;
+
 template <typename T>
 using linked_list_t = LinkedList<T, TypeBasedAllocator<LinkedListEntry<T>>>;
 
@@ -1868,7 +1870,9 @@
 }
 
 bool soinfo::PrelinkImage() {
-    phdr_table_get_dynamic_section(phdr, phnum, load_bias, &dynamic);
+  /* Extract dynamic section */
+  ElfW(Word) dynamic_flags = 0;
+  phdr_table_get_dynamic_section(phdr, phnum, load_bias, &dynamic, &dynamic_flags);
 
     /* We can't log anything until the linker is relocated */
     bool relocating_linker = (flags & FLAG_LINKER) != 0;
@@ -1877,8 +1881,6 @@
         DEBUG("si->base = %p si->flags = 0x%08x", reinterpret_cast<void*>(base), flags);
     }
 
-    /* Extract dynamic section */
-    ElfW(Word) dynamic_flags = phdr->p_flags;
     if (dynamic == nullptr) {
         if (!relocating_linker) {
             DL_ERR("missing PT_DYNAMIC in \"%s\"", name);
@@ -2240,7 +2242,7 @@
   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);
+                                 &linker_soinfo_for_gdb.dynamic, nullptr);
   insert_soinfo_into_debug_map(&linker_soinfo_for_gdb);
 }