Re:Hotpatching a C Function on x86
by benou on Friday April 01, 2016 @12:18PM
(#11405963)
GCC has some built-in limited support for that:
- 'ifunc' attribute [1] allows you to dynamically select the implementation at load time, which simplifies the usecase where you just want to have a single binary but use optimized function depending on the available HW (eg. use SSE4.2 if available or fallback to MMX on old platforms, etc.)
- asm goto [2] + custom section to keep track of the jmp instructions addresses. It allows you to dynamically change jmp addresses at runtime. A typical usecase is when you want to enable/disable a feature in the hot path at runtime, eg. instrumentation
[1] https://gcc.gnu.org/onlinedocs/gcc-4.7.2/gcc/Function-Attrib... [2] https://gcc.gnu.org/onlinedocs/gcc/Extended-Asm.html#GotoLab...