aboutsummaryrefslogtreecommitdiff
path: root/src/link/Elf/SharedObject.zig
AgeCommit message (Collapse)Author
2025-09-21Elf2: create a new linker from scratchJacob Young
This iteration already has significantly better incremental support. Closes #24110
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-11std.ArrayList: make unmanaged the defaultAndrew Kelley
2025-07-07compiler: update 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.
2024-11-16link: fix memory bugsJacob Young
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-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-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-12Replace deprecated default initializations with decl literalsLinus Groh
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-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.
2024-08-07elf: get hello-world glibc working againJakub Konka
2024-08-07elf: fix symbol resolution for ObjectsJakub Konka
2024-08-07elf: do not re-init Symbol when initializingJakub Konka
2024-08-07elf: fix compile errorsJakub Konka
2024-08-07elf: redo symbol mgmt and ownership in ZigObjectJakub Konka
2024-08-07elf: move symbol ownership to LinkerDefinedJakub Konka
2024-08-07elf: move symbol ownership to SharedObjectJakub Konka
2024-07-30elf: move merge subsections ownership into merge sectionsJakub Konka
2024-07-30elf: move ownership of atoms into objectsJakub Konka
2024-04-20link/elf: implement string mergingJakub Konka
2024-04-20link/elf: port macho symbol extras handlingJakub Konka
2024-02-12elf: do not prealloc input objects, pread selectivelyJakub Konka
2024-01-15add `SHT_NOBITS` checkDavid Rubin
2024-01-01linker: fix some allocator referencesAndrew Kelley
2024-01-01linker: update target referencesAndrew Kelley
2023-12-05elf: upcast e_shnum to u64 to check for valid rangesJakub Konka
2023-12-05elf: re-instate basic error reporting for LD script parserJakub Konka
2023-12-05elf: move basic parse error reporting to SharedObjectJakub Konka
2023-11-15elf: we were writing too many symbols in the symtabJakub Konka
2023-11-07elf: actually track output symtab index of symbolsJakub Konka
2023-11-05elf: init objects after parsing themJakub Konka
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-10-24elf: improve parsing of ld scripts and actually test linking against themJakub Konka
2023-10-18elf: parse GNU ld script as system lib indirectionJakub Konka
2023-10-16elf: fix 32bit buildJakub Konka
2023-10-16elf: fix synthetic section handling and actually parse DSOsJakub Konka
2023-10-16elf: re-enable dynamic linking codepathsJakub Konka