summaryrefslogtreecommitdiffstats
path: root/linker/linker.c
diff options
context:
space:
mode:
authorErik Gilling <konkers@android.com>2009-07-28 20:28:19 -0700
committerErik Gilling <konkers@android.com>2009-07-28 20:36:47 -0700
commitfde8642fc43bdd224e43e5ee9583a49a758fb03c (patch)
tree0c722ced21166d5b6a79cc7c0aa14d073934bdd4 /linker/linker.c
parent22b5eb858dcbb537f2522ad920ca793348d574a2 (diff)
downloadbionic-fde8642fc43bdd224e43e5ee9583a49a758fb03c.zip
bionic-fde8642fc43bdd224e43e5ee9583a49a758fb03c.tar.gz
bionic-fde8642fc43bdd224e43e5ee9583a49a758fb03c.tar.bz2
Prior to this change, the dynamic loader kept track of opened libraries either by their base name (i.e., libfoo.so instead of /system/lib/libfoo.so) when the shared library was loaded through the DT_NEEDED tag in an ELF header, or by whatever name was passed to dlopen(). This created a number of problems, among which: 1. dlopen("libfoo.so") and dlopen("/path/to/libfoo.so") would open the same library twice; 2. dlopen("/path/to/libfoo.so") and then dlopen("libbar.so"), where libbar.so depends on libfoo.so, would open libfoo.so twice. This patch makes the dynamic loader keep track of each loaded library by basename, which resolves the above ambiguity. The patch also enforces library lookup by base name, which means that it will refuse to load another library that has the same name. Thanks for the inspiration Iliyan. Signed-off-by: Erik Gilling <konkers@android.com> Cc: Iliyan Malchev <malchev@google.com>
Diffstat (limited to 'linker/linker.c')
-rw-r--r--linker/linker.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/linker/linker.c b/linker/linker.c
index 0c1af9d..789a828 100644
--- a/linker/linker.c
+++ b/linker/linker.c
@@ -976,6 +976,7 @@ load_library(const char *name)
int cnt;
unsigned ext_sz;
unsigned req_base;
+ const char *bname;
soinfo *si = NULL;
Elf32_Ehdr *hdr;
@@ -1009,7 +1010,8 @@ load_library(const char *name)
* same thing would happen if we failed during linking. Configuring the
* soinfo struct here is a lot more convenient.
*/
- si = alloc_info(name);
+ bname = strrchr(name, '/');
+ si = alloc_info(bname ? bname + 1 : name);
if (si == NULL)
goto fail;
@@ -1078,9 +1080,11 @@ init_library(soinfo *si)
soinfo *find_library(const char *name)
{
soinfo *si;
+ const char *bname = strrchr(name, '/');
+ bname = bname ? bname + 1 : name;
for(si = solist; si != 0; si = si->next){
- if(!strcmp(name, si->name)) {
+ if(!strcmp(bname, si->name)) {
if(si->flags & FLAG_ERROR) return 0;
if(si->flags & FLAG_LINKED) return si;
DL_ERR("OOPS: %5d recursive link to '%s'", pid, si->name);