+#ifdef PIC
+ /* We will unlink the first object only if this is a statically
+ linked program. */
+ assert (imap->l_prev != NULL);
+ imap->l_prev->l_next = imap->l_next;
+#else
+ if (imap->l_prev != NULL)
+ imap->l_prev->l_next = imap->l_next;
+ else
+ _dl_loaded = imap->l_next;
+#endif
+ if (imap->l_next)
+ imap->l_next->l_prev = imap->l_prev;
+
+ if (imap->l_versions != NULL)
+ free (imap->l_versions);
+ if (imap->l_origin != NULL && imap->l_origin != (char *) -1)
+ free ((char *) imap->l_origin);
+
+ /* This name always is allocated. */
+ free (imap->l_name);
+ /* Remove the list with all the names of the shared object. */
+ lnp = imap->l_libname;
+ do
+ {
+ struct libname_list *this = lnp;
+ lnp = lnp->next;
+ free (this);
+ }
+ while (lnp != NULL);
+
+ /* Remove the searchlists. */
+ if (imap->l_searchlist.r_duplist != imap->l_searchlist.r_list)
+ {
+ /* If a r_list exists there always also is a r_duplist. */
+ assert (imap->l_searchlist.r_list != NULL);
+ free (imap->l_searchlist.r_duplist);
+ }
+ if (imap != map && imap->l_searchlist.r_list != NULL)
+ free (imap->l_searchlist.r_list);
+
+ if (imap->l_phdr_allocated)
+ free ((void *) imap->l_phdr);
+
+ free (imap);