Merge "Adjust symbol lookup for DT_SYMBOLIC case"

This commit is contained in:
Elliott Hughes 2012-11-02 11:25:48 -07:00 committed by Gerrit Code Review
commit ed537239a9

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

@ -458,38 +458,68 @@ 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) {
/* /*
* If this object was built with symbolic relocations disabled, the * Local scope is executable scope. Just start looking into it right away
* first place to look to resolve external references is the main * for the shortcut.
* executable.
*/ */
if (!si->has_DT_SYMBOLIC) { if (si == somain) {
DEBUG("%5d %s: looking up %s in executable %s\n", s = soinfo_elf_lookup(si, elf_hash, name);
pid, si->name, name, somain->name);
s = soinfo_elf_lookup(somain, elf_hash, name);
if (s != NULL) { if (s != NULL) {
*lsi = somain; *lsi = si;
goto done; goto done;
} }
} } else {
/* Order of symbol lookup is controlled by DT_SYMBOLIC flag */
/* Look for symbols in the local scope (the object who is /*
* searching). This happens with C++ templates on i386 for some * If this object was built with symbolic relocations disabled, the
* reason. * first place to look to resolve external references is the main
* * executable.
* Notes on weak symbols: */
* The ELF specs are ambiguous about treatment of weak definitions in
* dynamic linking. Some systems return the first definition found
* and some the first non-weak definition. This is system dependent.
* Here we return the first definition found for simplicity. */
s = soinfo_elf_lookup(si, elf_hash, name); if (!si->has_DT_SYMBOLIC) {
if (s != NULL) { DEBUG("%5d %s: looking up %s in executable %s\n",
*lsi = si; pid, si->name, name, somain->name);
goto done; s = soinfo_elf_lookup(somain, elf_hash, name);
if (s != NULL) {
*lsi = somain;
goto done;
}
}
/* Look for symbols in the local scope (the object who is
* searching). This happens with C++ templates on i386 for some
* reason.
*
* Notes on weak symbols:
* The ELF specs are ambiguous about treatment of weak definitions in
* dynamic linking. Some systems return the first definition found
* and some the first non-weak definition. This is system dependent.
* Here we return the first definition found for simplicity. */
s = soinfo_elf_lookup(si, elf_hash, name);
if (s != NULL) {
*lsi = si;
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;
}
}
} }
} }