aboutsummaryrefslogtreecommitdiff
path: root/lib/std/macho.zig
AgeCommit message (Collapse)Author
2022-08-03macho: add missing align cast in LoadCommandIteratorJakub Konka
2022-08-03macho: update how we insert output sectionsJakub Konka
Instead of generating sections upfront, allow generation by scanning the object files for input -> output sections mapping. Next, always strive to keep output sections in the final container sorted as they appear in the final binary. This makes the linker less messy wrt handling of output sections sort order for dyld/macOS not to complain. There's still more work to be done for incremental context though to make this work but looks promising already.
2022-08-03macho: sync with zldJakub Konka
gitrev a2c32e972f8c5adfcda8ed2d99379ae868f59c24 https://github.com/kubkon/zld/commit/a2c32e972f8c5adfcda8ed2d99379ae868f59c24
2022-07-20macho: Pass sections by pointer when slicing namesCody Tapscott
We were accidentally returning a pointer to stack memory, because these arguments were passed by value. It's just an accident that stage 1 was passing these by reference, so things were alright until stage 3.
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-06-28macho: discriminate between normal and weak dylibsJakub Konka
Parse `-weak-lx` and `-weak_framework x` in the CLI.
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: add more codesig constantsJakub Konka
2022-03-19Sema: implement zirSwitchCaptureElse for error setsVeikka Tuominen
2022-03-13std+macho: revert and fix exposing Mach wrappers in std.os and std.cJakub Konka
2022-03-13std: fix imports for darwin specific flags and funcsJakub Konka
2022-03-13macos: add Mach task abstractionJakub Konka
`std.os.darwin.MachTask` wraps `mach_port_t` and can be used to issue kernel calls tied to the wrapped Mach kernel port/task.
2022-03-13macos: add more mach primitivesJakub Konka
2021-12-15macho: put `LC_*` consts in a typed enum(u32) LCJakub Konka
repeat for `PLATFORM_*` and `TOOL_*` sets
2021-12-10macho: move all helpers from commands.zig into std.machoJakub Konka
This way we will finally be able to share common parsing logic between different Zig components and 3rd party packages.
2021-12-10macho: move helper functions to libstdJakub Konka
Helper functions such as `commands.sectionName`, etc. should really belong in `std.macho.section_64` extern struct.
2021-11-30macho: move nlist_64 type/flags helpers to std.machoJakub Konka
2021-08-31macho: fix allocating sections within segment when parsing objectsJakub Konka
2021-08-24remove redundant license headers from zig standard libraryAndrew Kelley
We already have a LICENSE file that covers the Zig Standard Library. We no longer need to remind everyone that the license is MIT in every single file. Previously this was introduced to clarify the situation for a fork of Zig that made Zig's LICENSE file harder to find, and replaced it with their own license that required annual payments to their company. However that fork now appears to be dead. So there is no need to reinforce the copyright notice in every single file.
2021-08-10macho: swap out VERSION_MIN for BUILD_VERSIONJakub Konka
this makes the app successfully run on the iOS simluator!
2021-06-25Add fat/universal dylib support to zig ldTom Maenan Read Cutting
With this change zig ld can link with dynamic libraries contained within a fat/universal file that had multiple seperate binaries embedded within it for multi-arch support (in macOS). Whilst zig can still only create single-architecture executables - the ability to link with fat libraries is useful for cases where they are the easiest (or only) option to link against.
2021-05-18Merge remote-tracking branch 'origin/master' into stage2-whole-file-astgenAndrew Kelley
I want the updated Drone CI stuff to get the CI green.
2021-05-18zld: parse dylibs as positionalsJakub Konka
* add preliminary rpath support * enable shared_library test on x86_64 macOS
2021-05-18zld: parse dylib idJakub Konka
2021-04-22std: fix compile errors caught by stage2 AstGenAndrew Kelley
* `comptime const` is redundant * don't use `extern enum`; specify a tag type. `extern enum` is only when you need tags to alias. But aliasing tags is a smell. I will be making a proposal shortly to remove `extern enum` from the language. * there is no such thing as `packed enum`. * instead of `catch |_|`, omit the capture entirely. * unused function definition with missing parameter name * using `try` outside of a function or test
2021-04-21macho: fix typos in consts defsJakub Konka
2021-03-17zld: fix GOT loads and indirection on x86_64Jakub Konka
2021-03-17zld: start bringing x64 up to speedJakub Konka
2021-03-17zld: merge and sort sectionsJakub Konka
2021-03-17macho: offset table part of GOTJakub Konka
2021-01-26macho: add arm64 relocation type enumJakub Konka
2021-01-08libstd: add missing MachO rebase opcodes in macho.zigJakub Konka
2020-12-31Year++Frank Denis
2020-12-17lld+macho: lld xcomp to x86_64 macos now worksJakub Konka
2020-12-09macho: cleanup export trie generation and parsingJakub Konka
Now, ExportTrie is becoming usable for larger linking contexts such as linking in multiple object files, or relinking dylibs, etc.
2020-12-09small fixes and zig fmtVexu
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: fix incorrect rebaseJakub Konka
2020-11-26stage2 MachO: add source version load cmdJakub Konka
2020-11-26stage2 MachO: add min OS version load cmdJakub Konka
2020-11-16libstd: add more MachO consts and structsJakub Konka
2020-10-04Write out LC_DYSYMTAB together with dyld_stub_binder undef symbolJakub Konka
2020-10-04Generate more MachO exe boilerplateJakub Konka
* Convert draft to generate all relevant segments and sections in right places * Do not prealloc space in text blocks until we can NOP * Write out LC_LOAD_DYLINKER command * Add LC_LOAD_DYLIB command in order to specify to load libSystem * Redo update decl exports (similar to Elf globals, globals need to be contiguous in memory)
2020-09-08Fix bug where __text section would get overwrittenJakub Konka
Fixes a bug where the last written load command would accidentally override the beginning of the __text section. Also defines missing MachO constants and relocation structs/enums. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-30Add more missing MachO constants and structsJakub Konka
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24Add (empty) __TEXT segment load commandJakub Konka
Also, link against `libSystem` by default when targeting macOS. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24Clean up draft for merging into upstreamJakub Konka
Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>
2020-08-24Link against libSystem when generating Mach-O exeJakub Konka
This is required when generating an exe on macOS. Signed-off-by: Jakub Konka <kubkon@jakubkonka.com>