Skip to content

Commit

Permalink
Update SSA packages to remove dependency on pointer pkg
Browse files Browse the repository at this point in the history
Signed-off-by: Tyler Gu <[email protected]>
  • Loading branch information
tylergu committed Jul 4, 2024
1 parent e9886ea commit f6a8388
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 65 deletions.
17 changes: 11 additions & 6 deletions ssa/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,18 @@ module github.com/xlab-uiuc/acto/ssa

go 1.18

require golang.org/x/tools v0.1.10
require (
golang.org/x/tools v0.22.0
golang.org/x/tools/go/pointer v0.1.0-deprecated
)

require github.com/jinzhu/copier v0.3.2 // indirect
require (
github.com/jinzhu/copier v0.4.0 // indirect
golang.org/x/sync v0.7.0 // indirect
)

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

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

#include <stddef.h> /* for ptrdiff_t below */
#include <stddef.h>

#ifndef GO_CGO_EXPORT_PROLOGUE_H
#define GO_CGO_EXPORT_PROLOGUE_H
Expand Down Expand Up @@ -40,11 +40,17 @@ typedef long long GoInt64;
typedef unsigned long long GoUint64;
typedef GoInt64 GoInt;
typedef GoUint64 GoUint;
typedef __SIZE_TYPE__ GoUintptr;
typedef size_t GoUintptr;
typedef float GoFloat32;
typedef double GoFloat64;
#ifdef _MSC_VER
#include <complex.h>
typedef _Fcomplex GoComplex64;
typedef _Dcomplex GoComplex128;
#else
typedef float _Complex GoComplex64;
typedef double _Complex GoComplex128;
#endif

/*
static assertion to make sure the file is being used on architecture
Expand Down
79 changes: 38 additions & 41 deletions ssa/ssa.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

analysis "github.com/xlab-uiuc/acto/ssa/passes"
"github.com/xlab-uiuc/acto/ssa/util"
"golang.org/x/tools/go/callgraph/cha"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/pointer"
"golang.org/x/tools/go/ssa"
"golang.org/x/tools/go/ssa/ssautil"
)
Expand Down Expand Up @@ -48,7 +48,7 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
}

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

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

log.Println("Constructing call graph using pointer analysis")
pointerCfg := pointer.Config{
Mains: context.MainPackages,
BuildCallGraph: true,
}
log.Printf("Main packages %s\n", context.MainPackages)
result, err := pointer.Analyze(&pointerCfg)
if err != nil {
log.Fatalf("Failed to run pointer analysis to construct callgraph %V\n", err)
}
context.CallGraph = result.CallGraph
log.Println("Constructing call graph using CHA")
context.CallGraph = cha.CallGraph(context.Program)
log.Println("Finished constructing call graph")

valueFieldSetMap, frontierSet := analysis.GetValueToFieldMappingPass(context, prog, &seedType, &seedPkgPath)
Expand All @@ -106,43 +97,43 @@ func analyze(projectPath string, seedType string, seedPkgPath string) string {
for _, field := range mergedFieldSet.Fields() {
analysisResult.UsedPaths = append(analysisResult.UsedPaths, field.Path)
}
taintedFieldSet := analysis.TaintAnalysisPass(context, prog, frontierSet, valueFieldSetMap)
for _, field := range taintedFieldSet.Fields() {
analysisResult.TaintedPaths = append(analysisResult.TaintedPaths, field.Path)
}
// taintedFieldSet := analysis.TaintAnalysisPass(context, prog, frontierSet, valueFieldSetMap)
// for _, field := range taintedFieldSet.Fields() {
// analysisResult.TaintedPaths = append(analysisResult.TaintedPaths, field.Path)
// }

analysis.GetDefaultValue(context, frontierSet, valueFieldSetMap)
for value, constant := range context.DefaultValueMap {
for _, field := range context.ValueFieldMap[value].Fields() {
analysisResult.DefaultValues[field.String()] = constant.Value.ExactString()
}
}
// analysis.GetDefaultValue(context, frontierSet, valueFieldSetMap)
// for value, constant := range context.DefaultValueMap {
// for _, field := range context.ValueFieldMap[value].Fields() {
// analysisResult.DefaultValues[field.String()] = constant.Value.ExactString()
// }
// }

analysis.Dominators(context, frontierSet)
log.Printf("%s\n", context.String())
// analysis.Dominators(context, frontierSet)
// log.Printf("%s\n", context.String())

for field, conditionSet := range context.DomineeToConditions {
var path []string
json.Unmarshal([]byte(field), &path)
// for field, conditionSet := range context.DomineeToConditions {
// var path []string
// json.Unmarshal([]byte(field), &path)

analysisResult.FieldConditions = append(analysisResult.FieldConditions, conditionSet.ToPlainConditionSet(path))
// analysisResult.FieldConditions = append(analysisResult.FieldConditions, conditionSet.ToPlainConditionSet(path))

}
// }

copiedOverFieldSet := analysis.GetCopyOverFields(context)
// copiedOverFieldSet := analysis.GetCopyOverFields(context)

for _, field := range copiedOverFieldSet.Fields() {
analysisResult.CopiedOverPaths = append(analysisResult.CopiedOverPaths, field.Path)
log.Printf("Copied over path %s", field.Path)
}
// for _, field := range copiedOverFieldSet.Fields() {
// analysisResult.CopiedOverPaths = append(analysisResult.CopiedOverPaths, field.Path)
// log.Printf("Copied over path %s", field.Path)
// }

// analysis.FindUsesInConditions(context, frontierSet)
analysis.FindAllUses(context)
// analysis.FindAllUses(context)

analysis.GetFieldToK8sMapping(context, context.Program, &seedType, &seedPkgPath)
for field, mapping := range context.FieldToK8sMapping {
analysisResult.FieldToK8sMapping[field.EncodedPath()] = mapping
}
// analysis.GetFieldToK8sMapping(context, context.Program, &seedType, &seedPkgPath)
// for field, mapping := range context.FieldToK8sMapping {
// analysisResult.FieldToK8sMapping[field.EncodedPath()] = mapping
// }

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

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

analyze(*projectPath, *seedType, *seedPkgPath)
result := analyze(*projectPath, *seedType, *seedPkgPath)
resultFile, err := os.Create("result.json")
if err != nil {
fmt.Fprintf(os.Stderr, "failed to create file for result: %v", err)
return
}
resultFile.WriteString(result)
}

type AnalysisResult struct {
Expand Down
4 changes: 0 additions & 4 deletions ssa/util/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,6 @@ func FindSeedValues(prog *ssa.Program, seedType *string, pkgPath *string) []ssa.
if strings.Contains(f.Name(), "DeepCopy") {
continue
}
if f.String() == "github.com/rabbitmq/cluster-operator/internal/resource.updateProperty" {
// seedVariables = append(seedVariables, getSeedVariablesFromFunction(f, seed.Type())...)
f.WriteTo(log.Writer())
}
seedVariables = append(seedVariables, getSeedVariablesFromFunction(f, seed.Type())...)
}

Expand Down

0 comments on commit f6a8388

Please sign in to comment.