How to get the name of an indirect gnu function using dladdr?

I can not get the gnu extension for an elf with indirect functions to work with dladdr.

In the following example, fabsand sinthere are two dynamic function libmwhere sinalso an indirect function. A search fabsfrom its pointer works well, but sinnot found. I tried various flags dlopenand -rdynamicwithout success.

The debugger shows how sinevaluated from gnu-indirect-function variableto __sin_avx.

Am I missing something or indirect functions are not supported dladdr?

/*
    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
}
+4
source share
1 answer

- , dladdr?

, .

, ifuncs , ( sin) , . sin 4 :

libm_ifunc (__sin, (HAS_ARCH_FEATURE (FMA4_Usable) ? __sin_fma4 :
                    HAS_ARCH_FEATURE (AVX_Usable)
                    ? __sin_avx : __sin_sse2));
weak_alias (__sin, sin)

__sin_XXX Glibc, libm.so dladdr .

, , dladdr ifuncs...

, -fPIC

, , w/o -fPIC, , , PLT. , GOT, PLT name dladdr, sin symtab.

EDIT:

Glibc .

+3

Source: https://habr.com/ru/post/1666145/


All Articles