Adjust symbol lookup for DT_SYMBOLIC case

According ELF spec re. DT_SYMBOLIC:
This element's presence in a shared object library alters the dynamic
linker's symbol resolution algorithm for references within the library.
Instead of starting a symbol search with the executable file, the
dynamic linker starts from the shared object itself. If the shared
object fails to supply the referenced symbol, the dynamic linker then
searches the executable file and other shared objects as usual.

This change implements the last part.

Change-Id: Iae95d53d455313a4306f11733941bcd3596ac85f
Signed-off-by: Pavel Chupin <pavel.v.chupin@intel.com>
This commit is contained in:
Pavel Chupin 2012-10-31 13:55:51 +04:00
parent 084be59192
commit c77c434149

32
linker/linker.cpp Normal file → Executable file
View File

@ -425,7 +425,21 @@ soinfo_do_lookup(soinfo *si, const char *name, soinfo **lsi,
Elf32_Sym *s = NULL; Elf32_Sym *s = NULL;
int i; int i;
if (si != NULL) { if (si != NULL && somain != NULL) {
/*
* Local scope is executable scope. Just start looking into it right away
* for the shortcut.
*/
if (si == somain) {
s = soinfo_elf_lookup(si, elf_hash, name);
if (s != NULL) {
*lsi = si;
goto done;
}
} else {
/* Order of symbol lookup is controlled by DT_SYMBOLIC flag */
/* /*
* If this object was built with symbolic relocations disabled, the * If this object was built with symbolic relocations disabled, the
@ -458,6 +472,22 @@ soinfo_do_lookup(soinfo *si, const char *name, soinfo **lsi,
*lsi = si; *lsi = si;
goto done; goto done;
} }
/*
* If this object was built with -Bsymbolic and symbol is not found
* in the local scope, try to find the symbol in the main executable.
*/
if (si->has_DT_SYMBOLIC) {
DEBUG("%5d %s: looking up %s in executable %s after local scope\n",
pid, si->name, name, somain->name);
s = soinfo_elf_lookup(somain, elf_hash, name);
if (s != NULL) {
*lsi = somain;
goto done;
}
}
}
} }
/* Next, look for it in the preloads list */ /* Next, look for it in the preloads list */