856 Commits

Author SHA1 Message Date
Jakub Konka
51fba37af7 coff: add relocation for call_extern 2022-09-07 22:42:55 +02:00
Jakub Konka
a35f156cf6 coff: re-enable default entrypoint for Windows 2022-09-07 22:42:55 +02:00
Veikka Tuominen
9ce841a0f0 stage2 llvm: implement aarch64 C ABI
... at least enough to pass all the current tests.
2022-09-04 18:46:56 +03:00
Veikka Tuominen
0f61d1f0df stage2 llvm: improve handling of i128 on Windows C ABI 2022-09-03 03:42:42 +03:00
Veikka Tuominen
b83c037f9f Sema: only ABI sized packed structs are extern compatible 2022-09-03 01:04:46 +03:00
Luuk de Gram
8627858bbc
test/link: add test for extern resolution
Adds a linker tests to verify extern/undefined symbols
representing non-functions are being resolved correctly.
2022-08-30 18:32:08 +02:00
Luuk de Gram
4f72ac265a
wasm: create relocations for extern decls
This also fixes performing relocations for data symbols
of which the target symbol exists in an external object file.
We do this by checking if the target symbol was discarded,
and if so: get the new location so that we can find the
corresponding atom that belongs to said new location. Previously
it would always assume the symbol would live in the same file
as the atom/symbol that is doing the relocation.
2022-08-30 16:38:55 +02:00
Jakub Konka
601f2147e0 coff: cleanup relocations; remove COFF support from other backends
Given that COFF will want to support PIC from ground-up, there is no
point in leaving outdated code for COFF in other backends such as
arm or aarch64. Instead, when we are ready to look into those, we
can start figuring out what to add and where.
2022-08-30 10:42:21 +02:00
Jakub Konka
f0d4ce4494 coff: add basic handling of GOT PC relative indirection 2022-08-30 10:42:21 +02:00
Jakub Konka
90b3599c68 coff: reorganize the linker 2022-08-30 10:42:21 +02:00
Andrew Kelley
7453f56e67 stage2: explicitly tagged enums no longer have one possible value
Previously, Zig had inconsistent semantics for an enum like this:

`enum(u8){zero = 0}`

Although in theory this can only hold one possible value, the tag
`zero`, Zig no longer will treat the type this way. It will do loads and
stores, as if the type has runtime bits.

Closes #12619

Tests passed locally:
 * test-behavior
 * test-cases
2022-08-24 22:20:31 -07:00
Veikka Tuominen
62ff8871ed stage2+stage1: remove type parameter from bit builtins
Closes #12529
Closes #12511
Closes #6835
2022-08-22 11:19:20 +03:00
Luuk de Gram
63c25cc1cc wasm: fix callInstrinsic return value
Rather than storing it in a local and returning that,
we now keep this on the stack as all internal functions
expect it to be on the stack already and therefore were
generating extra `local.set` instructions.
2022-08-18 14:17:01 +02:00
Veikka Tuominen
40eac90280
Merge pull request #12416 from Vexu/stage2-safety
Stage2 error set safety improvements
2022-08-15 11:32:26 +03:00
joachimschmidt557
c9d9fd53a6
stage2 ARM: add inline memcpy to genSetStack 2022-08-13 17:00:03 +02:00
joachimschmidt557
91969ad908
stage2 ARM: Fix tracking of function return values 2022-08-13 17:00:03 +02:00
joachimschmidt557
4c5156544b
stage2 ARM: pass stack arguments in opposite order
Earlier arguments have a smaller address (i.e. towards the bottom of
the stack)
2022-08-13 17:00:00 +02:00
Jakub Konka
aeaffd42f6 x86: fix generating debug info for variables
Add handling for these additional `MCValue`s:
* `.immediate` - lower to `DW.OP.consts` or `DW.OP.constu` depending
  on signedness followed by popping off the DWARF stack with
  `DW.OP.stack_value`
