Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add check for Arm64 DWARF Expressions #2452

Closed
wants to merge 3 commits into from
Closed
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
53 changes: 37 additions & 16 deletions pkg/stack/unwind/dwarf_expression.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ const (
ExpressionUnknown DWARFExpressionID = iota
ExpressionPlt1
ExpressionPlt2
ExpressionArm1
ExpressionArm2
)

// DWARF expressions that we recognize.
Expand Down Expand Up @@ -71,25 +73,44 @@ func equalBytes(a, b []byte) bool {
return true
}

// expressionIdentifierX86 returns identifier for x86 DWARF Expressions.
func expressionIdentifierX86(cleanedExpression []byte) DWARFExpressionID {
if equalBytes(Plt1[:], cleanedExpression) {
return ExpressionPlt1
}
if equalBytes(Plt2[:], cleanedExpression) {
return ExpressionPlt2
}
return ExpressionUnknown
}

// expressionIdentifierArm64 returns identifier for Arm64 expressions.
func expressionIdentifierArm64(cleanedExpression []byte) DWARFExpressionID {
if equalBytes([]byte{frame.DW_CFA_def_cfa_expression}, cleanedExpression) {
return ExpressionArm1
}
if equalBytes([]byte{frame.DW_CFA_expression}, cleanedExpression) {
return ExpressionArm2
}
return ExpressionUnknown
}

// ExpressionIdentifier returns the identifier for recognized
// DWARF expressions.
func ExpressionIdentifier(expression []byte, arch elf.Machine) DWARFExpressionID {
if arch == elf.EM_X86_64 {
cleanedExpression := make([]byte, 0, len(expression))
for _, opcode := range expression {
if opcode == 0x0 {
continue
}
cleanedExpression = append(cleanedExpression, opcode)
}

if equalBytes(Plt1[:], cleanedExpression) {
return ExpressionPlt1
}

if equalBytes(Plt2[:], cleanedExpression) {
return ExpressionPlt2
cleanedExpression := make([]byte, 0, len(expression))
for _, opcode := range expression {
if opcode == 0x0 {
continue
}
cleanedExpression = append(cleanedExpression, opcode)
}
return ExpressionUnknown
var expressionID DWARFExpressionID
if arch == elf.EM_X86_64 {
expressionID = expressionIdentifierX86(cleanedExpression)
}
if arch == elf.EM_AARCH64 {
expressionID = expressionIdentifierArm64(cleanedExpression)
}
return expressionID
}
3 changes: 3 additions & 0 deletions pkg/stack/unwind/unwind_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ func (ptb *UnwindTableBuilder) PrintTable(writer io.Writer, file *objectfile.Obj
fmt.Fprintf(writer, "\tLoc: %x CFA: $%s=%-4d", unwindRow.Loc, CFAReg, unwindRow.CFA.Offset)
case frame.RuleExpression:
expressionID := ExpressionIdentifier(unwindRow.CFA.Expression, arch)
if expressionID == ExpressionArm1 || expressionID == ExpressionArm2 {
return fmt.Errorf("CFA rule at Loc: %x CFA: exp %d has not been implemented and is unexpected for Arm64", unwindRow.Loc, expressionID)
}
if expressionID == ExpressionUnknown {
fmt.Fprintf(writer, "\tLoc: %x CFA: exp ", unwindRow.Loc)
} else {
Expand Down
Loading