mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Move procid to dynamic facts render
Based on cl/504066914, this generates the proper procid offsets at build time. Package facts needs an update to properly skip underscore imports, which don't have facts for some reason (because they are unnamed?). Drop use of runtime.getprocid given that these generated code is pretty solid. PiperOrigin-RevId: 504926257
This commit is contained in:
committed by
gVisor bot
parent
2b5f0e1b8e
commit
0c38f72156
+19
-3
@@ -1,13 +1,29 @@
|
||||
load("//tools:defs.bzl", "go_library", "go_test")
|
||||
load("//tools:defs.bzl", "arch_genrule", "go_library", "go_test", "select_arch")
|
||||
load("//tools/nogo:defs.bzl", "nogo_facts")
|
||||
|
||||
package(licenses = ["notice"])
|
||||
|
||||
nogo_facts(
|
||||
name = "procid_impl",
|
||||
srcs = ["procid.go"],
|
||||
output = "procid_impl.s",
|
||||
template = select_arch(
|
||||
amd64 = "procid_amd64.s",
|
||||
arm64 = "procid_arm64.s",
|
||||
),
|
||||
)
|
||||
|
||||
arch_genrule(
|
||||
name = "procid_impl_arch",
|
||||
src = ":procid_impl",
|
||||
template = "procid_impl_%s.s",
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "procid",
|
||||
srcs = [
|
||||
"procid.go",
|
||||
"procid_amd64.s",
|
||||
"procid_arm64.s",
|
||||
":procid_impl_arch",
|
||||
],
|
||||
visibility = ["//visibility:public"],
|
||||
)
|
||||
|
||||
@@ -12,12 +12,16 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build go1.1
|
||||
// +build go1.1
|
||||
|
||||
// Package procid provides a way to get the current system thread identifier.
|
||||
package procid
|
||||
|
||||
import (
|
||||
"runtime"
|
||||
)
|
||||
|
||||
// Dummy references for facts.
|
||||
const _ = runtime.Compiler
|
||||
|
||||
// Current returns the current system thread identifier.
|
||||
//
|
||||
// Precondition: This should only be called with the runtime OS thread locked.
|
||||
|
||||
@@ -12,22 +12,19 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build amd64 && go1.8 && !go1.21 && go1.1
|
||||
// +build amd64,go1.8,!go1.21,go1.1
|
||||
|
||||
// //go:linkname directives type-checked by checklinkname. Any other
|
||||
// non-linkname assumptions outside the Go 1 compatibility guarantee should
|
||||
// have an accompanied vet check or version guard build tag.
|
||||
//go:build amd64
|
||||
// +build amd64
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
#define M_OFFSET {{ .import.runtime.g.m.Offset }}
|
||||
#define PROCID_OFFSET {{ .import.runtime.m.procid.Offset }}
|
||||
|
||||
TEXT ·Current(SB),NOSPLIT,$0-8
|
||||
// The offset specified here is the m_procid offset for Go1.8+.
|
||||
// Changes to this offset should be caught by the tests, and major
|
||||
// version changes require an explicit tag change above.
|
||||
// procid is in getg().m.procid.
|
||||
MOVQ TLS, AX
|
||||
MOVQ 0(AX)(TLS*1), AX
|
||||
MOVQ 48(AX), AX // g_m (may change in future versions)
|
||||
MOVQ 72(AX), AX // m_procid (may change in future versions)
|
||||
MOVQ M_OFFSET(AX), AX // gp.m
|
||||
MOVQ PROCID_OFFSET(AX), AX // mp.procid
|
||||
MOVQ AX, ret+0(FP)
|
||||
RET
|
||||
|
||||
@@ -12,21 +12,18 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build arm64 && go1.8 && !go1.21 && go1.1
|
||||
// +build arm64,go1.8,!go1.21,go1.1
|
||||
|
||||
// //go:linkname directives type-checked by checklinkname. Any other
|
||||
// non-linkname assumptions outside the Go 1 compatibility guarantee should
|
||||
// have an accompanied vet check or version guard build tag.
|
||||
//go:build arm64
|
||||
// +build arm64
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
#define M_OFFSET {{ .import.runtime.g.m.Offset }}
|
||||
#define PROCID_OFFSET {{ .import.runtime.m.procid.Offset }}
|
||||
|
||||
TEXT ·Current(SB),NOSPLIT,$0-8
|
||||
// The offset specified here is the m_procid offset for Go1.8+.
|
||||
// Changes to this offset should be caught by the tests, and major
|
||||
// version changes require an explicit tag change above.
|
||||
// procid is in getg().m.procid.
|
||||
MOVD g, R0 // g
|
||||
MOVD 48(R0), R0 // g_m (may change in future versions)
|
||||
MOVD 72(R0), R0 // m_procid (may change in future versions)
|
||||
MOVD M_OFFSET(R0), R0 // gp.m
|
||||
MOVD PROCID_OFFSET(R0), R0 // mp.procid
|
||||
MOVD R0, ret+0(FP)
|
||||
RET
|
||||
|
||||
@@ -230,6 +230,13 @@ func (b *Bundle) Package(pkg *types.Package) (*Package, error) {
|
||||
return facts, nil
|
||||
}
|
||||
|
||||
if b.reader == nil {
|
||||
// Nothing available.
|
||||
//
|
||||
// N.B. some bundles contain only cached packages.
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// Find based on the reader.
|
||||
for _, f := range b.reader.File {
|
||||
if f.Name != pkg.Path() {
|
||||
@@ -368,6 +375,9 @@ func Resolve(pkg *types.Package, localFacts *Package, allFacts *Bundle, allFactN
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if importFacts == nil {
|
||||
continue
|
||||
}
|
||||
r.walkScope(append(names, "import", importPkg.Name()), importPkg.Scope(), importFacts, allFactNames)
|
||||
}
|
||||
return r, nil
|
||||
|
||||
Reference in New Issue
Block a user