Skip to content

Commit 15f3bdc

Browse files
prattmicgvisor-bot
authored andcommitted
nogo: plumb SDK version as language version
Rather than hard-coding the language version, plumb the version from the rules_go GoSDK provider. The end result is a no-op: we analyze everything with the GoVersion matching the language version from go.mod. This is slightly different from go vet / go build. For dependencies, those would use the language version from their go.mod, which may be older. Surprisingly, this seems to be how rules_go works for all builds: it never passes -lang to the compiler, effectively building everything at the language version of the toolchain. The printf analyzer has a stricter check on uses of %q gated behind language version 1.26: https://cs.opensource.google/go/x/tools/+/master:go/analysis/passes/printf/printf.go;l=892;drc=a54c8a428f1496d97a2c4e795b4300e8985649e1. Fix the new findings in gVisor and suppress them in dependencies. PiperOrigin-RevId: 885633196
1 parent f7324fa commit 15f3bdc

File tree

12 files changed

+19
-23
lines changed

12 files changed

+19
-23
lines changed

nogo.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,12 @@ analyzers:
156156
suppress:
157157
- "fmt.Fprintln arg list ends with redundant newline"
158158
- "non-constant format string in call to .*"
159+
exclude:
160+
# Starting in 1.26, printf reports misuse of %q with more types. Many
161+
# of these are unfixed in upstream projects.
162+
- codes/codes.go # go.opentelemetry.io/otel
163+
- yaml.go # github.com/go-openapi/swag/yamlutils
164+
- staticcheck/sa1030/sa1030.go # staticcheck
159165
shift:
160166
generated: # Disabled for generated code; these shifts are well-defined.
161167
exclude: [".*"]

pkg/sentry/socket/netfilter/extensions.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,7 @@ func targetRevision(name string, netProto tcpip.NetworkProtocolNumber, rev uint8
203203
// with the netfilter package.
204204
func registerTargetMaker(tm targetMaker) {
205205
if _, ok := targetMakers[tm.id()]; ok {
206-
panic(fmt.Sprintf("multiple targets registered with name %q.", tm.id()))
206+
panic(fmt.Sprintf("multiple targets registered with id %+v.", tm.id()))
207207
}
208208
targetMakers[tm.id()] = tm
209209
}

pkg/tcpip/stack/nud_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,7 @@ func TestNUDConfigurationsMaxMulticastProbes(t *testing.T) {
568568
t.Fatalf("got stack.NUDConfigurations(%d, %d) = %s", nicID, ipv6.ProtocolNumber, err)
569569
}
570570
if got := sc.MaxMulticastProbes; got != test.want {
571-
t.Errorf("got MaxMulticastProbes = %q, want = %q", got, test.want)
571+
t.Errorf("got MaxMulticastProbes = %d, want = %d", got, test.want)
572572
}
573573
})
574574
}
@@ -619,7 +619,7 @@ func TestNUDConfigurationsMaxUnicastProbes(t *testing.T) {
619619
t.Fatalf("got stack.NUDConfigurations(%d, %d) = %s", nicID, ipv6.ProtocolNumber, err)
620620
}
621621
if got := sc.MaxUnicastProbes; got != test.want {
622-
t.Errorf("got MaxUnicastProbes = %q, want = %q", got, test.want)
622+
t.Errorf("got MaxUnicastProbes = %d, want = %d", got, test.want)
623623
}
624624
})
625625
}

runsc/container/container.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1753,7 +1753,7 @@ func setOOMScoreAdj(pid int, scoreAdj int) error {
17531753
log.Warningf("Process (%d) exited while setting oom_score_adj", pid)
17541754
return nil
17551755
}
1756-
return fmt.Errorf("setting oom_score_adj to %q: %v", scoreAdj, err)
1756+
return fmt.Errorf("setting oom_score_adj to %d: %v", scoreAdj, err)
17571757
}
17581758
return nil
17591759
}

