Commit graph

29123 commits

Author SHA1 Message Date
Andrew Kelley
5d29b9fad6 CI: enable builds of 0.12.x branch 2024-04-23 17:23:29 -07:00
Eric Joldasov
6de152ec7c std.zig.system: fix ELF file search
* Adjust buffer length a bit.
 * Fix detecting if file is a script. Logic below was unreachable,
 because 99% of scripts failed "At least 255 bytes long" check and were detected as ELF files.
 It should be "At least 4" instead (minimum value of "ELF magic length" and "smallest possible interpreter path length").
 * Fix parsing interpreter path, when text after shebang:
     1. does not have newline,
     2. has leading spaces and tabs,
     3. separates interpreter and arguments by tab or NUL.
 * Remove empty error set from `defaultAbiAndDynamicLinker`.

Signed-off-by: Eric Joldasov <bratishkaerik@landless-city.net>
2024-04-23 17:22:04 -07:00
clickingbuttons
cc25f75478 std.crypto: make ff.ct_unprotected.limbsCmpLt compile (#19741)
* std.crypto: make ff.ct_unprotected.limbsCmpLt compile

* std.crypto: add ff.ct test

* fix testCt to work on x86

* disable test on stage2-c

---------

Co-authored-by: Frank Denis <124872+jedisct1@users.noreply.github.com>
2024-04-23 17:17:02 -07:00
David Rubin
eb28c8aa35 error on undefined end index 2024-04-23 17:16:54 -07:00
Frank Denis
f6773232ac Fix WASI threads, again
Properly call the entrypoint when it doesn't return an optional error,
and use the per-thread copy of the arguments list.
2024-04-23 17:16:08 -07:00
Jacob Young
9deea9b1d8 x86_64: fix C abi for unions
Closes #19721
2024-04-23 17:16:03 -07:00
Jakub Konka
8e0a802ea1 link/macho: make --verbose-link represent the actual linker line 2024-04-23 17:15:47 -07:00
Jakub Konka
eb5d67b146 Merge pull request #19714 from ziglang/elf-merge-strings
link/elf: implement string merging
2024-04-23 17:14:03 -07:00
Jakub Konka
082e5091af Merge pull request #19710 from jacobly0/elf-segment-align
Elf: fix unaligned segments on non-linux
2024-04-23 17:13:22 -07:00
Jared Baur
3b1f9b476c Fix usage of unexpectedErrno
`unexpectedErrno` comes from `std.posix`, not `std.os`.
2024-04-23 17:12:24 -07:00
Marco F
2478b5bb0e update list of missing features in no-LLVM built zig2 2024-04-23 17:12:07 -07:00
Linus Groh
7974576967 std.fs.Dir.openDir: use wasi libc API when -lc
Same as #19680 but for directories.
2024-04-23 17:11:48 -07:00
Andrew Kelley
011a78325e start the 0.12.1 release cycle 2024-04-23 17:10:15 -07:00
Andrew Kelley
a685ab1499 Release 0.12.0 2024-04-19 14:00:35 -07:00
GethDW
db96ad4a16 std: fix Thread.Pool.spawn
`@alignCast` was required for args with greater alignment than that of a pointer.
2024-04-19 13:49:06 -07:00
Andrew Kelley
844da16d8e update .mailmap
keeps our contributor count in the release notes somewhat accurate
2024-04-19 13:16:09 -07:00
Jacob Young
ebce190321 llvm: fix debug info when running tests 2024-04-19 12:13:29 -07:00
Meghan Denny
f03829a2da
define std.crypto.sha2.Sha512224 (#19697)
* define std.crypto.sha2.Sha512224

* rename blunder

* add sha512-224 and sha512-256 tests

* fix Sha2x64 for variations that aren't a multiple of 64 bits
2024-04-19 14:50:46 +00:00
cryptocode
3adfaf91f7 The Mach-O header flags gained two new members at some point, and these are missing in the Zig std library. This PR adds these.
The macOS libc header is already up-to-date: 130fb5cb0f/lib/libc/include/any-macos-any/mach-o/loader.h (L232-L241)
2024-04-18 20:08:03 -07:00
Andrew Kelley
d06e5b4349 std.fs.Dir.openFile: use wasi libc API when -lc
Also removes the LOCK namespace from std.c.wasi because wasi libc does
not have flock.

closes #19336
related to #19352

Co-authored-by: Ryan Liptak <squeek502@hotmail.com>
2024-04-18 17:49:05 -07:00
Andrew Kelley
3c221463fd
Merge pull request #19689 from nektro/nektro-patch-29794
std: fix and add test for Build.dependencyFromBuildZig
2024-04-18 16:38:11 -07:00
Jacob Young
544397ce6d
Merge pull request #19649 from ziglang/x86_64-windows-ci
ci: add self-hosted `x86_64 windows`
2024-04-18 19:13:29 -04:00
Erik Arvstedt
130fb5cb0f cmake: support setting the dynamic linker 2024-04-18 12:16:24 -07:00
Meghan Denny
1b4ea80654
do more robust import
Co-authored-by: Carl Åstholm <carl@astholm.se>
2024-04-18 11:24:42 -07:00
Meghan Denny
0820aa4a46 std: fix and add test for Build.dependencyFromBuildZig 2024-04-18 03:07:44 -07:00
Andrew Kelley
22a97cd235 std.Build: revert --host-target, --host-cpu, --host-dynamic-linker
This is a partial revert of 105db13536.

As we learned from Void Linux packaging, these options are not actually
helpful since the distribution package manager may very well want to
cross-compile the packages that it is building.

So, let's not overcomplicate things. There are already the standard
options: -Dtarget, -Dcpu, and -Ddynamic-linker.

These options are generally provided when the project generates machine
code artifacts, however, there may be a project that does no such thing,
in which case it makes sense for these options to be missing. The Zig
Build System is a general-purpose build system, after all.
2024-04-18 03:02:13 -07:00
mlugg
21a6a1b0f2 Sema: cap depth of value printing in type names
Certain types (notably, `std.ComptimeStringMap`) were resulting in excessively
long type names when instantiated, which in turn resulted in excessively long
symbol names. These are problematic for two reasons:

* Symbol names are sometimes read by humans -- they ought to be readable.
* Some other applications (looking at you, xcode) trip on very long symbol names.

To work around this for now, we cap the depth of value printing at 1, as opposed
to the normal 3. This doesn't guarantee anything -- there could still be, for
instance, an incredibly long aggregate -- but it works around the issue in
practice for the time being.
2024-04-17 22:47:54 -07:00
David Rubin
187f0c1e26
Sema: correctly make inferred allocs constant
Resolves: #19677
2024-04-18 04:45:14 +00:00
Liviu Dudau
a0de077600 std.zig.system.linux: Use arm.zig detection for AArch64 CPU features
When building zig natively from source on an RK3588 SoC board, the
generated stage3 compiler will use unsupported 'sha256h.4s' instructions
due to mis-identified CPU features. This happens when trying to
compile a new project generated with "zig init"

$ ~/devel/zig/build/stage3/bin/zig build
thread 919 panic: Illegal instruction at address 0x1fdc0c4
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:223:29: 0x1fdc0c4 in round (zig)
                            asm volatile (
                            ^
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:168:20: 0x1fdca87 in final (zig)
            d.round(&d.buf);
                   ^
/home/dliviu/devel/zig/lib/std/crypto/sha2.zig:180:20: 0x1c8bb33 in finalResult (zig)
            d.final(&result);
                   ^
/mnt/home/dliviu/devel/zig/src/Package/Fetch.zig:754:49: 0x1a3a8eb in relativePathDigest (zig)
    return Manifest.hexDigest(hasher.finalResult());
                                                ^
/mnt/home/dliviu/devel/zig/src/main.zig:5128:53: 0x1a37413 in cmdBuild (zig)
                    Package.Fetch.relativePathDigest(build_mod.root, global_cache_directory),
                                                    ^
???:?:?: 0xff09ffffffffffff in ??? (???)
Unwind information for `???:0xff09ffffffffffff` was not available, trace may be incomplete

???:?:?: 0x3f7f137 in ??? (???)
Aborted (core dumped)

system/linux.zig parses "/proc/cpuinfo" to determine the CPU features, but it
seems to generate the wrong set of features from:

$ cat /proc/cpuinfo
processor	: 0
BogoMIPS	: 48.00
Features	: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x2
CPU part	: 0xd05
CPU revision	: 0
.....
processor	: 4
BogoMIPS	: 48.00
Features	: fp asimd evtstrm crc32 atomics fphp asimdhp cpuid asimdrdm lrcpc dcpop asimddp
CPU implementer	: 0x41
CPU architecture: 8
CPU variant	: 0x4
CPU part	: 0xd0b
CPU revision	: 0
.....

To fix this, use the Linux kernel way of reading the feature registers as documented
here: https://www.kernel.org/doc/html/latest/arch/arm64/cpu-feature-registers.html

arm.zig already has the code to parse the feature register values, we just need to
collect them in an array and pass them for identification.

Signed-off-by: Liviu Dudau <liviu@dudau.co.uk>
2024-04-17 15:06:48 -07:00
Andrew Kelley
1fb2381316
Merge pull request #19630 from mlugg/comptime-ptr-access-5
compiler: rework comptime pointer representation and access
2024-04-17 12:35:35 -07:00
mlugg
23062a5bed
Value: convert undefined values to 0xAA for bitwise operations
The operation `undefined & 0` ought to result in the value `0`, and likewise for
zeroing only some bits. `std/packed_int_array.zig` tests were failing because
this behavior was not implemented -- this issue was previously masked by faulty
bitcast logic which turned `undefined` values into `0xAA` on pointer loads.

Ideally, we would like to be able to track the undefined bits at comptime.
This is related to #19634.
2024-04-17 13:41:26 +01:00
mlugg
3c45a94528
Value: fix out-of-bounds slice access writing zero-bit undef value
I have no idea why this wasn't being hit on master before.
2024-04-17 13:41:26 +01:00
mlugg
03ad862197
compiler: un-implement #19634
This commit reverts the handling of partially-undefined values in
bitcasting to transform these bits into an arbitrary numeric value,
like happens on `master` today.

As @andrewrk rightly points out, #19634 has unfortunate consequences
for the standard library, and likely requires more thought. To avoid
a major breaking change, it has been decided to revert this design
decision for now, and make a more informed decision further down the
line.
2024-04-17 13:41:25 +01:00
mlugg
66630f6c93
test: disable newly failing test
I have noted several latent bugs in the handling of packed memory on
big-endian targets, and one of them has been exposed by the previous
commit, triggering this test failure. I am opting to disable it for now
on the ground that the commit preceding this one helps far more than it
hurts.
2024-04-17 13:41:25 +01:00
mlugg
d0e74ffe52
compiler: rework comptime pointer representation and access
We've got a big one here! This commit reworks how we represent pointers
in the InternPool, and rewrites the logic for loading and storing from
them at comptime.

Firstly, the pointer representation. Previously, pointers were
represented in a highly structured manner: pointers to fields, array
elements, etc, were explicitly represented. This works well for simple
cases, but is quite difficult to handle in the cases of unusual
reinterpretations, pointer casts, offsets, etc. Therefore, pointers are
now represented in a more "flat" manner. For types without well-defined
layouts -- such as comptime-only types, automatic-layout aggregates, and
so on -- we still use this "hierarchical" structure. However, for types
with well-defined layouts, we use a byte offset associated with the
pointer. This allows the comptime pointer access logic to deal with
reinterpreted pointers far more gracefully, because the "base address"
of a pointer -- for instance a `field` -- is a single value which
pointer accesses cannot exceed since the parent has undefined layout.
This strategy is also more useful to most backends -- see the updated
logic in `codegen.zig` and `codegen/llvm.zig`. For backends which do
prefer a chain of field and elements accesses for lowering pointer
values, such as SPIR-V, there is a helpful function in `Value` which
creates a strategy to derive a pointer value using ideally only field
and element accesses. This is actually more correct than the previous
logic, since it correctly handles pointer casts which, after the dust
has settled, end up referring exactly to an aggregate field or array
element.

In terms of the pointer access code, it has been rewritten from the
ground up. The old logic had become rather a mess of special cases being
added whenever bugs were hit, and was still riddled with bugs. The new
logic was written to handle the "difficult" cases correctly, the most
notable of which is restructuring of a comptime-only array (for
instance, converting a `[3][2]comptime_int` to a `[2][3]comptime_int`.
Currently, the logic for loading and storing work somewhat differently,
but a future change will likely improve the loading logic to bring it
more in line with the store strategy. As far as I can tell, the rewrite
has fixed all bugs exposed by #19414.

As a part of this, the comptime bitcast logic has also been rewritten.
Previously, bitcasts simply worked by serializing the entire value into
an in-memory buffer, then deserializing it. This strategy has two key
weaknesses: pointers, and undefined values. Representations of these
values at comptime cannot be easily serialized/deserialized whilst
preserving data, which means many bitcasts would become runtime-known if
pointers were involved, or would turn `undefined` values into `0xAA`.
The new logic works by "flattening" the datastructure to be cast into a
sequence of bit-packed atomic values, and then "unflattening" it; using
serialization when necessary, but with special handling for `undefined`
values and for pointers which align in virtual memory. The resulting
code is definitely slower -- more on this later -- but it is correct.

The pointer access and bitcast logic required some helper functions and
types which are not generally useful elsewhere, so I opted to split them
into separate files `Sema/comptime_ptr_access.zig` and
`Sema/bitcast.zig`, with simple re-exports in `Sema.zig` for their small
public APIs.

Whilst working on this branch, I caught various unrelated bugs with
transitive Sema errors, and with the handling of `undefined` values.
These bugs have been fixed, and corresponding behavior test added.

In terms of performance, I do anticipate that this commit will regress
performance somewhat, because the new pointer access and bitcast logic
is necessarily more complex. I have not yet taken performance
measurements, but will do shortly, and post the results in this PR. If
the performance regression is severe, I will do work to to optimize the
new logic before merge.

Resolves: #19452
Resolves: #19460
2024-04-17 13:41:25 +01:00
Jacob Young
77abd3a96a x86_64: fix miscompilation regression in package fetching code 2024-04-16 20:12:30 -04:00
Andrew Kelley
a2b834e8c7
Merge pull request #19654 from jacobly0/wasi-ver
Target: add wasi os version
2024-04-15 16:14:22 -07:00
Andrew Kelley
b78b2689ed
Merge pull request #19655 from squeek502/windows-argv-post-2008
ArgIteratorWindows: Match post-2008 C runtime rather than `CommandLineToArgvW`
2024-04-15 15:28:33 -07:00
Alex Kladov
ff18103ef6 std: improve std.once tests
* fix UB when Thread.spawn fails, and we try to join uninitialized
  threads (through new `thread_count` variable).
* make sure that the tests pins down synchronization guarantees: in the
  main thread, we can observe `1` due to synchronization from
  `Thread.join()`. To make sure that once uses Acq/Rel, and not just
  relaxed, we should also additionally check that each thread observes
  1, regardless of whether it was the one to call once.
2024-04-15 15:24:30 -07:00
Jakub Konka
1e5075f812 lib/std/Build/Step/CheckObject: dump section as string 2024-04-15 18:06:44 +02:00
Linus Groh
d483ba7250 zig init: Replace deprecated LazyPath.path with Build.path() 2024-04-15 16:55:04 +03:00
jd
d23a8e83d4 std.Build.Step.ConfigHeader: better error message 2024-04-15 04:10:13 -07:00
Ryan Liptak
cffe1999c6 windows_argv standalone test: Only test against MSVC if it's available 2024-04-15 02:09:48 -07:00
Ryan Liptak
f4c4c04f1c ArgIteratorWindows: Match post-2008 C runtime rather than CommandLineToArgvW
On Windows, the command line arguments of a program are a single WTF-16 encoded string and it's up to the program to split it into an array of strings. In C/C++, the entry point of the C runtime takes care of splitting the command line and passing argc/argv to the main function.

https://github.com/ziglang/zig/pull/18309 updated ArgIteratorWindows to match the behavior of CommandLineToArgvW, but it turns out that CommandLineToArgvW's behavior does not match the behavior of the C runtime post-2008. In 2008, the C runtime argv splitting changed how it handles consecutive double quotes within a quoted argument (it's now considered an escaped quote, e.g. `"foo""bar"` post-2008 would get parsed into `foo"bar`), and the rules around argv[0] were also changed.

This commit makes ArgIteratorWindows match the behavior of the post-2008 C runtime, and adds a standalone test that verifies the behavior matches both the MSVC and MinGW argv splitting exactly in all cases (it checks that randomly generated command line strings get split the same way).

The motivation here is roughly the same as when the same change was made in Rust (https://github.com/rust-lang/rust/pull/87580), that is (paraphrased):

- Consistent behavior between Zig and modern C/C++ programs
- Allows users to escape double quotes in a way that can be more straightforward

Additionally, the suggested mitigation for BatBadBut (https://flatt.tech/research/posts/batbadbut-you-cant-securely-execute-commands-on-windows/) relies on the post-2008 argv splitting behavior for roundtripping of the arguments given to `cmd.exe`. Note: it's not necessary for the suggested mitigation to work, but it is necessary for the suggested escaping to be parsed back into the intended argv by ArgIteratorWindows after being run through a `.bat` file.
2024-04-15 02:09:48 -07:00
Andrew Kelley
64b9893582
Merge pull request #19657 from ziglang/fs.Dir.Walker-null
std.fs.Dir.Walker: maintain a null byte in path names
2024-04-15 00:25:23 -07:00
Jacob Young
71ccdb5a66 ci: add self-hosted x86_64 windows 2024-04-14 21:26:09 -04:00
Jacob Young
425e38b6e0 WindowsSdk: fix for new x86_64-windows CI 2024-04-14 21:26:08 -04:00
Andrew Kelley
36060a774e fix namespacing of std.fs.Dir.Walker.Entry 2024-04-14 18:08:42 -07:00
Andrew Kelley
10106660e9 std.fs.Dir.Walker: maintain a null byte in path names 2024-04-14 17:59:43 -07:00
Jacob Young
60d5001ac8 wasi: change default os version to 0.1.0
This version represents "WASI Preview 1".

Closes #19581
2024-04-14 18:43:52 -04:00