Skip to content

Commit 217507e

Browse files
committed
runtime: set vdsoSP to caller's SP consistently
m.vdsoSP should be set to the SP of the caller of nanotime1, instead of the SP of nanotime1 itself, which matches m.vdsoPC. Otherwise the unmatched vdsoPC and vdsoSP would make the stack trace look like recursive. We already do it correctly on AMD64, 386, and RISCV64. This CL fixes the rest. Fixes #47324. Change-Id: I98b6fcfbe9fc6bdd28b8fe2a1299b7c505371dd4 Reviewed-on: https://go-review.googlesource.com/c/go/+/337590 Trust: Cherry Mui <[email protected]> Trust: Josh Bleecher Snyder <[email protected]> Reviewed-by: Josh Bleecher Snyder <[email protected]>
1 parent fe8347b commit 217507e

5 files changed

Lines changed: 47 additions & 9 deletions

File tree

src/runtime/pprof/pprof_test.go

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1544,3 +1544,33 @@ func TestTryAdd(t *testing.T) {
15441544
})
15451545
}
15461546
}
1547+
1548+
func TestTimeVDSO(t *testing.T) {
1549+
// Test that time functions have the right stack trace. In particular,
1550+
// it shouldn't be recursive.
1551+
1552+
p := testCPUProfile(t, stackContains, []string{"time.now"}, avoidFunctions(), func(dur time.Duration) {
1553+
t0 := time.Now()
1554+
for {
1555+
t := time.Now()
1556+
if t.Sub(t0) >= dur {
1557+
return
1558+
}
1559+
}
1560+
})
1561+
1562+
// Check for recursive time.now sample.
1563+
for _, sample := range p.Sample {
1564+
var seenNow bool
1565+
for _, loc := range sample.Location {
1566+
for _, line := range loc.Line {
1567+
if line.Function.Name == "time.now" {
1568+
if seenNow {
1569+
t.Fatalf("unexpected recursive time.now")
1570+
}
1571+
seenNow = true
1572+
}
1573+
}
1574+
}
1575+
}
1576+
}

src/runtime/sys_linux_arm.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -259,8 +259,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$8-12
259259
MOVW R1, 4(R13)
260260
MOVW R2, 8(R13)
261261

262+
MOVW $ret-4(FP), R2 // caller's SP
262263
MOVW LR, m_vdsoPC(R5)
263-
MOVW R13, m_vdsoSP(R5)
264+
MOVW R2, m_vdsoSP(R5)
264265

265266
MOVW m_curg(R5), R0
266267

@@ -351,8 +352,9 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$8-8
351352
MOVW R1, 4(R13)
352353
MOVW R2, 8(R13)
353354

355+
MOVW $ret-4(FP), R2 // caller's SP
354356
MOVW LR, m_vdsoPC(R5)
355-
MOVW R13, m_vdsoSP(R5)
357+
MOVW R2, m_vdsoSP(R5)
356358

357359
MOVW m_curg(R5), R0
358360

src/runtime/sys_linux_arm64.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -221,8 +221,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$24-12
221221
MOVD R2, 8(RSP)
222222
MOVD R3, 16(RSP)
223223

224+
MOVD $ret-8(FP), R2 // caller's SP
224225
MOVD LR, m_vdsoPC(R21)
225-
MOVD R20, m_vdsoSP(R21)
226+
MOVD R2, m_vdsoSP(R21)
226227

227228
MOVD m_curg(R21), R0
228229
CMP g, R0
@@ -304,8 +305,9 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$24-8
304305
MOVD R2, 8(RSP)
305306
MOVD R3, 16(RSP)
306307

308+
MOVD $ret-8(FP), R2 // caller's SP
307309
MOVD LR, m_vdsoPC(R21)
308-
MOVD R20, m_vdsoSP(R21)
310+
MOVD R2, m_vdsoSP(R21)
309311

310312
MOVD m_curg(R21), R0
311313
CMP g, R0

src/runtime/sys_linux_mips64x.s

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$16-12
229229
MOVV R2, 8(R29)
230230
MOVV R3, 16(R29)
231231

232+
MOVV $ret-8(FP), R2 // caller's SP
232233
MOVV R31, m_vdsoPC(R17)
233-
MOVV R29, m_vdsoSP(R17)
234+
MOVV R2, m_vdsoSP(R17)
234235

235236
MOVV m_curg(R17), R4
236237
MOVV g, R5
@@ -298,8 +299,9 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$16-8
298299
MOVV R2, 8(R29)
299300
MOVV R3, 16(R29)
300301

302+
MOVV $ret-8(FP), R2 // caller's SP
301303
MOVV R31, m_vdsoPC(R17)
302-
MOVV R29, m_vdsoSP(R17)
304+
MOVV R2, m_vdsoSP(R17)
303305

304306
MOVV m_curg(R17), R4
305307
MOVV g, R5

src/runtime/sys_linux_ppc64x.s

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,9 @@ TEXT runtime·walltime(SB),NOSPLIT,$16-12
205205
MOVD R5, 40(R1)
206206

207207
MOVD LR, R14
208+
MOVD $ret-FIXED_FRAME(FP), R5 // caller's SP
208209
MOVD R14, m_vdsoPC(R21)
209-
MOVD R15, m_vdsoSP(R21)
210+
MOVD R5, m_vdsoSP(R21)
210211

211212
MOVD m_curg(R21), R6
212213
CMP g, R6
@@ -297,9 +298,10 @@ TEXT runtime·nanotime1(SB),NOSPLIT,$16-8
297298
MOVD R4, 32(R1)
298299
MOVD R5, 40(R1)
299300

300-
MOVD LR, R14 // R14 is unchanged by C code
301+
MOVD LR, R14 // R14 is unchanged by C code
302+
MOVD $ret-FIXED_FRAME(FP), R5 // caller's SP
301303
MOVD R14, m_vdsoPC(R21)
302-
MOVD R15, m_vdsoSP(R21)
304+
MOVD R5, m_vdsoSP(R21)
303305

304306
MOVD m_curg(R21), R6
305307
CMP g, R6

0 commit comments

Comments
 (0)