https://gcc.gnu.org/bugzilla/show_bug.cgi?id=112980
--- Comment #14 from Michael Matz <matz at gcc dot gnu.org> --- (In reply to Kewen Lin from comment #13) > (In reply to Giuliano Belinassi from comment #12) > > With your patch we have: > > > > > .LPFE0: > > > ... > > Which seems what is expected. > > Hi Giuliano, thanks for your time on testing it! Could you kindly help to > explain a bit on why "In such way we can't use the this space to place a > trampoline to the new function"? Is it due to inefficient code like needing > more branches? > > global entry: > [b localentry] > L1: > [patched code] > localentry: > [b L1] > > Or some other reason which makes it unused at all? Hmm? But this is not how the global-to-local hand-off is implemented (and expected by tooling): a fall-through. The global entry sets up the GOT register, there simply is no '[b localentry]'. If you mean to imply that also the '[b localentry]' should be patched in at live-patch application time (and hence the GOT setup would need to be moved to still somewhere else), then you have the problem that (in the not-yet-patched case) as long as the L1-nops sit between global and local entry they will always be executed when the global entry is called. That's wasteful. Additionally tooling will be surprised if the address difference between global and local entry isn't exactly 8 (i.e. two instructions). The psABI allows for different values, of course. But I'm willing to bet that there are bugs in the wild when different values would be actually used. So, the nops-between-gep-and-lep could probably be somehow made to work with userspace live patching, but your most recent patch here makes this all mood. It generates exactly the sequence we want: a single nop at the LEP, and a configurable patching area outside of, but near to, the function (here: in front of the GEP).