Re:Does a compiler use all x86 instructions? (2010)
by pwdisswordfish on Wednesday August 24, 2016 @04:04PM
(#12354812)
GCC introduced __attribute__((ifunc(...))) precisely for this use case: https://gcc.gnu.org/onlinedocs/gcc/Common-Function-Attribute...
Re:Does a compiler use all x86 instructions? (2010)
by caf on Wednesday August 24, 2016 @09:00PM
(#12356300)
The resolution happens once only, just like other dynamic symbols - the result of the custom resolution call gets installed into the PLT, so subsequent calls will go directly to the right place.
That's the point of doing this in the linker - if you were going to look up the right function every call, you could do that entirely without special linker or compiler support.
Re:Does a compiler use all x86 instructions? (2010)
by gpderetta on Wednesday August 24, 2016 @03:57PM
(#12354763)
In principle the compiler can inline the specialized hash function and specialize its caller instead (recursively). GCC is supposed to do that, but I hear that the optimiziation is still a bit unreliable.
Normally, asm would do
at every place where slow_hash is invoked, but now it has to check at every invocation a pointer with the address of the function.Of course the loader could walk through all uses of the pointer to slow_hash and replace them by fast_hash on loading, but that won't work for selfmodifying (packed, or RE-protected) code.