* `.undef` - lower to `DW.OP.implicit_value`
* `.none` - lower to `DW.OP.lit0` followed by popping off the DWARF
  stack with `DW.OP.stack_value`

For any remaining unhandled case, we generate `DW.OP.nop` in order
not to mess up remaining DWARF info.
2022-08-12 12:05:34 +02:00
Veikka Tuominen
7c9979a02e stage2: generate a switch for @errSetCast safety 2022-08-12 11:40:37 +03:00
Luuk de Gram
b42ba7c3d4
wasm: free unused locals
When a local is no longer referenced or used, free it
so the local can be re-used by another instruction.
This means we generate less locals. Freeing this local
is a manual action and must only be used on temporaries
or where we are sure the local is not referenced by a
different AIR instruction, as that creates UB.

We now also no longer store a `WValue` when its tag is set to `none`
as those may never be referenced by any AIR instruction.
An assertion is done to make sure we never store a reference to a
`stack` value in our resolved instructions.
2022-08-11 11:08:01 +02:00
Luuk de Gram
a5e4fd7ef6
wasm: keep load values on the stack
We internally use a lot of `load`'s that used to put
the result in a newly created local. For instance, when is considered
byRef or when we need a specific field/element/bytes from a larger type.
However, sometimes we want to directly use this value and then forget about
it, which means storing it in a local first is wasted instructions as well
as wasted locals that shouldn't be generated in the first place.
With this change it's explicit and requires the usage of `toLocal`.
2022-08-11 11:08:00 +02:00
Luuk de Gram
3cd0cd12a0
wasm: leave signedAbsValue values on the stack 2022-08-11 11:08:00 +02:00
Luuk de Gram
cde16f61eb
wasm: wrapOperand - leave value on the stack
This also does it for `wrapBinOp` which internally uses the already
refactored `binOp` and `wrapOperand` heavily simplifying this
function and not duplicate the logic from `binOp`
2022-08-11 11:08:00 +02:00
Luuk de Gram
699bc6171d
wasm: Keep intcast values on stack 2022-08-11 11:08:00 +02:00
Luuk de Gram
305b113a53
wasm: keep result of cmp on the stack
By keeping the result on the stack, we prevent codegen
from generating unneccesary locals when we have subsequent instructions
that do not have to be re-used.
2022-08-11 11:08:00 +02:00
Luuk de Gram
cc6f2b67c6
wasm: binOp leave value on stack
Rather than always creating a new local and storing the result of
a binary operation into said local, we now leave it on top of the stack.
This allows for better codegen as we need less instructions, as well
as less total amount of locals.
2022-08-11 11:08:00 +02:00
Luuk de Gram
7e6dbd6398
wasm: Use free-lists for unused locals
When a local is no longer needed (for instance, it was used as
a temporary during arithmetic), it can be appended to one of
the typed freelists. This allows us to re-use locals and therefore
require less locals, reducing the binary size, as well as runtime
initialization.
2022-08-11 11:07:56 +02:00
Andrew Kelley
b3d463c9e6
Merge pull request #12337 from Vexu/stage2-safety
Stage2: implement remaining runtime safety checks
2022-08-06 14:59:10 -07:00
Veikka Tuominen
f46d7304b1 stage2: add runtime safety for invalid enum values 2022-08-05 22:13:58 +03:00
joachimschmidt557
f46c80b267
stage2 AArch64: improve correctness of register aliases
Also implements ptr_elem_ptr
2022-08-05 20:30:52 +02:00
joachimschmidt557
508b90fcfa
stage2 AArch64: implement basic integer rem/mod 2022-08-05 20:30:52 +02:00
joachimschmidt557
8b24c783c5
stage2 AArch64: implement basic integer division 2022-08-05 20:30:51 +02:00
joachimschmidt557
dcb236acf4
stage2 AArch64: memcpy support in store and more complete intcast 2022-08-05 20:30:51 +02:00
joachimschmidt557
02738228f2
stage2 AArch64: support returning values by reference
also adds some more support for slices passed as stack arguments
2022-08-05 20:30:51 +02:00
joachimschmidt557
65b3c27f24
stage2 AArch64: all arguments passed via stack from now on
Only in the Undefined calling convention, not in other calling
conventions
2022-08-05 20:30:51 +02:00
joachimschmidt557
cf3aaceed9
stage2 AArch64: introduce MCValue.stack_argument_offset
This new MCValue union member shares the same semantics as the MCValue
type of the same name in the ARM backend.
2022-08-05 20:30:51 +02:00
joachimschmidt557
423bef4dfc
stage2 AArch64: Fix struct_field_val for register_with_overflow
Now mirrors the behavior of the native ARM backend
2022-08-05 20:30:47 +02:00
antlilja
cd8070f94f
Removed param_names from Fn inside Module.zig
Removed the copy of param_names inside of Fn and changed to
implementation of getParamName to fetch to parameter name from the ZIR.
The signature of getParamName was also changed to take an additional
*Module argument.
2022-08-01 14:51:50 +02:00
Ikko Ashimine
ff125db53d wasm: fix typo in CodeGen.zig
occured -> occurred
2022-07-31 13:00:37 -07:00
joachimschmidt557
0fc79d602b stage2 ARM: more support for switch statements 2022-07-28 20:44:32 +00:00
r00ster91
baafb8a491 std.fmt: add more invalid format string errors 2022-07-27 18:07:53 +03:00
Luuk de Gram
6b4d4c70fd
wasm: Only allow lowering C-ABI compatible types 2022-07-25 06:34:00 +02:00
Luuk de Gram
200b2e4ee1
llvm: correctly lower c-abi for Wasm target
When lowering the return type for Wasm if the calling convention is `C`,
it now correctly lower it according to what clang does as specified in:
https://github.com/WebAssembly/tool-conventions/blob/main/BasicCABI.md

