-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Misc MachO linker improvements and link-tests refactor #13964
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Fix path written to `LC_ID_DYLIB` to include the current CWD (if any).
By pulling out the parallel hashing setup from `CodeSignature.zig`, we can now reuse it different places across MachO linker (for now; I can totally see its usefulness beyond MachO, eg. in COFF or ELF too). The parallel hasher is generic over actual hasher such as Sha256 or MD5. The implementation is kept as it was. For UUID calculation, depending on the linking mode: * incremental - since it only supports debug mode, we don't bother with MD5 hashing of the contents, and populate it with random data but only once per a sequence of in-place binary patches * traditional - in debug, we use random string (for speed); in release, we calculate the hash, however we use LLVM/LLD's trick in that we calculate a series of MD5 hashes in parallel and then one an MD5 of MD5 final hash to generate digest.
Member
Author
|
@andrewrk I have applied your patch #13919 (comment), let's see if this is enough to guarantee byte-for-byte reproducibility on macOS :-) |
I need to think some more how to calculate UUID in parallel, if it is even possible, to preserve UUID's determinism.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This turned out to be quite a large change for which I do apologise, but the vast majority of them is for the MachO linker so reviewing updates to the link-tests harness should be manageable. Anyhow, here's a summary of the changes.
MachO
Fixes #11737
MachO now generates a fully reproducible UUID value between runs. It matches the behaviour of Apple's
ld64in that calculating the UUID for a binary, we exclude regions in the final binary that are non-deterministic, i.e. depend on the presence of debug info stabs in the file, and these include:__LINKEDITsegment command headerLC_SYMTABandLC_DYSYMTABcommand headersLC_CODE_SIGNATUREcommand headerI would like to point out here that
llddoes not generate UUID this way thus not matching Apple's behavior: D92736.With this, running
produces two files with identical UUIDs even though one has debug info while the other doesn't.
While at it, I have thoroughly cleaned up how we track different offsets of interest in the final binary.
One thing I am not happy with is the fact that in order to calculate the UUID we have do streaming MD5 hashing. I have tried re-using the thread pool like we do for sha256 when code signing, however, due to the presence of gaps in the file due to exclusions, it is a non-trivial task. I will think about it some more though.
Finally, calculating a deterministic UUID is only enforced for release builds; debug builds hash some random string generating a valid MD5 hash but not reproducible between runs.
### Link testsMy previous solution to selective grepping and variable extracting of data from object dumps was unnecessarily complicated and so I took this opportunity to rewrite it a little (and simplify a lot!). It is how based around creating a tree-like structure of steps which are then resolved in a breadth-first manner.An example of old syntax:now becomeswhich I think is cleaner. The harness itself is definitely easier to extend now if need be. cc'ing @Luukdegram as you will probably want to take a look at this before it is merged.EDIT: After further thought, changes to the link test are not warranted in this PR and I have since reverted them back. (cc @Luukdegram, sorry for the noise!)