bazelbuild / bazelbuild/rules_apple

Non-deterministic linking when using default (ld64) linker

Open
#1,906 1 comment 1 reaction 0 assignees View on GitHub
Dominant language
Starlark
Stars
593
Forks
334
Avg merge
16h 48m
Merged PRs (30d)
9

Description

This is not a Bazel, nor rules apple issue but worth to have it documented (more context [here](https://bazelbuild.slack.com/archives/CD3QY5C2X/p1678791158903949)).

With some probability, the ordering of the `LC_LOAD_DYLIB` commands will vary between the test runs, thus the determinism of test bundles is going to be disrupted.

Repro steps can be found [here](https://github.com/sewerynplazuk/bazel-non-deterministic-test-bundles), although it is possible to reproduce this case without cleaning by relinking by putting something random in the linker arguments.

It should lead to
```
Load command 27
cmd LC_LOAD_WEAK_DYLIB
cmdsize 64
name /usr/lib/swift/libswiftFoundation.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 1.0.0
compatibility version 1.0.0
Load command 28
cmd LC_LOAD_WEAK_DYLIB
cmdsize 72
name /usr/lib/swift/libswiftCoreGraphics.dylib (offset 24)
time stamp 2 Thu Jan 1 01:00:02 1970
current version 120.100.0
compatibility version 1.0.0
```
these 2 commands switching places between the runs.

It's possible to use custom linker (i.e. [lld](https://github.com/keith/rules_apple_linker)) as a workaround. Please note that this can be risky for production builds.

I've filed the radar for the issue.

Contributor guide

Open the contributing guide

Research direction

Start with the linked reproduction repository and the issue’s documented linker output, then inspect this repository for the appropriate documentation location. Confirm the default ld64 behavior and the lld workaround before documenting the limitation, reproduction context, and production-build caution; done means the guidance is available in the project documentation.

Written by the indexing model from the issue text.

Assessment

Domain
build-system, documentation
Issue type
Documentation
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
32/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.