Name of indirect function evaluating to a hidden function?

listcrawler listcrawler@gmail.com
Mon Jan 9 13:31:00 GMT 2017


Hi

Is there a way to get the name of an indirect function (STT_GNU_IFUNC) 
which evaluates to a hidden function?

For example, the indirect function sin in libm resolves to __sin_avx on 
my system. __sin_avx is not exported and not found by calls to dladdr.

Is it possible to refer to the original indirect function sin, the one 
with the __attribute__ ifunc||, without resolving into __sin_avx?

See example code below.

Thanks


Hans Berghäll


/*
     compiled with g++-5 -fPIC -ldl
*/

#include <cmath>
#include <dlfcn.h>
#include <iostream>

char const * name (void * arg)
{
     void * h = dlopen (NULL, RTLD_LAZY);

     if (h)
     {
         Dl_info res;
         int status = dladdr (arg, & res);
         dlclose (h);

         if (status && res.dli_sname && arg == res.dli_saddr)
             return res.dli_sname;
     }

     return "";
}

int main ()
{
     std::cout << fabs (0.0) << " " << name ((void *) fabs) << 
std::endl; // found
     std::cout << sin  (0.0) << " " << name ((void *) sin ) << 
std::endl; // not found
}



More information about the Libc-help mailing list