Skip to content

Fix oso_prefix paths#347

Merged
keith merged 1 commit intomasterfrom
ks/fix-oso_prefix-paths
Sep 30, 2024
Merged

Fix oso_prefix paths#347
keith merged 1 commit intomasterfrom
ks/fix-oso_prefix-paths

Conversation

@keith
Copy link
Copy Markdown
Member

@keith keith commented Sep 30, 2024

When bazel executions actions in the sandbox, pwd is a path like this:

/private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/8/execroot/_main

Inside this directory are the inputs, which are symlinks to outside of
this pwd:

/private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/1/execroot/_main/bazel-out/darwin_arm64-dbg/bin/_objs/main/main.o -> /private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/execroot/_main/bazel-out/darwin_arm64-dbg/bin/_objs/main/main.o

ld64 resolves the absolute path to this object file, including resolving
symlinks, before it strips the -oso_prefix argument. Because of this
the previous __BAZEL_EXECUTION_ROOT__ replacement, which was the
sandbox pwd, isn't actually a prefix of the canonicalized object file
path, leading to -oso_prefix being a no-op, and absolute paths ending up
in the binary.

I think many folks didn't see this locally because it's common for Apple
projects to disable sandboxing for local development for perf reasons,
and that's when you're likely to have this debug info in the binary in
the first place.

With this change we add a new substitution that calculates the
sandbox-independent prefix and passes that along instead.

When bazel executions actions in the sandbox, pwd is a path like this:

```
/private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/8/execroot/_main
```

Inside this directory are the inputs, which are symlinks to outside of
this pwd:

```
/private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/sandbox/darwin-sandbox/1/execroot/_main/bazel-out/darwin_arm64-dbg/bin/_objs/main/main.o -> /private/var/tmp/_bazel_ksmiley/92410d0e3373f265902564b48493ac12/execroot/_main/bazel-out/darwin_arm64-dbg/bin/_objs/main/main.o
```

ld64 resolves the absolute path to this object file, including resolving
symlinks, _before_ it strips the -oso_prefix argument. Because of this
the previous `__BAZEL_EXECUTION_ROOT__` replacement, which was the
sandbox pwd, isn't actually a prefix of the canonicalized object file
path, leading to -oso_prefix being a no-op, and absolute paths ending up
in the binary.

I think many folks didn't see this locally because it's common for Apple
projects to disable sandboxing for local development for perf reasons,
and that's when you're likely to have this debug info in the binary in
the first place.

With this change we add a new substitution that calculates the
sandbox-independent prefix and passes that along instead.
@keith keith merged commit 8ee7a2d into master Sep 30, 2024
@keith keith deleted the ks/fix-oso_prefix-paths branch September 30, 2024 21:36
keith added a commit that referenced this pull request May 4, 2025
This linker bug was fixed in Xcode 16.3. It would be a bit of a pain to
support both so this just reverts the fix and users on the older
versions should stay on older apple_supports until they upgrade Xcode.

Fixes #401
Fixes #404

This reverts commit 8ee7a2d.
keith added a commit that referenced this pull request May 4, 2025
This linker bug was fixed in Xcode 16.3. It would be a bit of a pain to
support both so this just reverts the fix and users on the older
versions should stay on older apple_supports until they upgrade Xcode.

Fixes #401
Fixes #404

This reverts commit 8ee7a2d.
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.

2 participants