* CONFIG_FRAME_POINTER support for Clang
@ 2019-05-30 22:56 Tri Vo
2019-05-30 22:58 ` Nick Desaulniers
2019-05-30 23:13 ` Russell King - ARM Linux admin
0 siblings, 2 replies; 6+ messages in thread
From: Tri Vo @ 2019-05-30 22:56 UTC (permalink / raw)
To: linux; +Cc: irogers, Nick Desaulniers, Linux ARM, stefan
Hello Russell,
I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
with Clang compiler.
Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
So in order to accommodate Clang-emitted frame layout, I'm thinking of
providing Clang-specific implementation of code that relies on frame pointer,
most notably in these files:
lib/backtrace.S
arch/arm/kernel/stacktrace.c
arch/arm/net/bpf_jit_32.c
This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
code. Is that OK?
Another caveat is that Clang implementation of backtracing won't be able to
dump saved registers or dump precise pc value of the caller, because IIUC that
information is derived from APCS's fixed prologue.
What do you think about this approach?
Thanks,
Tri
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: CONFIG_FRAME_POINTER support for Clang
2019-05-30 22:56 CONFIG_FRAME_POINTER support for Clang Tri Vo
@ 2019-05-30 22:58 ` Nick Desaulniers
2019-05-30 23:12 ` Ian Rogers
2019-05-30 23:13 ` Russell King - ARM Linux admin
1 sibling, 1 reply; 6+ messages in thread
From: Nick Desaulniers @ 2019-05-30 22:58 UTC (permalink / raw)
To: Tri Vo
Cc: Ian Rogers, Russell King, Stefan Agner, clang-built-linux,
Matthias Kaehlcke, Manoj Gupta, Linux ARM
+ Some more lists/people
On Thu, May 30, 2019 at 3:56 PM Tri Vo <trong@android.com> wrote:
>
> Hello Russell,
>
> I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
> with Clang compiler.
>
> Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
> GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
>
> So in order to accommodate Clang-emitted frame layout, I'm thinking of
> providing Clang-specific implementation of code that relies on frame pointer,
> most notably in these files:
> lib/backtrace.S
> arch/arm/kernel/stacktrace.c
> arch/arm/net/bpf_jit_32.c
>
> This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
> code. Is that OK?
>
> Another caveat is that Clang implementation of backtracing won't be able to
> dump saved registers or dump precise pc value of the caller, because IIUC that
> information is derived from APCS's fixed prologue.
>
> What do you think about this approach?
>
> Thanks,
> Tri
--
Thanks,
~Nick Desaulniers
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: CONFIG_FRAME_POINTER support for Clang
2019-05-30 22:58 ` Nick Desaulniers
@ 2019-05-30 23:12 ` Ian Rogers
2019-05-30 23:14 ` Russell King - ARM Linux admin
0 siblings, 1 reply; 6+ messages in thread
From: Ian Rogers @ 2019-05-30 23:12 UTC (permalink / raw)
To: Nick Desaulniers
Cc: Tri Vo, Russell King, Stefan Agner, clang-built-linux,
Matthias Kaehlcke, Manoj Gupta, Linux ARM
Would it be practical to use __builtin_return_address for the caller's PC?
Thanks,
Ian
On Thu, May 30, 2019 at 3:58 PM Nick Desaulniers
<ndesaulniers@google.com> wrote:
>
> + Some more lists/people
>
> On Thu, May 30, 2019 at 3:56 PM Tri Vo <trong@android.com> wrote:
> >
> > Hello Russell,
> >
> > I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
> > with Clang compiler.
> >
> > Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
> > GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
> >
> > So in order to accommodate Clang-emitted frame layout, I'm thinking of
> > providing Clang-specific implementation of code that relies on frame pointer,
> > most notably in these files:
> > lib/backtrace.S
> > arch/arm/kernel/stacktrace.c
> > arch/arm/net/bpf_jit_32.c
> >
> > This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
> > code. Is that OK?
> >
> > Another caveat is that Clang implementation of backtracing won't be able to
> > dump saved registers or dump precise pc value of the caller, because IIUC that
> > information is derived from APCS's fixed prologue.
> >
> > What do you think about this approach?
> >
> > Thanks,
> > Tri
>
>
>
> --
> Thanks,
> ~Nick Desaulniers
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: CONFIG_FRAME_POINTER support for Clang
2019-05-30 22:56 CONFIG_FRAME_POINTER support for Clang Tri Vo
2019-05-30 22:58 ` Nick Desaulniers
@ 2019-05-30 23:13 ` Russell King - ARM Linux admin
2019-05-31 0:03 ` Tri Vo
1 sibling, 1 reply; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2019-05-30 23:13 UTC (permalink / raw)
To: Tri Vo; +Cc: irogers, Nick Desaulniers, stefan, Linux ARM
On Thu, May 30, 2019 at 03:56:06PM -0700, Tri Vo wrote:
> Hello Russell,
>
> I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
> with Clang compiler.
>
> Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
> GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
>
> So in order to accommodate Clang-emitted frame layout, I'm thinking of
> providing Clang-specific implementation of code that relies on frame pointer,
> most notably in these files:
> lib/backtrace.S
> arch/arm/kernel/stacktrace.c
> arch/arm/net/bpf_jit_32.c
What format stack frames does Clang use? I don't use clang, never seen
any clang ARM assembly, so I've no idea on this.
> This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
> code. Is that OK?
>
> Another caveat is that Clang implementation of backtracing won't be able to
> dump saved registers or dump precise pc value of the caller, because IIUC that
> information is derived from APCS's fixed prologue.
>
> What do you think about this approach?
>
> Thanks,
> Tri
>
> _______________________________________________
> linux-arm-kernel mailing list
> linux-arm-kernel@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: CONFIG_FRAME_POINTER support for Clang
2019-05-30 23:12 ` Ian Rogers
@ 2019-05-30 23:14 ` Russell King - ARM Linux admin
0 siblings, 0 replies; 6+ messages in thread
From: Russell King - ARM Linux admin @ 2019-05-30 23:14 UTC (permalink / raw)
To: Ian Rogers
Cc: Tri Vo, Nick Desaulniers, Stefan Agner, clang-built-linux,
Matthias Kaehlcke, Manoj Gupta, Linux ARM
On Thu, May 30, 2019 at 04:12:05PM -0700, Ian Rogers wrote:
> Would it be practical to use __builtin_return_address for the caller's PC?
That works for arguments of zero, but guaranteed for non-zero arguments.
>
> Thanks,
> Ian
>
> On Thu, May 30, 2019 at 3:58 PM Nick Desaulniers
> <ndesaulniers@google.com> wrote:
> >
> > + Some more lists/people
> >
> > On Thu, May 30, 2019 at 3:56 PM Tri Vo <trong@android.com> wrote:
> > >
> > > Hello Russell,
> > >
> > > I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
> > > with Clang compiler.
> > >
> > > Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
> > > GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
> > >
> > > So in order to accommodate Clang-emitted frame layout, I'm thinking of
> > > providing Clang-specific implementation of code that relies on frame pointer,
> > > most notably in these files:
> > > lib/backtrace.S
> > > arch/arm/kernel/stacktrace.c
> > > arch/arm/net/bpf_jit_32.c
> > >
> > > This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
> > > code. Is that OK?
> > >
> > > Another caveat is that Clang implementation of backtracing won't be able to
> > > dump saved registers or dump precise pc value of the caller, because IIUC that
> > > information is derived from APCS's fixed prologue.
> > >
> > > What do you think about this approach?
> > >
> > > Thanks,
> > > Tri
> >
> >
> >
> > --
> > Thanks,
> > ~Nick Desaulniers
>
--
RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: CONFIG_FRAME_POINTER support for Clang
2019-05-30 23:13 ` Russell King - ARM Linux admin
@ 2019-05-31 0:03 ` Tri Vo
0 siblings, 0 replies; 6+ messages in thread
From: Tri Vo @ 2019-05-31 0:03 UTC (permalink / raw)
To: Russell King - ARM Linux admin
Cc: irogers, Nick Desaulniers, stefan, clang-built-linux, mka,
manojgupta, Linux ARM
On Thu, May 30, 2019 at 4:13 PM Russell King - ARM Linux admin
<linux@armlinux.org.uk> wrote:
>
> On Thu, May 30, 2019 at 03:56:06PM -0700, Tri Vo wrote:
> > Hello Russell,
> >
> > I'm trying to implement support for CONFIG_FRAME_POINTER when building Linux
> > with Clang compiler.
> >
> > Currently, CONFIG_FRAME_POINTER relies on function prologue that is emitted by
> > GCC using -mapcs flag. However, APCS is obsolete and Clang doesn't support it.
> >
> > So in order to accommodate Clang-emitted frame layout, I'm thinking of
> > providing Clang-specific implementation of code that relies on frame pointer,
> > most notably in these files:
> > lib/backtrace.S
> > arch/arm/kernel/stacktrace.c
> > arch/arm/net/bpf_jit_32.c
>
> What format stack frames does Clang use? I don't use clang, never seen
> any clang ARM assembly, so I've no idea on this.
The set and order of registers pushed onto the stack is different with Clang.
Consequently, positions of saved registers relative to the value of FP are
different with Clang.
https://github.com/llvm-mirror/llvm/blob/master/lib/Target/ARM/ARMCallingConv.td#L256
For purposes of backtracing, the important difference is that LR is pushed
onto the stack at offset -4 from the value of FP with GCC + APCS, and at
offset +4 with Clang.
Also, unlike GCC, Clang's frame pointer always points to the location of the
previous frame pointer.
Here is a simple example:
https://godbolt.org/z/gJN0nz
>
> > This will likely involve putting "#ifdef CC_IS_CLANG" statements in the source
> > code. Is that OK?
> >
> > Another caveat is that Clang implementation of backtracing won't be able to
> > dump saved registers or dump precise pc value of the caller, because IIUC that
> > information is derived from APCS's fixed prologue.
> >
> > What do you think about this approach?
> >
> > Thanks,
> > Tri
> >
> > _______________________________________________
> > linux-arm-kernel mailing list
> > linux-arm-kernel@lists.infradead.org
> > http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
> >
>
> --
> RMK's Patch system: https://www.armlinux.org.uk/developer/patches/
> FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up
> According to speedtest.net: 11.9Mbps down 500kbps up
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2019-05-31 0:04 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-05-30 22:56 CONFIG_FRAME_POINTER support for Clang Tri Vo
2019-05-30 22:58 ` Nick Desaulniers
2019-05-30 23:12 ` Ian Rogers
2019-05-30 23:14 ` Russell King - ARM Linux admin
2019-05-30 23:13 ` Russell King - ARM Linux admin
2019-05-31 0:03 ` Tri Vo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox