aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/Object.zig
AgeCommit message (Collapse)Author
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-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: 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-25macho: fix memory leak and refactor Target usageJakub 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: 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: 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-05-27math: make `cast` return optional instead of an errorAli Chraghi
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-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