Re: [patches] [PATCH v2] riscv/ftrace: Add basic support

From: Alan Kao
Date: Tue Dec 12 2017 - 19:57:55 EST


On Mon, Dec 11, 2017 at 10:15:58AM -0800, Palmer Dabbelt wrote:
> On Wed, 06 Dec 2017 18:31:10 PST (-0800), nonerkao@xxxxxxxxx wrote:

Hi Palmer,

I forgot to explain this section in the previous reply:

> > +ENTRY(_mcount)
> > + la t4, ftrace_stub
> > +#ifdef CONFIG_FUNCTION_GRAPH_TRACER
> > + la t0, ftrace_graph_return
> > + ld t1, 0(t0)
> > + bne t1, t4, do_ftrace_graph_caller
> > +
> > + la t3, ftrace_graph_entry
> > + ld t2, 0(t3)
> > + la t6, ftrace_graph_entry_stub
> > + bne t2, t6, do_ftrace_graph_caller
> > +#endif
> > + la t3, ftrace_trace_function
> > + ld t5, 0(t3)
> > + bne t5, t4, do_trace
> > + ret
>
> * You can save an instruction when addressing by using somethingl like "ld
> t1, ftrace_graph_return" instead of "la t0, ftrace_graph_return; ld t1
> 0(t0)".
>

There are three "la-ld" instruction pairs for loading ftrace_graph_return,
ftrace_graph_entry, and ftrace_trace_function. All of them are function
pointers in C. The problem here is that, if we applied an "ld" inst. to a
function pointer, we would have loaded the content, which would be the
first 8 bytes in the function, rather than the address of the target function
that the function pointer stored before.

In brief, the logic of the "la-ld" pairs should be fine.

Alan