2020-11-16 00:59:30 -05:00
|
|
|
// Copyright 2009 The Go Authors. All rights reserved.
|
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
|
2020-11-19 20:49:23 -05:00
|
|
|
package base
|
2020-11-16 00:59:30 -05:00
|
|
|
|
|
|
|
|
import (
|
|
|
|
|
"encoding/json"
|
|
|
|
|
"flag"
|
|
|
|
|
"fmt"
|
2021-04-15 23:05:49 -04:00
|
|
|
"internal/buildcfg"
|
2022-03-07 10:32:51 -05:00
|
|
|
"internal/coverage"
|
2022-10-04 09:00:31 -04:00
|
|
|
"internal/platform"
|
2020-11-16 00:59:30 -05:00
|
|
|
"log"
|
|
|
|
|
"os"
|
2020-11-16 01:15:33 -05:00
|
|
|
"reflect"
|
2020-11-16 00:59:30 -05:00
|
|
|
"runtime"
|
|
|
|
|
"strings"
|
|
|
|
|
|
2022-03-21 13:45:50 -04:00
|
|
|
"cmd/internal/obj"
|
2020-11-16 00:59:30 -05:00
|
|
|
"cmd/internal/objabi"
|
|
|
|
|
"cmd/internal/sys"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func usage() {
|
|
|
|
|
fmt.Fprintf(os.Stderr, "usage: compile [options] file.go...\n")
|
|
|
|
|
objabi.Flagprint(os.Stderr)
|
|
|
|
|
Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
// Flag holds the parsed command-line flags.
|
|
|
|
|
// See ParseFlag for non-zero defaults.
|
|
|
|
|
var Flag CmdFlags
|
|
|
|
|
|
|
|
|
|
// A CountFlag is a counting integer flag.
|
|
|
|
|
// It accepts -name=value to set the value directly,
|
|
|
|
|
// but it also accepts -name with no =value to increment the count.
|
|
|
|
|
type CountFlag int
|
|
|
|
|
|
|
|
|
|
// CmdFlags defines the command-line flags (see var Flag).
|
|
|
|
|
// Each struct field is a different flag, by default named for the lower-case of the field name.
|
|
|
|
|
// If the flag name is a single letter, the default flag name is left upper-case.
|
|
|
|
|
// If the flag name is "Lower" followed by a single letter, the default flag name is the lower-case of the last letter.
|
|
|
|
|
//
|
|
|
|
|
// If this default flag name can't be made right, the `flag` struct tag can be used to replace it,
|
|
|
|
|
// but this should be done only in exceptional circumstances: it helps everyone if the flag name
|
|
|
|
|
// is obvious from the field name when the flag is used elsewhere in the compiler sources.
|
|
|
|
|
// The `flag:"-"` struct tag makes a field invisible to the flag logic and should also be used sparingly.
|
|
|
|
|
//
|
|
|
|
|
// Each field must have a `help` struct tag giving the flag help message.
|
|
|
|
|
//
|
|
|
|
|
// The allowed field types are bool, int, string, pointers to those (for values stored elsewhere),
|
|
|
|
|
// CountFlag (for a counting flag), and func(string) (for a flag that uses special code for parsing).
|
|
|
|
|
type CmdFlags struct {
|
|
|
|
|
// Single letters
|
|
|
|
|
B CountFlag "help:\"disable bounds checking\""
|
|
|
|
|
C CountFlag "help:\"disable printing of columns in error messages\""
|
|
|
|
|
D string "help:\"set relative `path` for local imports\""
|
|
|
|
|
E CountFlag "help:\"debug symbol export\""
|
|
|
|
|
I func(string) "help:\"add `directory` to import search path\""
|
|
|
|
|
K CountFlag "help:\"debug missing line numbers\""
|
2022-03-23 13:29:43 -07:00
|
|
|
L CountFlag "help:\"also show actual source file names in error messages for positions affected by //line directives\""
|
2020-11-16 01:15:33 -05:00
|
|
|
N CountFlag "help:\"disable optimizations\""
|
|
|
|
|
S CountFlag "help:\"print assembly listing\""
|
|
|
|
|
// V is added by objabi.AddVersionFlag
|
|
|
|
|
W CountFlag "help:\"debug parse tree after type checking\""
|
|
|
|
|
|
2021-09-17 10:07:41 -04:00
|
|
|
LowerC int "help:\"concurrency during compilation (1 means no concurrency)\""
|
|
|
|
|
LowerD flag.Value "help:\"enable debugging settings; try -d help\""
|
|
|
|
|
LowerE CountFlag "help:\"no limit on number of errors reported\""
|
|
|
|
|
LowerH CountFlag "help:\"halt on error\""
|
|
|
|
|
LowerJ CountFlag "help:\"debug runtime-initialized variables\""
|
|
|
|
|
LowerL CountFlag "help:\"disable inlining\""
|
|
|
|
|
LowerM CountFlag "help:\"print optimization decisions\""
|
|
|
|
|
LowerO string "help:\"write output to `file`\""
|
|
|
|
|
LowerP *string "help:\"set expected package import `path`\"" // &Ctxt.Pkgpath, set below
|
|
|
|
|
LowerR CountFlag "help:\"debug generated wrappers\""
|
|
|
|
|
LowerT bool "help:\"enable tracing for debugging the compiler\""
|
|
|
|
|
LowerW CountFlag "help:\"debug type checking\""
|
|
|
|
|
LowerV *bool "help:\"increase debug verbosity\""
|
2020-11-16 01:15:33 -05:00
|
|
|
|
|
|
|
|
// Special characters
|
cmd/compile: handle simple inlined calls in staticinit
Global variable initializers like
var myErr error = &myError{"msg"}
have been converted to statically initialized data
from the earliest days of Go: there is no init-time
execution or allocation for that line of code.
But if the expression is moved into an inlinable function,
the static initialization no longer happens.
That is, this code has always executed and allocated
at init time, even after we added inlining to the compiler,
which should in theory make this code equivalent to
the original:
func NewError(s string) error { return &myError{s} }
var myErr2 = NewError("msg")
This CL makes the static initialization rewriter understand
inlined functions consisting of a single return statement,
like in this example, so that myErr2 can be implemented as
statically initialized data too, just like myErr, with no init-time
execution or allocation.
A real example of code that benefits from this rewrite is
all globally declared errors created with errors.New, like
package io
var EOF = errors.New("EOF")
Package io no longer has to allocate and initialize EOF each
time a program starts.
Another example of code that benefits is any globally declared
godebug setting (using the API from CL 449504), like
package http
var http2server = godebug.New("http2server")
These are no longer allocated and initialized at program startup either.
The list of functions that are inlined into static initializers when
compiling std and cmd (along with how many times each occurs) is:
cmd/compile/internal/ssa.StringToAux (3)
cmd/compile/internal/walk.mkmapnames (4)
errors.New (360)
go/ast.NewIdent (1)
go/constant.MakeBool (4)
go/constant.MakeInt64 (3)
image.NewUniform (4)
image/color.ModelFunc (11)
internal/godebug.New (12)
vendor/golang.org/x/text/unicode/bidi.newBidiTrie (1)
vendor/golang.org/x/text/unicode/norm.newNfcTrie (1)
vendor/golang.org/x/text/unicode/norm.newNfkcTrie (1)
For the cmd/go binary, this CL cuts the number of init-time
allocations from about 1920 to about 1620 (a 15% reduction).
The total executable code footprint of init functions is reduced
by 24kB, from 137kB to 113kB (an 18% reduction).
The overall binary size is reduced by 45kB,
from 15.335MB to 15.290MB (a 0.3% reduction).
(The binary size savings is larger than the executable code savings
because every byte of executable code also requires corresponding
runtime tables for unwinding, source-line mapping, and so on.)
Also merge test/sinit_run.go, which had stopped testing anything
at all as of CL 161337 (Feb 2019) and initempty.go into a new test
noinit.go.
Fixes #30820.
Change-Id: I52f7275b1ac2a0a32e22c29f9095071c7b1fac20
Reviewed-on: https://go-review.googlesource.com/c/go/+/450136
Reviewed-by: Cherry Mui <cherryyz@google.com>
Reviewed-by: Cuong Manh Le <cuong.manhle.vn@gmail.com>
Reviewed-by: Joedian Reid <joedian@golang.org>
Reviewed-by: Keith Randall <khr@golang.org>
Reviewed-by: Than McIntosh <thanm@google.com>
Auto-Submit: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
2022-11-13 09:22:35 -05:00
|
|
|
Percent CountFlag "flag:\"%\" help:\"debug non-static initializers\""
|
|
|
|
|
CompilingRuntime bool "flag:\"+\" help:\"compiling runtime\""
|
2020-11-16 01:15:33 -05:00
|
|
|
|
|
|
|
|
// Longer names
|
|
|
|
|
AsmHdr string "help:\"write assembly header to `file`\""
|
2021-01-04 17:14:35 +08:00
|
|
|
ASan bool "help:\"build code compatible with C/C++ address sanitizer\""
|
2020-11-16 01:15:33 -05:00
|
|
|
Bench string "help:\"append benchmark times to `file`\""
|
|
|
|
|
BlockProfile string "help:\"write block profile to `file`\""
|
|
|
|
|
BuildID string "help:\"record `id` as the build id in the export metadata\""
|
|
|
|
|
CPUProfile string "help:\"write cpu profile to `file`\""
|
|
|
|
|
Complete bool "help:\"compiling complete package (no C or assembly)\""
|
2021-03-12 18:38:02 -05:00
|
|
|
ClobberDead bool "help:\"clobber dead stack slots (for debugging)\""
|
2021-03-17 19:15:38 -04:00
|
|
|
ClobberDeadReg bool "help:\"clobber dead registers (for debugging)\""
|
2020-11-16 01:15:33 -05:00
|
|
|
Dwarf bool "help:\"generate DWARF symbols\""
|
|
|
|
|
DwarfBASEntries *bool "help:\"use base address selection entries in DWARF\"" // &Ctxt.UseBASEntries, set below
|
|
|
|
|
DwarfLocationLists *bool "help:\"add location lists to DWARF in optimized mode\"" // &Ctxt.Flag_locationlists, set below
|
|
|
|
|
Dynlink *bool "help:\"support references to Go symbols defined in other shared libraries\"" // &Ctxt.Flag_dynlink, set below
|
|
|
|
|
EmbedCfg func(string) "help:\"read go:embed configuration from `file`\""
|
|
|
|
|
GenDwarfInl int "help:\"generate DWARF inline info records\"" // 0=disabled, 1=funcs, 2=funcs+formals/locals
|
|
|
|
|
GoVersion string "help:\"required version of the runtime\""
|
|
|
|
|
ImportCfg func(string) "help:\"read import configuration from `file`\""
|
|
|
|
|
InstallSuffix string "help:\"set pkg directory `suffix`\""
|
|
|
|
|
JSON string "help:\"version,file for JSON compiler/optimizer detail output\""
|
|
|
|
|
Lang string "help:\"Go language version source code expects\""
|
|
|
|
|
LinkObj string "help:\"write linker-specific object to `file`\""
|
|
|
|
|
LinkShared *bool "help:\"generate code that will be linked against Go shared libraries\"" // &Ctxt.Flag_linkshared, set below
|
|
|
|
|
Live CountFlag "help:\"debug liveness analysis\""
|
|
|
|
|
MSan bool "help:\"build code compatible with C/C++ memory sanitizer\""
|
|
|
|
|
MemProfile string "help:\"write memory profile to `file`\""
|
2021-09-17 09:56:21 -04:00
|
|
|
MemProfileRate int "help:\"set runtime.MemProfileRate to `rate`\""
|
2020-11-16 01:15:33 -05:00
|
|
|
MutexProfile string "help:\"write mutex profile to `file`\""
|
|
|
|
|
NoLocalImports bool "help:\"reject local (relative) imports\""
|
2022-03-07 10:32:51 -05:00
|
|
|
CoverageCfg func(string) "help:\"read coverage configuration from `file`\""
|
2020-11-16 01:15:33 -05:00
|
|
|
Pack bool "help:\"write to file.a instead of file.o\""
|
|
|
|
|
Race bool "help:\"enable race detector\""
|
|
|
|
|
Shared *bool "help:\"generate code that can be linked into a shared library\"" // &Ctxt.Flag_shared, set below
|
|
|
|
|
SmallFrames bool "help:\"reduce the size limit for stack allocated objects\"" // small stacks, to diagnose GC latency; see golang.org/issue/27732
|
|
|
|
|
Spectre string "help:\"enable spectre mitigations in `list` (all, index, ret)\""
|
|
|
|
|
Std bool "help:\"compiling standard library\""
|
|
|
|
|
SymABIs string "help:\"read symbol ABIs from `file`\""
|
|
|
|
|
TraceProfile string "help:\"write an execution trace to `file`\""
|
|
|
|
|
TrimPath string "help:\"remove `prefix` from recorded source file paths\""
|
2023-01-12 10:32:33 -08:00
|
|
|
WB bool "help:\"enable write barrier\"" // TODO: remove
|
2022-09-09 11:29:32 -07:00
|
|
|
PgoProfile string "help:\"read profile from `file`\""
|
2023-03-15 14:03:49 -07:00
|
|
|
Url bool "help:\"print explanatory URL with error message if applicable\""
|
2020-11-16 01:15:33 -05:00
|
|
|
|
|
|
|
|
// Configuration derived from flags; not a flag itself.
|
2020-11-16 00:59:30 -05:00
|
|
|
Cfg struct {
|
2020-11-16 01:15:33 -05:00
|
|
|
Embed struct { // set by -embedcfg
|
2020-11-16 00:59:30 -05:00
|
|
|
Patterns map[string][]string
|
|
|
|
|
Files map[string]string
|
|
|
|
|
}
|
2022-03-07 10:32:51 -05:00
|
|
|
ImportDirs []string // appended to by -I
|
|
|
|
|
ImportMap map[string]string // set by -importcfg
|
|
|
|
|
PackageFile map[string]string // set by -importcfg; nil means not in use
|
|
|
|
|
CoverageInfo *coverage.CoverFixupConfig // set by -coveragecfg
|
|
|
|
|
SpectreIndex bool // set by -spectre=index or -spectre=all
|
2020-12-23 00:05:23 -05:00
|
|
|
// Whether we are adding any sort of code instrumentation, such as
|
|
|
|
|
// when the race detector is enabled.
|
|
|
|
|
Instrumenting bool
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
// ParseFlags parses the command-line flags into Flag.
|
2020-11-16 00:59:30 -05:00
|
|
|
func ParseFlags() {
|
2020-11-16 01:15:33 -05:00
|
|
|
Flag.I = addImportDir
|
|
|
|
|
|
2022-11-02 17:21:09 -04:00
|
|
|
Flag.LowerC = runtime.GOMAXPROCS(0)
|
2021-09-17 10:07:41 -04:00
|
|
|
Flag.LowerD = objabi.NewDebugFlag(&Debug, DebugSSA)
|
2020-11-16 01:15:33 -05:00
|
|
|
Flag.LowerP = &Ctxt.Pkgpath
|
|
|
|
|
Flag.LowerV = &Ctxt.Debugvlog
|
|
|
|
|
|
2021-04-15 23:05:49 -04:00
|
|
|
Flag.Dwarf = buildcfg.GOARCH != "wasm"
|
2020-11-16 01:15:33 -05:00
|
|
|
Flag.DwarfBASEntries = &Ctxt.UseBASEntries
|
|
|
|
|
Flag.DwarfLocationLists = &Ctxt.Flag_locationlists
|
|
|
|
|
*Flag.DwarfLocationLists = true
|
|
|
|
|
Flag.Dynlink = &Ctxt.Flag_dynlink
|
|
|
|
|
Flag.EmbedCfg = readEmbedCfg
|
|
|
|
|
Flag.GenDwarfInl = 2
|
|
|
|
|
Flag.ImportCfg = readImportCfg
|
2022-03-07 10:32:51 -05:00
|
|
|
Flag.CoverageCfg = readCoverageCfg
|
2020-11-16 01:15:33 -05:00
|
|
|
Flag.LinkShared = &Ctxt.Flag_linkshared
|
|
|
|
|
Flag.Shared = &Ctxt.Flag_shared
|
|
|
|
|
Flag.WB = true
|
2021-06-16 21:41:28 -07:00
|
|
|
|
2022-10-25 23:01:44 -04:00
|
|
|
Debug.ConcurrentOk = true
|
2021-02-25 12:13:23 -08:00
|
|
|
Debug.InlFuncsWithClosures = 1
|
2023-02-10 02:20:56 +07:00
|
|
|
Debug.InlStaticInit = 1
|
2022-07-12 11:04:44 -07:00
|
|
|
Debug.SyncFrames = -1 // disable sync markers by default
|
2020-11-16 01:15:33 -05:00
|
|
|
|
2021-03-23 15:24:27 -07:00
|
|
|
Debug.Checkptr = -1 // so we can tell whether it is set explicitly
|
|
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
Flag.Cfg.ImportMap = make(map[string]string)
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
objabi.AddVersionFlag() // -V
|
|
|
|
|
registerFlags()
|
2020-11-16 00:59:30 -05:00
|
|
|
objabi.Flagparse(usage)
|
|
|
|
|
|
2022-10-14 12:04:52 -04:00
|
|
|
if gcd := os.Getenv("GOCOMPILEDEBUG"); gcd != "" {
|
|
|
|
|
// This will only override the flags set in gcd;
|
|
|
|
|
// any others set on the command line remain set.
|
|
|
|
|
Flag.LowerD.Set(gcd)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Debug.Gossahash != "" {
|
cmd/compile: experimental loop iterator capture semantics change
Adds:
GOEXPERIMENT=loopvar (expected way of invoking)
-d=loopvar={-1,0,1,2,11,12} (for per-package control and/or logging)
-d=loopvarhash=... (for hash debugging)
loopvar=11,12 are for testing, benchmarking, and debugging.
If enabled,for loops of the form `for x,y := range thing`, if x and/or
y are addressed or captured by a closure, are transformed by renaming
x/y to a temporary and prepending an assignment to the body of the
loop x := tmp_x. This changes the loop semantics by making each
iteration's instance of x be distinct from the others (currently they
are all aliased, and when this matters, it is almost always a bug).
3-range with captured iteration variables are also transformed,
though it is a more complex transformation.
"Optimized" to do a simpler transformation for
3-clause for where the increment is empty.
(Prior optimization of address-taking under Return disabled, because
it was incorrect; returns can have loops for children. Restored in
a later CL.)
Includes support for -d=loopvarhash=<binary string> intended for use
with hash search and GOCOMPILEDEBUG=loopvarhash=<binary string>
(use `gossahash -e loopvarhash command-that-fails`).
Minor feature upgrades to hash-triggered features; clients can specify
that file-position hashes use only the most-inline position, and/or that
they use only the basenames of source files (not the full directory path).
Most-inlined is the right choice for debugging loop-iteration change
once the semantics are linked to the package across inlining; basename-only
makes it tractable to write tests (which, otherwise, depend on the full
pathname of the source file and thus vary).
Updates #57969.
Change-Id: I180a51a3f8d4173f6210c861f10de23de8a1b1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/411904
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-12 15:33:57 -04:00
|
|
|
hashDebug = NewHashDebug("gossahash", Debug.Gossahash, nil)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Three inputs govern loop iteration variable rewriting, hash, experiment, flag.
|
|
|
|
|
// The loop variable rewriting is:
|
|
|
|
|
// IF non-empty hash, then hash determines behavior (function+line match) (*)
|
|
|
|
|
// ELSE IF experiment and flag==0, then experiment (set flag=1)
|
|
|
|
|
// ELSE flag (note that build sets flag per-package), with behaviors:
|
|
|
|
|
// -1 => no change to behavior.
|
|
|
|
|
// 0 => no change to behavior (unless non-empty hash, see above)
|
|
|
|
|
// 1 => apply change to likely-iteration-variable-escaping loops
|
|
|
|
|
// 2 => apply change, log results
|
|
|
|
|
// 11 => apply change EVERYWHERE, do not log results (for debugging/benchmarking)
|
|
|
|
|
// 12 => apply change EVERYWHERE, log results (for debugging/benchmarking)
|
|
|
|
|
//
|
|
|
|
|
// The expected uses of the these inputs are, in believed most-likely to least likely:
|
|
|
|
|
// GOEXPERIMENT=loopvar -- apply change to entire application
|
|
|
|
|
// -gcflags=some_package=-d=loopvar=1 -- apply change to some_package (**)
|
|
|
|
|
// -gcflags=some_package=-d=loopvar=2 -- apply change to some_package, log it
|
|
|
|
|
// GOEXPERIMENT=loopvar -gcflags=some_package=-d=loopvar=-1 -- apply change to all but one package
|
|
|
|
|
// GOCOMPILEDEBUG=loopvarhash=... -- search for failure cause
|
|
|
|
|
//
|
|
|
|
|
// (*) For debugging purposes, providing loopvar flag >= 11 will expand the hash-eligible set of loops to all.
|
2023-04-06 10:09:51 -04:00
|
|
|
// (**) Loop semantics, changed or not, follow code from a package when it is inlined; that is, the behavior
|
|
|
|
|
// of an application compiled with partially modified loop semantics does not depend on inlining.
|
cmd/compile: experimental loop iterator capture semantics change
Adds:
GOEXPERIMENT=loopvar (expected way of invoking)
-d=loopvar={-1,0,1,2,11,12} (for per-package control and/or logging)
-d=loopvarhash=... (for hash debugging)
loopvar=11,12 are for testing, benchmarking, and debugging.
If enabled,for loops of the form `for x,y := range thing`, if x and/or
y are addressed or captured by a closure, are transformed by renaming
x/y to a temporary and prepending an assignment to the body of the
loop x := tmp_x. This changes the loop semantics by making each
iteration's instance of x be distinct from the others (currently they
are all aliased, and when this matters, it is almost always a bug).
3-range with captured iteration variables are also transformed,
though it is a more complex transformation.
"Optimized" to do a simpler transformation for
3-clause for where the increment is empty.
(Prior optimization of address-taking under Return disabled, because
it was incorrect; returns can have loops for children. Restored in
a later CL.)
Includes support for -d=loopvarhash=<binary string> intended for use
with hash search and GOCOMPILEDEBUG=loopvarhash=<binary string>
(use `gossahash -e loopvarhash command-that-fails`).
Minor feature upgrades to hash-triggered features; clients can specify
that file-position hashes use only the most-inline position, and/or that
they use only the basenames of source files (not the full directory path).
Most-inlined is the right choice for debugging loop-iteration change
once the semantics are linked to the package across inlining; basename-only
makes it tractable to write tests (which, otherwise, depend on the full
pathname of the source file and thus vary).
Updates #57969.
Change-Id: I180a51a3f8d4173f6210c861f10de23de8a1b1db
Reviewed-on: https://go-review.googlesource.com/c/go/+/411904
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Run-TryBot: David Chase <drchase@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
2022-06-12 15:33:57 -04:00
|
|
|
|
|
|
|
|
if Debug.LoopVarHash != "" {
|
|
|
|
|
// This first little bit controls the inputs for debug-hash-matching.
|
|
|
|
|
basenameOnly := false
|
|
|
|
|
mostInlineOnly := true
|
|
|
|
|
if strings.HasPrefix(Debug.LoopVarHash, "FS") {
|
|
|
|
|
// Magic handshake for testing, use file suffixes only when hashing on a position.
|
|
|
|
|
// i.e., rather than /tmp/asdfasdfasdf/go-test-whatever/foo_test.go,
|
|
|
|
|
// hash only on "foo_test.go", so that it will be the same hash across all runs.
|
|
|
|
|
Debug.LoopVarHash = Debug.LoopVarHash[2:]
|
|
|
|
|
basenameOnly = true
|
|
|
|
|
}
|
|
|
|
|
if strings.HasPrefix(Debug.LoopVarHash, "IL") {
|
|
|
|
|
// When hash-searching on a position that is an inline site, default is to use the
|
|
|
|
|
// most-inlined position only. This makes the hash faster, plus there's no point
|
|
|
|
|
// reporting a problem with all the inlining; there's only one copy of the source.
|
|
|
|
|
// However, if for some reason you wanted it per-site, you can get this. (The default
|
|
|
|
|
// hash-search behavior for compiler debugging is at an inline site.)
|
|
|
|
|
Debug.LoopVarHash = Debug.LoopVarHash[2:]
|
|
|
|
|
mostInlineOnly = false
|
|
|
|
|
}
|
|
|
|
|
// end of testing trickiness
|
|
|
|
|
LoopVarHash = NewHashDebug("loopvarhash", Debug.LoopVarHash, nil)
|
|
|
|
|
if Debug.LoopVar < 11 { // >= 11 means all loops are rewrite-eligible
|
|
|
|
|
Debug.LoopVar = 1 // 1 means those loops that syntactically escape their dcl vars are eligible.
|
|
|
|
|
}
|
|
|
|
|
LoopVarHash.SetInlineSuffixOnly(mostInlineOnly)
|
|
|
|
|
LoopVarHash.SetFileSuffixOnly(basenameOnly)
|
|
|
|
|
} else if buildcfg.Experiment.LoopVar && Debug.LoopVar == 0 {
|
|
|
|
|
Debug.LoopVar = 1
|
2022-10-14 12:04:52 -04:00
|
|
|
}
|
|
|
|
|
|
cmd/compile: add debug-hash flag for fused-multiply-add
This adds a -d debug flag "fmahash" for hashcode search for
floating point architecture-dependent problems. This variable has no
effect on architectures w/o fused-multiply-add.
This was rebased onto the GOSSAHASH renovation so that this could have
its own dedicated environment variable, and so that it would be
cheap (a nil check) to check it in the normal case.
Includes a basic test of the trigger plumbing.
Sample use (on arm64, ppc64le, s390x):
% GOCOMPILEDEBUG=fmahash=001110110 \
go build -o foo cmd/compile/internal/ssa/testdata/fma.go
fmahash triggered main.main:24 101111101101111001110110
GOFMAHASH triggered main.main:20 010111010000101110111011
1.0000000000000002 1.0000000000000004 -2.220446049250313e-16
exit status 1
The intended use is in conjunction with github.com/dr2chase/gossahash,
which will probably acquire a flag "-fma" to streamline its use. This
tool+use was inspired by an ad hoc use of this technique "in anger"
to debug this very problem. This is also a dry-run for using this
same technique to identify code sensitive to loop variable
lifetime/capture, should we make that change.
Example intended use, with current search tool (using old environment
variable), for a test example:
gossahash -e GOFMAHASH GOMAGIC=GOFMAHASH go run fma.go
Trying go args=[...], env=[GOFMAHASH=1 GOMAGIC=GOFMAHASH]
go failed (81 distinct triggers): exit status 1
Trying go args=[...], env=[GOFMAHASH=11 GOMAGIC=GOFMAHASH]
go failed (39 distinct triggers): exit status 1
Trying go args=[...], env=[GOFMAHASH=011 GOMAGIC=GOFMAHASH]
go failed (18 distinct triggers): exit status 1
Trying go args=[...], env=[GOFMAHASH=0011 GOMAGIC=GOFMAHASH]
Trying go args=[...], env=[GOFMAHASH=1011 GOMAGIC=GOFMAHASH]
...
Trying go args=[...], env=[GOFMAHASH=0110111011 GOMAGIC=GOFMAHASH]
Trying go args=[...], env=[GOFMAHASH=1110111011 GOMAGIC=GOFMAHASH]
go failed (2 distinct triggers): exit status 1
Trigger string is 'GOFMAHASH triggered math.qzero:427 111111101010011110111011', repeated 6 times
Trigger string is 'GOFMAHASH triggered main.main:20 010111010000101110111011', repeated 1 times
Trying go args=[...], env=[GOFMAHASH=01110111011 GOMAGIC=GOFMAHASH]
go failed (1 distinct triggers): exit status 1
Trigger string is 'GOFMAHASH triggered main.main:20 010111010000101110111011', repeated 1 times
Review GSHS_LAST_FAIL.0.log for failing run
FINISHED, suggest this command line for debugging:
GOSSAFUNC='main.main:20 010111010000101110111011' \
GOFMAHASH=01110111011 GOMAGIC=GOFMAHASH go run fma.go
Change-Id: Ifa22dd8f1c37c18fc8a4f7c396345a364bc367d5
Reviewed-on: https://go-review.googlesource.com/c/go/+/394754
TryBot-Result: Gopher Robot <gobot@golang.org>
Run-TryBot: David Chase <drchase@google.com>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-10-21 18:10:23 -04:00
|
|
|
if Debug.Fmahash != "" {
|
|
|
|
|
FmaHash = NewHashDebug("fmahash", Debug.Fmahash, nil)
|
|
|
|
|
}
|
|
|
|
|
|
2022-10-04 09:00:31 -04:00
|
|
|
if Flag.MSan && !platform.MSanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
|
2021-04-15 23:05:49 -04:00
|
|
|
log.Fatalf("%s/%s does not support -msan", buildcfg.GOOS, buildcfg.GOARCH)
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
2022-10-04 09:00:31 -04:00
|
|
|
if Flag.ASan && !platform.ASanSupported(buildcfg.GOOS, buildcfg.GOARCH) {
|
2021-01-04 17:14:35 +08:00
|
|
|
log.Fatalf("%s/%s does not support -asan", buildcfg.GOOS, buildcfg.GOARCH)
|
|
|
|
|
}
|
2022-10-04 09:00:31 -04:00
|
|
|
if Flag.Race && !platform.RaceDetectorSupported(buildcfg.GOOS, buildcfg.GOARCH) {
|
2021-04-15 23:05:49 -04:00
|
|
|
log.Fatalf("%s/%s does not support -race", buildcfg.GOOS, buildcfg.GOARCH)
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
2022-12-04 15:06:45 +08:00
|
|
|
if (*Flag.Shared || *Flag.Dynlink || *Flag.LinkShared) && !Ctxt.Arch.InFamily(sys.AMD64, sys.ARM, sys.ARM64, sys.I386, sys.Loong64, sys.PPC64, sys.RISCV64, sys.S390X) {
|
2021-04-15 23:05:49 -04:00
|
|
|
log.Fatalf("%s/%s does not support -shared", buildcfg.GOOS, buildcfg.GOARCH)
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
2021-01-15 14:12:35 -08:00
|
|
|
parseSpectre(Flag.Spectre) // left as string for RecordFlags
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
Ctxt.Flag_shared = Ctxt.Flag_dynlink || Ctxt.Flag_shared
|
2020-11-16 00:59:30 -05:00
|
|
|
Ctxt.Flag_optimize = Flag.N == 0
|
2020-11-16 01:15:33 -05:00
|
|
|
Ctxt.Debugasm = int(Flag.S)
|
2019-08-20 17:39:09 -04:00
|
|
|
Ctxt.Flag_maymorestack = Debug.MayMoreStack
|
2022-05-05 17:22:17 -04:00
|
|
|
Ctxt.Flag_noRefName = Debug.NoRefName != 0
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:44:47 -05:00
|
|
|
if flag.NArg() < 1 {
|
2020-11-16 00:59:30 -05:00
|
|
|
usage()
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Flag.GoVersion != "" && Flag.GoVersion != runtime.Version() {
|
|
|
|
|
fmt.Printf("compile: version %q does not match go tool version %q\n", runtime.Version(), Flag.GoVersion)
|
|
|
|
|
Exit(2)
|
|
|
|
|
}
|
|
|
|
|
|
cmd/compile: require -p flag
The -p flag specifies the import path of the package being compiled.
This CL makes it required when invoking the compiler and
adjusts tests that invoke the compiler directly to conform to this
new requirement. The go command already passes the flag, so it
is unmodified in this CL. It is expected that any other Go build systems
also already pass -p, or else they will need to arrange to do so before
updating to Go 1.19. Of particular note, Bazel already does for rules
with an importpath= attribute, which includes all Gazelle-generated rules.
There is more cleanup possible now in cmd/compile, cmd/link,
and other consumers of Go object files, but that is left to future CLs.
Additional historical background follows but can be ignored.
Long ago, before the go command, or modules, or any kind of
versioning, symbols in Go archive files were named using just the
package name, so that for example func F in math/rand and func F in
crypto/rand would both be the object file symbol 'rand.F'. This led to
collisions even in small source trees, which made certain packages
unusable in the presence of other packages and generally was a problem
for Go's goal of scaling to very large source trees.
Fixing this problem required changing from package names to import
paths in symbol names, which was mostly straightforward. One wrinkle,
though, is that the compiler did not know the import path of the
package being compiled; it only knew the package name. At the time,
there was no go command, just Makefiles that people had invoking 6g
(now “go tool compile”) and then copying the resulting object file to
an importable location. That is, everyone had a custom build setup for
Go, because there was no standard one. So it was not particularly
attractive to change how the compiler was invoked, since that would
break approximately every Go user at the time. Instead, we arranged
for the compiler to emit, and other tools reading object files to
recognize, a special import path (the empty string, it turned out)
denoting “the import path of this object file”. This worked well
enough at the time and maintained complete command-line compatibility
with existing Go usage.
The changes implementing this transition can be found by searching
the Git history for “package global name space”, which is what they
eliminated. In particular, CL 190076 (a6736fa4), CL 186263 (758f2bc5),
CL 193080 (1cecac81), CL 194053 (19126320), and CL 194071 (531e6b77)
did the bulk of this transformation in January 2010.
Later, in September 2011, we added the -p flag to the compiler for
diagnostic purposes. The problem was that it was easy to create import
cycles, especially in tests, and these could not be diagnosed until
link time. You'd really want the compiler to diagnose these, for
example if the compilation of package sort noticed it was importing a
package that itself imported "sort". But the compilation of package
sort didn't know its own import path, and so it could not tell whether
it had found itself as a transitive dependency. Adding the -p flag
solved this problem, and its use was optional, since the linker would
still diagnose the import cycle in builds that had not updated to
start passing -p. This was CL 4972057 (1e480cd1).
There was still no go command at this point, but when we introduced
the go command we made it pass -p, which it has for many years at this
point.
Over time, parts of the compiler began to depend on the presence of
the -p flag for various reasonable purposes. For example:
In CL 6497074 (041fc8bf; Oct 2012), the race detector used -p to
detect packages that should not have race annotations, such as
runtime/race and sync/atomic.
In CL 13367052 (7276c02b; Sep 2013), a bug fix used -p to detect the
compilation of package reflect.
In CL 30539 (8aadcc55; Oct 2016), the compiler started using -p to
identify package math, to be able to intrinsify calls to Sqrt inside
that package.
In CL 61019 (9daee931; Sep 2017), CL 71430 (2c1d2e06; Oct 2017), and
later related CLs, the compiler started using the -p value when
creating various DWARF debugging information.
In CL 174657 (cc5eaf93; May 2019), the compiler started writing
symbols without the magic empty string whenever -p was used, to reduce
the amount of work required in the linker.
In CL 179861 (dde7c770; Jun 2019), the compiler made the second
argument to //go:linkname optional when -p is used, because in that
case the compiler can derive an appropriate default.
There are more examples. Today it is impossible to compile the Go
standard library without using -p, and DWARF debug information is
incomplete without using -p.
All known Go build systems pass -p. In particular, the go command
does, which is what nearly all Go developers invoke to build Go code.
And Bazel does, for go_library rules that set the importpath
attribute, which is all rules generated by Gazelle.
Gccgo has an equivalent of -p and has required its use in order to
disambiguate packages with the same name but different import paths
since 2010.
On top of all this, various parts of code generation for generics
are made more complicated by needing to cope with the case where -p
is not specified, even though it's essentially always specified.
In summary, the current state is:
- Use of the -p flag with cmd/compile is required for building
the standard library, and for complete DWARF information,
and to enable certain linker speedups.
- The go command and Bazel, which we expect account for just
about 100% of Go builds, both invoke cmd/compile with -p.
- The code in cmd/compile to support builds without -p is
complex and has become more complex with generics, but it is
almost always dead code and therefore not worth maintaining.
- Gccgo already requires its equivalent of -p in any build
where two packages have the same name.
All this supports the change in this CL, which makes -p required
and adjusts tests that invoke cmd/compile to add -p appropriately.
Future CLs will be able to remove all the code dealing with the
possibility of -p not having been specified.
Change-Id: I6b95b9d4cffe59c7bac82eb273ef6c4a67bb0e43
Reviewed-on: https://go-review.googlesource.com/c/go/+/391014
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-03-08 18:16:35 -05:00
|
|
|
if *Flag.LowerP == "" {
|
2022-03-21 13:45:50 -04:00
|
|
|
*Flag.LowerP = obj.UnlinkablePkg
|
cmd/compile: require -p flag
The -p flag specifies the import path of the package being compiled.
This CL makes it required when invoking the compiler and
adjusts tests that invoke the compiler directly to conform to this
new requirement. The go command already passes the flag, so it
is unmodified in this CL. It is expected that any other Go build systems
also already pass -p, or else they will need to arrange to do so before
updating to Go 1.19. Of particular note, Bazel already does for rules
with an importpath= attribute, which includes all Gazelle-generated rules.
There is more cleanup possible now in cmd/compile, cmd/link,
and other consumers of Go object files, but that is left to future CLs.
Additional historical background follows but can be ignored.
Long ago, before the go command, or modules, or any kind of
versioning, symbols in Go archive files were named using just the
package name, so that for example func F in math/rand and func F in
crypto/rand would both be the object file symbol 'rand.F'. This led to
collisions even in small source trees, which made certain packages
unusable in the presence of other packages and generally was a problem
for Go's goal of scaling to very large source trees.
Fixing this problem required changing from package names to import
paths in symbol names, which was mostly straightforward. One wrinkle,
though, is that the compiler did not know the import path of the
package being compiled; it only knew the package name. At the time,
there was no go command, just Makefiles that people had invoking 6g
(now “go tool compile”) and then copying the resulting object file to
an importable location. That is, everyone had a custom build setup for
Go, because there was no standard one. So it was not particularly
attractive to change how the compiler was invoked, since that would
break approximately every Go user at the time. Instead, we arranged
for the compiler to emit, and other tools reading object files to
recognize, a special import path (the empty string, it turned out)
denoting “the import path of this object file”. This worked well
enough at the time and maintained complete command-line compatibility
with existing Go usage.
The changes implementing this transition can be found by searching
the Git history for “package global name space”, which is what they
eliminated. In particular, CL 190076 (a6736fa4), CL 186263 (758f2bc5),
CL 193080 (1cecac81), CL 194053 (19126320), and CL 194071 (531e6b77)
did the bulk of this transformation in January 2010.
Later, in September 2011, we added the -p flag to the compiler for
diagnostic purposes. The problem was that it was easy to create import
cycles, especially in tests, and these could not be diagnosed until
link time. You'd really want the compiler to diagnose these, for
example if the compilation of package sort noticed it was importing a
package that itself imported "sort". But the compilation of package
sort didn't know its own import path, and so it could not tell whether
it had found itself as a transitive dependency. Adding the -p flag
solved this problem, and its use was optional, since the linker would
still diagnose the import cycle in builds that had not updated to
start passing -p. This was CL 4972057 (1e480cd1).
There was still no go command at this point, but when we introduced
the go command we made it pass -p, which it has for many years at this
point.
Over time, parts of the compiler began to depend on the presence of
the -p flag for various reasonable purposes. For example:
In CL 6497074 (041fc8bf; Oct 2012), the race detector used -p to
detect packages that should not have race annotations, such as
runtime/race and sync/atomic.
In CL 13367052 (7276c02b; Sep 2013), a bug fix used -p to detect the
compilation of package reflect.
In CL 30539 (8aadcc55; Oct 2016), the compiler started using -p to
identify package math, to be able to intrinsify calls to Sqrt inside
that package.
In CL 61019 (9daee931; Sep 2017), CL 71430 (2c1d2e06; Oct 2017), and
later related CLs, the compiler started using the -p value when
creating various DWARF debugging information.
In CL 174657 (cc5eaf93; May 2019), the compiler started writing
symbols without the magic empty string whenever -p was used, to reduce
the amount of work required in the linker.
In CL 179861 (dde7c770; Jun 2019), the compiler made the second
argument to //go:linkname optional when -p is used, because in that
case the compiler can derive an appropriate default.
There are more examples. Today it is impossible to compile the Go
standard library without using -p, and DWARF debug information is
incomplete without using -p.
All known Go build systems pass -p. In particular, the go command
does, which is what nearly all Go developers invoke to build Go code.
And Bazel does, for go_library rules that set the importpath
attribute, which is all rules generated by Gazelle.
Gccgo has an equivalent of -p and has required its use in order to
disambiguate packages with the same name but different import paths
since 2010.
On top of all this, various parts of code generation for generics
are made more complicated by needing to cope with the case where -p
is not specified, even though it's essentially always specified.
In summary, the current state is:
- Use of the -p flag with cmd/compile is required for building
the standard library, and for complete DWARF information,
and to enable certain linker speedups.
- The go command and Bazel, which we expect account for just
about 100% of Go builds, both invoke cmd/compile with -p.
- The code in cmd/compile to support builds without -p is
complex and has become more complex with generics, but it is
almost always dead code and therefore not worth maintaining.
- Gccgo already requires its equivalent of -p in any build
where two packages have the same name.
All this supports the change in this CL, which makes -p required
and adjusts tests that invoke cmd/compile to add -p appropriately.
Future CLs will be able to remove all the code dealing with the
possibility of -p not having been specified.
Change-Id: I6b95b9d4cffe59c7bac82eb273ef6c4a67bb0e43
Reviewed-on: https://go-review.googlesource.com/c/go/+/391014
Trust: Russ Cox <rsc@golang.org>
Run-TryBot: Russ Cox <rsc@golang.org>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
2022-03-08 18:16:35 -05:00
|
|
|
}
|
|
|
|
|
|
2020-11-16 00:59:30 -05:00
|
|
|
if Flag.LowerO == "" {
|
|
|
|
|
p := flag.Arg(0)
|
|
|
|
|
if i := strings.LastIndex(p, "/"); i >= 0 {
|
|
|
|
|
p = p[i+1:]
|
|
|
|
|
}
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
if i := strings.LastIndex(p, `\`); i >= 0 {
|
|
|
|
|
p = p[i+1:]
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if i := strings.LastIndex(p, "."); i >= 0 {
|
|
|
|
|
p = p[:i]
|
|
|
|
|
}
|
|
|
|
|
suffix := ".o"
|
|
|
|
|
if Flag.Pack {
|
|
|
|
|
suffix = ".a"
|
|
|
|
|
}
|
|
|
|
|
Flag.LowerO = p + suffix
|
|
|
|
|
}
|
2021-01-04 17:14:35 +08:00
|
|
|
switch {
|
|
|
|
|
case Flag.Race && Flag.MSan:
|
2020-11-16 00:59:30 -05:00
|
|
|
log.Fatal("cannot use both -race and -msan")
|
2021-01-04 17:14:35 +08:00
|
|
|
case Flag.Race && Flag.ASan:
|
|
|
|
|
log.Fatal("cannot use both -race and -asan")
|
|
|
|
|
case Flag.MSan && Flag.ASan:
|
|
|
|
|
log.Fatal("cannot use both -msan and -asan")
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
2021-01-04 17:14:35 +08:00
|
|
|
if Flag.Race || Flag.MSan || Flag.ASan {
|
|
|
|
|
// -race, -msan and -asan imply -d=checkptr for now.
|
2021-03-23 15:24:27 -07:00
|
|
|
if Debug.Checkptr == -1 { // if not set explicitly
|
|
|
|
|
Debug.Checkptr = 1
|
|
|
|
|
}
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Flag.CompilingRuntime && Flag.N != 0 {
|
|
|
|
|
log.Fatal("cannot disable optimizations while compiling runtime")
|
|
|
|
|
}
|
|
|
|
|
if Flag.LowerC < 1 {
|
|
|
|
|
log.Fatalf("-c must be at least 1, got %d", Flag.LowerC)
|
|
|
|
|
}
|
2022-11-02 17:21:09 -04:00
|
|
|
if !concurrentBackendAllowed() {
|
|
|
|
|
Flag.LowerC = 1
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Flag.CompilingRuntime {
|
|
|
|
|
// Runtime can't use -d=checkptr, at least not yet.
|
2020-11-16 01:17:25 -05:00
|
|
|
Debug.Checkptr = 0
|
2020-11-16 00:59:30 -05:00
|
|
|
|
|
|
|
|
// Fuzzing the runtime isn't interesting either.
|
2020-11-16 01:17:25 -05:00
|
|
|
Debug.Libfuzzer = 0
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
|
|
|
|
|
2021-03-23 15:24:27 -07:00
|
|
|
if Debug.Checkptr == -1 { // if not set explicitly
|
|
|
|
|
Debug.Checkptr = 0
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 00:59:30 -05:00
|
|
|
// set via a -d flag
|
2020-11-16 01:17:25 -05:00
|
|
|
Ctxt.Debugpcln = Debug.PCTab
|
2020-11-16 01:15:33 -05:00
|
|
|
}
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
// registerFlags adds flag registrations for all the fields in Flag.
|
|
|
|
|
// See the comment on type CmdFlags for the rules.
|
|
|
|
|
func registerFlags() {
|
|
|
|
|
var (
|
|
|
|
|
boolType = reflect.TypeOf(bool(false))
|
|
|
|
|
intType = reflect.TypeOf(int(0))
|
|
|
|
|
stringType = reflect.TypeOf(string(""))
|
|
|
|
|
ptrBoolType = reflect.TypeOf(new(bool))
|
|
|
|
|
ptrIntType = reflect.TypeOf(new(int))
|
|
|
|
|
ptrStringType = reflect.TypeOf(new(string))
|
|
|
|
|
countType = reflect.TypeOf(CountFlag(0))
|
|
|
|
|
funcType = reflect.TypeOf((func(string))(nil))
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
v := reflect.ValueOf(&Flag).Elem()
|
|
|
|
|
t := v.Type()
|
|
|
|
|
for i := 0; i < t.NumField(); i++ {
|
|
|
|
|
f := t.Field(i)
|
|
|
|
|
if f.Name == "Cfg" {
|
|
|
|
|
continue
|
|
|
|
|
}
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
var name string
|
|
|
|
|
if len(f.Name) == 1 {
|
|
|
|
|
name = f.Name
|
|
|
|
|
} else if len(f.Name) == 6 && f.Name[:5] == "Lower" && 'A' <= f.Name[5] && f.Name[5] <= 'Z' {
|
|
|
|
|
name = string(rune(f.Name[5] + 'a' - 'A'))
|
|
|
|
|
} else {
|
|
|
|
|
name = strings.ToLower(f.Name)
|
|
|
|
|
}
|
|
|
|
|
if tag := f.Tag.Get("flag"); tag != "" {
|
|
|
|
|
name = tag
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
help := f.Tag.Get("help")
|
|
|
|
|
if help == "" {
|
|
|
|
|
panic(fmt.Sprintf("base.Flag.%s is missing help text", f.Name))
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if k := f.Type.Kind(); (k == reflect.Ptr || k == reflect.Func) && v.Field(i).IsNil() {
|
|
|
|
|
panic(fmt.Sprintf("base.Flag.%s is uninitialized %v", f.Name, f.Type))
|
|
|
|
|
}
|
2020-11-16 00:59:30 -05:00
|
|
|
|
2020-11-16 01:15:33 -05:00
|
|
|
switch f.Type {
|
|
|
|
|
case boolType:
|
|
|
|
|
p := v.Field(i).Addr().Interface().(*bool)
|
|
|
|
|
flag.BoolVar(p, name, *p, help)
|
|
|
|
|
case intType:
|
|
|
|
|
p := v.Field(i).Addr().Interface().(*int)
|
|
|
|
|
flag.IntVar(p, name, *p, help)
|
|
|
|
|
case stringType:
|
|
|
|
|
p := v.Field(i).Addr().Interface().(*string)
|
|
|
|
|
flag.StringVar(p, name, *p, help)
|
|
|
|
|
case ptrBoolType:
|
|
|
|
|
p := v.Field(i).Interface().(*bool)
|
|
|
|
|
flag.BoolVar(p, name, *p, help)
|
|
|
|
|
case ptrIntType:
|
|
|
|
|
p := v.Field(i).Interface().(*int)
|
|
|
|
|
flag.IntVar(p, name, *p, help)
|
|
|
|
|
case ptrStringType:
|
|
|
|
|
p := v.Field(i).Interface().(*string)
|
|
|
|
|
flag.StringVar(p, name, *p, help)
|
|
|
|
|
case countType:
|
|
|
|
|
p := (*int)(v.Field(i).Addr().Interface().(*CountFlag))
|
|
|
|
|
objabi.Flagcount(name, help, p)
|
|
|
|
|
case funcType:
|
|
|
|
|
f := v.Field(i).Interface().(func(string))
|
|
|
|
|
objabi.Flagfn1(name, help, f)
|
2021-09-17 09:56:21 -04:00
|
|
|
default:
|
2021-09-17 10:07:41 -04:00
|
|
|
if val, ok := v.Field(i).Interface().(flag.Value); ok {
|
|
|
|
|
flag.Var(val, name, help)
|
|
|
|
|
} else {
|
|
|
|
|
panic(fmt.Sprintf("base.Flag.%s has unexpected type %s", f.Name, f.Type))
|
|
|
|
|
}
|
2020-11-16 01:15:33 -05:00
|
|
|
}
|
2020-11-16 00:59:30 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// concurrentFlagOk reports whether the current compiler flags
|
|
|
|
|
// are compatible with concurrent compilation.
|
|
|
|
|
func concurrentFlagOk() bool {
|
|
|
|
|
// TODO(rsc): Many of these are fine. Remove them.
|
|
|
|
|
return Flag.Percent == 0 &&
|
|
|
|
|
Flag.E == 0 &&
|
|
|
|
|
Flag.K == 0 &&
|
|
|
|
|
Flag.L == 0 &&
|
|
|
|
|
Flag.LowerH == 0 &&
|
|
|
|
|
Flag.LowerJ == 0 &&
|
|
|
|
|
Flag.LowerM == 0 &&
|
|
|
|
|
Flag.LowerR == 0
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func concurrentBackendAllowed() bool {
|
|
|
|
|
if !concurrentFlagOk() {
|
|
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Debug.S by itself is ok, because all printing occurs
|
|
|
|
|
// while writing the object file, and that is non-concurrent.
|
|
|
|
|
// Adding Debug_vlog, however, causes Debug.S to also print
|
|
|
|
|
// while flushing the plist, which happens concurrently.
|
2022-10-25 23:01:44 -04:00
|
|
|
if Ctxt.Debugvlog || !Debug.ConcurrentOk || Flag.Live > 0 {
|
2020-11-16 00:59:30 -05:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// TODO: Test and delete this condition.
|
2021-04-15 23:05:49 -04:00
|
|
|
if buildcfg.Experiment.FieldTrack {
|
2020-11-16 00:59:30 -05:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
// TODO: fix races and enable the following flags
|
2021-10-04 12:14:10 -07:00
|
|
|
if Ctxt.Flag_dynlink || Flag.Race {
|
2020-11-16 00:59:30 -05:00
|
|
|
return false
|
|
|
|
|
}
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func addImportDir(dir string) {
|
|
|
|
|
if dir != "" {
|
|
|
|
|
Flag.Cfg.ImportDirs = append(Flag.Cfg.ImportDirs, dir)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func readImportCfg(file string) {
|
|
|
|
|
if Flag.Cfg.ImportMap == nil {
|
|
|
|
|
Flag.Cfg.ImportMap = make(map[string]string)
|
|
|
|
|
}
|
|
|
|
|
Flag.Cfg.PackageFile = map[string]string{}
|
2022-08-28 03:38:00 +08:00
|
|
|
data, err := os.ReadFile(file)
|
2020-11-16 00:59:30 -05:00
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("-importcfg: %v", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
for lineNum, line := range strings.Split(string(data), "\n") {
|
|
|
|
|
lineNum++ // 1-based
|
|
|
|
|
line = strings.TrimSpace(line)
|
|
|
|
|
if line == "" || strings.HasPrefix(line, "#") {
|
|
|
|
|
continue
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var verb, args string
|
|
|
|
|
if i := strings.Index(line, " "); i < 0 {
|
|
|
|
|
verb = line
|
|
|
|
|
} else {
|
|
|
|
|
verb, args = line[:i], strings.TrimSpace(line[i+1:])
|
|
|
|
|
}
|
|
|
|
|
var before, after string
|
|
|
|
|
if i := strings.Index(args, "="); i >= 0 {
|
|
|
|
|
before, after = args[:i], args[i+1:]
|
|
|
|
|
}
|
|
|
|
|
switch verb {
|
|
|
|
|
default:
|
|
|
|
|
log.Fatalf("%s:%d: unknown directive %q", file, lineNum, verb)
|
|
|
|
|
case "importmap":
|
|
|
|
|
if before == "" || after == "" {
|
|
|
|
|
log.Fatalf(`%s:%d: invalid importmap: syntax is "importmap old=new"`, file, lineNum)
|
|
|
|
|
}
|
|
|
|
|
Flag.Cfg.ImportMap[before] = after
|
|
|
|
|
case "packagefile":
|
|
|
|
|
if before == "" || after == "" {
|
|
|
|
|
log.Fatalf(`%s:%d: invalid packagefile: syntax is "packagefile path=filename"`, file, lineNum)
|
|
|
|
|
}
|
|
|
|
|
Flag.Cfg.PackageFile[before] = after
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-03-07 10:32:51 -05:00
|
|
|
func readCoverageCfg(file string) {
|
|
|
|
|
var cfg coverage.CoverFixupConfig
|
2022-09-28 09:12:11 +00:00
|
|
|
data, err := os.ReadFile(file)
|
2022-03-07 10:32:51 -05:00
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("-coveragecfg: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(data, &cfg); err != nil {
|
|
|
|
|
log.Fatalf("error reading -coveragecfg file %q: %v", file, err)
|
|
|
|
|
}
|
|
|
|
|
Flag.Cfg.CoverageInfo = &cfg
|
|
|
|
|
}
|
|
|
|
|
|
2020-11-16 00:59:30 -05:00
|
|
|
func readEmbedCfg(file string) {
|
2022-08-28 03:38:00 +08:00
|
|
|
data, err := os.ReadFile(file)
|
2020-11-16 00:59:30 -05:00
|
|
|
if err != nil {
|
|
|
|
|
log.Fatalf("-embedcfg: %v", err)
|
|
|
|
|
}
|
|
|
|
|
if err := json.Unmarshal(data, &Flag.Cfg.Embed); err != nil {
|
|
|
|
|
log.Fatalf("%s: %v", file, err)
|
|
|
|
|
}
|
|
|
|
|
if Flag.Cfg.Embed.Patterns == nil {
|
|
|
|
|
log.Fatalf("%s: invalid embedcfg: missing Patterns", file)
|
|
|
|
|
}
|
|
|
|
|
if Flag.Cfg.Embed.Files == nil {
|
|
|
|
|
log.Fatalf("%s: invalid embedcfg: missing Files", file)
|
|
|
|
|
}
|
|
|
|
|
}
|
2020-11-16 01:15:33 -05:00
|
|
|
|
|
|
|
|
// parseSpectre parses the spectre configuration from the string s.
|
|
|
|
|
func parseSpectre(s string) {
|
|
|
|
|
for _, f := range strings.Split(s, ",") {
|
|
|
|
|
f = strings.TrimSpace(f)
|
|
|
|
|
switch f {
|
|
|
|
|
default:
|
|
|
|
|
log.Fatalf("unknown setting -spectre=%s", f)
|
|
|
|
|
case "":
|
|
|
|
|
// nothing
|
|
|
|
|
case "all":
|
|
|
|
|
Flag.Cfg.SpectreIndex = true
|
|
|
|
|
Ctxt.Retpoline = true
|
|
|
|
|
case "index":
|
|
|
|
|
Flag.Cfg.SpectreIndex = true
|
|
|
|
|
case "ret":
|
|
|
|
|
Ctxt.Retpoline = true
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if Flag.Cfg.SpectreIndex {
|
2021-04-15 23:05:49 -04:00
|
|
|
switch buildcfg.GOARCH {
|
2020-11-16 01:15:33 -05:00
|
|
|
case "amd64":
|
|
|
|
|
// ok
|
|
|
|
|
default:
|
2021-04-15 23:05:49 -04:00
|
|
|
log.Fatalf("GOARCH=%s does not support -spectre=index", buildcfg.GOARCH)
|
2020-11-16 01:15:33 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|