Re: [patches] [PATCH v2 2/6] riscv/ftrace: Add dynamic function tracer support

From: Stefan O'Rear
Date: Mon Jan 15 2018 - 02:31:13 EST


On Sun, Jan 14, 2018 at 10:47 PM, Alan Kao <nonerkao@xxxxxxxxx> wrote:
> + /*
> + * For the dynamic ftrace to work, here we should reserve at least
> + * 8 bytes for a functional auipc-jalr pair. Pseudo inst nop may be
> + * interpreted as different length in different models, so we manually
> + * *expand* two 4-byte nops here.
> + *
> + * Calling ftrace_update_ftrace_func would overwrite the nops below.
> + * Check ftrace_modify_all_code for details.
> + */
> + addi x0, x0, 0
> + addi x0, x0, 0

This relies on behavior of the assembler which is undocumented and, if
my reading of the specification is correct, a bug.

The documented way to assemble an sequence of 2 4-byte NOPs regardless
of subtarget is as follows:

.option push
.option norvc
nop
nop
.option pop

I have filed https://github.com/riscv/riscv-binutils-gdb/issues/135 to
get clarity on the assembler behavior; the explicit approach may be
preferable even if the assembler behavior turns out to be correct.

-s