19026 Commits

Author SHA1 Message Date
Andrew Kelley
ae0b0729fc LLD: there are fewer libraries to link against now 2022-07-01 22:13:12 -07:00
Andrew Kelley
d55d98919d update CPU features to LLVM 14
Notable changes:

`_i386`, `_i486`, and `_i686` are renamed to `i386`, `i486`,
and `i686` respectively. `std.zig.fmtId` is enhanced to support
formatting `i386` as `@"i386"`.

Some CPU features which are actually CPU models have been
properly flattened, such as `apple_a12`, `apple_a13`, `apple_a7`,
`cortex_a78c`, `exynos_m4`, `neoverse_e1`, `neoverse_n1`,
`neoverse_n2`, `neoverse_v1`.

Some CPU features have been added and some have been removed, following
LLVM's lead.

CSky CPU features support is added.
2022-07-01 21:35:19 -07:00
Andrew Kelley
d19290e603 stage1: update inline asm outputs to LLVM 14
LLVM pointers are transitioning to no longer have types, however, inline
assembly inputs and outputs which accept pointers need to know the
element type. So, inline assembly must be upgraded to add
elementtype(<ty>) annotations.
2022-07-01 20:11:06 -07:00
Andrew Kelley
1fa4a58d2c stage1: update to LLVM 14 API 2022-07-01 19:19:13 -07:00
Andrew Kelley
41a0b81731 CMake: disable deprecated function warnings
LLVM 14 deprecated a bunch of C API functions in preparation for opaque
pointer changes. However, they did not actually implement opaque pointer
semantics, so the deprecations are largely masturbatory. I have nothing
against masturbation, I am just busy trying to get the self hosted
compiler done for 0.10.0, so we will come back to this later.
2022-07-01 19:17:09 -07:00
Andrew Kelley
ceb3819c42 update libunwind to llvm 14.0.6 2022-07-01 16:39:31 -07:00
Andrew Kelley
aa964bd555 update libcxxabi to llvm 14.0.6 2022-07-01 16:39:29 -07:00
Andrew Kelley
bd680139d0 update libcxx to llvm 14.0.6 2022-07-01 16:31:47 -07:00
Andrew Kelley
c89dd15e1b Merge remote-tracking branch 'origin/master' into llvm14 2022-07-01 15:52:54 -07:00
Andrew Kelley
2360f8c490
Merge pull request #11974 from ziglang/fixfixfix
stage2 fixes
2022-07-01 17:29:31 -04:00
Andrew Kelley
7e2eb1326b
Merge pull request #11973 from Vexu/stage2-compile-errors
more stage2 compile error fixes
2022-07-01 17:29:18 -04:00
Jakub Konka
b79884eaf0 macho: implement pruning of unused segments and sections
This is a prelude to a more elaborate work which will implement
`-dead_strip` flag - garbage collection of unreachable atoms. Here,
when sorting sections, we also check that the section is actually
populated with some atoms, and if not, we exclude it from the final
linked image. This can happen when we do not import any symbols
from dynamic libraries in which case we will not be populating
the stubs sections or the GOT table, implying we can skip allocating
those sections. Furthermore, we also make a check that a segment
is actually occupied too, with the exception of `__TEXT` segment
which is non-optional given that it wraps the header and load commands
and thus is required by the `dyld` to perform dynamic linking, and
`__PAGEZERO` which is generally non-optional when the linked image
is an executable. For any other segment, if its section count is
zero, we mark it as dead and skip allocating it and generating
a load command for it.

This commit also includes some minor improvements to the linker such
as refactoring of the segment allocating codepaths, skipping
`__PAGEZERO` generation for dylibs, and skipping generation of zero-sized
atoms for special symbols such as `__mh_execute_header` and `___dso_handle`.
These special symbols are only allocated local and global symbol pair
and their VM addresses is set to the start of the `__TEXT` segment,
but no `Atom` is created, as it's not necessary given that they never
carry any machine code.