This makes use of the same logic as the Wasm backend, ensuring the
generated code does not diverge in function signatures.

When passing arguments accross the C-ABI for the Wasm target,
we want slightly different behavior than x86_64.
For instance: a struct with multiple fields must always be passed
by reference, even if its ABI size fits in a single integer.
However, we do pass larger integers such as 128bit by value,
which LLVM will correctly lower to use double arguments instead.
2022-07-25 06:34:00 +02:00
Luuk de Gram
bf28a47cf2
wasm: pass correct abi-size for scalar values
When returning an aggregate type that contains a scalar value (nested),
its abi-size is passed by bits, rather than bytes to `buildOpcode`.
2022-07-25 06:33:56 +02:00
Veikka Tuominen
d75fa86d70 stage2: implement @setFloatMode 2022-07-23 15:40:12 +03:00
Veikka Tuominen
ff7ec4efb5 Sema: bad union field access safety 2022-07-23 15:40:11 +03:00
Jakub Konka
41b91442f4 macho: improve logs for dyld info 2022-07-22 16:58:21 +02:00
Jakub Konka
9eb7e5182b macho: rework symbol handling to match zld/ELF
Now, each object file will store a mutable table of symbols that it
defines. Upon symbol resolution between object files, the symbol
will be updated with a globally allocated section ordinal and address
in virtual memory. If the object defines a globally available symbol,
its location only (comprising of the symbol index and object index)
will be stored in the globals map for easy access when relocating, etc.
This approach cleans up the symbol management significantly, and matches
the status quo used in zld/ELF.

Additionally, this makes scoping symbol stabs easier too as they are
now naturally contained within each object file.
2022-07-22 16:58:20 +02:00
joachimschmidt557
f89ace4d04
stage2 ARM: add integer modulo with constant power-of-two rhs 2022-07-12 23:22:15 +02:00
joachimschmidt557
47d1874218
stage2 ARM: implement division by constant int power-of-two divisors 2022-07-12 22:43:55 +02:00