aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm/Object.zig
AgeCommit message (Collapse)Author
2023-09-21compiler: move struct types into InternPool properAndrew Kelley
Structs were previously using `SegmentedList` to be given indexes, but were not actually backed by the InternPool arrays. After this, the only remaining uses of `SegmentedList` in the compiler are `Module.Decl` and `Module.Namespace`. Once those last two are migrated to become backed by InternPool arrays as well, we can introduce state serialization via writing these arrays to disk all at once. Unfortunately there are a lot of source code locations that touch the struct type API, so this commit is still work-in-progress. Once I get it compiling and passing the test suite, I can provide some interesting data points such as how it affected the InternPool memory size and performance comparison against master branch. I also couldn't resist migrating over a bunch of alignment API over to use the log2 Alignment type rather than a mismash of u32 and u64 byte units with 0 meaning something implicitly different and special at every location. Turns out you can do all the math you need directly on the log2 representation of alignments.
2023-07-19wasm-linker: prevent double-free on parse failureLuuk de Gram
2023-06-24all: migrate code to new cast builtin syntaxmlugg
Most of this migration was performed automatically with `zig fmt`. There were a few exceptions which I had to manually fix: * `@alignCast` and `@addrSpaceCast` cannot be automatically rewritten * `@truncate`'s fixup is incorrect for vectors * Test cases are not formatted, and their error locations change
2023-06-19all: zig fmt and rename "@XToY" to "@YFromX"Eric Joldasov
Signed-off-by: Eric Joldasov <bratishkaerik@getgoogleoff.me>
2023-06-16migration: std.math.{min, min3, max, max3} -> `@min` & `@max`r00ster91
2023-03-18wasm-linker: implement runtime TLS relocationsLuuk de Gram
2023-03-18wasm-linker: feature verifiction for shared-memLuuk de Gram
When the user enables shared-memory, we must ensure the linked objects have the 'atomics' and 'bulk-memory' features allowed.
2023-03-18wasm-linker: refactor Limits and add flagsLuuk de Gram
Rather than adding the flags "on-demand" during limits writing, we now properly parse them and store the flags within the limits itself. This also allows us to store whether we're using shared- memory or not. Only when the correct flag is set will we set the max within `Limits` or else we will leave it `undefined`.
2023-03-18wasm-linker: basic TLS supportLuuk de Gram
Linker now parses segments with regards to TLS segments. If the name represents a TLS segment but does not contain the TLS flag, we set it manually as the object file is created using an older compiler (LLVM). For now we panic when we find a TLS relocation and implement those later.
2023-03-09wasm-linker: store symbol's virtual addressLuuk de Gram
For data symbols we will now store its virtual address. This means we do no longer have to calculate it each time a relocation asks for the address. This is now done for all data symbols only once rather than every single relocation for that symbol. This now also allows us directly store the virtual address of synthetic symbols without having to create an atom for them. This means we also don't need to have a "synthetic" segment any longer and do not emit the synthetic symbols such as __heap_end and __heap_base into the final binary.
2023-02-18update std lib and compiler sources to new for loop syntaxAndrew Kelley
2023-02-01link: make Wasm atoms fully owned by the linkerLuuk de Gram
2022-12-18wasm-linker: Fix relocations for alias'd atomsLuuk de Gram
When an atom has one or multiple aliasses, we we could not find the target atom from the alias'd symbol. This is solved by ensuring that we also insert each alias symbol in the symbol-atom map.
2022-11-29std.mem.Allocator: allow shrink to failAndrew Kelley
closes #13535
2022-10-08wasm-linker: convert relocation addend to i32Luuk de Gram
Addends in relocations are signed integers as theoretically it could be a negative number. As Atom's offsets are relative to their parent section, the relocation value should still result in a postive number. For this reason, the final result is stored as an unsigned integer. Also, rather than using `null` for relocations that do not support addends. We set the value to 0 for those that do not support addends, and have to call `addendIsPresent` to determine if an addend exists or not. This means each Relocation costs 4 bytes less than before, saving memory while linking.
2022-09-12wasm-linker: rename self to descriptive nameLuuk de Gram
2022-09-09Merge pull request #12772 from ziglang/coff-basic-importsJakub Konka
coff: implement enough of the incremental linker to pass behavior and incremental tests on Windows
2022-09-07macho+wasm: unify and clean up closing file handlesJakub Konka
2022-09-07wasm-linker: support incremental debug infoLuuk de Gram
Although the wasm-linker previously already supported debug information in incremental-mode, this was no longer working as-is with the addition of supporting object-file-parsed debug information. This commit implements the Zig-created debug information structure from scratch which is a lot more robust and also allows being linked with debug information from other object files.
2022-09-07wasm-linker: perform debug relocationsLuuk de Gram
This correctly performs a relocation for debug sections. The result is that the wasm-linker can now correctly create a binary from object files while preserving all debug information.
2022-09-07wasm-linker: write debug sections from objectsLuuk de Gram
We now link relocatable debug sections with the correct section symbol and then allocate and resolve the debug atoms before writing them into the final binary. Although this does perform the relocation, the actual relocations are not done correctly yet.
2022-09-07wasm-linker: create atoms from debug sectionsLuuk de Gram
2022-09-07wasm/Object: parse debug sections into reloc dataLuuk de Gram
Rather than storing the name of a debug section into the structure `RelocatableData`, we use the `index` field as an offset into the debug names table. This means we do not have to store an extra 16 bytes for non-debug sections which can be massive for object files where each data symbol has its own data section. The name of a debug section can then be retrieved again when needed by using the offset and then reading until the 0-delimiter.
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-07-26std.fmt: require specifier for unwrapping ?T and E!TInKryption
2022-07-24Revert "std.fmt: require specifier for unwrapping ?T and E!T."Andrew Kelley
This reverts commit 7cbd586ace46a8e8cebab660ebca3cfc049305d9. This is causing a fail to build from source: ``` ./lib/std/fmt.zig:492:17: error: cannot format optional without a specifier (i.e. {?} or {any}) @compileError("cannot format optional without a specifier (i.e. {?} or {any})"); ^ ./src/link/MachO/Atom.zig:544:26: note: called from here log.debug(" RELA({s}) @ {x} => %{d} in object({d})", .{ ^ ``` I looked at the code to fix it but none of those args are optionals.
2022-07-24std.fmt: require specifier for unwrapping ?T and E!T.InKryption
Co-authored-by: Veikka Tuominen <git@vexu.eu>
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-24link: Implement API to get global symbol indexLuuk de Gram
2022-04-15update self hosted sources to language changesVeikka Tuominen
2022-04-14wasm-linker: Prevent overalignment for segmentsLuuk de Gram
Previously, the data segments were being aligned twice. This caused us to overalign the segment and therefore allocate a much larger size for each segment than was required. This fix ensures we align and set the size just once, ensuring semantically correct binaries as well as smaller binaries.
2022-04-14wasm-linker: Add function table indexesLuuk de Gram
When linking with an object file, verify if a relocation is a table index relocation. If that's the case, add the relocation target to the function table.
2022-04-14wasm-linker: Fix memory leakLuuk de Gram
This fixes a memory leak when an object file contains one or more element sections which then contains one or more function indexes. This commit ensures the slice of index functions for each element section will be freed upon resource deallocation also.
2022-03-06wasm: Call `generateSymbol` for updateDeclLuuk de Gram
To unify the wasm backend with the other backends, we will now call `generateSymbol` to lower a Decl into bytes. This means we also have to change some function signatures to comply with the linker interface. Since the general purpose generateSymbol is less featureful than wasm's, some tests are temporarily disabled.
2022-03-01wasm-linker: Intern globals, exports & importsLuuk de Gram
Symbols that have globals used to have their lookup key be the symbol name. This key is now the offset into the string table. Imports have both the module name (library name) and name (of the symbol), those strings are now also being interned. This can save us up to 24bytes per import which have both their module name and name de-duplicated. Module names are almost entirely the same for all imports, providing us with a big chance of saving us 12 bytes at least. Just like imports, exports can also have a seperate name than the internal symbol name. Rather than storing the slice, we now store the offset of this string instead.
2022-03-01wasm-linker: Intern all symbol namesLuuk de Gram
For all symbols read from object files as well as generated from Zig code will now be interned and have their offset into the string table saved on the `Symbol` instead. Besides interning, local symbols now also use a decl's fully qualified name. When a decl/symbol is extern/to-be-imported, the name of the decl itself will be used for symbol resolving. Similarly for symbols that will be exported, will have their 'export name' set.
2022-03-01wasm-object: Use given allocator rather than arenaLuuk de Gram
This is preliminary work for string interning in the wasm linker. Using an arena would defeat the purpose of de-duplicating strings as we wouldn't be able to free memory of duplicated strings. This change also means we can simplify wasm binary parsing, by creating a general purpose parser that parses the binary into its sections, but untyped. Doing this, allows us to re-use the base of that, for object file, but also debug info parsing.
2022-02-17wasm-linker: Simplify symbol namesLuuk de Gram
No longer duplicate the symbol name and instead take the pointer from the decl itself. Also fix 32bit build
2022-02-17wasm-linker: Allocate atoms and handle importsLuuk de Gram
We now correctly allocate and create atoms for symbols from other object files. Imports are now also resolved and appended when required. Besides those changes, we now duplicate all symbol names, so we can correctly generate unique names for unnamed constants. TODO: String interning
2022-02-17wasm-linker: Implement section mergingLuuk de Gram
This implements the merging of all sections, to generate a valid wasm binary where all symbols have been resolved and their respective sections have been merged into the final binary.
2022-02-17wasm-linker: Add Object file parsingLuuk de Gram
This upstreams the object file parsing from zwld, bringing us closer to being able to link stage2 code with object files/C-code as well as replacing lld with the self-hosted linker once feature complete.