Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions armhelpers/arm_helpers.go → asm/arm/helpers.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// Copyright The OpenTelemetry Authors
// SPDX-License-Identifier: Apache-2.0

// This package contains a series of helper functions that are useful for ARM disassembly.
package armhelpers // import "go.opentelemetry.io/ebpf-profiler/armhelpers"
package arm // import "go.opentelemetry.io/ebpf-profiler/asm/arm"

import (
"fmt"
Expand Down
13 changes: 6 additions & 7 deletions asm/arm/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ package arm // import "go.opentelemetry.io/ebpf-profiler/asm/arm"
import (
"fmt"

ah "go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
aa "golang.org/x/arch/arm64/arm64asm"
Expand Down Expand Up @@ -70,7 +69,7 @@ func ExtractTLSOffset(code []byte, baseAddr uint64, ef *pfelf.File) (int32, erro

// Check for MRS Xn, TPIDR_EL0 (system register S3_3_C13_C0_2)
if inst.Op == aa.MRS && inst.Args[1].String() == "S3_3_C13_C0_2" {
reg, ok := ah.Xreg2num(inst.Args[0])
reg, ok := Xreg2num(inst.Args[0])
if !ok {
continue
}
Expand All @@ -86,9 +85,9 @@ func ExtractTLSOffset(code []byte, baseAddr uint64, ef *pfelf.File) (int32, erro

// Check for ADD Xd, Xn, #imm
if nextInst.Op == aa.ADD {
destReg, destOk := ah.Xreg2num(nextInst.Args[0])
srcReg, srcOk := ah.Xreg2num(nextInst.Args[1])
imm, immOk := ah.DecodeImmediate(nextInst.Args[2])
destReg, destOk := Xreg2num(nextInst.Args[0])
srcReg, srcOk := Xreg2num(nextInst.Args[1])
imm, immOk := DecodeImmediate(nextInst.Args[2])

if destOk && srcOk && immOk && srcReg == tpReg {
if imm > 0 && imm < 0x1000 {
Expand All @@ -103,8 +102,8 @@ func ExtractTLSOffset(code []byte, baseAddr uint64, ef *pfelf.File) (int32, erro
if nextInst.Op == aa.LDR {
// Args[1] is MemImmediate
if mem, ok := nextInst.Args[1].(aa.MemImmediate); ok {
baseReg, regOk := ah.Xreg2num(mem.Base)
imm, immOk := ah.DecodeImmediate(mem)
baseReg, regOk := Xreg2num(mem.Base)
imm, immOk := DecodeImmediate(mem)

if regOk && immOk && baseReg == tpReg {
if imm > 0 && imm < 0x1000 {
Expand Down
4 changes: 2 additions & 2 deletions interpreter/golabels/tls_arm64.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ package golabels // import "go.opentelemetry.io/ebpf-profiler/interpreter/golabe
import (
"fmt"

"go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/libpf/pfelf"
"go.opentelemetry.io/ebpf-profiler/nativeunwind/elfunwindinfo"
Expand Down Expand Up @@ -82,7 +82,7 @@ func extractTLSGOffset(f *pfelf.File) (int32, error) {
// movk x27, #0x10
// For now, we'll just decode the immediate value from the movk instruction since the one from the movz
// instruction seems to always be 0.
imm, ok := armhelpers.DecodeImmediate(i.Args[1])
imm, ok := arm.DecodeImmediate(i.Args[1])
if ok {
return int32(imm), nil
}
Expand Down
6 changes: 3 additions & 3 deletions interpreter/hotspot/stubs.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"slices"
"strings"

"go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
"go.opentelemetry.io/ebpf-profiler/libpf"
"go.opentelemetry.io/ebpf-profiler/remotememory"
"go.opentelemetry.io/ebpf-profiler/support"
Expand Down Expand Up @@ -208,7 +208,7 @@ Outer:
if arg.Mode != aa.AddrPostIndex && arg.Mode != aa.AddrPreIndex {
continue
}
imm, ok := armhelpers.DecodeImmediate(arg)
imm, ok := arm.DecodeImmediate(arg)
if !ok {
continue
}
Expand All @@ -221,7 +221,7 @@ Outer:
continue Outer
}
}
imm, ok := armhelpers.DecodeImmediate(insn.Args[2])
imm, ok := arm.DecodeImmediate(insn.Args[2])
if !ok {
continue
}
Expand Down
16 changes: 8 additions & 8 deletions interpreter/php/decode_aarch64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"

ah "go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
"go.opentelemetry.io/ebpf-profiler/libpf"
aa "golang.org/x/arch/arm64/arm64asm"
)
Expand All @@ -34,13 +34,13 @@ func retrieveZendVMKindARM(code []byte) (uint, error) {
}

// We only care about writes into w0
dest, ok := ah.Xreg2num(inst.Args[0])
dest, ok := arm.Xreg2num(inst.Args[0])
if dest != 0 || !ok {
continue
}

if inst.Op == aa.MOV {
val, ok := ah.DecodeImmediate(inst.Args[1])
val, ok := arm.DecodeImmediate(inst.Args[1])
if !ok {
break
}
Expand Down Expand Up @@ -140,14 +140,14 @@ func retrieveJITBufferPtrARM(code []byte, addrBase libpf.SymbolValue) (
}

// We only care about writes into xn/wn registers.
dest, ok := ah.Xreg2num(inst.Args[0])
dest, ok := arm.Xreg2num(inst.Args[0])
if !ok {
continue
}

switch inst.Op {
case aa.ADD:
a2, ok := ah.DecodeImmediate(inst.Args[2])
a2, ok := arm.DecodeImmediate(inst.Args[2])
if !ok {
break
}
Expand All @@ -159,7 +159,7 @@ func retrieveJITBufferPtrARM(code []byte, addrBase libpf.SymbolValue) (
// Note that GDB lies to you here: it will give you
// a different value in the ASM listing compared to the
// disassembler
a2, ok := ah.DecodeImmediate(inst.Args[1])
a2, ok := arm.DecodeImmediate(inst.Args[1])
if !ok {
break
}
Expand All @@ -174,12 +174,12 @@ func retrieveJITBufferPtrARM(code []byte, addrBase libpf.SymbolValue) (
break
}

val, ok := ah.DecodeImmediate(m)
val, ok := arm.DecodeImmediate(m)
if !ok {
break
}

src, ok := ah.Xreg2num(m.Base)
src, ok := arm.Xreg2num(m.Base)
if !ok {
break
}
Expand Down
10 changes: 5 additions & 5 deletions interpreter/python/arm64_decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package python // import "go.opentelemetry.io/ebpf-profiler/interpreter/python"

import (
ah "go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
"go.opentelemetry.io/ebpf-profiler/libpf"
aa "golang.org/x/arch/arm64/arm64asm"
)
Expand Down Expand Up @@ -60,7 +60,7 @@ func decodeStubArgumentARM64(code []byte,
}

// Interested only on commands modifying Xn
dest, ok := ah.Xreg2num(inst.Args[0])
dest, ok := arm.Xreg2num(inst.Args[0])
if !ok {
continue
}
Expand All @@ -69,7 +69,7 @@ func decodeStubArgumentARM64(code []byte,
instRetval := libpf.SymbolValueInvalid
switch inst.Op {
case aa.ADD:
a2, ok := ah.DecodeImmediate(inst.Args[2])
a2, ok := arm.DecodeImmediate(inst.Args[2])
if !ok {
break
}
Expand All @@ -80,11 +80,11 @@ func decodeStubArgumentARM64(code []byte,
if !ok {
break
}
src, ok := ah.Xreg2num(m.Base)
src, ok := arm.Xreg2num(m.Base)
if !ok {
break
}
imm, ok := ah.DecodeImmediate(inst.Args[1])
imm, ok := arm.DecodeImmediate(inst.Args[1])
if !ok {
break
}
Expand Down
12 changes: 6 additions & 6 deletions libc/assembly_decode_aarch64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"

ah "go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
aa "golang.org/x/arch/arm64/arm64asm"
)

Expand Down Expand Up @@ -49,11 +49,11 @@ func analyzeTLSSetARM(code []byte) (uint32, error) {
switch inst.Op {
case aa.MOV:
// Track register moves
destReg, ok := ah.Xreg2num(inst.Args[0])
destReg, ok := arm.Xreg2num(inst.Args[0])
if !ok {
continue
}
if srcReg, ok := ah.Xreg2num(inst.Args[1]); ok {
if srcReg, ok := arm.Xreg2num(inst.Args[1]); ok {
arg[destReg] = arg[srcReg]
}
case aa.LDR:
Expand All @@ -63,12 +63,12 @@ func analyzeTLSSetARM(code []byte) (uint32, error) {
continue
}
var srcReg int
if srcReg, ok = ah.Xreg2num(m.Base); !ok || !arg[srcReg] {
if srcReg, ok = arm.Xreg2num(m.Base); !ok || !arg[srcReg] {
continue
}
// FIXME: m.imm is not public, but should be.
// https://github.com/golang/go/issues/51517
imm, ok := ah.DecodeImmediate(m)
imm, ok := arm.DecodeImmediate(m)
if !ok {
return 0, err
}
Expand All @@ -80,7 +80,7 @@ func analyzeTLSSetARM(code []byte) (uint32, error) {
return uint32(imm), nil
default:
// Reset register state if something unsupported happens on it
if destReg, ok := ah.Xreg2num(inst.Args[0]); ok {
if destReg, ok := arm.Xreg2num(inst.Args[0]); ok {
arg[destReg] = false
}
}
Expand Down
32 changes: 16 additions & 16 deletions libc/libc_aarch64.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"errors"
"fmt"

ah "go.opentelemetry.io/ebpf-profiler/armhelpers"
"go.opentelemetry.io/ebpf-profiler/asm/arm"
"go.opentelemetry.io/ebpf-profiler/stringutil"
aa "golang.org/x/arch/arm64/arm64asm"
)
Expand Down Expand Up @@ -57,7 +57,7 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
break
}

destReg, ok := ah.Xreg2num(inst.Args[0])
destReg, ok := arm.Xreg2num(inst.Args[0])
if !ok {
continue
}
Expand All @@ -80,7 +80,7 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
default:
// Track register moves
srcReg, ok := ah.Xreg2num(inst.Args[1])
srcReg, ok := arm.Xreg2num(inst.Args[1])
if !ok {
continue
}
Expand All @@ -100,12 +100,12 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
if !ok {
continue
}
srcReg, ok := ah.Xreg2num(m.Base)
srcReg, ok := arm.Xreg2num(m.Base)
if !ok {
continue
}
if regs[srcReg].status == TSDBase {
imm, ok := ah.DecodeImmediate(m)
imm, ok := arm.DecodeImmediate(m)
if !ok {
continue
}
Expand All @@ -122,11 +122,11 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
switch m := inst.Args[1].(type) {
case aa.MemExtend:
// LDR X0, [X1,W0,UXTW #3]
srcReg, ok := ah.Xreg2num(m.Base)
srcReg, ok := arm.Xreg2num(m.Base)
if !ok {
continue
}
srcIndex, ok := ah.Xreg2num(m.Index)
srcIndex, ok := arm.Xreg2num(m.Index)
if !ok {
continue
}
Expand All @@ -142,12 +142,12 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
case aa.MemImmediate:
// ldr x0, [x2, #8]
srcReg, ok := ah.Xreg2num(m.Base)
srcReg, ok := arm.Xreg2num(m.Base)
if !ok {
continue
}
if regs[srcReg].status == TSDElementBase {
i, ok := ah.DecodeImmediate(m)
i, ok := arm.DecodeImmediate(m)
if !ok {
continue
}
Expand All @@ -163,7 +163,7 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
case aa.UBFIZ:
// UBFIZ X0, X1, #4, #32
srcReg, ok := ah.Xreg2num(inst.Args[1])
srcReg, ok := arm.Xreg2num(inst.Args[1])
if !ok {
continue
}
Expand All @@ -179,13 +179,13 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
}
case aa.ADD:
srcReg, ok := ah.Xreg2num(inst.Args[1])
srcReg, ok := arm.Xreg2num(inst.Args[1])
if !ok {
continue
}
switch a2 := inst.Args[2].(type) {
case aa.ImmShift:
i, ok := ah.DecodeImmediate(a2)
i, ok := arm.DecodeImmediate(a2)
if !ok {
continue
}
Expand All @@ -205,11 +205,11 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
}
}
reg, ok := ah.DecodeRegister(regStr)
reg, ok := arm.DecodeRegister(regStr)
if !ok {
continue
}
srcReg2, ok := ah.Xreg2num(reg)
srcReg2, ok := arm.Xreg2num(reg)
if !ok {
continue
}
Expand All @@ -231,12 +231,12 @@ func extractTSDInfoARM(code []byte) (TSDInfo, error) {
}
}
case aa.SUB:
srcReg, ok := ah.Xreg2num(inst.Args[1])
srcReg, ok := arm.Xreg2num(inst.Args[1])
if !ok {
continue
}
if regs[srcReg].status != Unspec {
i, ok := ah.DecodeImmediate(inst.Args[2])
i, ok := arm.DecodeImmediate(inst.Args[2])
if !ok {
continue
}
Expand Down
Loading