aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/CodeSignature.zig
AgeCommit message (Collapse)Author
2025-08-30upgrade more old API usesAndrew Kelley
2025-08-28link.MachO: code sig size grows when emitting itAndrew Kelley
2025-08-28link.MachO: update to not use GenericWriterAndrew Kelley
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-07-22add more tracy hooksJakub Konka
2024-01-24macho: write to fileJakub Konka
2024-01-24macho: get the ball rolling!Jakub Konka
2024-01-24macho: copy over new implementation sources from zldJakub Konka
2023-10-31std.builtin.Endian: make the tags lower caseAndrew Kelley
Let's take this breaking change opportunity to fix the style of this enum.
2023-10-31mem: fix ub in writeIntJacob Young
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
2023-08-29macho: merge Zld state with MachO stateJakub Konka
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19macho: clean up hasher interfaceJakub Konka
2023-06-19macho: extract parallel hasher into a generic helper structJakub Konka
2023-06-17mem: rename align*Generic to mem.align*Motiejus Jakštys
Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-04-28compiler: use `@memcpy` instead of `std.mem.copy`Andrew Kelley
2023-03-15extract ThreadPool and WaitGroup from compiler to std libAndrew Kelley
2022-12-16macho: fix 32bit buildJakub Konka
2022-12-16macho: move parallel file hashing back to CodeSignatureJakub Konka
I need to think some more how to calculate UUID in parallel, if it is even possible, to preserve UUID's determinism.
2022-12-16macho: generalize parallel hasher; impl parallel MD5-like hashJakub Konka
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.
2022-10-23macho: temp hash buffer has to live as long as pread error resolutionJakub Konka
2022-10-23macho: increment temp buffer when calculating hashesJakub Konka
2022-10-22link.MachO: multi-thread first round of sha256 hashingAndrew Kelley
when computing the adhoc code signature
2022-08-03macho: sync with zldJakub Konka
gitrev a2c32e972f8c5adfcda8ed2d99379ae868f59c24 https://github.com/kubkon/zld/commit/a2c32e972f8c5adfcda8ed2d99379ae868f59c24
2022-07-01macho: implement pruning of unused segments and sectionsJakub Konka
This is a prelude to a more elaborate work which will implement `-dead_strip` flag - garbage collection of unreachable atoms. Here, when sorting sections, we also check that the section is actually populated with some atoms, and if not, we exclude it from the final linked image. This can happen when we do not import any symbols from dynamic libraries in which case we will not be populating the stubs sections or the GOT table, implying we can skip allocating those sections. Furthermore, we also make a check that a segment is actually occupied too, with the exception of `__TEXT` segment which is non-optional given that it wraps the header and load commands and thus is required by the `dyld` to perform dynamic linking, and `__PAGEZERO` which is generally non-optional when the linked image is an executable. For any other segment, if its section count is zero, we mark it as dead and skip allocating it and generating a load command for it. This commit also includes some minor improvements to the linker such as refactoring of the segment allocating codepaths, skipping `__PAGEZERO` generation for dylibs, and skipping generation of zero-sized atoms for special symbols such as `__mh_execute_header` and `___dso_handle`. These special symbols are only allocated local and global symbol pair and their VM addresses is set to the start of the `__TEXT` segment, but no `Atom` is created, as it's not necessary given that they never carry any machine code. Finally, we now always force-link against `libSystem` which turns out to be required for `dyld` to properly handle `LC_MAIN` load command on older macOS versions such as 10.15.7.
2022-04-01macho: set CS_LINKER_SIGNED flag in code signature generated by zldJakub Konka
This way, if the user wants to use `codesign` (or other tool) they will not be forced to `-f` force signature update. This matches the behavior promoted by Apple's `ld64` linker.
2022-03-22macho: extend CodeSignature to accept entitlementsJakub Konka
With this change, we can now bake in entitlements into the binary. Additionally, I see this as the first step towards full code signature support which includes baking in Apple issued certificates for redistribution, etc.
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-01Update ensureTotalCapacity to ensureTotalCapacityPrecise where it makes senseRyan Liptak
These calls are all late-initialization of ArrayList's that were initialized outside the current scope. This allows us to still get the potential memory-saving benefits of the 'precision' of initCapacity.
2021-09-19Update all ensureCapacity calls to the relevant non-deprecated versionRyan Liptak
2021-08-01macho: fix Trie and CodeSignature unit testsJakub Konka
after the cleanup.
2021-08-01macho: make CodeSignature accept allocator as paramJakub Konka
instead storing it within the struct.
2021-05-08update usage of std.testing in stage2Veikka Tuominen
2021-01-15macho: use target arch page_size for codesigJakub Konka
It turns out I was wrong and we can set the page size to the actual page size used by the target architecture when dividing the binary into chunks and calculating a hash of each chunk for embedding within the adhoc code signature. This shaves of a considerable amount of bytes since we divide the code signature section by at least 2x. I've also unified the `write` interface of `CodeSignature` struct to follow that used in every other bit of `MachO`; namely, the functions now accept a writer instead of a buffer, therefore, there is no need to manually track where to write each struct field anymore.
2021-01-01macho: unblock stage2 on 32bit platforms (#7632)Jakub Konka
* macho: unblock stage2 on 32bit platforms Unblocks compilation of stage2 on 32bit platforms, and fixes #7630. * Use libstd convention: reads - usize, writes - u64
2020-12-19macho: auto-coerce to sliceJakub Konka
2020-12-01macho: dynamically calculate code signature paddingJakub Konka
2020-12-01macho: unify code signature between stage1 and stage2Jakub Konka
2020-12-01lld: use commands.LoadCommand in self-hosted linkerJakub Konka
2020-12-01lld: add code signature to lld outputJakub Konka
2020-11-26stage2 macho: first, rough draft at trampoliningJakub Konka
2020-11-26stage2 macho: cleanup logsJakub Konka
2020-11-26stage2 macho: fix issues with codesigningJakub Konka
2020-11-26stage2 macho: generate a code sig (not valid yet)Jakub Konka
2020-11-26stage2 macho: add info about __TEXT segmentJakub Konka
2020-11-26stage2 macho: add empty CodeDirectory blobJakub Konka
2020-11-26stage2 macho: move code signature logic into structJakub Konka