aboutsummaryrefslogtreecommitdiff
path: root/src/link
AgeCommit message (Collapse)Author
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-23Merge pull request #21697 from mlugg/callconvMatthew Lugg
Replace `std.builtin.CallingConvention` with a tagged union, eliminating `@setAlignStack`
2024-10-21coff: fix incorrect default `image_base` values and re-enable shared library ↵kcbanner
tests on Windows This was the cause of aarch64-windows shared libraries causing "bad image" errors during load-time linking. I also re-enabled the tests that were surfacing this bug.
2024-10-20link.Dwarf: Fix function alignment calculation to match the rest of the linker.Alex Rønne Petersen
In particular, for user-specified alignment values, we need to do max(user_align, minFunctionAlignment()) to respect the ABI minimum.
2024-10-20link: Use defaultFunctionAlignment() when function alignment is unspecified.Alex Rønne Petersen
max(user_align, minFunctionAlignment()) is only appropriate when the user has actually given an explicit, non-zero alignment value.
2024-10-19link.Dwarf: handle `avr_signal` and `avr_builtin` callconvsmlugg
2024-10-19link: add clarifying commentmlugg
2024-10-19std.Target: rename `defaultCCallingConvention` and `Cpu.Arch.fromCallconv`mlugg
2024-10-19std: update for new `CallingConvention`mlugg
The old `CallingConvention` type is replaced with the new `NewCallingConvention`. References to `NewCallingConvention` in the compiler are updated accordingly. In addition, a few parts of the standard library are updated to use the new type correctly.
2024-10-19compiler: introduce new `CallingConvention`mlugg
This commit begins implementing accepted proposal #21209 by making `std.builtin.CallingConvention` a tagged union. The stage1 dance here is a little convoluted. This commit introduces the new type as `NewCallingConvention`, keeping the old `CallingConvention` around. The compiler uses `std.builtin.NewCallingConvention` exclusively, but when fetching the type from `std` when running the compiler (e.g. with `getBuiltinType`), the name `CallingConvention` is used. This allows a prior build of Zig to be used to build this commit. The next commit will update `zig1.wasm`, and then the compiler and standard library can be updated to completely replace `CallingConvention` with `NewCallingConvention`. The second half of #21209 is to remove `@setAlignStack`, which will be implemented in another commit after updating `zig1.wasm`.
2024-10-16std.Target: Remove isBpfFreestanding().Alex Rønne Petersen
The only use of this has nothing to do with the OS tag.
2024-10-13Merge pull request #21688 from Snektron/spirv-fixRobin Voetter
spirv: fix some bitrot
2024-10-13spirv: don't try to lower types which have no runtime bitsRobin Voetter
2024-10-12fix 32-bit buildAndrew Kelley
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-12macho: create dummy atom of size 0 marking end of a sectionJakub Konka
Some compilers such as Go reference the end of a section (addr + size) which cannot be contained in any non-zero atom (since then this atom would exceed section boundaries). In order to facilitate this behaviour, we create a dummy zero-sized atom at section end (addr + size).
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-11work around C backend bugAndrew Kelley
2024-10-11link.Elf.sortShdrs: tease out data dependenciesAndrew Kelley
In order to reduce the logic that happens in flush() we need to see which data is being accessed by all this logic, so we can see which operations depend on each other.
2024-10-11link.Elf: fix merge sections namespacingAndrew Kelley
`link.Elf.merge_section.MergeSection` -> `link.Elf.Merge.Section`
2024-10-11link.Elf: group section indexesAndrew Kelley
so they cannot be forgotten when updating them after sorting them.
2024-10-11link.Elf.ZigObject: make resetShdrIndexes non genericAndrew Kelley
2024-10-11link.Elf: fix phdr_gnu_stack_index not included in sortPhdrsAndrew Kelley
Adds type safety for program header indexes. Reduce the amount of state sortPhdrs has access to, helping make the data dependencies clear.
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-10-09Merge pull request #21629 from ziglang/elf-incrAndrew Kelley
elf: more incremental progress
2024-10-09Merge pull request #21644 from ziglang/macho-issue-21598Andrew Kelley
link.MachO: fix reporting undefined implicit symbols and fix a typo in InternalObject.addObjcMethnameSection method
2024-10-09link.Elf.Object.initAtoms: reduce state access and indirectionAndrew Kelley
The initAtoms function now only uses the `elf_file` parameter for reporting linker error messages, making it easier to see that the function has no data dependencies other than the Object struct itself, making it easier to parallelize or otherwise move that logic around. Also removed an indirect call via `addExtra` since we already know the atom's file is the current Object instance. All calls to `Atom.addExtra` should be audited for similar reasons. Also removed unjustified use of `inline fn`.
2024-10-09macho: fix a typo in InternalObject.addObjcMethnameSectionJakub Konka
2024-10-09macho: report special symbols if undefinedJakub Konka
Special symbols include explictly force undefined symbols passed via -u flag, missing entry point symbol, missing 'dyld_stub_binder' symbol, or missing '_objc_msgsend' symbol.
2024-10-09elf: revert growing atoms in Dwarf.resize for standard allocJakub Konka
2024-10-09elf: clean up how we create un-allocated sectionsJakub Konka
2024-10-09elf: change how we manage debug atoms in Dwarf linkerJakub Konka
2024-10-09elf: do not create atoms for section symbols that do not require itJakub Konka
2024-10-09elf: move setting section size back to Elf.growSectionJakub Konka
2024-10-09elf: drastically simplify extracting section size logicJakub Konka
2024-10-09elf: clear dynamic relocs before resolving relocs in atomsJakub Konka
When resolving and writing atoms to file, we may add dynamic relocs to the output buffer so clear the buffers before that happens.
2024-10-09elf: add some extra logging for created dynamic relocsJakub Konka
2024-10-09elf: do not panic if we already have create a PLT entry for a symbolJakub Konka
2024-10-09elf: fix creation of synthetic sectionsJakub Konka
2024-10-09elf: combine growAllocSection and growNonAllocSection into growSectionJakub Konka
2024-10-09elf: move sections in segments that need moving onlyJakub Konka
2024-10-09elf: mark objects as dirty/not-dirtyJakub Konka
This way we can track if we need to redo the object parsing or not.
2024-10-09elf: use arena for incremental cacheJakub Konka
2024-10-09elf: do not re-allocate AtomLists unless dirtiedJakub Konka
2024-10-09elf: clear dynamic relocs before repopulatingJakub Konka
2024-10-09elf: do not re-populate synthetic sections when updatingJakub Konka
2024-10-09elf: track atoms within AtomList with array hash mapJakub Konka
2024-10-09Dwarf: implement and test lexical blocksJacob Young
2024-10-08link.Elf: avoid needless file system reads in flush()Andrew Kelley
flush() must not do anything more than necessary. Determining the type of input files must be done only once, before flush. Fortunately, we don't even need any file system accesses to do this since that information is statically known in most cases, and in the rest of the cases can be determined by file extension alone. This commit also updates the nearby code to conform to the convention for error handling where there is exactly one error code to represent the fact that error messages have already been emitted. This had the side effect of improving the error message for a linker script parse error. "positionals" is not a linker concept; it is a command line interface concept. Zig's linker implementation should not mention "positionals". This commit deletes that array list in favor of directly making function calls, eliminating that heap allocation during flush().
2024-10-08link.Elf: avoid converting rpath data in flush()Andrew Kelley
The goal is to minimize as much as possible how much logic is inside flush(). So let's start by moving out obvious stuff. This data can be preformatted before flush().