https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70128
--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> --- I think anyone patching functions need to be considered special and undefined. In most cases they did not mean to do it. Just the kernel is special. > just add an optimization barrier on fn_addr (like asm ("" : "+g" (fn_addr))). I think that is the correct fix no matter what. As patching functions is not something which you can do normally because the .text section is read only.