This is the mail archive of the libc-hacker@sourceware.cygnus.com mailing list for the glibc project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: dlsym() annoyance


> If I call dlsym(NULL, "sym") and sym is a function in libc that's referred
> to directly in the program, dlsym returns an address in the PLT, same as
> writing ptr = sym.  If sym is not referred to directly, I get the actual
> address inside the shared library. Is there any way to force dlsym to give
> me the real address in all cases?  (This is for testing purposes, so I don't
> mind calling internal entry points.)

Nope, there ain't.  If the program itself used "sym", then it was linked
with a constant address for "sym" (in its PLT), and this is what "&sym"
means in that program.  If dlsym didn't return the same thing, then
"&sym" in the program would not be the same as "&sym" as indicated by dlsym.

This is enforced in elf/dl-lookup.c, where it calls elf_machine_lookup_noplt_p.

> Also, is there any way to get the text size of an arbitrary function from
> within the program?

Nope.  The only place that info lives is in the symbol table (st_size), and
if there is no symbol for a function then the info is lost entirely (at
link time).  For shared libraries and such, the dynamic symbol table is
there, but there is no easy way to get at it, except by looking at the
l_info fields yourself.


What is the root reason you want to do these things?


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]