The Hexagon XRay sled was 5 words (20 bytes) and the patched sequence clobbered r31 (the link register) via callr without saving it first. When the trampoline returned, the instrumented function's own allocframe would then save the wrong return address, causing a crash or misrouted return. Expand the sled to 7 words (28 bytes) and wrap the call with allocframe(#0)/deallocframe so the caller's r31:30 are preserved across the trampoline call. Detailed fixes: - HexagonAsmPrinter: emit 6 nop words after the jump (7 words total) - xray_hexagon.cpp: patch allocframe(#0) as first word, immext+r7 (func ID), immext+r6 (trampoline), callr r6, deallocframe; write the first word last for atomicity - xray_trampoline_hexagon.S: complete rewrite -- properly load and dereference the global handler pointer, save/restore r0-r5 and r31, add stack frame with correct 8-byte alignment, add jumpr r31 to actually return from trampolines - xray_interface.cpp: update Hexagon cSledLength from 20 to 28 - Update lit tests for 6-nop sled
41 lines
1.2 KiB
LLVM
41 lines
1.2 KiB
LLVM
; RUN: llc -mtriple=hexagon-unknown-elf < %s | FileCheck %s
|
|
; RUN: llc -mtriple=hexagon-unknown-linux-musl < %s | FileCheck %s
|
|
|
|
define i32 @foo() nounwind noinline uwtable "function-instrument"="xray-always" {
|
|
; CHECK-LABEL: .Lxray_sled_0:
|
|
; CHECK: jump .Ltmp[[#l:]]
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: .Ltmp
|
|
; CHECK-SAME: [[#l]]:
|
|
ret i32 0
|
|
; CHECK-LABEL: .Lxray_sled_1:
|
|
; CHECK: jump .Ltmp[[#l:]]
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: nop
|
|
; CHECK: .Ltmp
|
|
; CHECK-SAME: [[#l]]:
|
|
; CHECK: jumpr r31
|
|
}
|
|
; CHECK: .section xray_instr_map,"ao",@progbits,foo
|
|
; CHECK-NEXT: .Lxray_sleds_start0:
|
|
; CHECK-NEXT: [[TMP:.Ltmp[0-9]+]]:
|
|
; CHECK-NEXT: .word .Lxray_sled_0-[[TMP]]
|
|
; CHECK-NEXT: .word .Lfunc_begin0-([[TMP]]+4)
|
|
; CHECK-NEXT: .byte 0x00
|
|
; CHECK-NEXT: .byte 0x01
|
|
; CHECK-NEXT: .byte 0x02
|
|
; CHECK-NEXT: .space 5
|
|
; CHECK-LABEL: .Lxray_sleds_end0:
|
|
; CHECK-LABEL: xray_fn_idx
|
|
; CHECK: .word .Lxray_sleds_start0-.Lxray_fn_idx[[#]]
|
|
; CHECK-NEXT: .word 2
|