Skip to content

Commit d8cc954

Browse files
committed
_clone(): clear the frame pointer register
This patch prevents tools that rely on frame pointers from reading garbage past the main function of a thread. Note: This is normally only a concern when using profilers.
1 parent 84742d3 commit d8cc954

File tree

1 file changed

+49
-0
lines changed

1 file changed

+49
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
From c37d37ac362f00b709778a37348f370d850bf87f Mon Sep 17 00:00:00 2001
2+
From: Alicia Boya Garcia <aboya@igalia.com>
3+
Date: Wed, 30 Jul 2025 18:11:53 +0000
4+
Subject: [PATCH] arm/clone.S: Clear fp register, name thread_start
5+
6+
The frame pointer register (r11 in ARM) should be cleared before
7+
branching into the thread main function. Otherwise tools that depend on
8+
frame pointers (e.g. perf) won't be able to find the end of the call
9+
chain and will end up reading garbage.
10+
11+
This patch also names the function that calls the thread main function
12+
as thread_start. Before it was unnamed, it would appear in perf as a
13+
pointer, just like functions without symbols or broken backtraces, which
14+
can be quite confusing, especially given how many other things can
15+
already go wrong with frame pointers in ARM32.
16+
---
17+
sysdeps/unix/sysv/linux/arm/clone.S | 7 +++++--
18+
1 file changed, 5 insertions(+), 2 deletions(-)
19+
20+
diff --git a/sysdeps/unix/sysv/linux/arm/clone.S b/sysdeps/unix/sysv/linux/arm/clone.S
21+
index b7326439..c0ada233 100644
22+
--- a/sysdeps/unix/sysv/linux/arm/clone.S
23+
+++ b/sysdeps/unix/sysv/linux/arm/clone.S
24+
@@ -56,7 +56,7 @@ ENTRY(__clone)
25+
swi 0x0
26+
cfi_endproc
27+
cmp r0, #0
28+
- beq 1f
29+
+ beq thread_start
30+
pop {r4, r7}
31+
blt PLTJMP(C_SYMBOL_NAME(__syscall_error))
32+
RETINSTR(, lr)
33+
@@ -64,9 +64,12 @@ ENTRY(__clone)
34+
cfi_startproc
35+
PSEUDO_END (__clone)
36+
37+
-1:
38+
+thread_start:
39+
.fnstart
40+
.cantunwind
41+
+
42+
+ @ clear the frame pointer register
43+
+ mov r11, 0
44+
@ pick the function arg and call address off the stack and execute
45+
ldr r0, [sp, #4]
46+
ldr ip, [sp], #8
47+
--
48+
2.43.0
49+

0 commit comments

Comments
 (0)