aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/Object.zig
AgeCommit message (Collapse)Author
2025-11-20update deprecated ArrayListUnmanaged usage (#25958)Benjamin Jurk
2025-10-29Elf: fix alignment of merge subsectionsJacob Young
Closes #25565
2025-09-04link.Elf: truncate st_other to u3 before converting to std.elf.STVAlex Rønne Petersen
See 6b6e336e07308fd23f3061b5be11407956b2a460 for context, but note that in gABI 4.3, 3 bits are reserved for the visibility, up from the previous 2.
2025-08-31std.fmt: delete deprecated APIsAndrew Kelley
std.fmt.Formatter -> std.fmt.Alt std.fmt.format -> std.Io.Writer.print
2025-08-29std.Io: delete GenericReaderAndrew Kelley
and delete deprecated alias std.io
2025-08-28link.Elf: update to not use GenericWriterAndrew Kelley
2025-08-25start adding big endian RISC-V supportAlex Rønne Petersen
The big endian RISC-V effort is mostly driven by MIPS (the company) which is pivoting to RISC-V, and presumably needs a big endian variant to fill the niche that big endian MIPS (the ISA) did. GCC already supports these targets, but LLVM support will only appear in 22; this commit just adds the necessary target knowledge and checks on our end.
2025-07-31compiler: update to new flate APIAndrew Kelley
2025-07-11link.Elf: check files in archives for ELF magicIsaac Freund
Apparently raw LLVM IR Bitcode files ("Bitstreams") may appear in archives with LTO enabled. I observed this in the wild on Chimera Linux. I'm not yet sure if it's in scope for Zig to support these special archives, but we should at least give a correct error message.
2025-07-07compiler: update a bunch of format stringsAndrew Kelley
2025-07-07compiler: fix a bunch of format stringsAndrew Kelley
2025-07-07compiler: update all instances of std.fmt.FormatterAndrew Kelley
2025-06-19Target: pass and use locals by pointer instead of by valueJacob Young
This struct is larger than 256 bytes and code that copies it consistently shows up in profiles of the compiler.
2025-06-06Elf: support non-comdat groupsJacob Young
I haven't actually found any documentation about these, but apparently groups aren't always comdats.
2025-06-05std.Target: Introduce Cpu convenience functions for feature tests.Alex Rønne Petersen
Before: * std.Target.arm.featureSetHas(target.cpu.features, .has_v7) * std.Target.x86.featureSetHasAny(target.cpu.features, .{ .sse, .avx, .cmov }) * std.Target.wasm.featureSetHasAll(target.cpu.features, .{ .atomics, .bulk_memory }) After: * target.cpu.has(.arm, .has_v7) * target.cpu.hasAny(.x86, &.{ .sse, .avx, .cmov }) * target.cpu.hasAll(.wasm, &.{ .atomics, .bulk_memory })
2025-02-22zig build fmtAndrew Kelley
2025-01-15wasm linker: fix crashes when parsing compiler_rtAndrew Kelley
2024-11-22link: use target to determine risc-v eflag validityDavid Rubin
2024-10-29link/Elf: ensure we always sort all relocations by r_offset in -r modeJakub Konka
According to a comment in mold, this is the expected (and desired) condition by the linkers, except for some architectures (RISCV and Loongarch) where this condition does not have to upheld. If you follow the changes in this patch and in particular doc comments I have linked the comment/code in mold that explains and implements this. I have also modified `testEhFrameRelocatable` test to now test both cases such that `zig ld -r a.o b.o -o c.o` and `zig ld -r b.o a.o -o d.o`. In both cases, `c.o` and `d.o` should produce valid object files which was not the case before this patch.
2024-10-23unify parsing codepaths between relocatable and nonAndrew Kelley
2024-10-23link.Elf: untangle parseObject and parseArchiveAndrew Kelley
from link.Elf, so that they can be used earlier in the pipeline
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-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-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-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-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: track atoms within AtomList with array hash mapJakub Konka
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-09-23elf: fix condition for skipping symbols if atom is deadJakub Konka
Skipping the symbols too early when resolving would end up in the linker not deduping CIEs fully.
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-09-04elf: rename SectionChunk into AtomList and store as part of SectionJakub Konka
2024-09-04elf: create back/forward links for atoms within section chunksJakub Konka
2024-09-04elf: do not pad placeholders coming from input object filesJakub Konka
This is currently not entirely accurate since no padding will affect the last-most atom of ZigObject that should be padded.
2024-09-04elf: misc .eh_frame management fixesJakub Konka
2024-09-04elf: emit relocs for self-hosted generated .eh_frame sectionJakub Konka
2024-09-04elf: fix relocatable modeJakub Konka
2024-09-04elf: actually allocate atoms within each section chunkJakub Konka
2024-09-04elf: actually write allocated atoms in object filesJakub Konka
2024-09-04elf: allocate atom chunks using allocateChunk mechanics in objectsJakub Konka
2024-09-04elf: introduce SectionChunk - a container of atoms per object fileJakub Konka
2024-09-04elf: move initOutputSection into Elf from ObjectJakub Konka
2024-08-28std: update `std.builtin.Type` fields to follow naming conventionsmlugg
The compiler actually doesn't need any functional changes for this: Sema does reification based on the tag indices of `std.builtin.Type` already! So, no zig1.wasm update is necessary. This change is necessary to disallow name clashes between fields and decls on a type, which is a prerequisite of #9938.
2024-08-26Merge pull request #21212 from ziglang/elf-incrAndrew Kelley
elf: cleanups, cleanups, cleanups
2024-08-25elf: store atom refs for rela sections until we can do betterJakub Konka
2024-08-25elf: streamline sections containerJakub Konka
2024-08-23link: Rename InvalidCpuArch error to InvalidMachineType.Alex Rønne Petersen
2024-08-23std.{coff,elf}: Remove the {MachineType,EM}.toTargetCpuArch() functions.Alex Rønne Petersen
These are fundamentally incapable of producing accurate information for reasons I've laid out in #20771. Since our only use of these functions is to check that object files have the correct machine type, and since #21020 made `std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over to that and compare the machine type tags instead. Closes #20771.