supported.go raw

   1  // Copyright 2018 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 sys
   6  
   7  // RaceDetectorSupported reports whether goos/goarch supports the race
   8  // detector. There is a copy of this function in cmd/dist/test.go.
   9  // Race detector only supports 48-bit VMA on arm64. But it will always
  10  // return true for arm64, because we don't have VMA size information during
  11  // the compile time.
  12  func RaceDetectorSupported(goos, goarch string) bool {
  13  	switch goos {
  14  	case "linux":
  15  		return goarch == "amd64" || goarch == "ppc64le" || goarch == "arm64"
  16  	case "darwin", "freebsd", "netbsd", "windows":
  17  		return goarch == "amd64"
  18  	default:
  19  		return false
  20  	}
  21  }
  22  
  23  // MSanSupported reports whether goos/goarch supports the memory
  24  // sanitizer option. There is a copy of this function in cmd/dist/test.go.
  25  func MSanSupported(goos, goarch string) bool {
  26  	switch goos {
  27  	case "linux":
  28  		return goarch == "amd64" || goarch == "arm64"
  29  	default:
  30  		return false
  31  	}
  32  }
  33  
  34  // MustLinkExternal reports whether goos/goarch requires external linking.
  35  func MustLinkExternal(goos, goarch string) bool {
  36  	switch goos {
  37  	case "android":
  38  		if goarch != "arm64" {
  39  			return true
  40  		}
  41  	case "darwin":
  42  		if goarch == "arm64" {
  43  			return true
  44  		}
  45  	}
  46  	return false
  47  }
  48  
  49  // BuildModeSupported reports whether goos/goarch supports the given build mode
  50  // using the given compiler.
  51  func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
  52  	if compiler == "gccgo" {
  53  		return true
  54  	}
  55  
  56  	platform := goos + "/" + goarch
  57  
  58  	switch buildmode {
  59  	case "archive":
  60  		return true
  61  
  62  	case "c-archive":
  63  		// TODO(bcmills): This seems dubious.
  64  		// Do we really support c-archive mode on js/wasm‽
  65  		return platform != "linux/ppc64"
  66  
  67  	case "c-shared":
  68  		switch platform {
  69  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/s390x",
  70  			"android/amd64", "android/arm", "android/arm64", "android/386",
  71  			"freebsd/amd64",
  72  			"darwin/amd64",
  73  			"windows/amd64", "windows/386":
  74  			return true
  75  		}
  76  		return false
  77  
  78  	case "default":
  79  		return true
  80  
  81  	case "exe":
  82  		return true
  83  
  84  	case "pie":
  85  		switch platform {
  86  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x",
  87  			"android/amd64", "android/arm", "android/arm64", "android/386",
  88  			"freebsd/amd64",
  89  			"darwin/amd64",
  90  			"aix/ppc64",
  91  			"windows/386", "windows/amd64", "windows/arm":
  92  			return true
  93  		}
  94  		return false
  95  
  96  	case "shared":
  97  		switch platform {
  98  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
  99  			return true
 100  		}
 101  		return false
 102  
 103  	case "plugin":
 104  		switch platform {
 105  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
 106  			"android/amd64", "android/arm", "android/arm64", "android/386",
 107  			"darwin/amd64",
 108  			"freebsd/amd64":
 109  			return true
 110  		}
 111  		return false
 112  
 113  	default:
 114  		return false
 115  	}
 116  }
 117