2026-04-16 19:36 UTC
@bal4e @folkertdev
GNU ifuncs (it depends on glibc, special relocations in the elf file too) is not weirdly implemented if you understand how PLT and elf (dynamic) shared library PIC code works.
Basically all calls in a shared library is done via a PLT (and to a shared library from the main application). This is normally lazy binding too (but that does not matter here really).
Each PLT has a location which stores the function pointer at runtime. At load time the PLT location is set to loader location. And then that loader location call will resolve the function to the right location and store it back. For ifuncs instead of just doing a lookup of the symbol; it does that lookup and then calls that "resolver" function which returns another function. That new function is what is called/stored into the PLT location.
(non-lazying bindings work very similar except instead of a loader function be set to the PLT location, the resolver function is called at load time rather than lazy).
Replies (1)
-
@pinskia@hachyderm.io 2026-04-16 19:40
@bal4e @folkertdev The problems with ifuncs this way is a few issues; first the resolver function has to be simple and not do anything else except load from memory and return a function. Second is well it depends on glibc dynamic loader (I think the bonic loader now supports it; musl folks said they won't be). So it is not exactly portable. LLVM/clang supports this functionality and extends it to be more "portable" instead it adds check for null on a location and calls the resolver and sets the location that way. I have not looked into the exact details there though.