aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO
AgeCommit message (Collapse)Author
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-12-08macho: handle non-extern UNSIGNED relocs on arm64Jakub Konka
2021-12-08macho: do not write null symbols into undef symbols sectionJakub Konka
Also, skip creating stub entries for resolved globally defined regular symbols.
2021-12-05macho: don't prealloc sections when stage1Jakub Konka
2021-11-30allocgate: std Allocator interface refactorLee Cannon
2021-11-30macho: move nlist_64 type/flags helpers to std.machoJakub Konka
2021-11-30std lib API deprecations for the upcoming 0.9.0 releaseAndrew Kelley
See #3811
2021-11-29macho: POINTER_TO_GOT signals a need for a GOT entryJakub Konka
It also signals the need for GOT indirection (unless it can be optimised away via link-time constant optimisation).
2021-11-28macho: fix parsing addend for non-extern SIGNED_X relocJakub Konka
If `r_extern == 0` (the relocation is non-extern, meaning it targets a specific memory offset within the object's section) and if the relocation type signifies that the relocation requires correction for RIP such as SIGNED_1, then we need to subtract the correction, here 1 for SIGNED_1, from the calculated addend value as it's implicitly included.
2021-11-23zld: resolve frameworks in BFS orderJakub Konka
Handle clang's linker flag `-weak_framework` as a standard framework to link. This requires further investigation especially to do with weak imports and how to tie one with the other.
2021-11-22zld: parse ObjC ivars and eh_types in tapi v3 and v4Jakub Konka
2021-11-13macho: invalidate relocs after relinking relocatablesJakub Konka
2021-11-04Replace ArrayList.init/ensureTotalCapacity pairs with initCapacityRyan Liptak
Because ArrayList.initCapacity uses 'precise' capacity allocation, this should save memory on average, and definitely will save memory in cases where ArrayList is used where a regular allocated slice could have also be used.
2021-11-01Fix ensureTotalCapacity calls that should be ensureUnusedCapacity callsRyan Liptak
If these functions are called more than once, then the array list would no longer be guaranteed to have enough capacity during the appendAssumeCapacity calls. With ensureUnusedCapacity, they will always be guaranteed to have enough capacity regardless of how many times the function is called.
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-10-22macho: dump linker's state as JSONJakub Konka
Each element of the output JSON has the VM address of the generated binary nondecreasing (some elements might occupy the same VM address for example the atom and the relocation might coincide in the address space). The generated JSON can be inspected manually or via a preview tool `zig-snapshots` that I am currently working on and will allow the user to inspect interactively the state of the linker together with the positioning of sections, symbols, atoms and relocations within each snapshot state, and in the future, between snapshots too. This should allow for quicker debugging of the linker which is nontrivial when run in the incremental mode. Note that the state will only be dumped if the compiler is built with `-Dlink-snapshot` flag on, and then the compiler is passed `--debug-link-snapshot` flag upon compiling a source/project.
2021-10-13macho: redo relocation handling and lazy bind globalsJakub Konka
* apply late symbol resolution for globals - instead of resolving the exact location of a symbol in locals, globals or undefs, we postpone the exact resolution until we have a full picture for relocation resolution. * fixup stubs to defined symbols - this is currently a hack rather than a final solution. I'll need to work out the details to make it more approachable. Currently, we preemptively create a stub for a lazy bound global and fix up stub offsets in stub helper routine if the global turns out to be undefined only. This is quite wasteful in terms of space as we create stub, stub helper and lazy ptr atoms but don't use them for defined globals. * change log scope to .link for macho. * remove redundant code paths from Object and Atom. * drastically simplify the contents of Relocation struct (i.e., it is now a simple superset of macho.relocation_info), clean up relocation parsing and resolution logic.
2021-10-04migrate from `std.Target.current` to `@import("builtin").target`Andrew Kelley
closes #9388 closes #9321
2021-09-24stage2 codegen: move bit definitions to src/archjoachimschmidt557
2021-09-24Spelling corrections (#9833)Josh Soref
Signed-off-by: Josh Soref <jsoref@users.noreply.github.com> Co-authored-by: Josh Soref <jsoref@users.noreply.github.com>
2021-09-21macho: do not write temp and noname symbols to symtabJakub Konka
Remove currently obsolete AtomParser from Object.
2021-09-19Update all ensureCapacity calls to the relevant non-deprecated versionRyan Liptak
2021-09-16macho: implement object relinking in stage2Jakub Konka
* In watch mode, when changing the C source, we will trigger complete relinking of objects, dylibs and archives (atoms coming from the incremental updates stay put however). This means, we need to undo metadata populated when linking in objects, archives and dylibs. * Remove unused splitting section into atoms bit. This optimisation will probably be best rewritten from scratch once self-hosted matures so parking the idea for now. Also, for easier management of atoms spawned from the Object file, keep the atoms subgraph as part of the Object file struct. * Remove obsolete ref to static initializers in object struct. * Implement handling of global symbol collision in updateDeclExports.
2021-09-14macho: disable splitting sections into atoms in releaseJakub Konka
since we don't actually benefit from it just yet, and getting it right for release and dead code stripping will require some more thought put into it.
2021-09-13Merge remote-tracking branch 'origin/master' into zld-incrJakub Konka
2021-09-13macho: fix incremental compilationJakub Konka
2021-09-11macho: enable tracy in more places within the linkerJakub Konka
2021-09-10macho: rename blocks to atoms in Object.zigJakub Konka
2021-09-09macho: init process of renaming TextBlock to AtomJakub Konka
Initially, internally within the linker.
2021-09-09macho: don't allocate atoms when parsing objectsJakub Konka
2021-09-08macho: use smaller padding until we have branch islands on arm64Jakub Konka
Without branch islands, it is impossible to link self-hosted using the common linker path.
2021-09-07macho: store source section address of relocs in contextJakub Konka
This is particularly relevant for x86_64 and C++ when relocating StaticInit sections containing static initializers machine code. Then, in case of SIGNED_X relocations, it is necessary to have the full image of the VM address layout of the sections in the object file as this is how the addend needs to be adjusted for non-extern relocations.
2021-09-07macho: fix commands.zig testsJakub Konka
2021-09-06macho: make sure that parsed bss atoms are zero-filledJakub Konka
2021-09-06macho: fix noninclusion of data-in-codeJakub Konka
Also, calculate non-extern, section offset based addends for SIGNED and UNSIGNED relocations on x86_64 upfront as an offset wrt to the target symbol representing position of the section/atom within the final artifact.
2021-09-04macho: unfortunately, LINKEDIT commands NEED to be in orderJakub Konka
Otherwise, Apple's tooling goes mental and reports that the executable is malformed/fails strict validation. We absolutely have to get it right to support tools such `codesign` which are required to successfully launch an app on an iOS device for instance. When Zig matures enough so that we can ditch any Apple tooling and still be able to successfully codesign for iOS and other, we can revisit this area. Until then however, we are stuck in having to rewrite the LINKEDIT segment at every update run of the self-hosted. FYI, the strict layout for the MachO binary apparently is (please, read this with a pinch of salt as this is inferred by me): * __TEXT segment * __DATA_CONST segment * __DATA segment * __LINKEDIT segment * dyld info (rebase, bind, weak bind, lazy bind, export) * symbol table * dynamic symbol table * string table * code signature (if expected)
2021-09-03macho: dyld info subsections need to follow in strict orderJakub Konka
MachO, why are doing this to me?
2021-09-03std.hash_map: add StringIndexAdapter and StringIndexContextFnControlOption
2021-09-03macho: dirty export trie when adding globalsJakub Konka
Similarly, dirty rebase info when adding a GOT atom.
2021-09-02macho: implement basic section movement and reallocationJakub Konka
2021-09-01stage2: update for new usingnamespace semanticsAndrew Kelley
2021-09-01stage2: first pass at implementing usingnamespaceAndrew Kelley
Ran into a design flaw here which will need to get solved by having AstGen annotate ZIR with which instructions are closed over.
2021-09-01macho: fix condition for checking available size for an atomJakub Konka
2021-09-01macho: clean up allocating atom logicJakub Konka
Instead of checking for stage1 at every callsite, move the logic inside `allocateAtom`. This is fine since this logic will disappear anyhow once I add expanding and shifting segments and sections.
2021-09-01macho: do not reset section's size after allocating atomJakub Konka
2021-08-31macho: fix allocating sections within segment when parsing objectsJakub Konka
2021-08-31std.hash_map: add getKey methods (#9607)fn ⌃ ⌥
2021-08-30macho: add first pass at allocating parsed atoms in objectsJakub Konka
This commit makes it possible to combine self-hosted with a pre-compiled C object file, e.g.: ``` zig-out/bin/zig build-exe hello.zig add.o ``` where `add.o` is a pre-compiled C object file.
2021-08-27macho: remove sorting sections and refactor atom parsing in objectsJakub Konka