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
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
- name: golangci-lint
uses: golangci/golangci-lint-action@v9
with:
version: v2.11
version: v2.13
# Run go test to ensure tests pass
gotest:
name: tests
Expand Down
26 changes: 26 additions & 0 deletions cmd/stackwhere/list_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,32 @@ func TestListCollectionIncludesInstructionOnlyStackUsage(t *testing.T) {
}
}

func TestListCollectionSortsAfterInferringStackUsage(t *testing.T) {
cmd := root()
cmd.SetArgs([]string{"list", "../../testdata/noinline.o", "-j"})

var stdout bytes.Buffer
cmd.SetOut(&stdout)

if err := cmd.Execute(); err != nil {
t.Fatalf("list command failed: %v", err)
}

var got []stackview.ProgramStackUsage
if err := json.Unmarshal(stdout.Bytes(), &got); err != nil {
t.Fatalf("failed to decode JSON output: %v", err)
}

want := []stackview.ProgramStackUsage{
{Name: "entry", StackUsage: 8},
{Name: "z_known", StackUsage: 8},
{Name: "helper", StackUsage: 0},
}
if !slices.Equal(got, want) {
t.Fatalf("unexpected JSON output: got %#v want %#v", got, want)
}
}

func TestListCollectionIncludesVoidFunction(t *testing.T) {
cmd := root()
cmd.SetArgs([]string{"list", "../../testdata/noinline.o"})
Expand Down
6 changes: 3 additions & 3 deletions internal/stackview/stackview.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ func (a *Analyzer) CollectionSummaryInCollection() ([]ProgramStackUsage, error)
}

summary := a.CollectionSummary()
filtered := make([]ProgramStackUsage, 0, len(summary))
stackUsagePerProgram := make(map[string]int64, len(summary))
subProgsDwarf := a.tree.ByType(dbgdwarf.TagSubprogram)
for _, prog := range summary {
fn, ok := a.functions[prog.Name]
Expand All @@ -128,10 +128,10 @@ func (a *Analyzer) CollectionSummaryInCollection() ([]ProgramStackUsage, error)
prog.StackUsage = max(prog.StackUsage, inferredUsage)
}

filtered = append(filtered, prog)
stackUsagePerProgram[prog.Name] = prog.StackUsage
}

return filtered, nil
return SortProgramStackUsage(stackUsagePerProgram), nil
}

func stackUsageFromSlots(slots slotList) int64 {
Expand Down
9 changes: 9 additions & 0 deletions testdata/noinline.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#define __section(X) __attribute__((section(X), used))
#define __noinline __attribute__((noinline))
#define force_on_stack(x) asm volatile("" :: "r"(&(x)))

static __noinline void helper(int *value)
{
Expand All @@ -13,3 +14,11 @@ __section("tc") int entry(void *ctx)
helper(&value);
return value;
}

__section("tc/known") int z_known(void *ctx)
{
long value = 0;

force_on_stack(value);
return value;
}
Binary file modified testdata/noinline.o
Binary file not shown.