github.com/mtsmfm/go/src@v0.0.0-20221020090648-44bdcb9f8fde/internal/platform/supported.go (about)

     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 platform
     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" || goarch == "s390x"
    16  	case "darwin":
    17  		return goarch == "amd64" || goarch == "arm64"
    18  	case "freebsd", "netbsd", "openbsd", "windows":
    19  		return goarch == "amd64"
    20  	default:
    21  		return false
    22  	}
    23  }
    24  
    25  // MSanSupported reports whether goos/goarch supports the memory
    26  // sanitizer option.
    27  // There is a copy of this function in misc/cgo/testsanitizers/cc_test.go.
    28  func MSanSupported(goos, goarch string) bool {
    29  	switch goos {
    30  	case "linux":
    31  		return goarch == "amd64" || goarch == "arm64"
    32  	case "freebsd":
    33  		return goarch == "amd64"
    34  	default:
    35  		return false
    36  	}
    37  }
    38  
    39  // ASanSupported reports whether goos/goarch supports the address
    40  // sanitizer option.
    41  // There is a copy of this function in misc/cgo/testsanitizers/cc_test.go.
    42  func ASanSupported(goos, goarch string) bool {
    43  	switch goos {
    44  	case "linux":
    45  		return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
    46  	default:
    47  		return false
    48  	}
    49  }
    50  
    51  // FuzzSupported reports whether goos/goarch supports fuzzing
    52  // ('go test -fuzz=.').
    53  func FuzzSupported(goos, goarch string) bool {
    54  	switch goos {
    55  	case "darwin", "freebsd", "linux", "windows":
    56  		return true
    57  	default:
    58  		return false
    59  	}
    60  }
    61  
    62  // FuzzInstrumented reports whether fuzzing on goos/goarch uses coverage
    63  // instrumentation. (FuzzInstrumented implies FuzzSupported.)
    64  func FuzzInstrumented(goos, goarch string) bool {
    65  	switch goarch {
    66  	case "amd64", "arm64":
    67  		// TODO(#14565): support more architectures.
    68  		return FuzzSupported(goos, goarch)
    69  	default:
    70  		return false
    71  	}
    72  }
    73  
    74  // MustLinkExternal reports whether goos/goarch requires external linking.
    75  func MustLinkExternal(goos, goarch string) bool {
    76  	switch goos {
    77  	case "android":
    78  		if goarch != "arm64" {
    79  			return true
    80  		}
    81  	case "ios":
    82  		if goarch == "arm64" {
    83  			return true
    84  		}
    85  	}
    86  	return false
    87  }
    88  
    89  // BuildModeSupported reports whether goos/goarch supports the given build mode
    90  // using the given compiler.
    91  func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
    92  	if compiler == "gccgo" {
    93  		return true
    94  	}
    95  
    96  	platform := goos + "/" + goarch
    97  
    98  	switch buildmode {
    99  	case "archive":
   100  		return true
   101  
   102  	case "c-archive":
   103  		// TODO(bcmills): This seems dubious.
   104  		// Do we really support c-archive mode on js/wasm‽
   105  		return platform != "linux/ppc64"
   106  
   107  	case "c-shared":
   108  		switch platform {
   109  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   110  			"android/amd64", "android/arm", "android/arm64", "android/386",
   111  			"freebsd/amd64",
   112  			"darwin/amd64", "darwin/arm64",
   113  			"windows/amd64", "windows/386", "windows/arm64":
   114  			return true
   115  		}
   116  		return false
   117  
   118  	case "default":
   119  		return true
   120  
   121  	case "exe":
   122  		return true
   123  
   124  	case "pie":
   125  		switch platform {
   126  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   127  			"android/amd64", "android/arm", "android/arm64", "android/386",
   128  			"freebsd/amd64",
   129  			"darwin/amd64", "darwin/arm64",
   130  			"ios/amd64", "ios/arm64",
   131  			"aix/ppc64",
   132  			"windows/386", "windows/amd64", "windows/arm":
   133  			return true
   134  		}
   135  		return false
   136  
   137  	case "shared":
   138  		switch platform {
   139  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
   140  			return true
   141  		}
   142  		return false
   143  
   144  	case "plugin":
   145  		switch platform {
   146  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
   147  			"android/amd64", "android/arm", "android/arm64", "android/386",
   148  			"darwin/amd64", "darwin/arm64",
   149  			"freebsd/amd64":
   150  			return true
   151  		}
   152  		return false
   153  
   154  	default:
   155  		return false
   156  	}
   157  }
   158  
   159  func InternalLinkPIESupported(goos, goarch string) bool {
   160  	switch goos + "/" + goarch {
   161  	case "darwin/amd64", "darwin/arm64",
   162  		"linux/amd64", "linux/arm64", "linux/ppc64le",
   163  		"android/arm64",
   164  		"windows-amd64", "windows-386", "windows-arm":
   165  		return true
   166  	}
   167  	return false
   168  }