RFR: 8351440: Link with -reproducible on macOS
Magnus Ihse Bursie
ihse at openjdk.org
Mon Mar 10 13:11:58 UTC 2025
On Fri, 7 Mar 2025 20:46:32 GMT, Mikael Vidstedt <mikael at openjdk.org> wrote:
> 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]
Marked as reviewed by ihse (Reviewer).
-------------
PR Review: https://git.openjdk.org/jdk/pull/23949#pullrequestreview-2670900587
More information about the build-dev
mailing list