From 0fdf08d14fcfe928999d01ab62e031b82d4aa7bf Mon Sep 17 00:00:00 2001 From: Damian Gryski Date: Mon, 14 Apr 2025 17:01:03 -0700 Subject: [PATCH] add -nobounds (similar to -gcflags=-B) --- builder/build.go | 1 + compileopts/options.go | 1 + compiler/compiler.go | 1 + compiler/symbol.go | 4 ++++ main.go | 2 ++ 5 files changed, 9 insertions(+) diff --git a/builder/build.go b/builder/build.go index ee5f97ec5..cd650cfc4 100644 --- a/builder/build.go +++ b/builder/build.go @@ -214,6 +214,7 @@ func Build(pkgName, outpath, tmpdir string, config *compileopts.Config) (BuildRe MaxStackAlloc: config.MaxStackAlloc(), NeedsStackObjects: config.NeedsStackObjects(), Debug: !config.Options.SkipDWARF, // emit DWARF except when -internal-nodwarf is passed + Nobounds: config.Options.Nobounds, PanicStrategy: config.PanicStrategy(), } diff --git a/compileopts/options.go b/compileopts/options.go index 0ba8f359e..e718876a9 100644 --- a/compileopts/options.go +++ b/compileopts/options.go @@ -43,6 +43,7 @@ type Options struct { PrintCommands func(cmd string, args ...string) `json:"-"` Semaphore chan struct{} `json:"-"` // -p flag controls cap Debug bool + Nobounds bool PrintSizes string PrintAllocs *regexp.Regexp // regexp string PrintStacks bool diff --git a/compiler/compiler.go b/compiler/compiler.go index 28ec312dd..63d2c86ad 100644 --- a/compiler/compiler.go +++ b/compiler/compiler.go @@ -58,6 +58,7 @@ type Config struct { MaxStackAlloc uint64 NeedsStackObjects bool Debug bool // Whether to emit debug information in the LLVM module. + Nobounds bool // Whether to skip bounds checks PanicStrategy string } diff --git a/compiler/symbol.go b/compiler/symbol.go index 1226683d5..d3b8069a2 100644 --- a/compiler/symbol.go +++ b/compiler/symbol.go @@ -438,6 +438,10 @@ func (c *compilerContext) parsePragmas(info *functionInfo, f *ssa.Function) { } } } + + if c.Nobounds { + info.nobounds = true + } } // Check whether this function can be used in //go:wasmimport or diff --git a/main.go b/main.go index 465025156..5676c756d 100644 --- a/main.go +++ b/main.go @@ -1514,6 +1514,7 @@ func main() { printCommands := flag.Bool("x", false, "Print commands") parallelism := flag.Int("p", runtime.GOMAXPROCS(0), "the number of build jobs that can run in parallel") nodebug := flag.Bool("no-debug", false, "strip debug information") + nobounds := flag.Bool("nobounds", false, "do not emit bounds checks") ocdCommandsString := flag.String("ocd-commands", "", "OpenOCD commands, overriding target spec (can specify multiple separated by commas)") ocdOutput := flag.Bool("ocd-output", false, "print OCD daemon output during debug") port := flag.String("port", "", "flash port (can specify multiple candidates separated by commas)") @@ -1625,6 +1626,7 @@ func main() { SkipDWARF: *skipDwarf, Semaphore: make(chan struct{}, *parallelism), Debug: !*nodebug, + Nobounds: *nobounds, PrintSizes: *printSize, PrintStacks: *printStacks, PrintAllocs: printAllocs,