Closed Bug 2086340 Opened 1 month ago Closed 26 days ago

Local sccache builds can reuse an object file compiled in another checkout with different headers

Categories

(Firefox Build System :: General, defect)

defect

Tracking

(firefox161 fixed)

RESOLVED FIXED
161 Branch
Tracking Status
firefox161 --- fixed

People

(Reporter: Logan, Assigned: Logan)

References

(Blocks 1 open bug)

Details

Attachments

(1 external file)

Since bug 2031965, configure sets SCCACHE_BASEDIRS to the objdir and srcdir by default. Local builds use the disk cache, where sccache 0.18 enables preprocessor cache mode, and those two together hit https://github.com/mozilla/sccache/issues/2863: the preprocessor cache key is computed with base directories stripped, but the stored manifest records absolute include paths and is validated against the first checkout's files. A second checkout can then get the first one's object even though its headers differ.

The sccache server only uses the base directories it was started with, so building two worktrees back to back with one server doesn't trigger it. It happens once the server restarts from the other worktree (the 600s idle timeout, or sccache --stop-server), which is a normal way to switch between worktrees.

Reproduced on macOS with ~/.mozbuild/sccache/sccache 0.18.0 and ~/.mozbuild/clang, client-side mode on, each compile setting SCCACHE_BASEDIRS to only its own tree:

  1. Two trees with an identical main.c that returns offsetof(struct S, b), and a cfg.h declaring struct S { int a; int b; } in tree A and struct S { int a; int pad; int b; } in tree B.
  2. Compile in A (starts the server), stop the server, compile in B (starts a new one).
  3. B's object returns 4 instead of 8; it is A's object.

To trigger it, a translation unit needs to be identical in both checkouts while a header it includes differs, and the first checkout's headers have to still be on disk unchanged. That is routine for worktrees a few commits apart, and the result is a silently wrong object rather than a build error.

Automation isn't affected: GCS/S3 storage leaves preprocessor cache mode off in sccache 0.18.

Rust ignores SCCACHE_BASEDIRS in 0.18, and with preprocessor cache mode the C/C++ keys only line up across worktrees after such a restart, so the default buys local builds very little. Proposed fix: only set the default in automation, keep the developer override, and document the SCCACHE_DIRECT=false workaround for anyone setting it by hand. The default can come back once Firefox pins an sccache with a fix (https://github.com/mozilla/sccache/pull/2868 is open).

With basedirs set, sccache's preprocessor cache (enabled by default for
local disk caches) can hand back an object compiled in another checkout
whose headers differ, as in mozilla/sccache#2863. Automation uses remote
storage, where the preprocessor cache is off, so keep the default there.

Assignee: nobody → loganrosen
Status: NEW → ASSIGNED

Follow-up for after this lands: once the sccache we pin in taskcluster/kinds/fetch/toolchains.yml includes a fix for https://github.com/mozilla/sccache/issues/2863 (currently https://github.com/mozilla/sccache/pull/2868, not yet merged or released), drop the moz_automation condition on default_sccache_basedirs so local builds get the cross-checkout path rewriting back, and revert the docs workaround.

Pushed by loganrosen@gmail.com: https://github.com/mozilla-firefox/firefox/commit/c6a620a8c4e2 https://hg.mozilla.org/integration/autoland/rev/347d4567601c Only set SCCACHE_BASEDIRS by default in automation. r=firefox-build-system-reviewers,glandium
Status: ASSIGNED → RESOLVED
Closed: 26 days ago
Resolution: --- → FIXED
Target Milestone: --- → 161 Branch
See Also: → 2098965
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: