aboutsummaryrefslogtreecommitdiff
path: root/src/link/Wasm/Object.zig
AgeCommit message (Collapse)Author
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.