aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO
AgeCommit message (Collapse)Author
2022-09-09macho: use globals free list like in COFF linkerJakub Konka
2022-09-07macho+wasm: unify and clean up closing file handlesJakub Konka
2022-08-30coff: reorganize the linkerJakub Konka
2022-08-24Merge pull request #12574 from Vexu/remove-bit-op-type-paramAndrew Kelley
stage2+stage1: remove type parameter from bit builtins
2022-08-23macho: fix compile errors in std.debugJakub Konka
2022-08-23std.debug: implement support for DWARFv5Andrew Kelley
2022-08-22Dwarf: Added stroffsetsptr support (#12270)Keith Chambers
* Added support for stroffsetsptr class in Dwarf stdlib * Proper initializion of debug_str_offsets in DwarfInfo * Added missing null initializer to DwarfInfo in Macho * Added missing is_64 field to getAttrString in DwarfInfo * Fixed formatting * Added missing is_64 param to getAttrString * Added required cast to usize * Adding missing .debug_str_offsets initialization * getAttrString now uses the str_offsets_base attr
2022-08-22stage2+stage1: remove type parameter from bit builtinsVeikka Tuominen
Closes #12529 Closes #12511 Closes #6835
2022-08-12macho: update __DWARF sections before and after writing out __LINKEDITJakub Konka
2022-08-10link.MachO: use accurate alignment attribute on pointersAndrew Kelley
Also adds a new method to ArrayList: appendUnalignedSlice
2022-08-10Revert "macho: allow unaligned offsets in object files"Andrew Kelley
This reverts commit 45c444ff18b43d30a7277e346174ba6eca4a6193.
2022-08-10macho: allow unaligned offsets in object filesJakub Konka
2022-08-03macho: do not preempt segment headers; do it when commiting to fileJakub Konka
This way, tracking segment-to-section mapping becomes a lot easier since it's effectively just start index plus number of sections defined within the segment. If a section becomes empty however care needs to be taken to remove the header upon committing to the final binary.
2022-08-03macho: fix linking in incremental contextJakub Konka
Fix incorrect writing of symtab and strtab in dSYM bundle in incremental context. Fix incorrectly navigating unnamed consts (freeing) in incremental context. This is currently hard-coded to require all consts to land in `__TEXT,__const`, which is wrong and needs a rewrite.
2022-08-03macho: cleanup output section selection logicJakub Konka
Cache only section indexes used by the linker for synthetic sections and/or incremental codepath.
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-27std.fmt: add more invalid format string errorsr00ster91
2022-07-26std.fmt: require specifier for unwrapping ?T and E!TInKryption
2022-07-25macho: fix memory leak and refactor Target usageJakub Konka
2022-07-22macho: include __StaticInit input sections as GC rootsJakub Konka
2022-07-22macho: dead_strip defaults: off for debug, on for releaseJakub Konka
2022-07-22macho: move GC code into dead_strip.zig moduleJakub Konka
Implement marking live atoms that reference other live atoms if required by the compiler (via section attribute).
2022-07-22macho: sort subsection symbols by seniorityJakub Konka
2022-07-22macho: do not GC local symbols unless reference dead symbolsJakub Konka
If a local references another local, we keep it. If it doesn't reference anything, we keep it. Otherwise, we dead strip it.
2022-07-22macho: parse data-in-code when writing LINKEDIT segmentJakub Konka
2022-07-22macho: do not store stabs; generate on-the-fly insteadJakub Konka
2022-07-22macho: improve logs for dyld infoJakub Konka
2022-07-22macho: don't store GC roots globallyJakub Konka
Instead, if dead-strip was requested, create a temp container and pass it around.
2022-07-22macho: link atom starting section by orig section idJakub Konka
In x86_64 relocs, it can so happen that the compiler refers to the same atom by both the actual assigned symbol and the start of the section. In this case, we need to link the two together so add an alias.
2022-07-22macho: rework symbol handling for incremental stage2 buildsJakub Konka
2022-07-22macho: fix compilation issues on 32bit hostsJakub Konka
2022-07-22macho: rework symbol handling to match zld/ELFJakub Konka
Now, each object file will store a mutable table of symbols that it defines. Upon symbol resolution between object files, the symbol will be updated with a globally allocated section ordinal and address in virtual memory. If the object defines a globally available symbol, its location only (comprising of the symbol index and object index) will be stored in the globals map for easy access when relocating, etc. This approach cleans up the symbol management significantly, and matches the status quo used in zld/ELF. Additionally, this makes scoping symbol stabs easier too as they are now naturally contained within each object file.
2022-07-22macho: remove unused fields from AtomJakub Konka
2022-07-22macho: split section into subsections if requested and/or possibleJakub Konka
2022-07-22macho: put parsing into an atom into a helperJakub Konka
2022-07-22macho: read the entire file contents into memory at onceJakub Konka
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: annotate weak imports when linking with weak lib/frameworkJakub Konka
2022-06-28macho: discriminate between normal and weak dylibsJakub Konka
Parse `-weak-lx` and `-weak_framework x` in the CLI.
2022-05-27math: make `cast` return optional instead of an errorAli Chraghi
2022-05-22Return an error when macOS ABI is not {none, simulator, macabi}Jakub Konka
2022-05-22Set macOS/iPhoneOS/tvOS/watchOS ABI to none (unspecified) by defaultJakub Konka
Prior to this change we would assume the ABI for Apple targets to be GNU which could result in subtle errors in LLVM emitting calls to non-existent system libc provided functions such as `_sincosf` which is a GNU extension and as such is not provided by macOS for example. This would result in linker errors where the linker would not be able to find the said symbol in `libSystem.tbd`. With this change, we now correctly identify macOS (and other Apple platforms) as having ABI `unknown` which translates to unspecified in LLVM under-the-hood: ``` // main.ll target triple = "aarch64-unknown-macos-unknown" ``` Note however that we never suffix the target OS with target version such as `macos11` or `macos12` which means we fail to instruct LLVM of potential optimisations provided by the OS such as the availability of function `___sincosf_stret`. I suggest we investigate that in a follow-up commit.
2022-05-06link/MachO: use const instead of var and limit scope of varsAndrew Kelley
2022-05-06Sema: solve a false positive "depends on itself"Andrew Kelley
This improves the ABI alignment resolution code. This commit fully enables the MachO linker code in stage3. Note, however, that there are still miscompilations in stage3.
2022-04-21dwarf: clean up allocations in std.dwarf moduleJakub Konka
While this code probably could do with some love and a redesign, this commit fixes the allocations by making sure we explicitly pass an allocator where required, and we use arenas for temporary or narrowly-scoped objects such as a `Die` (for `Die` in particular, not every `FormValue` will be allocated - we could duplicate, or we can use an arena which is the proposal of this commit).
2022-04-15stage2 macho: workaround stage2 bugsVeikka Tuominen
2022-04-14stage2: progress towards stage3Andrew Kelley
* The `@bitCast` workaround is removed in favor of `@ptrCast` properly doing element casting for slice element types. This required an enhancement both to stage1 and stage2. * stage1 incorrectly accepts `.{}` instead of `{}`. stage2 code that abused this is fixed. * Make some parameters comptime to support functions in switch expressions (as opposed to making them function pointers). * Avoid relying on local temporaries being mutable. * Workarounds for when stage1 and stage2 disagree on function pointer types. * Workaround recursive formatting bug with a `@panic("TODO")`. * Remove unreachable `else` prongs for some inferred error sets. All in effort towards #89.
2022-04-13macho,x64: resolve debug info relocs for RIP-based addressingJakub Konka
Sometimes we will want to generate debug info for a constant that has been lowered to memory and not copied anywhere else. For this we will need to defer resolution on PIE platforms until all locals (including GOT entries) have been allocated.
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.