Skip to content

checklocks: enforce logging output ownership - #14347

Open
tamird wants to merge 4 commits into
google:masterfrom
tamird:checklocks-log-output
Open

checklocks: enforce logging output ownership#14347
tamird wants to merge 4 commits into
google:masterfrom
tamird:checklocks-log-output

Conversation

@tamird

@tamird tamird commented Aug 22, 2026

Copy link
Copy Markdown
Contributor

Depends on #14346. The change specific to this proposal is 32161d8. The current comparison against master also includes prerequisite commits; those prerequisites must land and be removed from this branch before submission.

Enforce mutex ownership of the line-writer buffer and log writer error counter. Keep atomic fast-path reads of the counter while requiring its updates to be both atomic and locked, and retain the emitter's borrowed buffer lifetime.

Require atomic access to the default logger pointer. The checker support from 6d996eb also covers its existing deferred test restoration. Keep SetTarget's concurrent-use restriction separate from pointer atomicity.

Assisted-by: Codex

@tamird

tamird commented Aug 22, 2026

Copy link
Copy Markdown
Contributor Author

r? @EtiennePerot Could you review logging ownership and the pure deferred-atomic integration?

Focused local Bazel checks passed. Upstream checks have not reported yet. This comparison currently includes the prerequisites linked in the description.

Assisted-by: Codex

tamird added 4 commits August 22, 2026 09:23
Recognize atomicbitops Racy methods as non-atomic operations. Permit
mixed-mode RacyLoad only when all guards are held, and require atomic
writes with all guards held exclusively. Distinguish shared-lock reads
from lock-free atomic reads so an RLock cannot authorize writes.

Check atomic uses of annotated globals at the consuming instruction
instead of discarding that instruction. Keep unannotated-global behavior
unchanged, preserve function and closure ignores, and distinguish writes
to a global from stores of its address.

Resolve generic instantiations to their original declarations before
classifying atomic operations. This recognizes atomic.Pointer methods
without bypassing package or mixed-access checks for generic calls.

Assisted-by: Codex
The Go parser places standalone variable documentation on GenDecl,
while checklocks only reads ValueSpec.Doc. As a result, standalone
global lock and atomic annotations are silently ignored. A multi-name
declaration also exports facts only for its first variable.

Keep the enclosing declaration when collecting global facts. Read
its documentation for standalone declarations and retain per-entry
documentation for var blocks. Export fresh facts for each named
variable, skipping blank identifiers.

Extend the existing local and cross-package fixtures to cover these
forms, atomic direct writes, and var-block comment boundaries.

Assisted-by: Codex
Atomic-use checking rejects valid deferred operations, including the
global logger's restoration with atomic.Pointer.Store once its
declaration annotation is active.

Classify pure atomic defers using the ordinary atomic-call rules,
preserving generic method support and the existing explicit-force
bypass. Guarded defers remain rejected: checking their locks when
registered would not establish ownership when executed.

Extend the existing atomic fixtures to cover deferred consumers and the
conservative boundaries for mixed accesses, Racy methods, and
goroutines.

Assisted-by: Codex
Enforce mutex ownership of the line-writer buffer, dropped-message
counter and reported-call-site map. Keep the counter's atomic fast-path
reads and require atomic updates under its mutex. Retain the emitter's
borrowed buffer lifetime and the map's exclusive package initialization.

Require atomic access to the default logger pointer and logging level.
Copy the level atomically when replacing the target, while preserving
SetTarget's concurrent-use restriction. The prerequisite checker changes
also support the existing deferred logger restoration.

Repair the existing dropped-message assertion to compare the complete,
ordered output, including the formatted count, instead of rejecting
equal lines and accepting incorrect expected values.

Assisted-by: Codex
@tamird
tamird force-pushed the checklocks-log-output branch from 32161d8 to ae8ddf5 Compare August 22, 2026 16:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant