github.com/JimmyHuang454/JLS-go@v0.0.0-20230831150107-90d536585ba0/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  	return MustLinkExternalGo121(goos, goarch, false)
    77  }
    78  
    79  // MustLinkExternalGo121 reports whether goos/goarch requires external linking,
    80  // with or without cgo dependencies. [This version back-ported from
    81  // Go 1.21 as part of a test].
    82  func MustLinkExternalGo121(goos, goarch string, withCgo bool) bool {
    83  	if withCgo {
    84  		switch goarch {
    85  		case "loong64",
    86  			"mips", "mipsle", "mips64", "mips64le",
    87  			"riscv64":
    88  			// Internally linking cgo is incomplete on some architectures.
    89  			// https://go.dev/issue/14449
    90  			return true
    91  		case "arm64":
    92  			if goos == "windows" {
    93  				// windows/arm64 internal linking is not implemented.
    94  				return true
    95  			}
    96  		case "ppc64":
    97  			// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
    98  			// https://go.dev/issue/8912
    99  			return true
   100  		}
   101  
   102  		switch goos {
   103  		case "android":
   104  			return true
   105  		case "dragonfly":
   106  			// It seems that on Dragonfly thread local storage is
   107  			// set up by the dynamic linker, so internal cgo linking
   108  			// doesn't work. Test case is "go test runtime/cgo".
   109  			return true
   110  		}
   111  	}
   112  
   113  	switch goos {
   114  	case "android":
   115  		if goarch != "arm64" {
   116  			return true
   117  		}
   118  	case "ios":
   119  		if goarch == "arm64" {
   120  			return true
   121  		}
   122  	}
   123  	return false
   124  }
   125  
   126  // BuildModeSupported reports whether goos/goarch supports the given build mode
   127  // using the given compiler.
   128  func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
   129  	if compiler == "gccgo" {
   130  		return true
   131  	}
   132  
   133  	platform := goos + "/" + goarch
   134  
   135  	switch buildmode {
   136  	case "archive":
   137  		return true
   138  
   139  	case "c-archive":
   140  		// TODO(bcmills): This seems dubious.
   141  		// Do we really support c-archive mode on js/wasm‽
   142  		return platform != "linux/ppc64"
   143  
   144  	case "c-shared":
   145  		switch platform {
   146  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   147  			"android/amd64", "android/arm", "android/arm64", "android/386",
   148  			"freebsd/amd64",
   149  			"darwin/amd64", "darwin/arm64",
   150  			"windows/amd64", "windows/386", "windows/arm64":
   151  			return true
   152  		}
   153  		return false
   154  
   155  	case "default":
   156  		return true
   157  
   158  	case "exe":
   159  		return true
   160  
   161  	case "pie":
   162  		switch platform {
   163  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   164  			"android/amd64", "android/arm", "android/arm64", "android/386",
   165  			"freebsd/amd64",
   166  			"darwin/amd64", "darwin/arm64",
   167  			"ios/amd64", "ios/arm64",
   168  			"aix/ppc64",
   169  			"windows/386", "windows/amd64", "windows/arm", "windows/arm64":
   170  			return true
   171  		}
   172  		return false
   173  
   174  	case "shared":
   175  		switch platform {
   176  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
   177  			return true
   178  		}
   179  		return false
   180  
   181  	case "plugin":
   182  		switch platform {
   183  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
   184  			"android/amd64", "android/arm", "android/arm64", "android/386",
   185  			"darwin/amd64", "darwin/arm64",
   186  			"freebsd/amd64":
   187  			return true
   188  		}
   189  		return false
   190  
   191  	default:
   192  		return false
   193  	}
   194  }
   195  
   196  func InternalLinkPIESupported(goos, goarch string) bool {
   197  	switch goos + "/" + goarch {
   198  	case "darwin/amd64", "darwin/arm64",
   199  		"linux/amd64", "linux/arm64", "linux/ppc64le",
   200  		"android/arm64",
   201  		"windows-amd64", "windows-386", "windows-arm":
   202  		return true
   203  	}
   204  	return false
   205  }