30 Commits
Author SHA1 Message Date
Tamir Duberstein 6f79697120 Fix S1021 violations and drop suppression 2026-02-10 11:56:14 -08:00
Tamir Duberstein 2882eec4b4 Fix QF1003 violations and drop suppression 2026-02-10 11:55:50 -08:00
Tamir DubersteinandgVisor bot 7c117d1aca Update Go to 1.25.5
- **checkescape: improve error output**
  The output now includes stderr on failure e.g.:
  ```
  checkescape: tools/checkescape/test2/test2.go:98:6: stack: possible split on function entry (2 omitted) → (possible, error running "external/rules_go++go_sdk+main___download_0/bin/go tool objdump bazel-out/k8-fastbuild-ST-04c87098fb12/bin/tools/checkescape/test2/test2.a": exit status 2 (go: no such tool "objdump")) (GOOARCH=amd64, GOOS=linux)
  ```

  Simplify various bits of the implementation while I'm here:
  - Use a set of strings rather than a list to avoid some O(n) operations.
  - Use `CommandContext` to ensure proper cleanup.
  - Remove stderr pipe and goroutine by setting `Stderr` to a
    `bytes.Buffer`.
  - Use `bufio.Scanner` instead of manually calling
    `(*bufio.Reader).ReadString` and handling errors.
  - Remove `NextLine` loop label.
-  **go_stateify: plumb go binary to goimports**
    This avoids go_stateify relying on `go` being available outside of the
    bazel sandbox.
- **Update Go to 1.25.5**
  Reduce duplication of the version information in various places:
  - Use `go_sdk.from_file` instead of repeating the version encoded in
    `go.mod` in `MODULE.bazel`.

  Add a workaround to allow `objdump` to be lazily compiled in the manner
  introduced in https://go.dev/issue/71867 when invoked under bazel in
  checkescape.

