Skip to content

Add best effort macOS reproducibility flags#692

Open
keith wants to merge 2 commits intobazelbuild:mainfrom
keith:ks/add-best-effort-macos-reproducibility-flags
Open

Add best effort macOS reproducibility flags#692
keith wants to merge 2 commits intobazelbuild:mainfrom
keith:ks/add-best-effort-macos-reproducibility-flags

Conversation

@keith
Copy link
Copy Markdown
Member

@keith keith commented Apr 15, 2026

Without -ffile-compilation-dir=. (or a similar flag), debug info in
.o files contains the absolute path to the compile time execroot.
Without -Wl,-oso_prefix,. final binaries contain N_OSO stabs that
contain absolute paths to the files link time execroot.

This still leaves 1 known hole that is the absolute path to Xcode is
embedded in debug info, but that doesn't break debuggability like these
2 issues do, it just makes the binaries non hermetic. Fixing that one
requires a compiler wrapper.

All of these issues are fixed in apple_support, but for folks not using
that toolchain these are pretty low risk to add here. The only issue is
if people have very old versions of Xcode / the Xcode command line tools
these flags won't exist.

More info about these paths in https://www.smileykeith.com/2025/09/21/understanding-apple-debug-info/

@keith
Copy link
Copy Markdown
Member Author

keith commented Apr 16, 2026

  • oso_prefix was added in Xcode 11.3.1 in january 2020 (using . as the value wasn't supported until 13.0, but it would still accept it, it would just not work)
  • ffile-compilation-dir was added in Xcode 13.3 in march 2022

i think we're past those enough to not worry about that anymore

Copy link
Copy Markdown
Collaborator

@armandomontanez armandomontanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice! Would be nice to do similar with Linux with the caveat that toolchains are much more diverse in that world.

@armandomontanez armandomontanez added type: bug Something that should be working isn't working P2 We'll consider working on this in future. (Assignee optional) category: toolchains labels Apr 16, 2026
@armandomontanez
Copy link
Copy Markdown
Collaborator

Might be worth discussing toolchain configuration compatibility expectations at the next sync. Added to the agenda.

@keith
Copy link
Copy Markdown
Member Author

keith commented Apr 16, 2026

that is actually somewhat solved today by this:

if "requires_darwin" not in execution_info:
# This prevents gcc from writing the unpredictable (and often irrelevant)
# value of getcwd() into the debug info.
env = env | {"PWD": "/proc/self/cwd"}

@keith
Copy link
Copy Markdown
Member Author

keith commented Apr 20, 2026

as discussed in the meeting today I updated this to dynamically check if this feature is supported

Copy link
Copy Markdown
Collaborator

@armandomontanez armandomontanez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@armandomontanez armandomontanez added the untriaged Team member has to triage this issue - assign priority, type, and owner (if possible). label Apr 20, 2026
lilygorsheneva
lilygorsheneva previously approved these changes Apr 21, 2026
keith added 2 commits April 24, 2026 10:18
Without `-ffile-compilation-dir=.` (or a similar flag), debug info in
`.o` files contains the absolute path to the compile time execroot.
Without `-Wl,-oso_prefix,.` final binaries contain `N_OSO` stabs that
contain absolute paths to the files link time execroot.

This still leaves 1 known hole that is the absolute path to Xcode is
embedded in debug info, but that doesn't break debuggability like these
2 issues do, it just makes the binaries non hermetic. Fixing that one
requires a compiler wrapper.

All of these issues are fixed in apple_support, but for folks not using
that toolchain these are pretty low risk to add here. The only issue is
if people have very old versions of Xcode / the Xcode command line tools
these flags won't exist.

More info about these paths in https://www.smileykeith.com/2025/09/21/understanding-apple-debug-info/
@keith keith force-pushed the ks/add-best-effort-macos-reproducibility-flags branch from 208bc4d to ddfdc07 Compare April 24, 2026 17:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

category: toolchains P2 We'll consider working on this in future. (Assignee optional) type: bug Something that should be working isn't working untriaged Team member has to triage this issue - assign priority, type, and owner (if possible).

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants