aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Object.zig
AgeCommit message (Collapse)Author
2022-03-15std.dwarf: implement basic DWARF 5 parsingWilliam Sengir
DWARF 5 moves around some fields and adds a few new ones that can't be parsed or ignored by our current DWARF 4 parser. This isn't a complete implementation of DWARF 5, but this is enough to make stack traces mostly work. Line numbers from C++ don't show up, but I know the info is there. I think the answer is to iterate through .debug_line_str in getLineNumberInfo, but I didn't want to fall into an even deeper rabbit hole tonight.
2022-01-13zld: fix num nlist calc when there's no dynsymtabJakub Konka
Handle `__DATA,.rustc` section containing `rustc` metadata - this is required to get crates like `serde_derive` link properly. Note to self: this special section has to be copied __verbatim__ from the relocatable object file - this includes preserving its size even though unpadded according the section's required alignment.
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-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-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-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-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-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: 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-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: 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-27macho: remove sorting sections and refactor atom parsing in objectsJakub Konka
2021-08-11macho: move parsing logic for Object, Archive and Dylib into MachOJakub Konka
This way, the functionality is better segregated, and we finally do not unnecessarily reparse dynamic libraries that were already visited and parsed.
2021-08-10macho: fix parsing target string when linking against tbdsJakub Konka
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 allocate Dylib on the heapJakub Konka
instead, immediately transfer ownership to MachO struct. Also, revert back to try-ok-fail parsing approach of objects, archives, and dylibs. It seems easier to try and fail than check if the file *is* of a certain type given that a dylib may be a stub and parsing yaml twice in a row seems very wasteful. Hint for the future: if we optimise yaml/TAPI parsing, this approach may be rethought!
2021-08-01macho: don't allocate Archives on the heapJakub Konka
instead, transfer ownership directly to MachO struct.
2021-08-01macho: don't allocate Objects on the heapJakub Konka
instead, ownership is transferred to MachO. This makes Object management align closer with data-oriented design.
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: sort nlists within object before filtering by typeJakub Konka
Previously, we'd filter the nlists assuming they were correctly ordered by type: local < extern defined < undefined within the object's symbol table but this doesn't seem to be guaranteed, therefore, we sort by type and address in one go, and filter defined from undefined afterwards.
2021-07-22macho: fix memory leaks when emptying TextBlocksJakub Konka
This happens on every call to `TextBlock.empty` by the `Module`.
2021-07-21macho: fix text block managementJakub Konka
For the time being, until we rewrite how atoms are handled across linkers, store two tables in the MachO linker: one for TextBlocks directly created and managed by the linker, and one for TextBlocks that were spawned by Module.Decl. This allows for correct memory clean up after linking is done.
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-17zld: demote logging back to debug from warnJakub Konka
2021-07-17zld: correctly set n_sect for sections as symbolsJakub 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-16zld: draft symbol resolver on macho.nlist_64 onlyJakub 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.