2520 Commits

Author SHA1 Message Date
Jakub Konka
2cdbad6f10 elf+aarch64: handle PREL64 reloc 2024-03-09 19:34:34 +01:00
Jakub Konka
229468b7a9 elf+aarch64: fix 32bit build 2024-03-09 18:55:52 +01:00
Jakub Konka
859f9a22c4 elf+aarch64: implement basic thunk support 2024-03-08 22:46:18 +01:00
Jakub Konka
7c5ddb6ae4 elf+aarch64: handle PREL32 reloc 2024-03-08 22:46:18 +01:00
Jakub Konka
47100bd40a elf+aarch64: handle TLS GD model 2024-03-08 22:46:18 +01:00
Jakub Konka
b343103567 elf+aarch64: handle gottp and .tls_common 2024-03-08 22:46:18 +01:00
Jakub Konka
7258d143e3 elf+aarch64: fix incorrectly emitted TLSDESC relocs 2024-03-08 22:46:17 +01:00
Jakub Konka
b5642b4f85 elf+aarch64: set _GLOBAL_OFFSET_TABLE_ to .got section 2024-03-08 22:46:17 +01:00
Jakub Konka
d9069cbe2c elf+aarch64: relax TLSDESC for executables 2024-03-08 22:46:17 +01:00
Jakub Konka
310cef0972 elf+aarch64: handle TLSDESC non-relaxed 2024-03-08 22:46:17 +01:00
Jakub Konka
109d2321b0 link: refactor common aarch64 helpers 2024-03-08 22:46:17 +01:00
Jakub Konka
c1dbf01aa3 elf+aarch64: resolve TLS LE model 2024-03-08 22:46:17 +01:00
Jakub Konka
69f9f359dd elf+aarch64: use correctly offset tp address 2024-03-08 22:46:17 +01:00
Jakub Konka
0af5d2e9b6 elf+aarch64: implement .plt.got 2024-03-08 22:46:17 +01:00
Jakub Konka
1cf45fb209 elf+aarch64: implement enough to link dynamically with gcc as the driver 2024-03-08 22:46:17 +01:00
Andrew Kelley
97aa5f7b8a
Merge pull request #19190 from mlugg/struct-equivalence
compiler: namespace type equivalence based on AST node + captures
2024-03-07 18:41:45 -08:00
Dillen Meijboom
377ecc6afb feat: add support for --enable-new-dtags and --disable-new-dtags 2024-03-06 17:52:05 -08:00
mlugg
975b859377
InternPool: create specialized functions for loading namespace types
Namespace types (`struct`, `enum`, `union`, `opaque`) do not use
structural equality - equivalence is based on their Decl index (and soon
will change to AST node + captures). However, we previously stored all
other information in the corresponding `InternPool.Key` anyway. For
logical consistency, it makes sense to have the key only be the true key
(that is, the Decl index) and to load all other data through another
function. This introduces those functions, by the name of
`loadStructType` etc. It's a big diff, but most of it is no-brainer
changes.

In future, it might be nice to eliminate a bunch of the loaded state in
favour of accessor functions on the `LoadedXyzType` types (like how we
have `LoadedUnionType.size()`), but that can be explored at a later
date.
2024-03-06 21:26:37 +00:00
Jakub Konka
9e402704e2 macho: correctly find N_GSYM symbols when parsing symbol stabs
In `ld -r` mode, the linker will emit `N_GSYM` for any defined
external symbols as well as private externals. In the former case,
the thing is easy since `N_EXT` bit will be set in the nlist's type.
In the latter however we will encounter a local symbol with `N_PEXT`
bit set (non-extern, but was private external) which we also need
to include when resolving symbol stabs.