COPYBARA_INTEGRATE_REVIEW=https://github.com/google/gvisor/pull/12452 from tamird:update-go 6c7f6400f5d3ea883096eef18d365c97f875bc68
PiperOrigin-RevId: 853572845
2026-01-07 23:11:36 -08:00
Koichi Shiraishi 5677ce4285 all: remove use io/ioutil deprecated package & fix some deprecated thing
Signed-off-by: Koichi Shiraishi <[email protected]>
2024-10-10 20:36:24 +09:00
gVisor bot b73718c7df Fix printf violations inside of the gvisor code
Recently printf.Analyzer has become stricter
(https://github.com/golang/go/issues/60529)
which led to new findings.
gvisor nogo tests run this analyzer and fail if it produces findings.

PiperOrigin-RevId: 671657227
2024-09-06 00:45:23 -07:00
Adin ScannellandgVisor bot 2911d8c3b8 Add default_applicable_licenses rules to packages.
PiperOrigin-RevId: 513581243
2023-03-02 10:50:04 -08:00
Adin ScannellandgVisor bot 234d1c6a9f Move goid to dynamic facts render.
This removes the need for ongoing tags.

This change requires some minor updates to remove dependency cycles, since
the goid package is a base library used by many internals (log, sync, etc.).

PiperOrigin-RevId: 504066914
2023-01-23 13:29:37 -08:00
Kevin KrakauerandgVisor bot 3a76efe831 convert uses of interface{} to any
Done via:
  find . -name "*.go" | xargs sed -i -E 's/interface\{\}/any/g'

PiperOrigin-RevId: 487033228
2022-11-08 13:14:06 -08:00
Nicolas LacasseandgVisor bot 320ffab1a9 checkescape: Treat syscall.RawSyscall() as though its arguments do not escape.
...as we do for unix.RawSyscall.

PiperOrigin-RevId: 452181471
2022-05-31 17:55:32 -07:00
Kevin KrakauerandgVisor bot c946a298fd checkescape: address ARM relative offsets
`go tool objdump` produces relative offsets for BL instructions as a number of
instructions rather than a number of bytes. Calculate the byte offset ourselves.

Example passing run on ARM machine:
https://buildkite.com/gvisor/pipeline/builds/14732#018106ac-ac8e-4636-9a5a-bde1641b1175

Filed bug upstream about confusing output here:
https://github.com/golang/go/issues/53117

PiperOrigin-RevId: 452137751
2022-05-31 14:16:25 -07:00
Ayush RanjanandgVisor bot 2026e1f078 Reformat codebase.
PiperOrigin-RevId: 449358041
2022-05-17 17:48:35 -07:00
Etienne PerotandgVisor bot ffeb98263d Fix broken +checkescape annotation in sleep package.
Make `checkescape` check for variants of `+checkescape` that would silently be
ignored. #codehealth

PiperOrigin-RevId: 436882400
2022-03-23 18:54:56 -07:00
Adin ScannellandgVisor bot 8b60115f51 Ensure that nogo is enabled.
A recent change stopped using the correct file (the export data, not the
archive) and checklocks started failing. Unfortunately, this was suppressed,
since the filter command was not failing with findings.

This change fixes that problem and adds a test to ensure that this cannot
happen again. If nogo starts failing to identify problems, the sanity_test in
nogo/sanity will also start to fail.

This change also requires updating the WORKSPACE to the latest rules_go and
Go version, in order to pick up the fixed go_tools. The latest rules_go in
turn required an updated bazel, which in turn required a minor change in the
coverdata implementation.

Fixing the fact propagation brought forward a number of problems with caching
for bazel workers. Its unclear whether this was a core worker issue or whether
some caching was broken, but the situation was basically undebugable. Instead,
the way facts are stored and loaded is optimized to be able to remove the use
of workers altogether and ideally make nogo debuggable.

PiperOrigin-RevId: 426327186
2022-02-03 23:45:40 -08:00
Adin ScannellandgVisor bot dedef233cd Refactor nogo and provide facts render.
This change makes the core nogo package less of a "catch all", and splits
functionality into multiple packages. Instead of separate binaries for each
function, a single "cli" package is added with subcommands, and the core
starlark wrappers are also refactored to minimize redundancy.

The new "cli" package also adds support for a "render" command, which
allows factors to be rendered via a Go text template. This is useful for
debugging, but also allows code generation to be updated to use this
mechanism. This eliminates the use of a QEMU wrapper for the older
arch_genrule, and allows the use of a native bazel transition to extract
facts for the appropriate generated file. In other words, the correct facts
will be rendered for generating XXX_arm64.s, even on amd64.

PiperOrigin-RevId: 422846459
2022-01-19 10:26:27 -08:00
Adin ScannellandgVisor bot 0f15e2418e Mix checklocks and atomic analyzers.
This change makes the checklocks analyzer considerable more powerful, adding:
* The ability to traverse complex structures, e.g. to have multiple nested
  fields as part of the annotation.
* The ability to resolve simple anonymous functions and closures, and perform
  lock analysis across these invocations. This does not apply to closures that
  are passed elsewhere, since it is not possible to know the context in which
  they might be invoked.
* The ability to annotate return values in addition to receivers and other
  parameters, with the same complex structures noted above.
* Ignoring locking semantics for "fresh" objects, i.e. objects that are
  allocated in the local frame (typically a new-style function).
* Sanity checking of locking state across block transitions and returns, to
  ensure that no unexpected locks are held.

Note that initially, most of these findings are excluded by a comprehensive
nogo.yaml. The findings that are included are fundamental lock violations.
The changes here should be relatively low risk, minor refactorings to either
include necessary annotations to simplify the code structure (in general
removing closures in favor of methods) so that the analyzer can be easily
track the lock state.

This change additional includes two changes to nogo itself:
* Sanity checking of all types to ensure that the binary and ast-derived
  types have a consistent objectpath, to prevent the bug above from occurring
  silently (and causing much confusion). This also requires a trick in
  order to ensure that serialized facts are consumable downstream. This can
  be removed with https://go-review.googlesource.com/c/tools/+/331789 merged.
* A minor refactoring to isolation the objdump settings in its own package.
  This was originally used to implement the sanity check above, but this
  information is now being passed another way. The minor refactor is preserved
  however, since it cleans up the code slightly and is minimal risk.

PiperOrigin-RevId: 382613300
2021-07-01 15:07:56 -07:00
Adin ScannellandgVisor bot 89a86310a4 Fix nogo analysis.
Ignore calls to atomic functions in case there is no analysis information.
It is unclear why this has broken in some cases, perhaps these functions
have been replaced by intrinsics as an optimization?

PiperOrigin-RevId: 374682441
2021-05-19 10:56:45 -07:00
Adin ScannellandgVisor bot 34475e288b Remove go_tool_library references.
This is required only for the built-in bazel nogo functionality.
Since we roll these targets manually via the wrappers, we don't need
to use go_tool_library. The inconsistent use of these targets leads
to conflicting instantiations of go_default_library and go_tool_library,
which both contain the same output files.

PiperOrigin-RevId: 355184975
2021-02-02 09:37:09 -08:00
Adin ScannellandgVisor bot 0dab30d83f Fix simple mistakes identified by goreportcard.
These are primarily simplification and lint mistakes. However, minor
fixes are also included and tests added where appropriate.

PiperOrigin-RevId: 351425971
2021-01-12 12:38:22 -08:00
Michael PrattandgVisor bot f6db45a80c Include objdump failures in test output.
We log a warning if objdump fails, but this appears in the build log, not test
log, which can make it hard to notice.

Include it with the actual escape output as context on "(possible)" to make it
more clear when something is wrong.

PiperOrigin-RevId: 350355759
2021-01-06 08:17:30 -08:00
gVisor bot 6f647e22da Merge pull request #5169 from laijs:fix-typo-whicy
PiperOrigin-RevId: 350200437
2021-01-05 12:54:23 -08:00
Lai Jiangshan 005d3def1d typo: change whicy to which
Signed-off-by: Lai Jiangshan <[email protected]>
2020-12-27 11:28:16 +08:00
Adin ScannellandgVisor bot 69f0412910 Remove existing nogo exceptions.
PiperOrigin-RevId: 347047550
2020-12-11 12:06:49 -08:00
Adin ScannellandgVisor bot 56dd1e2544 Remove legacy bazel configurations.
Using the newer bazel rules necessitates a transition from proto1 to
proto2. In order to resolve the incompatibility between proto2 and
gogoproto, the cri runtimeoptions proto must be vendored.

Further, some of the semantics of bazel caching changed during the
transition. It is now necessary to:

- Ensure that :gopath depends only on pure library targets, as the
  propagation of go_binary build attributes (pure, static) will
  affected the generated files (though content remains the same,
  there are conflicts with respect to the gopath).
- Update bazel.mk to include the possibility of binaries in the
  bazel-out directory, as it will now put runsc and others there.
  This required some refinements to the mechanism of extracting
  paths, since some the existing regex resulted in false positives.
- Change nogo rules to prevent escape generation on binary targets.
  For some reason, the newer version of bazel attempted to run the
  nogo analysis on the binary targets, which fails due to the fact
  that objdump does not work on the final binary. This must be due
  to a change in the semantics of aspects in bazel3.

PiperOrigin-RevId: 337958324
2020-10-19 16:28:40 -07:00
Adin ScannellandgVisor bot e0b72735d6 Minor nogo cleanup.
PiperOrigin-RevId: 336126583
2020-10-08 11:24:21 -07:00
Andrei Vagin 0d924ccd0d tools/checkescape: trim the "(SB)" before searching it in the allowed list
Signed-off-by: Andrei Vagin <[email protected]>
2020-10-02 14:27:49 -07:00
Adin ScannellandgVisor bot 9bed26f8b4 Save addresses for "allowed" functions.
PiperOrigin-RevId: 335086850
2020-10-02 13:14:16 -07:00
Adin ScannellandgVisor bot b4e156ba6c Change nogo failures to test failures, instead of build failures.
PiperOrigin-RevId: 329408633
2020-08-31 17:09:20 -07:00
Adin ScannellandgVisor bot 99902c4fb2 Support stdlib analyzers with nogo.
This immediately revealed an escape analysis violation (!), where
the sync.Map was being used in a context that escapes were not
allowed. This is a relatively minor fix and is included.

PiperOrigin-RevId: 328611237
2020-08-26 14:42:35 -07:00
Adin ScannellandgVisor bot 8282a265f0 Support for saving pointers to fields in the state package.
Previously, it was not possible to encode/decode an object graph which
contained a pointer to a field within another type. This was because the
encoder was previously unable to disambiguate a pointer to an object and a
pointer within the object.

This CL remedies this by constructing an address map tracking the full memory
range object occupy. The encoded Refvalue message has been extended to allow
references to children objects within another object. Because the encoding
process may learn about object structure over time, we cannot encode any
objects under the entire graph has been generated.

This CL also updates the state package to use standard interfaces intead of
reflection-based dispatch in order to improve performance overall. This
includes a custom wire protocol to significantly reduce the number of
allocations and take advantage of structure packing.

As part of these changes, there are a small number of minor changes in other
places of the code base:

* The lists used during encoding are changed to use intrusive lists with the
  objectEncodeState directly, which required that the ilist Len() method is
  updated to work properly with the ElementMapper mechanism.

* A bug is fixed in the list code wherein Remove() called on an element that is
  already removed can corrupt the list (removing the element if there's only a
  single element). Now the behavior is correct.

* Standard error wrapping is introduced.

* Compressio was updated to implement the new wire.Reader and wire.Writer
  inteface methods directly. The lack of a ReadByte and WriteByte caused issues
  not due to interface dispatch, but because underlying slices for a Read or
  Write call through an interface would always escape to the heap!

* Statify has been updated to support the new APIs.

See README.md for a description of how the new mechanism works.

PiperOrigin-RevId: 318010298
2020-06-23 23:34:06 -07:00
Adin ScannellandgVisor bot bc65fedb36 Add internal nogo analysis & checkescape tool.
See tools/nogo/README.md.

The checkescape tool is able to perform recursive escape analysis, using the
actual generated binary to confirm the results produced by the compiler itself.

As an initial use case, this replaces the manual escape analysis tests used for
go_marshal, and validates that the CopyIn and CopyOut paths will not require
any allocation or stack splits.

Updates #2243

PiperOrigin-RevId: 307532986
2020-04-20 20:58:20 -07:00