Skip to content

macos: recover paths that restart at a symbolic link - #31

Draft
LalitMaganti wants to merge 1 commit into
macos-record-4from
macos-record-5
Draft

LalitMaganti wants to merge 1 commit into
macos-record-4from
macos-record-5

Conversation

@LalitMaganti

@LalitMaganti LalitMaganti commented Sep 16, 2026 •

Copy link
Copy Markdown
Owner

Summary

Recovers the paths of files opened through a relative symbolic link. Without this, #29 resolves them against the wrong directory.

Fifth of seven steps towards #2. Stacked on #30.

Why

When a lookup follows a relative link, the kernel reports the link's text and the rest of the path. It does not report the directory that holds the link. A read through Homebrew's ../Cellar links or the SDK's MacOSX.sdk link therefore arrives as a path with no starting point. Resolving it against the process's directory produces a path that does not exist.

Changes

  • Vnodes: with each lookup, the kernel reports a vnode, which identifies the file it found. When any process looks a file up by its absolute path, Buildprof remembers that path for the vnode. A later lookup through a link is then matched by its vnode. For a name that does not exist yet, the vnode identifies the directory instead. A match then also needs the file names to agree.
  • Links near the root: a link such as /var, which points at private/var, makes a path continue from the root. Buildprof checks whether the first name exists in the process's directory or at the root. It checks again every time, because a build creates and deletes directories as it goes.

Links that no process ever looks up by absolute path are still resolved against the process's directory. #49 records those as unknown instead.

Benchmarks

Share of paths that match what Endpoint Security reports for the same build:

Build Before After
Clean cargo build 68% 83%
make 64% 92%

With the whole stack, build outputs, crate sources and project files match 99 to 100% of the time. The paths that still differ are reads of toolchain files.

Testing

Unit tests cover recovering a lookup that restarted at a symbolic link, and resolving one that restarted at a link near the root.

@LalitMaganti
LalitMaganti added this pull request to stack #32 September 16, 2026 12:57
@LalitMaganti
LalitMaganti force-pushed the macos-record-5 branch 2 times, most recently from bbd2501 to d342da5 Compare September 16, 2026 13:31
@LalitMaganti
LalitMaganti removed this pull request from stack #32 October 18, 2026 02:40
@LalitMaganti
LalitMaganti added this pull request to stack #48 October 18, 2026 02:40
@LalitMaganti
LalitMaganti force-pushed the macos-record-5 branch 2 times, most recently from e25a613 to 7fecd8b Compare October 18, 2026 06:13
@LalitMaganti
LalitMaganti force-pushed the macos-record-5 branch 2 times, most recently from 514c37b to 52c55ad Compare October 18, 2026 06:57
@LalitMaganti LalitMaganti changed the title [DNM] macos: recover paths that restart at a symbolic link macos: recover paths that restart at a symbolic link Oct 18, 2026
The kernel reports the path a lookup ended with. Following a relative
symbolic link therefore loses where the lookup started. A read through
Homebrew's links or the SDK's link arrives as the text after the link.
Resolving that against the process's directory invents a path that does
not exist.

This adds two recoveries.

- The kernel reports a vnode with each lookup. When any process looks a
  file up by its absolute path, Buildprof remembers that path for the
  vnode, and a later lookup through a link matches it. For a name that
  does not exist yet, the vnode identifies the directory instead. A
  match then also needs the file names to agree.
- A link near the root, like /var, points at private/var. Buildprof
  checks whether the first name exists in the process's directory or at
  the root. It checks every time, because a build creates and deletes
  directories as it goes.

On a clean cargo build, the share of paths that match what Endpoint
Security reports goes from 68% to 83%. On a make build it goes from 64%
to 92%.

This branch has not been deployed

No deployments
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