Symbol binding in shared libraries...

Roland McGrath roland@frob.com
Fri Mar 10 11:47:00 GMT 2000


>    bp = ((char*)map->l_info[DT_STRTAB]->d_un.d_ptr) + sym->st_name;
> to
>    bp = ((char*)map->l_info[DT_STRTAB]->d_un.d_ptr) + refsym->st_name;

The former is incorrect.  SYM is a symbol from another object (you don't
know which at this point in the code), and you are using its string-table
offset with the string table from the MAP object.  REFSYM is a symbol in
the MAP object that has the name you want, so the latter is correct.  This
sort of oversight suggests to me you might not have read all the code you
are working with as closely as you could have.

> The dynamic loader seems to be binding to the PLT entry in the main
> executable for fflush, rather than the address of fflush in libc.so.

It is clearly stated in the spec (I don't have a citation off hand) that
this is the specified behavior for references that aren't from a PLT.
Consider `return &foo;' in a shared object and `if (ptr == &foo)' in the
main executable, where `&foo' in non-PIC code will have been fixed at link
time to the address of the executable's PLT entry for `foo'.


More information about the Libc-hacker mailing list