mirror of
https://github.com/netbirdio/gvisor.git
synced 2026-05-22 17:12:49 -07:00
Update checklinkname to avoid hard-coded names.
PiperOrigin-RevId: 510524474
This commit is contained in:
committed by
gVisor bot
parent
45b3776646
commit
c829d82a8f
@@ -62,6 +62,7 @@ global:
|
||||
- "panic recovered: no type for \\*ast.SelectorExpr"
|
||||
- "panic recovered: no types.Object for ast.Ident SetTypeErrors"
|
||||
- "panic recovered: unexpected CompositeLit type: invalid type"
|
||||
- "panic recovered: interface conversion: ssa.Member is \\*ssa.NamedConst"
|
||||
exclude:
|
||||
- ".*/vet/testdata/.*"
|
||||
- ".*/runtime/testdata/.*"
|
||||
@@ -79,6 +80,8 @@ global:
|
||||
- "return with unexpected locks held.*"
|
||||
- "incompatible return states.*"
|
||||
- "may require checklocks annotation for.*"
|
||||
# For some reason, the types package falls down.
|
||||
- "panic recovered: .*types/sizes.go:82: assertion failed"
|
||||
exclude:
|
||||
# Generated: exempt all.
|
||||
- pkg/shim/runtimeoptions/runtimeoptions_cri.go
|
||||
@@ -184,16 +187,22 @@ analyzers:
|
||||
checklinkname:
|
||||
external: # Enabled.
|
||||
suppress:
|
||||
# We don't care to check every single linkname in the Go standard
|
||||
# library. Suppress findings about stdlib linkname targets we haven't
|
||||
# described in checklinkname.
|
||||
#
|
||||
# Note that we _do_ want to check the signature of the known linkname
|
||||
# targets in the standard library, so we still need to run
|
||||
# checklinkname on stdlib generally.
|
||||
- "linkname to unknown symbol"
|
||||
# Suppress bad linkname directives in the internals. This may be fixed
|
||||
# by the patch: https://go-review.googlesource.com/c/go/+/466615
|
||||
- "symbol \"runtime_pollWaitCanceled\".*"
|
||||
- "symbol \"runtime_procPin\".*"
|
||||
exclude:
|
||||
- ".*/containerd/sys/subprocess_unsafe_linux.go"
|
||||
internal:
|
||||
suppress:
|
||||
# See above.
|
||||
- "symbol \"runtime_pollWaitCanceled\".*"
|
||||
- "symbol \"runtime_procPin\".*"
|
||||
generated:
|
||||
suppress:
|
||||
# See above.
|
||||
- "symbol \"runtime_pollWaitCanceled\".*"
|
||||
- "symbol \"runtime_procPin\".*"
|
||||
SA1019: # Use of deprecated identifier.
|
||||
# disable for now due to misattribution from golang.org/issue/44195.
|
||||
generated:
|
||||
|
||||
@@ -4,13 +4,9 @@ package(licenses = ["notice"])
|
||||
|
||||
go_library(
|
||||
name = "checklinkname",
|
||||
srcs = [
|
||||
"check_linkname.go",
|
||||
"known.go",
|
||||
],
|
||||
srcs = ["check_linkname.go"],
|
||||
nogo = False,
|
||||
stateify = False,
|
||||
visibility = ["//tools/nogo:__subpackages__"],
|
||||
deps = [
|
||||
"@org_golang_x_tools//go/analysis:go_default_library",
|
||||
],
|
||||
deps = ["@org_golang_x_tools//go/analysis:go_default_library"],
|
||||
)
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,119 +0,0 @@
|
||||
// Copyright 2021 The gVisor Authors.
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
package checklinkname
|
||||
|
||||
// knownLinknames is the set of the symbols for which we can do a rudimentary
|
||||
// type-check on.
|
||||
//
|
||||
// When analyzing the remote package (e.g., runtime), we verify the symbol
|
||||
// signature matches 'remote'. When analyzing local packages with //go:linkname
|
||||
// directives, we verify the symbol signature matches 'local'.
|
||||
//
|
||||
// Usually these are identical, but may differ slightly if equivalent
|
||||
// replacement types are used in the local packages, such as a copy of a struct
|
||||
// or uintptr instead of a pointer type.
|
||||
//
|
||||
// NOTE: It is the responsibility of the developer to verify the safety of the
|
||||
// signatures used here! This analyzer only checks that types match this map;
|
||||
// it does not verify compatibility of the entries themselves.
|
||||
//
|
||||
// //go:linkname directives with no corresponding entry here will trigger a
|
||||
// finding.
|
||||
//
|
||||
// We preform only rudimentary string-based type-checking due to limitations in
|
||||
// the analysis framework. Ideally, from the local package we'd lookup the
|
||||
// remote symbol's types.Object and perform robust type-checking.
|
||||
// Unfortunately, remote symbols are typically loaded from the remote package's
|
||||
// gcexportdata. Since //go:linkname targets are usually not exported symbols,
|
||||
// they are no included in gcexportdata and we cannot load their types.Object.
|
||||
//
|
||||
// TODO(b/165820485): Add option to specific per-version signatures.
|
||||
var knownLinknames = map[string]map[string]linknameSignatures{
|
||||
"runtime": {
|
||||
"cputicks": {
|
||||
local: "func() int64",
|
||||
},
|
||||
"entersyscall": {
|
||||
local: "func()",
|
||||
},
|
||||
"entersyscallblock": {
|
||||
local: "func()",
|
||||
},
|
||||
"exitsyscall": {
|
||||
local: "func()",
|
||||
},
|
||||
"fastrand": {
|
||||
local: "func() uint32",
|
||||
},
|
||||
"gopark": {
|
||||
// TODO(b/165820485): add verification of waitReason
|
||||
// size and reason and traceEv values.
|
||||
local: "func(unlockf func(uintptr, unsafe.Pointer) bool, lock unsafe.Pointer, reason uint8, traceEv byte, traceskip int)",
|
||||
remote: "func(unlockf func(*runtime.g, unsafe.Pointer) bool, lock unsafe.Pointer, reason runtime.waitReason, traceEv byte, traceskip int)",
|
||||
},
|
||||
"goready": {
|
||||
local: "func(gp uintptr, traceskip int)",
|
||||
remote: "func(gp *runtime.g, traceskip int)",
|
||||
},
|
||||
"goyield": {
|
||||
local: "func()",
|
||||
},
|
||||
"memmove": {
|
||||
local: "func(to unsafe.Pointer, from unsafe.Pointer, n uintptr)",
|
||||
},
|
||||
"throw": {
|
||||
local: "func(s string)",
|
||||
},
|
||||
"wakep": {
|
||||
local: "func()",
|
||||
},
|
||||
"nanotime": {
|
||||
local: "func() int64",
|
||||
},
|
||||
},
|
||||
"sync": {
|
||||
"runtime_canSpin": {
|
||||
local: "func(i int) bool",
|
||||
},
|
||||
"runtime_doSpin": {
|
||||
local: "func()",
|
||||
},
|
||||
"runtime_Semacquire": {
|
||||
// The only difference here is the parameter names. We
|
||||
// can't just change our local use to match remote, as
|
||||
// the stdlib runtime and sync packages also disagree
|
||||
// on the name, and the analyzer checks that use as
|
||||
// well.
|
||||
local: "func(addr *uint32)",
|
||||
remote: "func(s *uint32)",
|
||||
},
|
||||
"runtime_Semrelease": {
|
||||
// See above.
|
||||
local: "func(addr *uint32, handoff bool, skipframes int)",
|
||||
remote: "func(s *uint32, handoff bool, skipframes int)",
|
||||
},
|
||||
},
|
||||
"syscall": {
|
||||
"runtime_BeforeFork": {
|
||||
local: "func()",
|
||||
},
|
||||
"runtime_AfterFork": {
|
||||
local: "func()",
|
||||
},
|
||||
"runtime_AfterForkInChild": {
|
||||
local: "func()",
|
||||
},
|
||||
},
|
||||
}
|
||||
@@ -19,7 +19,7 @@ import (
|
||||
_ "unsafe" // for go:linkname.
|
||||
)
|
||||
|
||||
//go:linkname DetachedLinkname runtime.fastrand
|
||||
//go:linkname detachedLinkname runtime.fastrand
|
||||
|
||||
//go:linkname attachedLinkname runtime.entersyscall
|
||||
func attachedLinkname()
|
||||
@@ -30,5 +30,5 @@ func AttachedLinkname() {
|
||||
attachedLinkname()
|
||||
}
|
||||
|
||||
// DetachedLinkname has a linkname elsewhere in the file.
|
||||
func DetachedLinkname() uint32
|
||||
// detachedLinkname has a linkname elsewhere in the file.
|
||||
func detachedLinkname() uint32
|
||||
|
||||
@@ -727,6 +727,12 @@ func SplitPackages(srcs []string, srcRootPrefix string) map[string][]string {
|
||||
continue
|
||||
}
|
||||
|
||||
// Place the special runtime package (functions emitted by the
|
||||
// compiler itself) into the runtime packages.
|
||||
if strings.Contains(filename, "cmd/compile/internal/typecheck/_builtin/runtime.go") {
|
||||
pkg = "runtime"
|
||||
}
|
||||
|
||||
// Add to the package.
|
||||
sources[pkg] = append(sources[pkg], filename)
|
||||
}
|
||||
|
||||
@@ -342,7 +342,6 @@ nogo_aspect = go_rule(
|
||||
|
||||
def _nogo_test_impl(ctx):
|
||||
"""Check nogo findings."""
|
||||
nogo_target_info = ctx.attr._target[NogoTargetInfo]
|
||||
|
||||
# Ensure there's a single dependency.
|
||||
if len(ctx.attr.deps) != 1:
|
||||
|
||||
Reference in New Issue
Block a user