diff options
-rw-r--r-- | builder/build.go | 2 | ||||
-rw-r--r-- | compileopts/config.go | 9 | ||||
-rw-r--r-- | compileopts/options.go | 1 | ||||
-rw-r--r-- | compiler/compiler_test.go | 2 | ||||
-rw-r--r-- | go.mod | 1 | ||||
-rw-r--r-- | go.sum | 2 | ||||
-rw-r--r-- | main.go | 8 | ||||
-rw-r--r-- | transform/stacksize.go | 2 | ||||
-rw-r--r-- | transform/stacksize_test.go | 1 |
9 files changed, 25 insertions, 3 deletions
diff --git a/builder/build.go b/builder/build.go index b171dc1f2..990d00b89 100644 --- a/builder/build.go +++ b/builder/build.go @@ -178,7 +178,7 @@ func Build(pkgName, outpath string, config *compileopts.Config, action func(Buil Scheduler: config.Scheduler(), AutomaticStackSize: config.AutomaticStackSize(), - DefaultStackSize: config.Target.DefaultStackSize, + DefaultStackSize: config.StackSize(), NeedsStackObjects: config.NeedsStackObjects(), Debug: true, } diff --git a/compileopts/config.go b/compileopts/config.go index 9ee6d0aa3..e1d1a311f 100644 --- a/compileopts/config.go +++ b/compileopts/config.go @@ -175,6 +175,15 @@ func (c *Config) AutomaticStackSize() bool { return false } +// StackSize returns the default stack size to be used for goroutines, if the +// stack size could not be determined automatically at compile time. +func (c *Config) StackSize() uint64 { + if c.Options.StackSize != 0 { + return c.Options.StackSize + } + return c.Target.DefaultStackSize +} + // UseThinLTO returns whether ThinLTO should be used for the given target. Some // targets (such as wasm) are not yet supported. // We should try and remove as many exceptions as possible in the future, so diff --git a/compileopts/options.go b/compileopts/options.go index 80667b8ee..242884abb 100644 --- a/compileopts/options.go +++ b/compileopts/options.go @@ -28,6 +28,7 @@ type Options struct { GC string PanicStrategy string Scheduler string + StackSize uint64 // goroutine stack size (if none could be automatically determined) Serial string Work bool // -work flag to print temporary build directory InterpTimeout time.Duration diff --git a/compiler/compiler_test.go b/compiler/compiler_test.go index 81deacbc7..2ed26921f 100644 --- a/compiler/compiler_test.go +++ b/compiler/compiler_test.go @@ -79,7 +79,7 @@ func TestCompiler(t *testing.T) { RelocationModel: config.RelocationModel(), Scheduler: config.Scheduler(), AutomaticStackSize: config.AutomaticStackSize(), - DefaultStackSize: config.Target.DefaultStackSize, + DefaultStackSize: config.StackSize(), NeedsStackObjects: config.NeedsStackObjects(), } machine, err := NewTargetMachine(compilerConfig) @@ -9,6 +9,7 @@ require ( github.com/chromedp/chromedp v0.7.6 github.com/gofrs/flock v0.8.1 github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf + github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf github.com/marcinbor85/gohex v0.0.0-20200531091804-343a4b548892 github.com/mattn/go-colorable v0.1.8 go.bug.st/serial v1.3.5 @@ -22,6 +22,8 @@ github.com/gofrs/flock v0.8.1 h1:+gYjHKf32LDeiEEFhQaotPbLuUXjY5ZqxKgXy7n59aw= github.com/gofrs/flock v0.8.1/go.mod h1:F1TvTiK9OcQqauNUHlbJvyl9Qa1QvF/gOUDKA14jxHU= github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf h1:7+FW5aGwISbqUtkfmIpZJGRgNFg2ioYPvFaUxdqpDsg= github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf/go.mod h1:RpwtwJQFrIEPstU94h88MWPXP2ektJZ8cZ0YntAmXiE= +github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf h1:FtEj8sfIcaaBfAKrE1Cwb61YDtYq9JxChK1c7AKce7s= +github.com/inhies/go-bytesize v0.0.0-20220417184213-4913239db9cf/go.mod h1:yrqSXGoD/4EKfF26AOGzscPOgTTJcyAwM2rpixWT+t4= github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY= github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y= github.com/mailru/easyjson v0.7.7 h1:UGYAvKxe3sBsEDzO8ZeWOSlIQfWFlxbzLZe7hwFURr0= @@ -26,6 +26,7 @@ import ( "time" "github.com/google/shlex" + "github.com/inhies/go-bytesize" "github.com/mattn/go-colorable" "github.com/tinygo-org/tinygo/builder" "github.com/tinygo-org/tinygo/compileopts" @@ -1318,6 +1319,12 @@ func main() { var tags buildutil.TagsFlag flag.Var(&tags, "tags", "a space-separated list of extra build tags") target := flag.String("target", "", "chip/board name or JSON target specification file") + var stackSize uint64 + flag.Func("stack-size", "goroutine stack size (if unknown at compile time)", func(s string) error { + size, err := bytesize.Parse(s) + stackSize = uint64(size) + return err + }) printSize := flag.String("size", "", "print sizes (none, short, full)") printStacks := flag.Bool("print-stacks", false, "print stack sizes of goroutines") printAllocsString := flag.String("print-allocs", "", "regular expression of functions for which heap allocations should be printed") @@ -1398,6 +1405,7 @@ func main() { GOARCH: goenv.Get("GOARCH"), GOARM: goenv.Get("GOARM"), Target: *target, + StackSize: stackSize, Opt: *opt, GC: *gc, PanicStrategy: *panicStrategy, diff --git a/transform/stacksize.go b/transform/stacksize.go index 4d8a13816..7be49238f 100644 --- a/transform/stacksize.go +++ b/transform/stacksize.go @@ -40,7 +40,7 @@ func CreateStackSizeLoads(mod llvm.Module, config *compileopts.Config) []string stackSizesGlobal := llvm.AddGlobal(mod, stackSizesGlobalType, "internal/task.stackSizes") stackSizesGlobal.SetSection(".tinygo_stacksizes") defaultStackSizes := make([]llvm.Value, len(functions)) - defaultStackSize := llvm.ConstInt(functions[0].Type(), config.Target.DefaultStackSize, false) + defaultStackSize := llvm.ConstInt(functions[0].Type(), config.StackSize(), false) for i := range defaultStackSizes { defaultStackSizes[i] = defaultStackSize } diff --git a/transform/stacksize_test.go b/transform/stacksize_test.go index c38a7b2f8..a96b7bb02 100644 --- a/transform/stacksize_test.go +++ b/transform/stacksize_test.go @@ -13,6 +13,7 @@ func TestCreateStackSizeLoads(t *testing.T) { testTransform(t, "testdata/stacksize", func(mod llvm.Module) { // Run optimization pass. transform.CreateStackSizeLoads(mod, &compileopts.Config{ + Options: &compileopts.Options{}, Target: &compileopts.TargetSpec{ DefaultStackSize: 1024, }, |