philpem,
@philpem@digipres.club avatar

Learning about the gcc attribute ((ifunc ("resolve_xxx"))) construct is making me wonder what the hell the person who thought it up was drinking, smoking or eating, and the code review team too.

I'm struggling to think of a reasonable usecase for this monstrosity of a construct.

https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attributes.html#index-ifunc-function-attribute

penguin42,
@penguin42@mastodon.org.uk avatar

@philpem I've seen it being used for selecting an AVX/etc/etc version of a function, it's pretty hairy though, and as I remember breaks things like static builds.

philpem,
@philpem@digipres.club avatar

@penguin42 I feel like a wrapper function containing a switch block is a much better way of achieving the same thing, and without breaking static builds...

penguin42,
@penguin42@mastodon.org.uk avatar

@philpem Except that's costly if you want to do it to say a libc function or something where you'd have to write a wrapper function so that memcpy has the swtich and calls memcpy_avx etc

philpem,
@philpem@digipres.club avatar

@penguin42 I'm not quite seeing how ifunc is an improvement, isn't it doing the same thing?

penguin42,
@penguin42@mastodon.org.uk avatar

@philpem I think it ends up doing it during the shared library loading, at the point the shared linker binds the program to the library that has the ifunc in it; so after that's executed it becomes as efficient as calling any other shared library function.

philpem,
@philpem@digipres.club avatar

@penguin42 in that case it feels like a function pointer would be almost as efficient (preinitialise on load then have the wrapper call it), without the obfuscatory effects of the ifunc. plus it can be boundschecked if needed to see if the fptr is one of the valid functions, ie a corruption canary.

penguin42,
@penguin42@mastodon.org.uk avatar

@philpem Right, almost; I'm not sure if the semantics allow you to make publicly defined C library functions actually be pointers.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • random
  • ngwrru68w68
  • rosin
  • GTA5RPClips
  • osvaldo12
  • love
  • Youngstown
  • slotface
  • khanakhh
  • everett
  • kavyap
  • mdbf
  • DreamBathrooms
  • thenastyranch
  • magazineikmin
  • megavids
  • InstantRegret
  • normalnudes
  • tacticalgear
  • cubers
  • ethstaker
  • modclub
  • cisconetworking
  • Durango
  • anitta
  • Leos
  • tester
  • provamag3
  • JUstTest
  • All magazines