aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm/Archive.zig
AgeCommit message (Collapse)Author
2025-04-27chore(std.mem): Rename `trimLeft` and `trimRight`Shun Sakai
Rename `trimLeft` to `trimStart`, and `trimRight` to `trimEnd`. `trimLeft` and `trimRight` functions remain as deprecated aliases for these new names.
2025-01-15fix bad archive name calculationAndrew Kelley
2025-01-15wasm linker: allow undefined imports when lib name is providedAndrew Kelley
and expose object_host_name as an option for setting the lib name for object files, since the wasm linking standards don't specify a way to do it.
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-11-01link.File.Wasm.Archive: simplifyAndrew Kelley
Don't use the reader interface Avoid unnecessary heap allocations At first I started working on incorporating the Archive fields into the Wasm data model, however, I realized a better strategy: simply omit Archive data from the serialized linker state. Those files can be trivially reparsed on next compiler process start. If they haven't changed, great. Otherwise if they have, the prelink phase needs to be restarted anyway.
2024-10-31link.File.Wasm: unify the string tablesAndrew Kelley
Before, the wasm struct had a string table, the ZigObject had a string table, and each Object had a string table. Now there is just the one. This makes for more efficient use of memory and simplifies logic, particularly with regards to linker state serialization. This commit additionally adds significantly more integer type safety.
2024-10-31link.File.Wasm: conform to naming conventionsAndrew Kelley
2024-10-31link.File.Wasm.Archive: remove header fieldAndrew Kelley
it's not needed
2024-10-30link.File.Wasm: parse inputs in compilation pipelineAndrew Kelley
Primarily, this moves linker input parsing from flush() into the linker task queue, which is executed simultaneously with the frontend. I also made it avoid redundantly opening the same archive file N times for each object file inside. Furthermore, hard code fixed buffer stream rather than using a generic stream type. Finally, I fixed the error handling of the Wasm.Archive.parse function. Please pay attention to this pattern of returning a struct rather than accepting a mutable struct as an argument. This ensures function-level atomicity and makes resource management straightforward. Deletes the file and path fields from Archive and Object. Removed a well-meaning but ultimately misguided suggestion about how to think about ZigObject since thinking about it that way has led to problematic anti-DOD patterns.
2024-09-12Replace deprecated default initializations with decl literalsLinus Groh
2024-06-13std: Convert deprecated aliases to compile errors and fix usagesRyan Liptak
Deprecated aliases that are now compile errors: - `std.fs.MAX_PATH_BYTES` (renamed to `std.fs.max_path_bytes`) - `std.mem.tokenize` (split into `tokenizeAny`, `tokenizeSequence`, `tokenizeScalar`) - `std.mem.split` (split into `splitSequence`, `splitAny`, `splitScalar`) - `std.mem.splitBackwards` (split into `splitBackwardsSequence`, `splitBackwardsAny`, `splitBackwardsScalar`) - `std.unicode` + `utf16leToUtf8Alloc`, `utf16leToUtf8AllocZ`, `utf16leToUtf8`, `fmtUtf16le` (all renamed to have capitalized `Le`) + `utf8ToUtf16LeWithNull` (renamed to `utf8ToUtf16LeAllocZ`) - `std.zig.CrossTarget` (moved to `std.Target.Query`) Deprecated `lib/std/std.zig` decls were deleted instead of made a `@compileError` because the `refAllDecls` in the test block would trigger the `@compileError`. The deleted top-level `std` namespaces are: - `std.rand` (renamed to `std.Random`) - `std.TailQueue` (renamed to `std.DoublyLinkedList`) - `std.ChildProcess` (renamed/moved to `std.process.Child`) This is not exhaustive. Deprecated aliases that I didn't touch: + `std.io.*` + `std.Build.*` + `std.builtin.Mode` + `std.zig.c_translation.CIntLiteralRadix` + anything in `src/`
2024-03-19extract std.posix from std.osAndrew Kelley
closes #5019
2024-02-29wasm: integrate linker errors with `Compilation`Luuk de Gram
Rather than using the logger, we now emit proper 'compiler'-errors just like the ELF and MachO linkers with notes. We now also support emitting multiple errors before quiting the linking process in certain phases, such as symbol resolution. This means we will print all symbols which were resolved incorrectly, rather than the first one we encounter.
2023-10-31std.builtin.Endian: make the tags lower caseAndrew Kelley
Let's take this breaking change opportunity to fix the style of this enum.
2023-10-31mem: fix ub in writeIntJacob Young
Use inline to vastly simplify the exposed API. This allows a comptime-known endian parameter to be propogated, making extra functions for a specific endianness completely unnecessary.
2022-12-16wasm-linker: Fix archive symbols parsingLuuk de Gram
When parsing the table of contents containing the symbols and their positions we initially used the index within the map to retrieve the offset. However, during resizing of the underlaying array this would invalidate those indexes which meant incorrect offsets were being stored for symbols. We now use the current symbol index to also get the index into the symbol position instead.
2022-09-12wasm-linker: rename self to descriptive nameLuuk de Gram
2022-09-07macho+wasm: unify and clean up closing file handlesJakub Konka
2022-08-20wasm/Object: parse using the correct file sizeLuuk de Gram
When an object file is being parsed from within an archive file, we provide the object file size to ensure we do not read past the object file. This is because follow up object files can exist there, as well as an LF character to notate the end of the file was reached. Such a character is invalid within the object file. This also fixes a bug in getting the function/global type for defined globals/functions from object files as it was missing the substraction with the import count of the respective type.
2022-08-20wasm/archive: correctly parse long file namesLuuk de Gram
Wasm archive files are encoded the same way as GNU. This means that the header notates the character index within the long file name list rather than the length of the name. The entire name is then delimited by an LF character (0x0a). This also makes a cosmetic update to remove the `self` name, and rather label it as `archive` instead.
2022-06-24wasm-linker: Parse object file from the archiveLuuk de Gram
Rather than finding the original object file, we seekTo to the object file's position within the archive file, and from there open a new file handle. This file handle is passed to the `Object` parser which will create the object.
2022-06-24fix memory leaksLuuk de Gram
2022-06-24wasm-linker: Resolve symbols from archivesLuuk de Gram
Lazily load object files by default, and only load the object file when an unresolved symbol has been found within an archive.
2022-06-24wasm-linker: Implement Archive parsingLuuk de Gram
This implements a very basic archive file parser that validates the magic bytes, and then parses the symbol table and stores the symbol and their position.