aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/TextBlock.zig
AgeCommit message (Collapse)Author
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-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-03macho: dirty export trie when adding globalsJakub Konka
Similarly, dirty rebase info when adding a GOT atom.
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-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-26macho: write all atoms in flush so that we can resolve relocsJakub Konka
2021-08-26macho: save lazy binding info as part of the atomJakub Konka
2021-08-25macho: add GOT entries as actual atomsJakub Konka
2021-08-12macho: simplify symbol management and resolutionJakub Konka
instead of globally storing unresolved and tentative defs, store indices to actual symbols in the functions that are responsible for symbol resolution.
2021-08-02macho: refactor management of section ordinalsJakub Konka
Instead of storing a two-way relation (seg,sect) <=> ordinal we get the latter with `getIndex((seg, sect))`.
2021-08-01macho: don't store allocator in ObjectJakub Konka
instead, pass it in functions that require it. Also, when parsing relocs, make Object part of the context struct where we pass in additional goodies such as `*MachO` or `*Allocator`.
2021-07-23macho: re-enable parsing sections into atomsJakub Konka
However, make it default only when building in release modes since it's a prelude to advanced dead code stripping not very useful in debug.
2021-07-22macho: assign and cache section ordinals upon creationJakub Konka
then, when sorting sections within segments, clear and redo the ordinals since we re-apply them to symbols anyway. It is vital to have the ordinals consistent with parsing and resolving relocs however.
2021-07-22macho: fix memory leaks when emptying TextBlocksJakub Konka
This happens on every call to `TextBlock.empty` by the `Module`.
2021-07-20macho: use adapters to directly reference strtabJakub Konka
Thanks to this, we no longer need to do allocs per symbol name landing in the symbol resolver, plus we do not need to actively track if the string was already inserted into the string table.
2021-07-20macho: add stub relocs when adding extern fnJakub Konka
in self-hosted.
2021-07-18zld: move contents of Zld into MachO moduleJakub Konka
2021-07-18zld: migrate symbol mgmt to incremental backendJakub Konka
2021-07-17zld: demote logging back to debug from warnJakub Konka
2021-07-17zld: fixup flush functionJakub Konka
2021-07-17zld: correctly set n_sect for sections as symbolsJakub Konka
2021-07-17zld: adjust resolving relocs logic to the new approachJakub Konka
2021-07-17zld: simplify and move Relocations into TextBlockJakub Konka
It makes sense to have them as a dependent type since they only ever deal with TextBlocks. Simplify Relocations to rely on symbol indices and symbol resolver rather than pointers.
2021-07-16zld: replace parsed reloc with a simple wrapper around macho.relocation_infoJakub Konka
2021-07-15zld: move TextBlock into standalone fileJakub Konka
which should make managing the logic of parsing and resolving relocs that much simpler to parse.