Beispiel #1
0
int
do_test (void)
{
  void *handle;
  int (*sym) (void); /* We load ref1 from glreflib1.c.  */
  Dl_info info;
  int ret;


  handle = dlopen ("glreflib1.so", RTLD_NOW);
  if (handle == NULL)
    error (EXIT_FAILURE, 0, "cannot load: glreflib1.so");

  sym = dlsym (handle, "ref1");
  if (sym == NULL)
    error (EXIT_FAILURE, 0, "dlsym failed");

  memset (&info, 0, sizeof (info));
  ret = dladdr (sym, &info);

  if (ret == 0)
    error (EXIT_FAILURE, 0, "dladdr failed");

  printf ("address of ref1 = %lx\n",
	  (unsigned long int)  DL_LOOKUP_ADDRESS (sym));
  printf ("ret = %d\n", ret);
  printf ("info.dli_fname = %p (\"%s\")\n", info.dli_fname, info.dli_fname);
  printf ("info.dli_fbase = %p\n", info.dli_fbase);
  printf ("info.dli_sname = %p (\"%s\")\n", info.dli_sname, info.dli_sname);
  printf ("info.dli_saddr = %p\n", info.dli_saddr);

  if (info.dli_fname == NULL)
    error (EXIT_FAILURE, 0, "dli_fname is NULL");
  if (info.dli_fbase == NULL)
    error (EXIT_FAILURE, 0, "dli_fbase is NULL");
  if (info.dli_sname == NULL)
    error (EXIT_FAILURE, 0, "dli_sname is NULL");
  if (info.dli_saddr == NULL)
    error (EXIT_FAILURE, 0, "dli_saddr is NULL");

  dlclose (handle);

  return 0;
}
Beispiel #2
0
   You should have received a copy of the GNU Lesser General Public
   License along with the GNU C Library; if not, write to the Free
   Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
   02111-1307 USA.  */

#include <dlfcn.h>
#include <stddef.h>
#include <ldsodefs.h>


int
internal_function
_dl_addr (const void *address, Dl_info *info,
	  struct link_map **mapp, const ElfW(Sym) **symbolp)
{
  const ElfW(Addr) addr = DL_LOOKUP_ADDRESS (address);
  struct link_map *match;
  const ElfW(Sym) *symtab, *matchsym, *symtabend;
  const char *strtab;
  ElfW(Word) strtabsize;

  /* Protect against concurrent loads and unloads.  */
  __rtld_lock_lock_recursive (GL(dl_load_lock));

  /* Find the highest-addressed object that ADDRESS is not below.  */
  match = NULL;
  for (Lmid_t ns = 0; ns < DL_NNS; ++ns)
    for (struct link_map *l = GL(dl_ns)[ns]._ns_loaded; l; l = l->l_next)
      if (addr >= l->l_map_start && addr < l->l_map_end)
	{
	  /* We know ADDRESS lies within L if in any shared object.