Elektrine lite

← Feed

@bal4e@tech.lgbt

2026-04-16 19:23 UTC

@folkertdev Mhm. To clarify what I meant by "ifuncs": I meant the general idea of "have an indirect function call and update the ptr on the first invocation", nothing more specific. If GCC's ifunc impl is weird (and that is what you were referring to) we can ignore it. If you had disqualified the general idea of ifuncs, I'd be curious to know why; I hope you can dig up the details. Maybe they are hard to implement portably.

Replies (2)

  • @pinskia@hachyderm.io 2026-04-16 19:36

    @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).

    Open ##1411458

  • @folkertdev@hachyderm.io 2026-04-16 20:17

    @bal4e ah, right, that totally works. e.g. https://crates.io/crates/multiversion So we'd want something like this conceptually, but in std/the compiler. We're not using this in zlib-rs in part because it did not seem to matter that much versus just a well-predicted branch but mostly because of the additional unsafety.

    Open ##1411461