runsc/container/shared_volume_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func TestSharedVolume(t *testing.T) {
7676
if ws, err := c.executeSync(conf, argsTestFile); err != nil {
7777
t.Fatalf("unexpected error testing file %q: %v", filename, err)
7878
} else if ws.ExitStatus() == 0 {
79-
t.Errorf("test %q exited with code %v, wanted not zero", ws.ExitStatus(), err)
79+
t.Errorf("test %q exited with code %v, wanted not zero", filename, ws.ExitStatus())
8080
}
8181

8282
// Create the file from outside of the sandbox.

runsc/sandbox/sandbox.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1448,7 +1448,7 @@ func (s *Sandbox) destroy() error {
14481448
if pid != 0 {
14491449
log.Debugf("Killing sandbox %q", s.ID)
14501450
if err := unix.Kill(pid, unix.SIGKILL); err != nil && err != unix.ESRCH {
1451-
return fmt.Errorf("killing sandbox %q PID %q: %w", s.ID, pid, err)
1451+
return fmt.Errorf("killing sandbox %q PID %d: %w", s.ID, pid, err)
14521452
}
14531453
if err := s.waitForStopped(); err != nil {
14541454
return fmt.Errorf("waiting sandbox %q stop: %w", s.ID, err)

test/cmd/test_app/fds.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ func (fds *fdSender) Execute(ctx context.Context, f *flag.FlagSet, args ...any)
8989
w := s.Writer(true)
9090
w.ControlMessage.PackFDs(int(fileToSend.Fd()))
9191
if _, err := w.WriteVec([][]byte{{'a'}}); err != nil {
92-
log.Fatalf("Error sending FD %q over socket %q: %v", fileToSend.Fd(), fds.socketPath, err)
92+
log.Fatalf("Error sending FD %d over socket %q: %v", fileToSend.Fd(), fds.socketPath, err)
9393
}
9494

9595
log.Print("FD SENDER exiting successfully")

tools/bazeldefs/defs.bzl

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,3 @@ def bpf_program(name, src, bpf_object, visibility, hdrs):
106106
outs = [bpf_object],
107107
cmd = "clang -O2 -Wall -Werror -target bpf -c $< -o $@ -I/usr/include/$$(uname -m)-linux-gnu",
108108
)
109-
110-
def get_goversion():
111-
"""Returns the current go-version used to build gVisor."""
112-
return "1.25.5"

tools/bazeldefs/go.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def go_context(ctx, goos = None, goarch = None):
188188
goarch = goarch or go_ctx.sdk.goarch,
189189
goos = goos or go_ctx.sdk.goos,
190190
gotags = go_ctx.tags,
191+
lang_version = "go" + go_ctx.sdk.version, # go_ctx.sdk.version excludes the go prefix.
191192
nogo_args = nogo_args,
192193
runfiles = depset([go_ctx.go] + go_ctx.sdk.srcs.to_list() + go_ctx.sdk.tools.to_list() + go_ctx.stdlib.libs.to_list()),
193194
stdlib_srcs = go_ctx.sdk.srcs,

tools/defs.bzl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ change for Google-internal and bazel-compatible rules.
77

88
load("//tools:arch.bzl", "arch_genrule", "arch_transition_impl")
99
load("//tools/bazeldefs:cc.bzl", _cc_binary = "cc_binary", _cc_flags_supplier = "cc_flags_supplier", _cc_grpc_library = "cc_grpc_library", _cc_library = "cc_library", _cc_proto_library = "cc_proto_library", _cc_test = "cc_test", _cc_toolchain = "cc_toolchain", _gbenchmark = "gbenchmark", _gbenchmark_internal = "gbenchmark_internal", _grpcpp = "grpcpp", _gtest = "gtest", _select_gtest = "select_gtest")
10-
load("//tools/bazeldefs:defs.bzl", _BuildSettingInfo = "BuildSettingInfo", _bool_flag = "bool_flag", _bpf_program = "bpf_program", _build_test = "build_test", _bzl_library = "bzl_library", _coreutil = "coreutil", _default_net_util = "default_net_util", _get_goversion = "get_goversion", _more_shards = "more_shards", _most_shards = "most_shards", _proto_library = "proto_library", _select_arch = "select_arch", _select_system = "select_system", _short_path = "short_path", _version = "version")
10+
load("//tools/bazeldefs:defs.bzl", _BuildSettingInfo = "BuildSettingInfo", _bool_flag = "bool_flag", _bpf_program = "bpf_program", _build_test = "build_test", _bzl_library = "bzl_library", _coreutil = "coreutil", _default_net_util = "default_net_util", _more_shards = "more_shards", _most_shards = "most_shards", _proto_library = "proto_library", _select_arch = "select_arch", _select_system = "select_system", _short_path = "short_path", _version = "version")
1111
load("//tools/bazeldefs:go.bzl", _gazelle = "gazelle", _go_binary = "go_binary", _go_cov = "go_cov", _go_grpc_and_proto_libraries = "go_grpc_and_proto_libraries", _go_imports = "go_imports", _go_library = "go_library", _go_path = "go_path", _go_proto_library = "go_proto_library", _go_test = "go_test", _gotsan_flag_values = "gotsan_flag_values", _gotsan_values = "gotsan_values", _select_goarch = "select_goarch", _select_goos = "select_goos")
1212
load("//tools/bazeldefs:pkg.bzl", _pkg_deb = "pkg_deb", _pkg_tar = "pkg_tar")
1313
load("//tools/bazeldefs:platforms.bzl", _default_platform = "default_platform", _platform_capabilities = "platform_capabilities", _platforms = "platforms", _save_restore_platforms = "save_restore_platforms")
@@ -25,7 +25,6 @@ BuildSettingInfo = _BuildSettingInfo
2525
default_net_util = _default_net_util
2626
select_arch = _select_arch
2727
select_system = _select_system
28-
get_goversion = _get_goversion
2928
short_path = _short_path
3029
coreutil = _coreutil
3130
more_shards = _more_shards

0 commit comments

Comments
 (0)