Skip to content

Commit dd5dc6f

Browse files
committed
arm64 replace call code use X27 register instead of X17 to avoid crash
1 parent 58bb448 commit dd5dc6f

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

asm_bytes.go

+3-6
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,10 @@ const (
1111
// arm/arm64
1212
var (
1313
armReplaceCallCode = []byte{0x04, 0xF0, 0x1F, 0xE5} //LDR PC, [PC, #-4]
14-
// X16 and X17 are the IP0 and IP1 intra-procedure-call corruptible registers -
15-
// since Go only uses them for the stack prologue and epilogue calculations,
16-
// and we should already be clear of that by the time we hit a R_CALLARM64,
17-
// so we should be able to safely use them for far jumps
14+
// register X27 reserved for liblink. see:^src/cmd/objfile/obj/arm64/a.out.go
1815
arm64ReplaceCALLCode = []byte{
19-
0x51, 0x00, 0x00, 0x58, // LDR X17 [PC+8] - read 64 bit address from PC+8 into X17
20-
0x20, 0x02, 0x1f, 0xd6, // BR X17 - jump to address in X17
16+
0x5B, 0x00, 0x00, 0x58, // LDR X27 [PC+8] - read 64 bit address from PC+8 into X27
17+
0x60, 0x03, 0x1F, 0xD6, // BR X27 - jump to address in X27
2118
}
2219
arm64Bcode = []byte{0x00, 0x00, 0x00, 0x14} // B [PC+0x0]
2320
arm64LDRcode = []byte{0x00, 0x00, 0x40, 0xF9} // LDR XX [XX]

0 commit comments

Comments
 (0)