github.com/AndrienkoAleksandr/go@v0.0.19/src/intern/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  func MSanSupported(goos, goarch string) bool {
    28  	switch goos {
    29  	case "linux":
    30  		return goarch == "amd64" || goarch == "arm64"
    31  	case "freebsd":
    32  		return goarch == "amd64"
    33  	default:
    34  		return false
    35  	}
    36  }
    37  
    38  // ASanSupported reports whether goos/goarch supports the address
    39  // sanitizer option.
    40  func ASanSupported(goos, goarch string) bool {
    41  	switch goos {
    42  	case "linux":
    43  		return goarch == "arm64" || goarch == "amd64" || goarch == "riscv64" || goarch == "ppc64le"
    44  	default:
    45  		return false
    46  	}
    47  }
    48  
    49  // FuzzSupported reports whether goos/goarch supports fuzzing
    50  // ('go test -fuzz=.').
    51  func FuzzSupported(goos, goarch string) bool {
    52  	switch goos {
    53  	case "darwin", "freebsd", "linux", "windows":
    54  		return true
    55  	default:
    56  		return false
    57  	}
    58  }
    59  
    60  // FuzzInstrumented reports whether fuzzing on goos/goarch uses coverage
    61  // instrumentation. (FuzzInstrumented implies FuzzSupported.)
    62  func FuzzInstrumented(goos, goarch string) bool {
    63  	switch goarch {
    64  	case "amd64", "arm64":
    65  		// TODO(#14565): support more architectures.
    66  		return FuzzSupported(goos, goarch)
    67  	default:
    68  		return false
    69  	}
    70  }
    71  
    72  // MustLinkExternal reports whether goos/goarch requires external linking
    73  // with or without cgo dependencies.
    74  func MustLinkExternal(goos, goarch string, withCgo bool) bool {
    75  	if withCgo {
    76  		switch goarch {
    77  		case "loong64",
    78  			"mips", "mipsle", "mips64", "mips64le",
    79  			"riscv64":
    80  			// Internally linking cgo is incomplete on some architectures.
    81  			// https://go.dev/issue/14449
    82  			return true
    83  		case "arm64":
    84  			if goos == "windows" {
    85  				// windows/arm64 internal linking is not implemented.
    86  				return true
    87  			}
    88  		case "ppc64":
    89  			// Big Endian PPC64 cgo internal linking is not implemented for aix or linux.
    90  			// https://go.dev/issue/8912
    91  			return true
    92  		}
    93  
    94  		switch goos {
    95  		case "android":
    96  			return true
    97  		case "dragonfly":
    98  			// It seems that on Dragonfly thread local storage is
    99  			// set up by the dynamic linker, so internal cgo linking
   100  			// doesn't work. Test case is "go test runtime/cgo".
   101  			return true
   102  		}
   103  	}
   104  
   105  	switch goos {
   106  	case "android":
   107  		if goarch != "arm64" {
   108  			return true
   109  		}
   110  	case "ios":
   111  		if goarch == "arm64" {
   112  			return true
   113  		}
   114  	}
   115  	return false
   116  }
   117  
   118  // BuildModeSupported reports whether goos/goarch supports the given build mode
   119  // using the given compiler.
   120  // There is a copy of this function in cmd/dist/test.go.
   121  func BuildModeSupported(compiler, buildmode, goos, goarch string) bool {
   122  	if compiler == "gccgo" {
   123  		return true
   124  	}
   125  
   126  	platform := goos + "/" + goarch
   127  	if _, ok := osArchSupportsCgo[platform]; !ok {
   128  		return false // platform unrecognized
   129  	}
   130  
   131  	switch buildmode {
   132  	case "archive":
   133  		return true
   134  
   135  	case "c-archive":
   136  		switch goos {
   137  		case "aix", "darwin", "ios", "windows":
   138  			return true
   139  		case "linux":
   140  			switch goarch {
   141  			case "386", "amd64", "arm", "armbe", "arm64", "arm64be", "loong64", "ppc64le", "riscv64", "s390x":
   142  				// linux/ppc64 not supported because it does
   143  				// not support external linking mode yet.
   144  				return true
   145  			default:
   146  				// Other targets do not support -shared,
   147  				// per ParseFlags in
   148  				// cmd/compile/internal/base/flag.go.
   149  				// For c-archive the Go tool passes -shared,
   150  				// so that the result is suitable for inclusion
   151  				// in a PIE or shared library.
   152  				return false
   153  			}
   154  		case "freebsd":
   155  			return goarch == "amd64"
   156  		}
   157  		return false
   158  
   159  	case "c-shared":
   160  		switch platform {
   161  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/386", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   162  			"android/amd64", "android/arm", "android/arm64", "android/386",
   163  			"freebsd/amd64",
   164  			"darwin/amd64", "darwin/arm64",
   165  			"windows/amd64", "windows/386", "windows/arm64":
   166  			return true
   167  		}
   168  		return false
   169  
   170  	case "default":
   171  		return true
   172  
   173  	case "exe":
   174  		return true
   175  
   176  	case "pie":
   177  		switch platform {
   178  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/loong64", "linux/ppc64le", "linux/riscv64", "linux/s390x",
   179  			"android/amd64", "android/arm", "android/arm64", "android/386",
   180  			"freebsd/amd64",
   181  			"darwin/amd64", "darwin/arm64",
   182  			"ios/amd64", "ios/arm64",
   183  			"aix/ppc64",
   184  			"windows/386", "windows/amd64", "windows/arm", "windows/arm64":
   185  			return true
   186  		}
   187  		return false
   188  
   189  	case "shared":
   190  		switch platform {
   191  		case "linux/386", "linux/amd64", "linux/arm", "linux/arm64", "linux/ppc64le", "linux/s390x":
   192  			return true
   193  		}
   194  		return false
   195  
   196  	case "plugin":
   197  		switch platform {
   198  		case "linux/amd64", "linux/arm", "linux/arm64", "linux/386", "linux/s390x", "linux/ppc64le",
   199  			"android/amd64", "android/386",
   200  			"darwin/amd64", "darwin/arm64",
   201  			"freebsd/amd64":
   202  			return true
   203  		}
   204  		return false
   205  
   206  	default:
   207  		return false
   208  	}
   209  }
   210  
   211  func InternalLinkPIESupported(goos, goarch string) bool {
   212  	switch goos + "/" + goarch {
   213  	case "android/arm64",
   214  		"darwin/amd64", "darwin/arm64",
   215  		"linux/amd64", "linux/arm64", "linux/ppc64le",
   216  		"windows/386", "windows/amd64", "windows/arm", "windows/arm64":
   217  		return true
   218  	}
   219  	return false
   220  }
   221  
   222  // DefaultPIE reports whether goos/goarch produces a PIE binary when using the
   223  // "default" buildmode. On Windows this is affected by -race,
   224  // so force the caller to pass that in to centralize that choice.
   225  func DefaultPIE(goos, goarch string, isRace bool) bool {
   226  	switch goos {
   227  	case "android", "ios":
   228  		return true
   229  	case "windows":
   230  		if isRace {
   231  			// PIE is not supported with -race on windows;
   232  			// see https://go.dev/cl/416174.
   233  			return false
   234  		}
   235  		return true
   236  	case "darwin":
   237  		return goarch == "arm64"
   238  	}
   239  	return false
   240  }
   241  
   242  // CgoSupported reports whether goos/goarch supports cgo.
   243  func CgoSupported(goos, goarch string) bool {
   244  	return osArchSupportsCgo[goos+"/"+goarch]
   245  }
   246  
   247  // ExecutableHasDWARF reports whether the linked executable includes DWARF
   248  // symbols on goos/goarch.
   249  func ExecutableHasDWARF(goos, goarch string) bool {
   250  	switch goos {
   251  	case "plan9", "ios":
   252  		return false
   253  	}
   254  	return true
   255  }