[RFC] Allocate GNU property bits for frame pointer and leaf frame pointer
Jake Adamson
jakeadamson@google.com
Wed Nov 11 21:49:16 GMT 2026
Hi Florian,
Thanks for the detailed feedback and the glibc malloc/free examples.
Simplifying this to a single bit with the invariant you described makes a
lot of sense, and it cleans up the linker semantics nicely:
Just to reiterate to make sure we are on the same page. The property promises
that throughout all executable code in the object, the architecture's
activation-record
chain register (as defined by each psABI e.g., x29 on AArch64, %rbp on
x86-64, s0/fp
on RISC-V, or r11 under AAPCS frame-chain rules on ARM) either retains
its incoming
value from the caller or points to a valid activation record in the
chain, then backtracers
are guaranteed that walking the chain will never dereference a
register repurposed by
register allocation (-fomit-frame-pointer) or clobbered by assembly.
At worst, an async
sample in a frameless leaf or shrink-wrapped fast path may miss the
immediate caller
unless handled by a top-frame heuristic, while the rest of the chain
remains intact.
With those changes, the generic definition would shrink to a single bit
(e.g., under a generic UINT32_AND property, or per-psABI FEATURE_1_AND
if preferred by the list):
#define GNU_PROPERTY_1_FRAME_CHAIN (1U << 0)
Does framing it around an activation-record chain with each psABI
defining the concrete
register and record rules match what you had in mind?
Also, do folks have a preference between a generic UINT32_AND property
that could
be used for backtracing versus processor-specific FEATURE_1_AND bits, given that
each psABI still needs to define the underlying chain layout?
Thanks,
Jake
On Thu, Nov 5, 2026 at 2:24 AM Florian Weimer <fweimer@redhat.com> wrote:
>
> * Jake Adamson via Gnu-gabi:
>
> > Our goal for Android is to have lower overhead backtrace generation
> > for profiling, tracing, and crash stack unwinding of native user space
> > code. To that end, we are adding frame pointer-only stack unwinding to
> > Android and looking into ways to know if what we are unwinding has
> > frame pointers and leaf frame pointers.
> >
> > The reason we want to add two bits is to confirm whether leaf frame
> > pointers are enabled as well. This allows us to get consistent unwinds
> > without relying on heuristics like using the link register or falling
> > back to DWARF for leaf functions.
>
> You still need heuristics for memset/memcpy/malloc/free, which don't
> have a frame pointer even if glibc is compiled with maximum frame
> pointers.
>
> The happy paths in malloc and free in glibc currently looks like this:
>
> Dump of assembler code for function __GI___libc_malloc:
> 0x00000000000833e0 <+0>: endbr64
> 0x00000000000833e4 <+4>: test %rdi,%rdi
> 0x00000000000833e7 <+7>: js 0x8345e <__GI___libc_malloc+126>
> 0x00000000000833e9 <+9>: lea 0x17(%rdi),%rax
> 0x00000000000833ed <+13>: mov 0x16be04(%rip),%rdx # 0x1ef1f8 <mp_+120>
> 0x00000000000833f4 <+20>: cmp $0x1f,%rax
> 0x00000000000833f8 <+24>: jbe 0x83458 <__GI___libc_malloc+120>
> 0x00000000000833fa <+26>: and $0xfffffffffffffff0,%rax
> 0x00000000000833fe <+30>: cmp %rdx,%rax
> 0x0000000000083401 <+33>: jae 0x8345e <__GI___libc_malloc+126>
> 0x0000000000083403 <+35>: mov %rax,%rdx
> 0x0000000000083406 <+38>: shr $0x4,%rdx
> 0x000000000008340a <+42>: sub $0x2,%rdx
> 0x000000000008340e <+46>: cmp $0x3f,%rdx
> 0x0000000000083412 <+50>: ja 0x83470 <__GI___libc_malloc+144>
> 0x0000000000083414 <+52>: mov 0x16b965(%rip),%rax # 0x1eed80
> 0x000000000008341b <+59>: lea 0x12(%rdx),%rsi
> 0x000000000008341f <+63>: mov %fs:(%rax),%rcx
> 0x0000000000083423 <+67>: mov 0x8(%rcx,%rsi,8),%rax
> 0x0000000000083428 <+72>: test %rax,%rax
> 0x000000000008342b <+75>: je 0x8345e <__GI___libc_malloc+126>
> 0x000000000008342d <+77>: test $0xf,%al
> 0x000000000008342f <+79>: jne 0x834d8 <__GI___libc_malloc+248>
> 0x0000000000083435 <+85>: mov %rax,%rdi
> 0x0000000000083438 <+88>: shr $0xc,%rdi
> 0x000000000008343c <+92>: xor (%rax),%rdi
> 0x000000000008343f <+95>: mov %rdi,0x8(%rcx,%rsi,8)
> 0x0000000000083444 <+100>: addw $0x1,(%rcx,%rdx,2)
> 0x0000000000083449 <+105>: movq $0x0,0x8(%rax)
> 0x0000000000083451 <+113>: ret
>
> Dump of assembler code for function __GI___libc_free:
> 0x0000000000083930 <+0>: endbr64
> 0x0000000000083934 <+4>: test %rdi,%rdi
> 0x0000000000083937 <+7>: je 0x83a20 <__GI___libc_free+240>
> 0x000000000008393d <+13>: test $0xf,%dil
> 0x0000000000083941 <+17>: jne 0x83a10 <__GI___libc_free+224>
> 0x0000000000083947 <+23>: mov -0x8(%rdi),%r10
> 0x000000000008394b <+27>: mov %r10,%r9
> 0x000000000008394e <+30>: and $0xfffffffffffffff8,%r9
> 0x0000000000083952 <+34>: cmp 0x16b89f(%rip),%r9 # 0x1ef1f8 <mp_+120>
> 0x0000000000083959 <+41>: lea -0x20(%r9),%rcx
> 0x000000000008395d <+45>: jae 0x839d6 <__GI___libc_free+166>
> 0x000000000008395f <+47>: mov 0x17285a(%rip),%rsi # 0x1f61c0 <tcache_key>
> 0x0000000000083966 <+54>: cmp %rsi,0x8(%rdi)
> 0x000000000008396a <+58>: je 0x83a28 <__GI___libc_free+248>
> 0x0000000000083970 <+64>: mov 0x16b409(%rip),%rdx # 0x1eed80
> 0x0000000000083977 <+71>: lea -0x20(%r9),%rcx
> 0x000000000008397b <+75>: mov %rcx,%rax
> 0x000000000008397e <+78>: mov %fs:(%rdx),%r8
> 0x0000000000083982 <+82>: shr $0x4,%rax
> 0x0000000000083986 <+86>: cmp $0x3ff,%rcx
> 0x000000000008398d <+93>: ja 0x839c0 <__GI___libc_free+144>
> 0x000000000008398f <+95>: movzwl (%r8,%rax,2),%edx
> 0x0000000000083994 <+100>: test %dx,%dx
> 0x0000000000083997 <+103>: je 0x839c6 <__GI___libc_free+150>
> 0x0000000000083999 <+105>: mov %rdi,%rcx
> 0x000000000008399c <+108>: sub $0x1,%edx
> 0x000000000008399f <+111>: mov %rsi,0x8(%rdi)
> 0x00000000000839a3 <+115>: shr $0xc,%rcx
> 0x00000000000839a7 <+119>: xor 0x98(%r8,%rax,8),%rcx
> 0x00000000000839af <+127>: mov %rcx,(%rdi)
> 0x00000000000839b2 <+130>: mov %rdi,0x98(%r8,%rax,8)
> 0x00000000000839ba <+138>: mov %dx,(%r8,%rax,2)
> 0x00000000000839bf <+143>: ret
>
> This is from a -fno-omit-frame-pointer -mno-omit-leaf-frame-pointer
> build. I believe LLVM has similar optimizations that cannot be easily
> switched off without significantly impacting performance.
>
> In practice, -mno-omit-leaf-frame-pointer does not seem to have much of
> an effect. I brought it up as a strawman in a Fedora discussion, and it
> has since developed a life of its own.
>
> A single flag that promises that the frame pointer register remains
> either unchanged, or is replaced with a valid pointer to a frame pointer
> chain would still be useful. Ideally, the wording should reflect that
> some architectures have a frame pointer register that cannot be used to
> walk a list of procedure activation records. Instead, they use a
> different register, and compilers may treat that register as allocatable
> by default (like the frame pointer register on other architectures).
>
> Thanks,
> Florian
>
More information about the Gnu-gabi
mailing list