Finally, we now always force-link against `libSystem` which turns out
to be required for `dyld` to properly handle `LC_MAIN` load command
on older macOS versions such as 10.15.7.
2022-07-01 22:05:22 +02:00
Frank Denis
ee01dd4032
crypto: add the Xoodoo permutation, prepare for Gimli deprecation (#11866)
Gimli was a game changer. A permutation that is large enough to be
used in sponge-like constructions, yet small enough to be compact
to implement and fast on a wide range of platforms.

And Gimli being part of the Zig standard library was awesome.

But since then, Gimli entered the NIST Lightweight Cryptography
Competition, competing againt other candidates sharing a similar set
of properties.

Unfortunately, Gimli didn't pass the 3rd round.

There are no practical attacks against Gimli when used correctly, but
NIST's decision means that Gimli is unlikely to ever get any traction.

So, maybe the time has come to move Gimli from the standard library
to another repository.

We shouldn't do it without providing an alternative, though.
And the best candidate for this is probably Xoodoo.

Xoodoo is the core function of Xoodyak, one of the finalists of the
NIST LWC competition, and the most direct competitor to Gimli. It is
also a 384-bit permutation, so it can easily be used everywhere Gimli
was used with no parameter changes.

It is the building block of Xoodyak (for actual encryption and hashing)
as well as Charm, that some Zig applications are already using.

Like Gimli that it was heavily inspired from, it is compact and
suitable for constrained environments.

This change adds the Xoodoo permutation to std.crypto.core.

The set of public functions includes everything required to later
implement existing Xoodoo-based constructions.

In order to prepare for the Gimli deprecation, the default
CSPRNG was changed to a Xoodoo-based that works exactly the same way.
2022-07-01 13:18:08 +02:00
Frank Denis
48fd92365a
std.crypto.hash: allow creating hash functions from compositions (#11965)
A hash function cascade was a common way to avoid length-extension
attacks with traditional hash functions such as the SHA-2 family.

Add `std.crypto.hash.composition` to do exactly that using arbitrary
hash functions, and pre-define the common SHA2-based ones.

With this, we can now sign and verify Bitcoin signatures in pure Zig.
2022-07-01 11:37:41 +02:00
Veikka Tuominen
2029601cb2 AstGen: use elem_{ptr,val}_node for array access syntax 2022-07-01 10:22:26 +03:00
Veikka Tuominen
a6bf8c2593 Sema: add more validation to zirFieldParentPtr 2022-07-01 10:22:25 +03:00
Veikka Tuominen
e6ebf56dd6 Sema: validate @intToEnum int operand type 2022-07-01 10:22:25 +03:00
Veikka Tuominen
ae7b32eb62 Sema: validate deref operator type and value 2022-07-01 10:22:25 +03:00
Veikka Tuominen
3c73f71177 Sema: prefer func.onwer_decl for compilelog src 2022-07-01 10:22:25 +03:00
Veikka Tuominen
3014a0d5f1 Sema: validate callconv 2022-07-01 10:22:25 +03:00
Veikka Tuominen
6d24c40b6e Sema: improve bitcast to enum error 2022-07-01 09:29:13 +03:00
Andrew Kelley
095e24e537 stage2: implement alignment calculation of vectors
closes #11856
2022-06-30 19:39:41 -07:00
Andrew Kelley
d3542be875 LLVM: be sure to never pass align(0) attribute
This can happen with pointers to zero-bit types.

This commit fixes an LLVM assertion being tripped.
2022-06-30 18:33:02 -07:00
Andrew Kelley
c030ec1884 LLVM: use unnamed struct llvm type for unions when necessary
The constant value lowering for unions was missing a check for whether
the payload was itself an unnamed struct. Lowerings of other types
already handle this case.

closes #11971
2022-06-30 18:33:02 -07:00
Andrew Kelley
67db2b85b7 remove plan9 test coverage
This regressed; the plan9 linker code is crashing when trying to build
compiler-rt and we have no active plan9 maintainers involved in the Zig
project. Anyone is welcome to come over and take the role; however, it's
not one of the tier 1, 2, or 3 targets, so we will not be blocking
progress towards 1.0 on plan9.
2022-06-30 18:33:02 -07:00
Andrew Kelley
152462e2e1 stage2: object format affects whether LLVM can be used 2022-06-30 18:33:02 -07:00
Andrew Kelley
902dc8c721 CI: update freebsd pkg install command 2022-06-30 17:57:00 -07:00
Andrew Kelley
1951051e3d
Merge pull request #11942 from Vexu/stage2-compile-errors
Move passing stage1 compile error tests to stage2
2022-06-30 18:39:46 -04:00
Andrew Kelley
77a334451f
Merge pull request #11967 from ziglang/runtime-float-negation
stage2: lower float negation explicitly + modify hash/eql logic for floats
2022-06-30 17:34:05 -04:00
Mikko Kaihlavirta
be18459c81
std.event: use .{} to initiate Lock to unlocked state
Co-authored-by: Mikko Kaihlavirta <kaihlavirta@gmail.com>
2022-07-01 00:09:36 +03:00
Andrew Kelley
b3b96b5e28 LLVM: lower float negation with xor a constant
Rather than a compiler-rt call in the case that LLVM does not support
lowering the fneg instruction.
2022-06-30 11:48:37 -07:00
Veikka Tuominen
4cde6dd109 adjust tests that didn't pass CI 2022-06-30 21:47:26 +03:00
Veikka Tuominen
4f200eda9f stage2 llvm: ensure @tagName functions are unique 2022-06-30 21:47:25 +03:00
Veikka Tuominen
90ae37cc00 tests: move compile errors not planned for stage2 2022-06-30 09:57:38 +02:00
Veikka Tuominen
cc3336c784 Sema: add source location to coerce result ptr, fix negation error 2022-06-30 09:57:38 +02:00
Veikka Tuominen
979910dc38 Sema: validate shift amounts and switch ranges 2022-06-30 09:57:38 +02:00
Veikka Tuominen
6cadac18b8 Sema: improve auto generated union enum name 2022-06-30 09:57:38 +02:00
Veikka Tuominen
2e7dc5e151 Sema: improve vector overflow errors 2022-06-30 09:57:38 +02:00
Veikka Tuominen
03b356e34a Sema: improve @call errors 2022-06-30 09:57:38 +02:00
Veikka Tuominen
3204d00a5e move passing stage1 compile error tests to stage2 2022-06-30 09:57:38 +02:00
Andrew Kelley
c8531faaf5 stage2: hash/eql of fixed-size floats use bit pattern
Zig guarantees the memory layout of f16, f32, f64, f80, and f128 which
means for generic function purposes, values of these types need to be
compared on the basis of their bits in memory. This means nan-packing
can be used with generic functions, for example.

For comptime_float, the sign is observable, whether it is nan is
observable, but not any more kinds of bit patterns are observable.

This fixes the std.fmt tests that check printing "-nan".
2022-06-30 00:54:03 -07:00
Andrew Kelley
6bc6e47b15 stage2: lower float negation explicitly
Rather than lowering float negation as `0.0 - x`.

 * Add AIR instruction for float negation.
 * Add compiler-rt functions for f128, f80 negation

closes #11853
2022-06-30 00:02:00 -07:00
Andrew Kelley
c248af3bdc LLVM: fix lowering of untagged union types
The LLVM backend was calculating the amount of padding solely based
on the payload size. However, in the case where there is no union
tag, this fails to take into account alignment.

Closes #11857
2022-06-30 02:43:05 -04:00
Andrew Kelley
54454fd010 std.math.big.int: breaking API changes to prevent UAF
Many of the Managed methods accepted by-val parameters which could
reference Limb slices that became invalid memory after any
ensureCapacity calls. Now, Managed methods accept `*const Managed`
parameters so that if the function allows aliasing and the
ensure-capacity call resizes the Limb slice, it also affects the
aliased parameters, avoiding use-after-free bugs.

This is a breaking change that reduces the requirement for callsites to
manually make the ensure-capacity changes prior to calling many of the
Managed methods.

Closes #11897
2022-06-29 22:06:27 -04:00
Veikka Tuominen
8f2f0d8f08
Merge pull request #11962 from LordMZTE/fix/cast-or-call-parens
translate-c: fix cast or call macro with parenthesis
2022-06-29 21:36:13 +03:00
Andrew Kelley
98681b2da0
Merge pull request #11958 from ziglang/store-to-inferred-ptr
stage2: fix miscompilations for peer expressions any time they needed coercions to runtime types
2022-06-29 14:26:23 -04:00
Jakub Konka
7cc4176448 clang: add Zig equivalent for -headerpad_max_install_names cli flag 2022-06-29 17:21:32 +02:00
Jakub Konka
59359b2547 aarch64: add airRetLoad for register mcv 2022-06-29 17:19:49 +02:00
LordMZTE
b4ecc02471
translate-c: fix token pasting operator without parens 2022-06-29 16:59:18 +02:00
LordMZTE
7b32062775
translate-c: fix cast or call macro with parenthesis 2022-06-29 16:03:29 +02:00