Skip to content

Commit f6a8388

Browse files
committed
Update SSA packages to remove dependency on pointer pkg
Signed-off-by: Tyler Gu <[email protected]>
1 parent e9886ea commit f6a8388

File tree

5 files changed

+71
-65
lines changed

5 files changed

+71
-65
lines changed

ssa/go.mod

+11-6
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,18 @@ module github.com/xlab-uiuc/acto/ssa
22

33
go 1.18
44

5-
require golang.org/x/tools v0.1.10
5+
require (
6+
golang.org/x/tools v0.22.0
7+
golang.org/x/tools/go/pointer v0.1.0-deprecated
8+
)
69

7-
require github.com/jinzhu/copier v0.3.2 // indirect
10+
require (
11+
github.com/jinzhu/copier v0.4.0 // indirect
12+
golang.org/x/sync v0.7.0 // indirect
13+
)
814

915
require (
10-
github.com/goki/ki v1.1.8
11-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 // indirect
12-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a // indirect
13-
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df // indirect
16+
github.com/goki/ki v1.1.17
17+
golang.org/x/mod v0.18.0 // indirect
18+
golang.org/x/sys v0.21.0 // indirect
1419
)

ssa/go.sum

+14-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
github.com/goki/ki v1.1.8 h1:CAkUXKuPeyhEuoX7++Wi+S0FM8VwOPd5fxaT+Cbgm7E=
2-
github.com/goki/ki v1.1.8/go.mod h1:8CF/Hl5lI5x09rlPLfJtw9w2XW/K6FK9eodjpeAKmNU=
3-
github.com/jinzhu/copier v0.3.2 h1:QdBOCbaouLDYaIPFfi1bKv5F5tPpeTwXe4sD0jqtz5w=
4-
github.com/jinzhu/copier v0.3.2/go.mod h1:24xnZezI2Yqac9J61UC6/dG/k76ttpq0DdJI3QmUvro=
5-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3 h1:kQgndtyPBW/JIYERgdxfwMYh3AVStj88WQTlNDi2a+o=
6-
golang.org/x/mod v0.6.0-dev.0.20220106191415-9b9b3d81d5e3/go.mod h1:3p9vT2HGsQu2K1YbXdKPJLVgG5VJdoTa1poYQBtP1AY=
7-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a h1:dGzPydgVsqGcTRVwiLJ1jVbufYwmzD3LfVPLKsKg+0k=
8-
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
9-
golang.org/x/tools v0.1.10 h1:QjFRCZxdOhBJ/UNgnBZLbNV13DlbnK0quyivTnXJM20=
10-
golang.org/x/tools v0.1.10/go.mod h1:Uh6Zz+xoGYZom868N8YTex3t7RhtHDBrE8Gzo9bV56E=
11-
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df h1:5Pf6pFKu98ODmgnpvkJ3kFUOQGGLIzLIkbzUHp47618=
12-
golang.org/x/xerrors v0.0.0-20220517211312-f3a8303e98df/go.mod h1:K8+ghG5WaK9qNqU5K3HdILfMLy1f3aNYFI/wnl100a8=
1+
github.com/goki/ki v1.1.17 h1:+g4FFSEB5tkw1h2+Ql2F40t47ilIX881KLxGp6800SI=
2+
github.com/goki/ki v1.1.17/go.mod h1:E+kCXzhA/chnUfo7ecneVn0A4n35KkXpJmFlRSkXhIY=
3+
github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8=
4+
github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg=
5+
golang.org/x/mod v0.18.0 h1:5+9lSbEzPSdWkH32vYPBwEpX8KwDbM52Ud9xBUvNlb0=
6+
golang.org/x/mod v0.18.0/go.mod h1:hTbmBsO62+eylJbnUtE2MGJUyE7QWk4xUqPFrRgJ+7c=
7+
golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M=
8+
golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
9+
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
10+
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
11+
golang.org/x/tools v0.22.0 h1:gqSGLZqv+AI9lIQzniJ0nZDRG5GBPsSi+DRNHWNz6yA=
12+
golang.org/x/tools v0.22.0/go.mod h1:aCwcsjqvq7Yqt6TNyX7QMU2enbQ/Gt0bo6krSeEri+c=
13+
golang.org/x/tools/go/pointer v0.1.0-deprecated h1:PwCkqv2FT35Z4MVxR/tUlvLoL0TkxDjShpBrE4p18Ho=
14+
golang.org/x/tools/go/pointer v0.1.0-deprecated/go.mod h1:Jd+I2inNruJ+5VRdS+jU4S1t17z5y+UCCRa/eBRwilA=

