linker: Refactoring step 3 of many

Extract linker executable specific code to linker_main.cpp;
this part of code does not have a place in libdl.a/so.

Bug: http://b/14998480
Bug: http://b/30706810
Test: mm && run bionic-unit-tests
Change-Id: I90f7475e93a919b0f9525da22928089ad35b8f6c
diff --git a/linker/linker_soinfo.h b/linker/linker_soinfo.h
index d7b584e..a0fe9e2 100644
--- a/linker/linker_soinfo.h
+++ b/linker/linker_soinfo.h
@@ -342,4 +342,15 @@
 // This function is used by dlvsym() to calculate hash of sym_ver
 uint32_t calculate_elf_hash(const char* name);
 
+const char* fix_dt_needed(const char* dt_needed, const char* sopath);
+
+template<typename F>
+void for_each_dt_needed(const soinfo* si, F action) {
+  for (const ElfW(Dyn)* d = si->dynamic; d->d_tag != DT_NULL; ++d) {
+    if (d->d_tag == DT_NEEDED) {
+      action(fix_dt_needed(si->get_string(d->d_un.d_val), si->get_realpath()));
+    }
+  }
+}
+
 #endif  /* __LINKER_SOINFO_H */