[PATCH] riscv: Terminate the frame-pointer chain at entry points [BZ #34950]

Palmer Dabbelt palmer@dabbelt.com
Thu Nov 12 19:00:31 GMT 2026


On Thu, 12 Nov 2026 10:55:50 PST (-0800), bergner@oss.tenstorrent.com wrote:
> On 11/11/26 1:40 PM, Tommy Chen wrote:
>> _start, __thread_start and __thread_start_clone3 do not clear s0, so
>> the outermost frame record can link to a stale value instead of NULL.
>> The RISC-V psABI requires "The end of the frame record chain is
>> indicated by a NULL pointer appearing as the next link in the chain"
>> [1].  Frame-pointer unwinders such as perf --call-graph fp follow the
>> stale link into unrelated memory.
>>
>> Clear s0 at the three entry points, as x86_64 (xorl %ebp, %ebp) and
>> aarch64 (mov x29, 0) already do in start.S, clone.S and clone3.S.
>
> I don't see any real problems with clearing s0/fp here, so LGTM.
>
> Reviewed-by: Peter Bergner <bergner@tenstorrent.com>
>
>
> However, is this something you actually hit?  I ask, because GCC and LLVM
> default to -fomit-frame-pointer, including when building GLIBC, so it seems
> doubtful you could backtrace using s0/fp all the way through the userspace
> call stack to _start.  ...unless you have a specially built userland where
> you use -fno-omit-frame-pointer everywhere or have a very short call stack
> and are very lucky that nothing uses s0 to hold ordinary values.

At least Fedora defaults to enabling frame pointers already.

https://lists.fedoraproject.org/archives/list/devel@lists.fedoraproject.org/thread/OOJDAKTJB5WGMOZRXTUX7FTPFBF3H7WE/

(though I'm getting blocked as a bot right now, so not 100% sure that's 
a relevant link)

>
> Peter


More information about the Libc-alpha mailing list