ssa/libanalysis.h

+8-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
#line 1 "cgo-builtin-export-prolog"
77

8-
#include <stddef.h> /* for ptrdiff_t below */
8+
#include <stddef.h>
99

1010
#ifndef GO_CGO_EXPORT_PROLOGUE_H
1111
#define GO_CGO_EXPORT_PROLOGUE_H
@@ -40,11 +40,17 @@ typedef long long GoInt64;
4040
typedef unsigned long long GoUint64;
4141
typedef GoInt64 GoInt;
4242
typedef GoUint64 GoUint;
43-
typedef __SIZE_TYPE__ GoUintptr;
43+
typedef size_t GoUintptr;
4444
typedef float GoFloat32;
4545
typedef double GoFloat64;
46+
#ifdef _MSC_VER
47+
#include <complex.h>
48+
typedef _Fcomplex GoComplex64;
49+
typedef _Dcomplex GoComplex128;
50+
#else
4651
typedef float _Complex GoComplex64;
4752
typedef double _Complex GoComplex128;
53+
#endif
4854

4955
/*
5056
static assertion to make sure the file is being used on architecture

ssa/ssa.go

+38-41
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@ import (
1313

1414
analysis "github.com/xlab-uiuc/acto/ssa/passes"
1515
"github.com/xlab-uiuc/acto/ssa/util"
16+
"golang.org/x/tools/go/callgraph/cha"
1617
"golang.org/x/tools/go/packages"
17-
"golang.org/x/tools/go/pointer"
1818
"golang.org/x/tools/go/ssa"
1919
"golang.org/x/tools/go/ssa/ssautil"
2020
)
@@ -48,7 +48,7 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
4848
}
4949

5050
// Create SSA packages for well-typed packages and their dependencies.
51-
prog, _ := ssautil.AllPackages(initial, 0)
51+
prog, _ := ssautil.AllPackages(initial, ssa.PrintFunctions)
5252

5353
// Build SSA code for the whole program.
5454
prog.Build()
@@ -75,17 +75,8 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
7575
log.Println("Running initial pass...")
7676
log.Printf("Root Module is %s\n", context.RootModule.Path)
7777

78-
log.Println("Constructing call graph using pointer analysis")
79-
pointerCfg := pointer.Config{
80-
Mains: context.MainPackages,
81-
BuildCallGraph: true,
82-
}
83-
log.Printf("Main packages %s\n", context.MainPackages)
84-
result, err := pointer.Analyze(&pointerCfg)
85-
if err != nil {
86-
log.Fatalf("Failed to run pointer analysis to construct callgraph %V\n", err)
87-
}
88-
context.CallGraph = result.CallGraph
78+
log.Println("Constructing call graph using CHA")
79+
context.CallGraph = cha.CallGraph(context.Program)
8980
log.Println("Finished constructing call graph")
9081

9182
valueFieldSetMap, frontierSet := analysis.GetValueToFieldMappingPass(context, prog, &seedType, &seedPkgPath)
@@ -106,43 +97,43 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
10697
for _, field := range mergedFieldSet.Fields() {
10798
analysisResult.UsedPaths = append(analysisResult.UsedPaths, field.Path)
10899
}
109-
taintedFieldSet := analysis.TaintAnalysisPass(context, prog, frontierSet, valueFieldSetMap)
110-
for _, field := range taintedFieldSet.Fields() {
111-
analysisResult.TaintedPaths = append(analysisResult.TaintedPaths, field.Path)
112-
}
100+
// taintedFieldSet := analysis.TaintAnalysisPass(context, prog, frontierSet, valueFieldSetMap)
101+
// for _, field := range taintedFieldSet.Fields() {
102+
// analysisResult.TaintedPaths = append(analysisResult.TaintedPaths, field.Path)
103+
// }
113104

114-
analysis.GetDefaultValue(context, frontierSet, valueFieldSetMap)
115-
for value, constant := range context.DefaultValueMap {
116-
for _, field := range context.ValueFieldMap[value].Fields() {
117-
analysisResult.DefaultValues[field.String()] = constant.Value.ExactString()
118-
}
119-
}
105+
// analysis.GetDefaultValue(context, frontierSet, valueFieldSetMap)
106+
// for value, constant := range context.DefaultValueMap {
107+
// for _, field := range context.ValueFieldMap[value].Fields() {
108+
// analysisResult.DefaultValues[field.String()] = constant.Value.ExactString()
109+
// }
110+
// }
120111

121-
analysis.Dominators(context, frontierSet)
122-
log.Printf("%s\n", context.String())
112+
// analysis.Dominators(context, frontierSet)
113+
// log.Printf("%s\n", context.String())
123114

124-
for field, conditionSet := range context.DomineeToConditions {
125-
var path []string
126-
json.Unmarshal([]byte(field), &path)
115+
// for field, conditionSet := range context.DomineeToConditions {
116+
// var path []string
117+
// json.Unmarshal([]byte(field), &path)
127118

128-
analysisResult.FieldConditions = append(analysisResult.FieldConditions, conditionSet.ToPlainConditionSet(path))
119+
// analysisResult.FieldConditions = append(analysisResult.FieldConditions, conditionSet.ToPlainConditionSet(path))
129120

130-
}
121+
// }
131122

132-
copiedOverFieldSet := analysis.GetCopyOverFields(context)
123+
// copiedOverFieldSet := analysis.GetCopyOverFields(context)
133124

134-
for _, field := range copiedOverFieldSet.Fields() {
135-
analysisResult.CopiedOverPaths = append(analysisResult.CopiedOverPaths, field.Path)
136-
log.Printf("Copied over path %s", field.Path)
137-
}
125+
// for _, field := range copiedOverFieldSet.Fields() {
126+
// analysisResult.CopiedOverPaths = append(analysisResult.CopiedOverPaths, field.Path)
127+
// log.Printf("Copied over path %s", field.Path)
128+
// }
138129

139130
// analysis.FindUsesInConditions(context, frontierSet)
140-
analysis.FindAllUses(context)
131+
// analysis.FindAllUses(context)
141132

142-
analysis.GetFieldToK8sMapping(context, context.Program, &seedType, &seedPkgPath)
143-
for field, mapping := range context.FieldToK8sMapping {
144-
analysisResult.FieldToK8sMapping[field.EncodedPath()] = mapping
145-
}
133+
// analysis.GetFieldToK8sMapping(context, context.Program, &seedType, &seedPkgPath)
134+
// for field, mapping := range context.FieldToK8sMapping {
135+
// analysisResult.FieldToK8sMapping[field.EncodedPath()] = mapping
136+
// }
146137

147138
marshalled, _ := json.MarshalIndent(analysisResult, "", "\t")
148139
return string(marshalled[:])
@@ -191,7 +182,13 @@ func main() {
191182

192183
log.Printf("Building ssa program for project %s\n", *projectPath)
193184

194-
analyze(*projectPath, *seedType, *seedPkgPath)
185+
result := analyze(*projectPath, *seedType, *seedPkgPath)
186+
resultFile, err := os.Create("result.json")
187+
if err != nil {
188+
fmt.Fprintf(os.Stderr, "failed to create file for result: %v", err)
189+
return
190+
}
191+
resultFile.WriteString(result)
195192
}
196193

197194
type AnalysisResult struct {

ssa/util/util.go

-4
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,6 @@ func FindSeedValues(prog *ssa.Program, seedType *string, pkgPath *string) []ssa.
139139
if strings.Contains(f.Name(), "DeepCopy") {
140140
continue
141141
}
142-
if f.String() == "github.com/rabbitmq/cluster-operator/internal/resource.updateProperty" {
143-
// seedVariables = append(seedVariables, getSeedVariablesFromFunction(f, seed.Type())...)
144-
f.WriteTo(log.Writer())
145-
}
146142
seedVariables = append(seedVariables, getSeedVariablesFromFunction(f, seed.Type())...)
147143
}
148144

0 commit comments

Comments
 (0)