aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/DebugSymbols.zig
AgeCommit message (Collapse)Author
2025-11-20update deprecated ArrayListUnmanaged usage (#25958)Benjamin Jurk
2025-09-08fix linker code writing undefined memory to the output fileAndrew Kelley
missing `extern` on a struct. but also all these instances that call pwriteAll with a `@ptrCast` are endianness bugs. this should be changed to use File.Writer and call writeSliceEndian instead. this commit fixes one immediate problem but does not fix everything.
2025-08-28link.MachO: update to not use GenericWriterAndrew Kelley
2025-07-07MachO: revert unfinished changesAndrew Kelley
2025-07-07MachO: update to new std.io APIsAndrew Kelley
2025-06-12link: divorce LLD from the self-hosted linkersmlugg
Similar to the previous commit, this commit untangles LLD integration from the self-hosted linkers. Despite the big network of functions which were involved, it turns out what was going on here is quite simple. The LLD linking logic is actually very self-contained; it requires a few flags from the `link.File.OpenOptions`, but that's really about it. We don't need any of the mutable state on `Elf`/`Coff`/`Wasm`, for instance. There was some legacy code trying to handle support for using self-hosted codegen with LLD, but that's not a supported use case, so I've just stripped it out. For now, I've just pasted the logic for linking the 3 targets we currently support using LLD for into this new linker implementation, `link.Lld`; however, it's almost certainly possible to combine some of the logic and simplify this file a bit. But to be honest, it's not actually that bad right now. This commit ends up eliminating the distinction between `flush` and `flushZcu` (formerly `flushModule`) in linkers, where the latter previously meant something along the lines of "flush, but if you're going to be linking with LLD, just flush the ZCU object file, don't actually link"?. The distinction here doesn't seem like it was properly defined, and most linkers seem to treat them as essentially identical anyway. Regardless, all calls to `flushZcu` are gone now, so it's deleted -- one `flush` to rule them all! The end result of this commit and the preceding one is that LLVM and LLD fit into the pipeline much more sanely: * If we're using LLVM for the ZCU, that state is on `zcu.llvm_object` * If we're using LLD to link, then the `link.File` is a `link.Lld` * Calls to "ZCU link functions" (e.g. `updateNav`) lower to calls to the LLVM object if it's available, or otherwise to the `link.File` if it's available (neither is available under `-fno-emit-bin`) * After everything is done, linking is finalized by calling `flush` on the `link.File`; for `link.Lld` this invokes LLD, for other linkers it flushes self-hosted linker state There's one messy thing remaining, and that's how self-hosted function codegen in a ZCU works; right now, we process AIR with a call sequence something like this: * `link.doTask` * `Zcu.PerThread.linkerUpdateFunc` * `link.File.updateFunc` * `link.Elf.updateFunc` * `link.Elf.ZigObject.updateFunc` * `codegen.generateFunction` * `arch.x86_64.CodeGen.generate` So, we start in the linker, take a scenic detour through `Zcu`, go back to the linker, into its implementation, and then... right back out, into code which is generic over the linker implementation, and then dispatch on the *backend* instead! Of course, within `arch.x86_64.CodeGen`, there are some more places which switch on the `link` implementation being used. This is all pretty silly... so it shall be my next target.
2025-06-12compiler: slightly untangle LLVM from the linkersmlugg
The main goal of this commit is to make it easier to decouple codegen from the linkers by being able to do LLVM codegen without going through the `link.File`; however, this ended up being a nice refactor anyway. Previously, every linker stored an optional `llvm.Object`, which was populated when using LLVM for the ZCU *and* linking an output binary; and `Zcu` also stored an optional `llvm.Object`, which was used only when we needed LLVM for the ZCU (e.g. for `-femit-llvm-bc`) but were not emitting a binary. This situation was incredibly silly. It meant there were N+1 places the LLVM object might be instead of just 1, and it meant that every linker had to start a bunch of methods by checking for an LLVM object, and just dispatching to the corresponding method on *it* instead if it was not `null`. Instead, we now always store the LLVM object on the `Zcu` -- which makes sense, because it corresponds to the object emitted by, well, the Zig Compilation Unit! The linkers now mostly don't make reference to LLVM. `Compilation` makes sure to emit the LLVM object if necessary before calling `flush`, so it is ready for the linker. Also, all of the `link.File` methods which act on the ZCU -- like `updateNav` -- now check for the LLVM object in `link.zig` instead of in every single individual linker implementation. Notably, the change to LLVM emit improves this rather ludicrous call chain in the `-fllvm -flld` case: * Compilation.flush * link.File.flush * link.Elf.flush * link.Elf.linkWithLLD * link.Elf.flushModule * link.emitLlvmObject * Compilation.emitLlvmObject * llvm.Object.emit Replacing it with this one: * Compilation.flush * llvm.Object.emit ...although we do currently still end up in `link.Elf.linkWithLLD` to do the actual linking. The logic for invoking LLD should probably also be unified at least somewhat; I haven't done that in this commit.
2025-03-02link: fixed bugs uncovered by changing the cache modeJacob Young
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-08-27Dwarf: implement .eh_frameJacob Young
2024-08-16Dwarf: rework self-hosted debug info from scratchJacob Young
This is in preparation for incremental and actually being able to debug executables built by the x86_64 backend.
2024-07-18macho: fix compile errorsJakub Konka
2024-07-04compiler: type.zig -> Type.zigmlugg
2024-02-21MachO: fix `calcLoadCommandsSize` computationJacob Young
Closes #19026
2024-02-08macho: move Dwarf handle to ZigObject from DebugSymbolsJakub Konka
2024-01-29macho: flush Dwarf module before flushing dSYMJakub Konka
2024-01-29macho: re-enable dSYM but don't write anything to it yetJakub Konka
2024-01-29macho: re-enable emitting empty dSYM bundleJakub Konka
2024-01-01linkers: update references to "options" fieldAndrew Kelley
2024-01-01linker: update target referencesAndrew Kelley
2023-11-04elf: redo strings management in the linkerJakub Konka
* atom names - are stored locally and pulled from defining object's strtab * local symbols - same * global symbols - in principle, we could store them locally, but for better debugging experience - when things go wrong - we store the offsets in a global strtab used by the symbol resolver
2023-08-29macho: merge Zld state with MachO stateJakub Konka
2023-08-29macho: unify concept of SymbolWithLoc across driversJakub Konka
2023-08-29macho: remove page_size field as it can be computed when and where requiredJakub Konka
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-17mem: rename align*Generic to mem.align*Motiejus Jakštys
Anecdote 1: The generic version is way more popular than the non-generic one in Zig codebase: git grep -w alignForward | wc -l 56 git grep -w alignForwardGeneric | wc -l 149 git grep -w alignBackward | wc -l 6 git grep -w alignBackwardGeneric | wc -l 15 Anecdote 2: In my project (turbonss) that does much arithmetic and alignment I exclusively use the Generic functions. Anecdote 3: we used only the Generic versions in the Macho Man's linker workshop.
2023-04-21macho: use generic TableSection for GOT mgmtJakub Konka
2023-04-13macho: refactor common logic between synthetic tablesJakub Konka
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-01link: use strtab.StringTable in DwarfJakub Konka
2023-01-25elf+macho: append null to DWARF strtab to avoid overlapping sectsJakub Konka
Otherwise, we were risking having strtab zero-sized and overlap with another section.
2022-12-16macho: store LC headers to often updated LINKEDIT sectionsJakub Konka
2022-12-16macho: generalize parallel hasher; impl parallel MD5-like hashJakub Konka
By pulling out the parallel hashing setup from `CodeSignature.zig`, we can now reuse it different places across MachO linker (for now; I can totally see its usefulness beyond MachO, eg. in COFF or ELF too). The parallel hasher is generic over actual hasher such as Sha256 or MD5. The implementation is kept as it was. For UUID calculation, depending on the linking mode: * incremental - since it only supports debug mode, we don't bother with MD5 hashing of the contents, and populate it with random data but only once per a sequence of in-place binary patches * traditional - in debug, we use random string (for speed); in release, we calculate the hash, however we use LLVM/LLD's trick in that we calculate a series of MD5 hashes in parallel and then one an MD5 of MD5 final hash to generate digest.
2022-12-09dwarf: resolve all relative paths when generating include_dirs and ↵Jakub Konka
file_names lists
2022-12-09dsym: hint linker when file range copy is not necessaryJakub Konka
2022-12-09dsym: reuse growSection where possibleJakub Konka
2022-12-09dwarf: move any remaining section growth to dsymJakub Konka
2022-12-09dwarf: move growing debug_aranges section to dsymJakub Konka
2022-12-09dsym: finish markDirty helperJakub Konka
2022-12-09dwarf: move growing debug_abbrev section to dsymJakub Konka
2022-12-09dwarf+d_sym: move logic for growing section to d_symJakub Konka
2022-12-09dwarf: track source files via *const Module.File pointersJakub Konka
2022-12-04dsym: dummy repush to check the linux CIJakub Konka
2022-12-04dsym: recalculate DWARF segment size when finalizingJakub Konka
2022-12-04dsym+dwarf: remove copyRangeAllOverlappingAllocJakub Konka
2022-12-04dsym: refactor API - do not store ptr to MachOJakub Konka
2022-12-04dsym: add helper for accessing dwarf seg pointerJakub Konka
2022-12-04dsym: rename updateLinkeditSegment to finalizeDwarfSegmentJakub Konka
This is the checkpoint where we finalize the VM of the primary binary.
2022-12-04dsym: make sure DWARF segment comes before LINKEDITJakub Konka
This will greatly simplify incremental updates to DWARF sections within the bundle.
2022-11-18run zig fmt on everything checked by CIStevie Hryciw