Source file src/cmd/compile/internal/base/base.go

     1  // Copyright 2009 The Go Authors. All rights reserved.
     2  // Use of this source code is governed by a BSD-style
     3  // license that can be found in the LICENSE file.
     4  
     5  package base
     6  
     7  import (
     8  	"os"
     9  )
    10  
    11  var atExitFuncs []func()
    12  
    13  func AtExit(f func()) {
    14  	atExitFuncs = append(atExitFuncs, f)
    15  }
    16  
    17  func Exit(code int) {
    18  	for i := len(atExitFuncs) - 1; i >= 0; i-- {
    19  		f := atExitFuncs[i]
    20  		atExitFuncs = atExitFuncs[:i]
    21  		f()
    22  	}
    23  	os.Exit(code)
    24  }
    25  
    26  // To enable tracing support (-t flag), set EnableTrace to true.
    27  const EnableTrace = false
    28  
    29  func Compiling(pkgs []string) bool {
    30  	if Ctxt.Pkgpath != "" {
    31  		for _, p := range pkgs {
    32  			if Ctxt.Pkgpath == p {
    33  				return true
    34  			}
    35  		}
    36  	}
    37  
    38  	return false
    39  }
    40  
    41  // The racewalk pass is currently handled in three parts.
    42  //
    43  // First, for flag_race, it inserts calls to racefuncenter and
    44  // racefuncexit at the start and end (respectively) of each
    45  // function. This is handled below.
    46  //
    47  // Second, during buildssa, it inserts appropriate instrumentation
    48  // calls immediately before each memory load or store. This is handled
    49  // by the (*state).instrument method in ssa.go, so here we just set
    50  // the Func.InstrumentBody flag as needed. For background on why this
    51  // is done during SSA construction rather than a separate SSA pass,
    52  // see issue #19054.
    53  //
    54  // Third we remove calls to racefuncenter and racefuncexit, for leaf
    55  // functions without instrumented operations. This is done as part of
    56  // ssa opt pass via special rule.
    57  
    58  // TODO(dvyukov): do not instrument initialization as writes:
    59  // a := make([]int, 10)
    60  
    61  // Do not instrument the following packages at all,
    62  // at best instrumentation would cause infinite recursion.
    63  var NoInstrumentPkgs = []string{
    64  	"runtime/internal/atomic",
    65  	"runtime/internal/math",
    66  	"runtime/internal/sys",
    67  	"runtime/internal/syscall",
    68  	"runtime",
    69  	"runtime/race",
    70  	"runtime/msan",
    71  	"runtime/asan",
    72  	"internal/cpu",
    73  }
    74  
    75  // Don't insert racefuncenter/racefuncexit into the following packages.
    76  // Memory accesses in the packages are either uninteresting or will cause false positives.
    77  var NoRacePkgs = []string{"sync", "sync/atomic"}
    78  

View as plain text