Added support for dladdr()

dladdr() is a GNU extension function, which allows the caller to retrieve
symbol information for a specified memory address.  It is useful for things
like generating backtrace information at runtime.

Change-Id: I3a1def1a6c9c666d93e1e97b7d260dfa5b9b79a9
diff --git a/linker/linker.c b/linker/linker.c
index 6d57cbc..f5294d9 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -538,6 +538,40 @@
     return 0;
 }
 
+soinfo *find_containing_library(void *addr)
+{
+    soinfo *si;
+
+    for(si = solist; si != NULL; si = si->next)
+    {
+        if((unsigned)addr >= si->base && (unsigned)addr - si->base < si->size) {
+            return si;
+        }
+    }
+
+    return NULL;
+}
+
+Elf32_Sym *find_containing_symbol(void *addr, soinfo *si)
+{
+    unsigned int i;
+    unsigned soaddr = (unsigned)addr - si->base;
+
+    /* Search the library's symbol table for any defined symbol which
+     * contains this address */
+    for(i=0; i<si->nchain; i++) {
+        Elf32_Sym *sym = &si->symtab[i];
+
+        if(sym->st_shndx != SHN_UNDEF &&
+           soaddr >= sym->st_value &&
+           soaddr < sym->st_value + sym->st_size) {
+            return sym;
+        }
+    }
+
+    return NULL;
+}
+
 #if 0
 static void dump(soinfo *si)
 {