summaryrefslogtreecommitdiffstats
path: root/linker
diff options
context:
space:
mode:
authorMatt Fischer <matt.fischer@garmin.com>2009-12-31 12:17:56 -0600
committerGarmin Android technology group <android@garmin.com>2010-04-08 10:14:47 -0500
commit1698d9ebfc7e27271852a1fdf305a2ac37b3ebe4 (patch)
tree0affbb40a92f4391db962805610d78e71ac5f043 /linker
parent350bb359fa5e31e3dfae8be6b1ce7ee3495f0da7 (diff)
downloadbionic-1698d9ebfc7e27271852a1fdf305a2ac37b3ebe4.zip
bionic-1698d9ebfc7e27271852a1fdf305a2ac37b3ebe4.tar.gz
bionic-1698d9ebfc7e27271852a1fdf305a2ac37b3ebe4.tar.bz2
Fixed support for RTLD_NEXT in dlsym()
The previous implementation of this flag was broken--it behaved identically to RTLD_DEFAULT. This adds a proper implementation, which examines the address of the calling function, and uses it to determine which library to use to begin the symbol search process. Change-Id: I2ad2b46363f68932af63a3828a22f9c7987eea67
Diffstat (limited to 'linker')
-rw-r--r--linker/dlfcn.c10
-rw-r--r--linker/linker.c8
-rw-r--r--linker/linker.h2
3 files changed, 15 insertions, 5 deletions
diff --git a/linker/dlfcn.c b/linker/dlfcn.c
index dcadce5..30f5f4c 100644
--- a/linker/dlfcn.c
+++ b/linker/dlfcn.c
@@ -90,9 +90,15 @@ void *dlsym(void *handle, const char *symbol)
}
if(handle == RTLD_DEFAULT) {
- sym = lookup(symbol, &found);
+ sym = lookup(symbol, &found, NULL);
} else if(handle == RTLD_NEXT) {
- sym = lookup(symbol, &found);
+ void *ret_addr = __builtin_return_address(0);
+ soinfo *si = find_containing_library(ret_addr);
+
+ sym = NULL;
+ if(si && si->next) {
+ sym = lookup(symbol, &found, si->next);
+ }
} else {
found = (soinfo*)handle;
sym = lookup_in_library(found, symbol);
diff --git a/linker/linker.c b/linker/linker.c
index 87fb19b..451e96c 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -512,13 +512,17 @@ Elf32_Sym *lookup_in_library(soinfo *si, const char *name)
/* This is used by dl_sym(). It performs a global symbol lookup.
*/
-Elf32_Sym *lookup(const char *name, soinfo **found)
+Elf32_Sym *lookup(const char *name, soinfo **found, soinfo *start)
{
unsigned elf_hash = 0;
Elf32_Sym *s = NULL;
soinfo *si;
- for(si = solist; (s == NULL) && (si != NULL); si = si->next)
+ if(start == NULL) {
+ start = solist;
+ }
+
+ for(si = start; (s == NULL) && (si != NULL); si = si->next)
{
if(si->flags & FLAG_ERROR)
continue;
diff --git a/linker/linker.h b/linker/linker.h
index 8cd56b0..68ac275 100644
--- a/linker/linker.h
+++ b/linker/linker.h
@@ -224,7 +224,7 @@ extern soinfo libdl_info;
soinfo *find_library(const char *name);
unsigned unload_library(soinfo *si);
Elf32_Sym *lookup_in_library(soinfo *si, const char *name);
-Elf32_Sym *lookup(const char *name, soinfo **found);
+Elf32_Sym *lookup(const char *name, soinfo **found, soinfo *start);
soinfo *find_containing_library(void *addr);
Elf32_Sym *find_containing_symbol(void *addr, soinfo *si);
const char *linker_get_error(void);