hashDebug = NewHashDebug("gossahash", Debug.Gossahash, nil)
}
+ // Compute whether we're compiling the runtime from the package path. Test
+ // code can also use the flag to set this explicitly.
+ if Flag.Std && objabi.LookupPkgSpecial(Ctxt.Pkgpath).Runtime {
+ Flag.CompilingRuntime = true
+ }
+
// 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) (*)
}
}
- 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)
}
}
if Flag.CompilingRuntime {
+ // It is not possible to build the runtime with no optimizations,
+ // because the compiler cannot eliminate enough write barriers.
+ Flag.N = 0
+
// Runtime can't use -d=checkptr, at least not yet.
Debug.Checkptr = 0
if gogcflags != "" {
compile = append(compile, strings.Fields(gogcflags)...)
}
- if pkg == "runtime" {
- compile = append(compile, "-+")
- }
if len(sfiles) > 0 {
compile = append(compile, "-asmhdr", goasmh)
}
// The 'path' used for GOROOT_FINAL when -trimpath is specified
const trimPathGoRootFinal string = "$GOROOT"
-var runtimePackages = map[string]struct{}{
- "internal/abi": struct{}{},
- "internal/bytealg": struct{}{},
- "internal/coverage/rtcov": struct{}{},
- "internal/cpu": struct{}{},
- "internal/goarch": struct{}{},
- "internal/goos": struct{}{},
- "runtime": struct{}{},
- "runtime/internal/atomic": struct{}{},
- "runtime/internal/math": struct{}{},
- "runtime/internal/sys": struct{}{},
- "runtime/internal/syscall": struct{}{},
-}
-
// The Go toolchain.
type gcToolchain struct{}
if p.Standard {
defaultGcFlags = append(defaultGcFlags, "-std")
}
- _, compilingRuntime := runtimePackages[p.ImportPath]
- compilingRuntime = compilingRuntime && p.Standard
- if compilingRuntime {
- // runtime compiles with a special gc flag to check for
- // memory allocations that are invalid in the runtime package,
- // and to implement some special compiler pragmas.
- defaultGcFlags = append(defaultGcFlags, "-+")
- }
// If we're giving the compiler the entire package (no C etc files), tell it that,
// so that it can give good error messages about forward declarations.
if p.Internal.FuzzInstrument {
gcflags = append(gcflags, fuzzInstrumentFlags()...)
}
- if compilingRuntime {
- // Remove -N, if present.
- // It is not possible to build the runtime with no optimizations,
- // because the compiler cannot eliminate enough write barriers.
- for i := 0; i < len(gcflags); i++ {
- if gcflags[i] == "-N" {
- copy(gcflags[i:], gcflags[i+1:])
- gcflags = gcflags[:len(gcflags)-1]
- i--
- }
- }
- }
// Add -c=N to use concurrent backend compilation, if possible.
if c := gcBackendConcurrency(gcflags); c > 1 {
defaultGcFlags = append(defaultGcFlags, fmt.Sprintf("-c=%d", c))
// PkgSpecial indicates special build properties of a given runtime-related
// package.
type PkgSpecial struct {
+ // Runtime indicates that this package is "runtime" or imported by
+ // "runtime". This has several effects (which maybe should be split out):
+ //
+ // - Implicit allocation is disallowed.
+ //
+ // - Various runtime pragmas are enabled.
+ //
+ // - Optimizations are always enabled.
+ //
+ // This should be set for runtime and all packages it imports, and may be
+ // set for additional packages.
+ //
+ // TODO(austin): Test that all of `go list -deps runtime` is marked Runtime.
+ Runtime bool
+
// AllowAsmABI indicates that assembly in this package is allowed to use ABI
// selectors in symbol names. Generally this is needed for packages that
// interact closely with the runtime package or have performance-critical
AllowAsmABI bool
}
+var runtimePkgs = []string{
+ "runtime",
+
+ "runtime/internal/atomic",
+ "runtime/internal/math",
+ "runtime/internal/sys",
+ "runtime/internal/syscall",
+
+ "internal/abi",
+ "internal/bytealg",
+ "internal/coverage/rtcov",
+ "internal/cpu",
+ "internal/goarch",
+ "internal/goos",
+}
+
var allowAsmABIPkgs = []string{
"runtime",
"reflect",
f(&s)
pkgSpecials[elt] = s
}
+ for _, pkg := range runtimePkgs {
+ set(pkg, func(ps *PkgSpecial) { ps.Runtime = true })
+ }
for _, pkg := range allowAsmABIPkgs {
set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })
}