15236 Commits

Author SHA1 Message Date
Ali Chraghi
db181b173f
Update hash & crypto benchmarks run comment (#9790)
* sync function arguments name with other same functions
2021-09-19 23:03:18 -07:00
Martin Wickham
cfd5b81850 Fix compiler builds with tracy on the mingw target 2021-09-20 01:59:25 -04:00
Malcolm Still
1f61076ffb I'm working on a WebAssembly interpreter in zig. WebAssembly uses LEB128 encoding throughout its specification.
The WebAssembly spec requires signed LEB128 to be encoded up to a maximum number of bytes (max 5 bytes for i32, max 10 bytes for i64) and that "unused" bits are all 0 if the number is positive and all 1 if the number is negative. The Zig LEB128 implementation already enforces the max number of bytes and does check the unused bytes https://github.com/ziglang/zig/blob/master/lib/std/leb128.zig#L70-L79.

However, the WebAssembly test suite has a number of tests that were failing validation (expecting the wasm module to fail validation, but when running the tests, those examples were actually passing validation):

    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L893-L902
    https://github.com/malcolmstill/foxwren/blob/master/test/testsuite/binary-leb128.wast#L934-L943

Notably the failures are both cases of negative numbers and the top 4 bits of the last byte are zero. And I believe this is the issue: we're only currently checking the "unused" / remaining_bits if we overflow, but in the case of 0x0_ no overflow happens and so the bits go unchecked.

In other words:

    \xff\xff\xff\xff\7f rightly successfully decodes (because it overflows and the remaining bits are 0b1111)
    \xff\xff\xff\xff\6f rightly errors with overflow (because it overflows and the remaining bits are 0b1110)
    \xff\xff\xff\xff\0f incorrectly decodes when it should error (because the top 4 bits are all 0, and so no overflow occurs and no check that the unused bits are 1 happens)

This PR adds a the remaining_bits check in an else branch of the @shlWithOverflow when we're looking at the last byte and the number being decoded is negative.

Note: this means a couple of the test cases in leb128.zig that are down as decoding shouldn't actually decode so I added the appropriate 1 bits.
2021-09-20 01:58:18 -04:00
Andrew Kelley
9fa723ee50 stage2: implement @atomicStore 2021-09-19 15:08:38 -07:00
Jakub Konka
2a0c44fff3 elf: add amd64 relocation types
I believe these are Linux specific so they will need to be os-gated
in `elf.zig` at some point, but I reckon it should be fine to have
them as-is right now since the ELF linker work will mainly be done
on x86-64 Linux at first.
2021-09-19 14:02:22 +02:00
Ryan Liptak
224d4de747 Improve ensureTotalCapacity call in ChildProcess.collectOutputWindows
Take current len and max_output_bytes into account instead of unconditionally using bump_amt
2021-09-19 13:52:56 +02:00
Ryan Liptak
59f5053bed Update all ensureCapacity calls to the relevant non-deprecated version 2021-09-19 13:52:56 +02:00
Ryan Liptak
feeb25908b std.PriorityDequeue: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for PriorityDequeue.
2021-09-19 13:52:56 +02:00
Ryan Liptak
2be3b1d2bf std.PriorityQueue: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for PriorityQueue.
2021-09-19 13:52:56 +02:00
Ryan Liptak
cfe71cb67a std.fifo.LinearFifo: ensureUnusedCapacity and ensureTotalCapacity
Same as c8ae581fef6506a8234cdba1355ba7f0f449031a, but for LinearFifo.
2021-09-19 13:52:56 +02:00
Jens Goldberg
d2b5105f54
Add Linux ioctl creation utilities (#9748)
* Add Linux ioctl creation utilities

* Apply suggestions from code review

Co-authored-by: Veikka Tuominen <git@vexu.eu>

* Update lib/std/os/linux.zig

Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>

Co-authored-by: Veikka Tuominen <git@vexu.eu>
Co-authored-by: zigazeljko <ziga.zeljko@gmail.com>
2021-09-18 09:56:11 +03:00
Andrew Kelley
f0b1eec809 ci: update to new sourcehut access token 2021-09-17 11:12:11 -07:00
Jakub Konka
d8375696f6 elf: add a couple missing special section indexes SHN_ 2021-09-17 12:12:50 +02:00
Andrew Kelley
b58d8aa05f stage2: improve LLVM backend for enums
* support lowering enum types and constants to LLVM IR
 * fix cmp instruction to support enum operands
2021-09-16 21:57:46 -07:00
Andrew Kelley
091a98f524 stage2: fix global variables with inferred type
Also, when a global variable does have a type, perform coercion on it.
2021-09-16 21:43:01 -07:00
Andrew Kelley
dbe9a5114e stage2: implement @setAlignStack and 128-bit cmpxchg
* test runner is improved to respect `error.SkipZigTest`
 * start code is improved to `@setAlignStack(16)` before calling main()
 * the newly passing behavior test has a workaround for the fact that
   stage2 cannot yet call `std.Target.x86.featureSetHas()` at comptime.
   This is blocking on comptime closures. The workaround is that there
   is a new decl `@import("builtin").stage2_x86_cx16` which is a `bool`.
 * Implement `@setAlignStack`. This language feature should be re-evaluated
   at some point - I'll file an issue for it.
 * LLVM backend: apply/remove the cold attribute and noinline attribute
   where appropriate.
 * LLVM backend: loads and stores are properly annotated with alignment
   and volatile attributes.
 * LLVM backend: allocas are properly annotated with alignment.
 * Type: fix integers reporting wrong alignment for 256-bit integers and
   beyond. Once you get to 16 byte aligned, there is no further
   alignment for larger integers.
2021-09-16 21:03:55 -07:00
Andrew Kelley
dc9d76b630 ci: go back to passing state for linux
This commit reverts 6d37ae95edc06f15e4e77f64e8e637dd5d269183 and
8f8294a809f9d975735377e7bfcc2c47ccfc4cb7. I don't know why they caused a
failure but that investigation can happen while the CI is green.
2021-09-16 16:40:06 -07:00
Andrew Kelley
d11f42c2b2 zig cc: support -S and -emit-llvm CLI parameters
closes #6425
2021-09-16 16:39:04 -07:00
Andrew Kelley
6d37ae95ed build.zig: support -Duse-zig-libcxx
This supports the case when it is known that LLVM, Clang, LLD were built
with Clang (or `zig c++`). This commit updates the Linux CI script to
pass this since we build using a zig tarball.
2021-09-16 13:09:32 -07:00
Andrew Kelley
8f8294a809 ci: linux: enable LLVM stage2 tests 2021-09-16 11:21:56 -07:00
Andrew Kelley
2c8b201d05 build: make -Dskip-stage2-tests not build stage2
for the test-toolchain step
2021-09-16 11:21:56 -07:00
Andrew Kelley
ab84ba39d0 move behavior test to "passing for stage2" section 2021-09-16 11:21:56 -07:00
Stephen Gutekanst
dc214e041e std/special: fix 'zig test --test-evented-io
Investigating hexops/zorex#4, I found that `--test-evented-io` is currently broken in
the latest Zig nightly. See #9779 for a small reproduction.

The issue is that allocation errors here are not correctly handled, as this function
returns `void` and all other error cases `@panic`, the allocation failure should also
use `@panic`.

Fixes #9779
Helps hexops/zorex#4

Signed-off-by: Stephen Gutekanst <stephen@hexops.com>
2021-09-16 20:56:05 +03:00
Žiga Željko
6f85a67987 stage2 Module: fix for 32 bit 2021-09-16 20:55:13 +03:00
Jakub Konka
983d6dcd9e macho: implement object relinking in stage2
* In watch mode, when changing the C source, we will trigger complete
  relinking of objects, dylibs and archives (atoms coming from the
  incremental updates stay put however). This means, we need to undo
  metadata populated when linking in objects, archives and dylibs.
* Remove unused splitting section into atoms bit. This optimisation
  will probably be best rewritten from scratch once self-hosted
  matures so parking the idea for now. Also, for easier management
  of atoms spawned from the Object file, keep the atoms subgraph as
  part of the Object file struct.
* Remove obsolete ref to static initializers in object struct.
* Implement handling of global symbol collision in updateDeclExports.
2021-09-16 12:38:47 +02:00
Stephen Gregoratto
506f24cac2 Set the Storage socket sizes to be system defined
Some systems (Solaris, OpenBSD, AIX) change their definitions of
sockaddr_storage to be larger than 128 bytes. This comment adds a new
constant in the `sockaddr` that defines the size for every system.

Fixes #9759
2021-09-16 13:32:55 +03:00
Ryan Liptak
db940a2c81 std.unicode: cleanup allocations on error in allocating functions
Fixes leaks when `utf16leToUtf8Alloc`/`utf16leToUtf8AllocZ`/`utf8ToUtf16LeWithNull` return an error and adds relevant test cases
2021-09-16 11:43:07 +02:00
Kirjastonhoitaja
e1bf350b4d net.Address: Fix writing 0-bytes when formatting Unix addresses
The entire 'path' array would get written to the formatting function,
when it should instead be treated as a regular zero-terminated string.

Note that this doesn't handle abstract paths on Linux, those paths
*start* with a \0 byte and are hence treated as empty strings instead.
But fixing that would require more adjustments than just formatting, in
particular to getOsSockLen().
2021-09-16 11:35:12 +02:00
Andrew Kelley
d5c1d24964 stage2: fix "cmpxchg with ptr" test case
* Sema: fix atomic operand checking to allow pointers.
 * LLVM backend: implement pointer-like optional constants.
 * LLVM backend: fix `is_non_null` and `optional_payload` instructions
   to support pointer-like optionals.
 * Type: introduce `isPtrAtRuntime` method.
 * Type: fix `isPtrLikeOptional` to get the correct answer for allowzero
   pointers and slices.
2021-09-15 19:55:57 -07:00
Andrew Kelley
b67d1810be stage2: implement @atomicRmw and @atomicLoad
* langref: add some more "see also" links for atomics
 * Add the following AIR instructions
   - atomic_load
   - atomic_store_unordered
   - atomic_store_monotonic
   - atomic_store_release
   - atomic_store_seq_cst
   - atomic_rmw
 * Implement those AIR instructions in LLVM and C backends.
 * AstGen: make the `ty` result locations for `@atomicRmw`, `@atomicLoad`,
   and `@atomicStore` be `coerced_ty` to avoid unnecessary ZIR
   instructions when Sema will be doing the coercions redundantly.
 * Sema for `@atomicLoad` and `@atomicRmw` is done, however Sema for
   `@atomicStore` is not yet implemented.
   - comptime eval for `@atomicRmw` is not yet implemented.
 * Sema: flesh out `coerceInMemoryAllowed` a little bit more. It can now
   handle pointers.
2021-09-15 19:00:35 -07:00
Jonathan Marler
f83a4b444c fix __chkstk on aarch64 2021-09-15 20:41:58 -04:00
Andrew Kelley
19691c0b17 stage2: implement @fence 2021-09-15 12:37:32 -07:00
Jonathan Marler
e5fd45003e azure pipeline fix removal of recently run exe
The following is an azure failure that occured Sep 13:

del : Cannot remove item D:\a\1\s\sfx.exe: The process cannot access the file 'D:\a\1\s\sfx.exe' because it is being used by another process.

Windows will keep a hold of recently run exeutables even after their process has exited.  To avoid this I've just removed the deletion of the exe file.  It's about 70 MB so it's probably OK.
2021-09-15 13:47:09 -04:00
Michal Ziulek
e06052f201
Added implementation for _fseeki64 and _ftelli64 from mingw-w64 9.0.0 (#9402). (#9766)
* Added fseeki64.c from mingw-w64 9.0.0. This file was missing in Zig distribution. This file contains implementation for _fseeki64 and _ftelli64 functions.
2021-09-15 13:38:00 -04:00
Andrew Kelley
2b90e2c284 ci: azure: update to newer msys2 release 2021-09-15 10:32:33 -07:00
Jakub Konka
25416d8121 macho: when adding extern fn, check if already resolved
This way, we will generate valid relocation info in the codegen.
2021-09-15 16:51:56 +02:00
Andrew Kelley
0395b35cee stage2: implement cmpxchg and improve comptime eval
* Implement Sema for `@cmpxchgWeak` and `@cmpxchgStrong`. Both runtime
   and comptime codepaths are implement.
 * Implement Codegen for LLVM backend and C backend.
 * Add LazySrcLoc.node_offset_builtin_call_argX 3...5
 * Sema: rework comptime control flow.
   - `error.ComptimeReturn` is used to signal that a comptime function
     call has returned a result (stored in the Inlining struct).
     `analyzeCall` notices this and handles the result.
   - The ZIR instructions `break_inline`, `block_inline`,
     `condbr_inline` are now redundant and can be deleted. `break`,
     `block`, and `condbr` function equivalently inside a comptime scope.
   - The ZIR instructions `loop` and `repeat` also are modified to
     directly perform comptime control flow inside a comptime scope,
     skipping an unnecessary mechanism for analysis of runtime code.
     This makes Zig perform closer to an interpreter when evaluating
     comptime code.
 * Sema: zirRetErrValue looks at Sema.ret_fn_ty rather than sema.func
   for adding to the inferred error set. This fixes a bug for
    inlined/comptime function calls.
 * Implement ZIR printing for cmpxchg.
 * stage1: make cmpxchg respect --single-threaded
   - Our LLVM C++ API wrapper failed to expose this boolean flag before.
 * Fix AIR printing for struct fields showing incorrect liveness data.
2021-09-14 21:58:22 -07:00
Travis Martin
5d14590ed1 Remove WIN16 version of WSAOVERLAPPED. Use LPWSAOVERLAPPED_COMPLETION_ROUTINE 2021-09-14 15:36:08 -04:00
Jacob G-W
370be12652 plan9 linker: fix for 32 bit 2021-09-14 19:04:09 +03:00
Jonathan Marler
010ca69864
add functions to decode an epoch timestamp (#9040)
* add functions to decode an epoch timestamp

The code added here is alternative to the libc gmtime function. This function takes a unix epoch timestamp and decodes it into things like the year/day/time/etc. I looked at various libc implementations to see how it was implemented and this appears to be correct. I reorganized it so that applications can choose which data they need rather than calcualting it all in a single function. The data structures layout the order of operations required to decode various things like the year/month or time of day.

* set Month.jan to 1 instead of 0 to avoid +1 in conversion to numeric

* add another test

* remove unnecessary comptimeMod
2021-09-14 19:02:23 +03:00
Jakub Konka
85f065a511
Merge pull request #9676 from ziglang/zld-incr
MachO: merges stage1 with self-hosted codepath
2021-09-14 14:20:11 +02:00
Philipp Lühmann
d1908c9f66
zig fmt: Keep callconv(.Inline) on function pointer types
Co-authored-by: Philipp Lühmann <mail@philipp.lu>
2021-09-14 11:36:26 +02:00
Jakub Konka
05763f43b3 macho: disable splitting sections into atoms in release
since we don't actually benefit from it just yet, and getting
it right for release and dead code stripping will require some more
thought put into it.
2021-09-14 10:28:58 +02:00
Andrew Kelley
264acfdf3c stage2: fix incorrect spelling of AtomicOrder 2021-09-13 22:01:40 -07:00
Andrew Kelley
97d69e3352 stage2: add array_to_slice AIR instruction 2021-09-13 21:37:11 -07:00
Andrew Kelley
a9a21c5988 stage2: Type/Value use an enum rather than usize
Makes debugging nicer when you want to look at Type/Value
2021-09-13 21:14:40 -07:00
Andrew Kelley
5529febab0 stage2: implement Value.copy for structs and unions
The stage2_os hack inside `@import("builtin")` is no longer needed.
2021-09-13 20:11:35 -07:00
Jakub Konka
a38b636045 Merge remote-tracking branch 'origin/master' into zld-incr 2021-09-13 23:40:38 +02:00
Jakub Konka
760241ce50 macho: use the cache system to know if need to relink objects
This applies to stage2 where we make use of the cache system to work
out if we need to relink objects when performing incremental updates.
When the process is restarted however, while in principle the idea is
to carry on where we left off by reparsing the prelinked binary from
file, the required machinery is not there yet, and therefore we always
fully relink upon restart.
2021-09-13 23:02:21 +02:00
Jakub Konka
46a10401f0 macho: fix logic for updating exports in incremental codepath 2021-09-13 22:11:20 +02:00