The major change in the logic for parsing symbol stabs per input
object file is that we no longer try to force-resolve a `N_GSYM`
as a global symbol. This was a mistake since every symbol stab
always describes a symbol defined within the parsed input object file.
We then work out if we should forward `N_GSYM` in the output symtab
after we have resolved all symbols, but never before - intel we lack
when initially parsing symbol stabs. Therefore, we simply record
which symbol has a debug symbol stab, and work out its precise type
when emitting output symtab after symbol resolution has been done.
2024-03-01 10:18:10 +01:00
Luuk de Gram
202ed7330f
fix memory leaks 2024-02-29 15:52:43 +01:00
Luuk de Gram
196ba706a0
wasm: gc fixes and re-enable linker tests
Certain symbols were left unmarked, meaning they would not be emit into
the final binary incorrectly. We now mark the synthetic symbols to ensure
they are emit as they are already created under the circumstance they're
needed for. This also re-enables disabled tests that were left disabled
in a previous merge conflict.
Lastly, this adds the shared-memory test to the test harnass as it was
previously forgotten and therefore regressed.
2024-02-29 15:24:08 +01:00
Luuk de Gram
5ba5a2c133
wasm: integrate linker errors with Compilation
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.
2024-02-29 15:24:07 +01:00
Luuk de Gram
5ef8321338
wasm: make symbol indexes a non-exhaustive enum
This introduces some type safety so we cannot accidently give an atom
index as a symbol index. This also means we do not have to store any
optionals and therefore allow for memory optimizations. Lastly, we can
now always simply access the symbol index of an atom, rather than having
to call `getSymbolIndex` as it is easy to forget.
2024-02-29 15:24:07 +01:00
Luuk de Gram
c99ef23862
wasm: consolidate flushModule and linkWithZld
We now use a single function to use the in-house WebAssembly linker
rather than wasm-ld. For both incremental compilation and traditional
linking we use the same codepath.
2024-02-29 15:24:04 +01:00
Luuk de Gram
5aec88fa41
wasm: correctly generate relocations for type index
Previously we could directly write the type index because we used the
index that was known in the final binary. However, as we now process
the Zig module as its own relocatable object file, we must ensure to
generate a relocation for type indexes. This also ensures that we can
later link the relocatable object file as a standalone also.

This also fixes generating indirect function table entries for ZigObject
as it now correctly points to the relocation symbol index rather than
the symbol index that owns the relocation.
2024-02-29 15:23:05 +01:00
Luuk de Gram
5a0f2af7e4
wasm: reimplement Zig errors in linker 2024-02-29 15:23:04 +01:00
Luuk de Gram
c153f94c89
wasm: ensure unique function indexes
We cannot keep function indexes as maxInt(u32) due to functions being
dedupliated when they point to the same function. For this reason we now
use a regular arraylist which will have new functions appended to, and
when deleted, its index is appended to the free list, allowing us to
re-use slots in the function list.
2024-02-29 15:23:04 +01:00
Luuk de Gram
fde8c2f41a
wasm: reimplement deleteDeclExport
Removes the symbol from the decl's list of exports, marks it as dead,
as well as appends it to the symbol free list. Also removes it from
the list of global symbols as all exports are global.

In the future we should perhaps use a map for the export list to prevent
linear lookups. But this requires a benchmark as having more than 1
export for the same decl is very rare.
2024-02-29 15:23:04 +01:00
Luuk de Gram
8f96e7eec1
wasm: re-implement updateExports
We now correctly create a symbol for each exported decl with its export-
name. The symbol points to the same linker-object. We store a map from
decl to all of its exports so we can update exports if it already exists
rather than infinitely create new exports.
2024-02-29 15:23:04 +01:00
Luuk de Gram
a028b10b9f
wasm: update freeDecl and finishDecl
We now parse the decls right away into atoms and allocate the
corresponding linker-object, such as segment and function, rather than
waiting until `flushModule`.
2024-02-29 15:23:04 +01:00
Luuk de Gram
4d14374a66
wasm: Move createFunction to ZigObject
This function was previously only called by the backend which generates
a synthetical function that is not represented by any AIR or Zig code.
For this reason, the ownership is moved to the zig-object and stored
there so it can be linked with the other object files without the driver
having to specialize it.
2024-02-29 15:23:04 +01:00
Luuk de Gram
0a030d6598
wasm: Use File.Index for symbol locations
Rather than using the optional, we now directly use `File.Index` which
can already represent an unknown file due to its `.null` value. This
means we do not pay for the memory cost.

