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

Fix PIE tests on ppc64le port #3498

Merged
merged 2 commits into from
Sep 14, 2023
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
2 changes: 0 additions & 2 deletions Documentation/backend_test_health.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ Tests skipped by each supported backend:
* 1 broken - cgo stacktraces
* linux/ppc64le/native skipped = 1
* 1 broken in linux ppc64le
* linux/ppc64le/native/pie skipped = 11
* 11 broken - pie mode
* pie skipped = 2
* 2 upstream issue - https://github.com/golang/go/issues/29322
* ppc64le skipped = 11
Expand Down
10 changes: 9 additions & 1 deletion pkg/proc/ppc64le_disasm.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,25 @@ func init() {
var tinyStacksplit = opcodeSeq{uint64(ppc64asm.ADDI), uint64(ppc64asm.CMPLD), uint64(ppc64asm.BC)}
var smallStacksplit = opcodeSeq{uint64(ppc64asm.ADDI), uint64(ppc64asm.CMPLD), uint64(ppc64asm.BC)}
var bigStacksplit = opcodeSeq{uint64(ppc64asm.ADDI), uint64(ppc64asm.CMPLD), uint64(ppc64asm.BC), uint64(ppc64asm.STD), uint64(ppc64asm.STD), uint64(ppc64asm.MFSPR)}
var adjustTOCPrologueOnPIE = opcodeSeq{uint64(ppc64asm.ADDIS), uint64(ppc64asm.ADDI)}

var unixGetG = opcodeSeq{uint64(ppc64asm.LD)}
var prologue opcodeSeq
prologuesPPC64LE = make([]opcodeSeq, 0, 3)
prologue = make(opcodeSeq, 0, 1)
for _, getG := range []opcodeSeq{unixGetG} {
for _, stacksplit := range []opcodeSeq{tinyStacksplit, smallStacksplit, bigStacksplit} {
prologue := make(opcodeSeq, 0, len(getG)+len(stacksplit))
prologue = append(prologue, getG...)
prologue = append(prologue, stacksplit...)
prologuesPPC64LE = append(prologuesPPC64LE, prologue)
}
}
// On PIE mode special prologue is generated two instructions before the function entry point that correlates to call target
// address, Teach delve to recognize this sequence to appropriately adjust PC address so that the breakpoint is actually hit
// while doing step
TOCprologue := make(opcodeSeq, 0, len(adjustTOCPrologueOnPIE))
TOCprologue = append(TOCprologue, adjustTOCPrologueOnPIE...)
prologuesPPC64LE = append(prologuesPPC64LE, TOCprologue)
}

func ppc64leAsmDecode(asmInst *AsmInstruction, mem []byte, regs *op.DwarfRegisters, memrw MemoryReadWriter, bi *BinaryInfo) error {
Expand Down
33 changes: 16 additions & 17 deletions pkg/proc/proc_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -905,7 +905,6 @@ func (l1 *loc) match(l2 proc.Stackframe) bool {
}

func TestStacktrace(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
stacks := [][]loc{
{{4, "main.stacktraceme"}, {8, "main.func1"}, {16, "main.main"}},
{{4, "main.stacktraceme"}, {8, "main.func1"}, {12, "main.func2"}, {17, "main.main"}},
Expand Down Expand Up @@ -990,7 +989,6 @@ func stackMatch(stack []loc, locations []proc.Stackframe, skipRuntime bool) bool

func TestStacktraceGoroutine(t *testing.T) {
skipOn(t, "broken - cgo stacktraces", "darwin", "arm64")
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")

mainStack := []loc{{14, "main.stacktraceme"}, {29, "main.main"}}
if goversion.VersionAfterOrEqual(runtime.Version(), 1, 11) {
Expand Down Expand Up @@ -1315,7 +1313,6 @@ func TestVariableEvaluation(t *testing.T) {
}

func TestFrameEvaluation(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
protest.AllowRecording(t)
lenient := false
if runtime.GOOS == "windows" {
Expand Down Expand Up @@ -2308,7 +2305,6 @@ func TestNextDeferReturnAndDirectCall(t *testing.T) {
}

func TestNextPanicAndDirectCall(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Next should not step into a deferred function if it is called
// directly, only if it is called through a panic or a deferreturn.
// Here we test the case where the function is called by a panic
Expand All @@ -2326,7 +2322,6 @@ func TestStepCall(t *testing.T) {
}

func TestStepCallPtr(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Tests that Step works correctly when calling functions with a
// function pointer.
if goversion.VersionAfterOrEqual(runtime.Version(), 1, 11) && !protest.RegabiSupported() {
Expand All @@ -2336,17 +2331,26 @@ func TestStepCallPtr(t *testing.T) {
{6, 7},
{7, 11}}, "", t)
} else {
testseq("teststepprog", contStep, []nextTest{
{9, 10},
{10, 5},
{5, 6},
{6, 7},
{7, 11}}, "", t)
if runtime.GOOS == "linux" && runtime.GOARCH == "ppc64le" && buildMode == "pie" {
testseq("teststepprog", contStep, []nextTest{
{9, 10},
{10, 5},
{5, 6},
{6, 7},
{7, 10},
{10, 11}}, "", t)
} else {
testseq("teststepprog", contStep, []nextTest{
{9, 10},
{10, 5},
{5, 6},
{6, 7},
{7, 11}}, "", t)
}
}
}

func TestStepReturnAndPanic(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Tests that Step works correctly when returning from functions
// and when a deferred function is called when panic'ing.
testseq("defercall", contStep, []nextTest{
Expand All @@ -2358,7 +2362,6 @@ func TestStepReturnAndPanic(t *testing.T) {
}

func TestStepDeferReturn(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Tests that Step works correctly when a deferred function is
// called during a return.
testseq("defercall", contStep, []nextTest{
Expand All @@ -2373,7 +2376,6 @@ func TestStepDeferReturn(t *testing.T) {
}

func TestStepIgnorePrivateRuntime(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Tests that Step will ignore calls to private runtime functions
// (such as runtime.convT2E in this case)
switch {
Expand Down Expand Up @@ -2752,7 +2754,6 @@ func TestIssue594(t *testing.T) {
}

func TestStepOutPanicAndDirectCall(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// StepOut should not step into a deferred function if it is called
// directly, only if it is called through a panic.
// Here we test the case where the function is called by a panic
Expand Down Expand Up @@ -5569,7 +5570,6 @@ func TestManualStopWhileStopped(t *testing.T) {
}

func TestDwrapStartLocation(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Tests that the start location of a goroutine is unwrapped in Go 1.17 and later.
withTestProcess("goroutinestackprog", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
setFunctionBreakpoint(p, t, "main.stacktraceme")
Expand Down Expand Up @@ -6071,7 +6071,6 @@ func TestEscapeCheckUnreadable(t *testing.T) {
}

func TestStepShadowConcurrentBreakpoint(t *testing.T) {
skipOn(t, "broken - pie mode", "linux", "ppc64le", "native", "pie")
// Checks that a StepBreakpoint can not shadow a concurrently hit user breakpoint
withTestProcess("stepshadow", t, func(p *proc.Target, grp *proc.TargetGroup, fixture protest.Fixture) {
break2 := setFunctionBreakpoint(p, t, "main.stacktraceme2")
Expand Down