17 Commits

Author SHA1 Message Date
Andrew Kelley
934573fc5d Revert "std.fmt: require specifier for unwrapping ?T and E!T."
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-24 11:50:10 -07:00
InKryption
7cbd586ace
std.fmt: require specifier for unwrapping ?T and E!T.
Co-authored-by: Veikka Tuominen <git@vexu.eu>
2022-07-24 12:01:56 +03:00
Luuk de Gram
241180216f wasm-linker: Parse object file from the archive
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-24 08:12:17 +02:00
Luuk de Gram
c9f929a18b fix memory leaks 2022-06-24 08:12:17 +02:00
Luuk de Gram
8d03e4fc6b link: Implement API to get global symbol index 2022-06-24 08:12:17 +02:00
Veikka Tuominen
6ad510d832 update self hosted sources to language changes 2022-04-15 11:17:19 +03:00
Luuk de Gram
d66c61a2cf wasm-linker: Prevent overalignment for segments
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-14 22:53:13 +02:00
Luuk de Gram
cf37101108 wasm-linker: Add function table indexes
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-14 22:53:13 +02:00
Luuk de Gram
321a164269 wasm-linker: Fix memory leak
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-04-14 22:53:13 +02:00
Luuk de Gram
5a45fe2dba
wasm: Call generateSymbol for updateDecl
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-06 19:38:50 +01:00
Luuk de Gram
f5a31cb0d6 wasm-linker: Intern globals, exports & imports
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-01 08:35:20 +01:00
Luuk de Gram
b1159ab7ae wasm-linker: Intern all symbol names
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-01 08:35:20 +01:00
Luuk de Gram
49f01c0a0c wasm-object: Use given allocator rather than arena
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-03-01 08:35:20 +01:00
Luuk de Gram
ced958e8a8 wasm-linker: Simplify symbol names
No longer duplicate the symbol name and instead take the pointer from the decl itself.
Also fix 32bit build
2022-02-17 18:11:48 +01:00
Luuk de Gram
a4622501bd wasm-linker: Allocate atoms and handle imports
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-17 18:11:48 +01:00
Luuk de Gram
f1cc5f33e8 wasm-linker: Implement section merging
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-17 18:11:48 +01:00
Luuk de Gram
e7be0bef43 wasm-linker: Add Object file parsing
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.
2022-02-17 18:11:48 +01:00