This type of index is now used for:
- SymbolLoc
- Key of the functions map
- InitFunc

Now we can simply pass things like atom.file, object.file, loc.file etc
whenever we need to access its representing object file which makes it
a lot easier.
2024-02-29 15:23:03 +01:00
Luuk de Gram
94f3a18c88
wasm: Add File abstraction 2024-02-29 15:23:03 +01:00
Luuk de Gram
cbc8d33062
wasm: fix symbol resolution and atom processing 2024-02-29 15:23:03 +01:00
Luuk de Gram
143e9599d6
wasm: use File abstraction instead of object
When merging sections we now make use of the `File` abstraction so all
objects such as globals, functions, imports, etc are also merged from
the `ZigObject` module. This allows us to use a singular way to perform
each link action without having to check the kind of the file.
The logic is mostly handled in the abstract file module, unless its
complexity warrants the handling within the corresponding module itself.
2024-02-29 15:23:03 +01:00
Luuk de Gram
12505c6d3d
wasm: store File.Index on the Atom
Also, consolidate the creation of Atoms so they all use `createAtom`.
2024-02-29 15:23:03 +01:00
Luuk de Gram
f6896ef218
wasm: create linking objects in correct module
CodeGen will create linking objects such as symbols, function types, etc
in ZigObject, rather than in the linker driver where the final result
will be stored. They will end up in the linker driver module during
the `flush` phase instead.

This must mean we must call functions such as `addOrGetFuncType` in the
correct namespace or else it will be created in the incorrect list and
therefore return incorrect indexes.
2024-02-29 15:23:03 +01:00
Luuk de Gram
9b3c8fd3a8
wasm: initialize a ZigObject when required
When we have a ZigCompileUnit and don't use LLVM, we initialize the
ZigObject which will encapsulate the Zig Module as an object file in-
memory. During initialization we also create symbols which the object
will need such as the stack pointer.
2024-02-29 15:23:02 +01:00
Luuk de Gram
e54177e852
wasm: move incremental Dwarf info into ZigObject 2024-02-29 15:23:02 +01:00
Luuk de Gram
ba0e84a411
wasm: move Zig module-linkage to ZigObject
Rather than specializing the linker-driver to be able to handle objects
generated by a ZCU, we store all data in-memory in ZigObject. ZigObject
acts more like a regular object file which will allow us to treat it
as us. This will make linking much more simple, but will also reduce
the complexity of incremental-linking as we can simply update ZigObject
and relink it.
2024-02-29 15:22:58 +01:00
Andrew Kelley
f7d095d372 use hash.addListOfBytes where applicable 2024-02-28 20:38:24 -07:00
Andrew Kelley
a4380a30f5 move zig libc command to be lazily built
part of #19063

This is a prerequisite for doing the same for Resinator.
2024-02-27 22:55:00 -07:00
Andrew Kelley
d51aa9748f change default WASI stack size
to match the other operating systems. 16 MiB

closes #18885
2024-02-26 10:33:17 -08:00
Jacob Young
d656c2a7ab test: rework how filtering works
* make test names contain the fully qualified name
 * make test filters match the fully qualified name
 * allow multiple test filters, where a test is skipped if it does not
   match any of the specified filters
2024-02-25 19:12:08 -08:00
Jakub Konka
429e542f3f macho: count rebases for synthetic __objc_selrefs 2024-02-26 02:22:36 +01:00
Jakub Konka
2901026425 macho: fix section to segment mapping 2024-02-26 02:22:36 +01:00
Jakub Konka
d7276c1527 macho: actually set SG_READ_ONLY on __DATA_CONST segment 2024-02-26 02:22:36 +01:00
Jakub Konka
7230b68b35
Merge pull request #19034 from ziglang/elf-riscv
elf: add basic aarch64 and riscv64 support
2024-02-23 21:41:14 +01:00
Jakub Konka
a92e6146da elf+riscv: return an error for unimplemented HI20 forward lookup 2024-02-21 23:49:22 +01:00
Jakub Konka
6236f5b810 link+riscv: simplify bitSlice helper 2024-02-21 23:40:44 +01:00