if architecture == nil {
log.Fatalf("unrecognized architecture %s", GOARCH)
}
- compilingRuntime := objabi.IsRuntimePackagePath(*flags.Importpath)
+ compilingRuntime := objabi.LookupPkgSpecial(*flags.Importpath).AllowAsmABI
ctxt := obj.Linknew(architecture.LinkArch)
ctxt.Debugasm = flags.PrintOut
return string(p)
}
-
-// IsRuntimePackagePath examines 'pkgpath' and returns TRUE if it
-// belongs to the collection of "runtime-related" packages, including
-// "runtime" itself, "reflect", "syscall", and the
-// "runtime/internal/*" packages. The compiler and/or assembler in
-// some cases need to be aware of when they are building such a
-// package, for example to enable features such as ABI selectors in
-// assembly sources.
-func IsRuntimePackagePath(pkgpath string) bool {
- rval := false
- switch pkgpath {
- case "runtime":
- rval = true
- case "reflect":
- rval = true
- case "syscall":
- rval = true
- case "internal/bytealg":
- rval = true
- default:
- rval = strings.HasPrefix(pkgpath, "runtime/internal")
- }
- return rval
-}
--- /dev/null
+// Copyright 2023 The Go Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style
+// license that can be found in the LICENSE file.
+
+package objabi
+
+import "sync"
+
+// PkgSpecial indicates special build properties of a given runtime-related
+// package.
+type PkgSpecial struct {
+ // AllowAsmABI indicates that assembly in this package is allowed to use ABI
+ // selectors in symbol names. Generally this is needed for packages that
+ // interact closely with the runtime package or have performance-critical
+ // assembly.
+ AllowAsmABI bool
+}
+
+var allowAsmABIPkgs = []string{
+ "runtime",
+ "reflect",
+ "syscall",
+ "internal/bytealg",
+ "runtime/internal/syscall",
+ "runtime/internal/startlinetest",
+}
+
+var (
+ pkgSpecials map[string]PkgSpecial
+ pkgSpecialsOnce sync.Once
+)
+
+// LookupPkgSpecial returns special build properties for the given package path.
+func LookupPkgSpecial(pkgPath string) PkgSpecial {
+ pkgSpecialsOnce.Do(func() {
+ // Construct pkgSpecials from various package lists. This lets us use
+ // more flexible logic, while keeping the final map simple, and avoids
+ // the init-time cost of a map.
+ pkgSpecials = make(map[string]PkgSpecial)
+ set := func(elt string, f func(*PkgSpecial)) {
+ s := pkgSpecials[elt]
+ f(&s)
+ pkgSpecials[elt] = s
+ }
+ for _, pkg := range allowAsmABIPkgs {
+ set(pkg, func(ps *PkgSpecial) { ps.AllowAsmABI = true })
+ }
+ })
+ return pkgSpecials[pkgPath]
+}