• Guo Ren's avatar
    riscv: Using PATCHABLE_FUNCTION_ENTRY instead of MCOUNT · afc76b8b
    Guo Ren authored
    This patch changes the current detour mechanism of dynamic ftrace
    which has been discussed during LPC 2020 RISCV-MC [1].
    
    Before the patch, we used mcount for detour:
    <funca>:
    	addi sp,sp,-16
    	sd   ra,8(sp)
    	sd   s0,0(sp)
    	addi s0,sp,16
    	mv   a5,ra
    	mv   a0,a5
    	auipc ra,0x0 -> nop
    	jalr  -296(ra) <_mcount@plt> ->nop
    	...
    
    After the patch, we use nop call site area for detour:
    <funca>:
    	nop -> REG_S ra, -SZREG(sp)
    	nop -> auipc ra, 0x?
    	nop -> jalr ?(ra)
    	nop -> REG_L ra, -SZREG(sp)
    	...
    
    The mcount mechanism is mixed with gcc function prologue which is
    not very clear. The patchable function entry just put 16 bytes nop
    before the front of the function prologue which could be filled
    with a separated detour mechanism.
    
    [1] https://www.linuxplumbersconf.org/event/7/contributions/807/Signed-off-by: default avatarGuo Ren <guoren@linux.alibaba.com>
    Signed-off-by: default avatarPalmer Dabbelt <palmerdabbelt@google.com>
    afc76b8b
mcount-dyn.S 3.96 KB