RFR: 8351440: Link with -reproducible on macOS
Mikael Vidstedt
mikael at openjdk.org
Fri Mar 7 22:03:22 UTC 2025
Background (from JBS):
Recent versions of Xcode, most likely starting with Xcode 15, do not produce deterministic binaries/libraries out of the box. In particular, the UUID data in the LC_UUID load command is not stable.
After spending some significant time trying to understand why, it turns out that the linker has started including the last modified time stamp of the object files in the (debug?) data and that time stamp data is included in the computed UUID "hash". So even if the rest of the data is the same between two builds, the build time (or, more accurately, the time when the object file gets written to the file system) now affects the UUID and therefore the data of the resulting .dylib files.
It seems (unconfirmed) like this may be an artifact of Xcode 15 using a new linker ("ld-prime") which may or may not be why the behavior has changed.
After spending even more time trying to understand what to do about it I noticed this in the ld man page:
-reproducible
By default output content will be deterministic, but small changes in input files such as a compilation time might affect certain data structures in the linked binary. This option instructs ld to create a reproducible output binary by ignoring certain input properties or using alternative algorithms.
And, adding that flag (-Wl,-reproducible to clang) does indeed seem to solve the issue.
Testing:
* Manual verification with both Xcode14.3.1 and Xcode 15.4
* tier1,builds-tier[2-5]
-------------
Commit messages:
- 8351440: Link with -reproducible on macOS
Changes: https://git.openjdk.org/jdk/pull/23949/files
Webrev: https://webrevs.openjdk.org/?repo=jdk&pr=23949&range=00
Issue: https://bugs.openjdk.org/browse/JDK-8351440
Stats: 1 line in 1 file changed: 0 ins; 0 del; 1 mod
Patch: https://git.openjdk.org/jdk/pull/23949.diff
Fetch: git fetch https://git.openjdk.org/jdk.git pull/23949/head:pull/23949
PR: https://git.openjdk.org/jdk/pull/23949
More information about the build-dev
mailing list