aboutsummaryrefslogtreecommitdiff
path: root/src/link/MachO/relocatable.zig
AgeCommit message (Collapse)Author
5 dayslink: update to new file system APIsAndrew Kelley
5 daysupdate occurences of setEndPos to setLengthAndrew Kelley
5 daysupdate all stat() to stat(io)Andrew Kelley
5 daysupdate all occurrences of openFile to receive an io instanceAndrew Kelley
6 dayscompiler: replace thread pool with `std.Io`Matthew Lugg
Eliminate the `std.Thread.Pool` used in the compiler for concurrency and asynchrony, in favour of the new `std.Io.async` and `std.Io.concurrent` primitives. This removes the last usage of `std.Thread.Pool` in the Zig repository.
2025-10-10MachO: emit absolute path in N_OSO stabsmlugg
This path being relative is unconventional and causes issues for us if the output artifact is ever used from a different cwd than the one it was built from. The behavior implemented by this commit of always emitting these paths as absolute was actually the behavior in 0.14.x, but it regressed in 0.15.1 due to internal reworks to path handling which led to relative paths being more common in the compiler internals. Resolves: #25433
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-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28link.MachO: update to not use GenericWriterAndrew Kelley
2025-08-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-07-07compiler: fix a bunch of format stringsAndrew Kelley
2025-07-07MachO: revert unfinished changesAndrew Kelley
2025-07-07MachO: update to new std.io APIsAndrew Kelley
2025-02-25Compilation: correct when to include ubsanDavid Rubin
2025-02-25move libubsan to `lib/` and integrate it into `-fubsan-rt`David Rubin
2025-01-15elf linker: conform to explicit error setsAndrew Kelley
2025-01-15macho linker: conform to explicit error setsAndrew Kelley
Makes linker functions have small error sets, required to report diagnostics properly rather than having a massive error set that has a lot of codes. Other linker implementations are not ported yet. Also the branch is not passing semantic analysis yet.
2025-01-15wasm linker: aggressive DODificationAndrew Kelley
The goals of this branch are to: * compile faster when using the wasm linker and backend * enable saving compiler state by directly copying in-memory linker state to disk. * more efficient compiler memory utilization * introduce integer type safety to wasm linker code * generate better WebAssembly code * fully participate in incremental compilation * do as much work as possible outside of flush(), while continuing to do linker garbage collection. * avoid unnecessary heap allocations * avoid unnecessary indirect function calls In order to accomplish this goals, this removes the ZigObject abstraction, as well as Symbol and Atom. These abstractions resulted in overly generic code, doing unnecessary work, and needless complications that simply go away by creating a better in-memory data model and emitting more things lazily. For example, this makes wasm codegen emit MIR which is then lowered to wasm code during linking, with optimal function indexes etc, or relocations are emitted if outputting an object. Previously, this would always emit relocations, which are fully unnecessary when emitting an executable, and required all function calls to use the maximum size LEB encoding. This branch introduces the concept of the "prelink" phase which occurs after all object files have been parsed, but before any Zcu updates are sent to the linker. This allows the linker to fully parse all objects into a compact memory model, which is guaranteed to be complete when Zcu code is generated. This commit is not a complete implementation of all these goals; it is not even passing semantic analysis.
2024-10-23rework linker inputsAndrew Kelley
* Compilation.objects changes to Compilation.link_inputs which stores objects, archives, windows resources, shared objects, and strings intended to be put directly into the dynamic section. Order is now preserved between all of these kinds of linker inputs. If it is determined the order does not matter for a particular kind of linker input, that item should be moved to a different array. * rename system_libs to windows_libs * untangle library lookup from CLI types * when doing library lookup, instead of using access syscalls, go ahead and open the files and keep the handles around for passing to the cache system and the linker. * during library lookup and cache file hashing, use positioned reads to avoid affecting the file seek position. * library directories are opened in the CLI and converted to Directory objects, warnings emitted for those that cannot be opened.
2024-10-23link.MachO: remove buggy multi-threadingAndrew Kelley
thread-sanitizer reports data races here when running test-link. I tried only removing the ones that triggered races, but after 10 back and forths with the compiler and tsan, I got impatient and removed all of them. next time, let's be sure the test suite runs tsan-clean before merging any changes that add parallelism. after this commit, `zig build test-link` completes without any tsan warnings. closes #21778
2024-10-12link.Elf: eliminate an O(N^2) algorithm in flush()Andrew Kelley
Make shared_objects a StringArrayHashMap so that deduping does not need to happen in flush. That deduping code also was using an O(N^2) algorithm, which is not allowed in this codebase. There is another violation of this rule in resolveSymbols but this commit does not address it. This required reworking shared object parsing, breaking it into independent components so that we could access soname earlier. Shared object parsing had a few problems that I noticed and fixed in this commit: * Many instances of incorrect use of align(1). * `shnum * @sizeOf(elf.Elf64_Shdr)` can overflow based on user data. * `@divExact` can cause illegal behavior based on user data. * Strange versyms logic that wasn't present in mold nor lld. The logic was not commented and there is no git blame information in ziglang/zig nor kubkon/zld. I changed it to match mold and lld instead. * Use of ArrayList for slices of memory that are never resized. * finding DT_VERDEFNUM in a different loop than finding DT_SONAME. Ultimately I think we should follow mold's lead and ignore this integer, relying on null termination instead. * Doing logic based on VER_FLG_BASE rather than ignoring it like mold and LLD do. No comment explaining why the behavior is different. * Mutating the original ELF symbols rather than only storing the mangled name on the new Symbol struct. I noticed something that I didn't try to address in this commit: Symbol stores a lot of redundant information that is already present in the ELF symbols. I suspect that the codebase could benefit from reworking Symbol to not store redundant information. Additionally: * Add some type safety to std.elf. * Eliminate 1-3 file system reads for determining the kind of input files, by taking advantage of file name extension and handling error codes properly. * Move more error handling methods to link.Diags and make them infallible and thread-safe * Make the data dependencies obvious in the parameters of parseSharedObject. It's now clear that the first two steps (Header and Parsed) can be done during the main Compilation pipeline, rather than waiting for flush().
2024-10-11link: consolidate diagnosticsAndrew Kelley
By organizing linker diagnostics into this struct, it becomes possible to share more code between linker backends, and more importantly it becomes possible to pass only the Diag struct to some functions, rather than passing the entire linker state object in. This makes data dependencies more obvious, making it easier to rearrange code and to multithread. Also fix MachO code abusing an atomic variable. Not only was it using the wrong atomic operation, it is unnecessary additional state since the state is already being protected by a mutex.
2024-10-10link: fix false positive crtbegin/crtend detectionAndrew Kelley
Embrace the Path abstraction, doing more operations based on directory handles rather than absolute file paths. Most of the diff noise here comes from this one. Fix sorting of crtbegin/crtend atoms. Previously it would look at all path components for those strings. Make the C runtime path detection partially a pure function, and move some logic to glibc.zig where it belongs.
2024-08-23link: Rename InvalidCpuArch error to InvalidMachineType.Alex Rønne Petersen
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-22macho: write sections in parallel in -r modeJakub Konka
2024-07-22macho: calc section sizes in parallel in -r modeJakub Konka
2024-07-22macho: run more things in parallelJakub Konka
2024-07-22macho: redo input file parsing in prep for multithreadingJakub Konka
2024-07-18macho: fix 32bit compilation issuesJakub Konka
2024-07-18macho: re-enable writing out static archive with ZigObjectJakub Konka
2024-07-18macho: skip resizing incremental Zig sections in r modeJakub Konka
2024-07-18macho: emit relocs for non-zig-sections in ZigObjectJakub Konka
2024-07-18macho: bring back relocatable mode for ZigObjectJakub Konka
2024-07-18macho: re-enable calculating num of relocs for ZigObjectJakub Konka
2024-07-18macho: re-enable relocatable modeJakub Konka
2024-07-18macho: bring back parts of r modeJakub Konka
2024-07-18macho: bring back parts of arJakub Konka
2024-07-18macho: move unwind info records ownership to ObjectsJakub Konka
2024-05-24link/macho: fix perf bug in DWARF parsingJakub Konka
2024-05-23link/macho: dedup literals in objects and internal object fileJakub Konka
2024-03-30cbe: rewrite `CType`Jacob Young
Closes #14904
2024-02-21MachO: fix `calcLoadCommandsSize` computationJacob Young
Closes #19026
2024-02-10macho: include compiler-rt in static lib if requestedJakub Konka
2024-02-08macho: fix alignment of objects in archiveJakub Konka
2024-02-08macho: fix incorrect skip conditions for zig and dwarf sectionsJakub Konka
2024-02-08macho: alloc improvement for relocatableJakub Konka
2024-02-08macho: couple small fixesJakub Konka
2024-02-07macho: parse input object files specifically for incl in archiveJakub Konka
2024-02-07macho: fix invalid ZigObject size calculationJakub Konka