Commit Graph

10472 Commits

Author SHA1 Message Date
Andrew Kelley
eb1a199dff
Merge pull request #20885 from ziglang/simplify-tokenizer
std.zig.tokenizer: simplification and spec conformance
2024-07-31 19:52:34 -07:00
Andrew Kelley
059856acfc
Merge pull request #20878 from tiehuis/std-math-complex-fixes
std.math.complex fixes
2024-07-31 19:19:27 -07:00
Andrew Kelley
c2b8afcac9 tokenizer: tabs and carriage returns spec conformance 2024-07-31 16:57:42 -07:00
Andrew Kelley
a7029496d1 remove hard tabs from source code
these are illegal according to the spec
2024-07-31 16:57:42 -07:00
Andrew Kelley
377e8579f9 std.zig.tokenizer: simplify
I pointed a fuzzer at the tokenizer and it crashed immediately. Upon
inspection, I was dissatisfied with the implementation. This commit
removes several mechanisms:
* Removes the "invalid byte" compile error note.
* Dramatically simplifies tokenizer recovery by making recovery always
  occur at newlines, and never otherwise.
* Removes UTF-8 validation.
* Moves some character validation logic to `std.zig.parseCharLiteral`.

Removing UTF-8 validation is a regression of #663, however, the existing
implementation was already buggy. When adding this functionality back,
it must be fuzz-tested while checking the property that it matches an
independent Unicode validation implementation on the same file. While
we're at it, fuzzing should check the other properties of that proposal,
such as no ASCII control characters existing inside the source code.

Other changes included in this commit:

* Deprecate `std.unicode.utf8Decode` and its WTF-8 counterpart. This
  function has an awkward API that is too easy to misuse.
* Make `utf8Decode2` and friends use arrays as parameters, eliminating a
  runtime assertion in favor of using the type system.

After this commit, the crash found by fuzzing, which was
"\x07\xd5\x80\xc3=o\xda|a\xfc{\x9a\xec\x91\xdf\x0f\\\x1a^\xbe;\x8c\xbf\xee\xea"
no longer causes a crash. However, I did not feel the need to add this
test case because the simplified logic eradicates most crashes of this
nature.
2024-07-31 16:57:42 -07:00
David Rubin
2b8a71489a
start: remove riscv condition 2024-07-31 13:40:00 -07:00
Evan Haas
1cc74f3cae
aro_translate_c: fix formatting 2024-07-31 10:33:44 -07:00
Evan Haas
aa5a1105e8
aro_translate_c: do not translate atomic types 2024-07-31 10:04:21 -07:00
Evan Haas
b3f5769930
aro_translate_c: handle opaque struct defs in prototypes 2024-07-31 09:35:07 -07:00
Evan Haas
6a103d87f6
aro_translate_c: basic typedef support 2024-07-31 09:35:07 -07:00
Evan Haas
055077f9dd
aro_translate_c: improve record translation
Move field record decl translation into `transType` instead of `transDecl`
2024-07-31 09:35:07 -07:00
Evan Haas
c57fcd1db5
aro_translate_c: demote functions with bodies to extern
Translating statements is currently not supported; demoting to extern is
better than crashing.
2024-07-31 09:35:07 -07:00
Evan Haas
4300a9c417
aro_translate_c: Make function decls public 2024-07-31 09:35:07 -07:00
Evan Haas
5cc9e18277
aro_translate_c: Translate enum types 2024-07-31 09:35:07 -07:00
Evan Haas
2f2f35105e
aro_translate_c: translate pointer types 2024-07-31 09:35:07 -07:00
Evan Haas
e32cde2568
aro_translate_c: translate incomplete arrays 2024-07-31 09:35:07 -07:00
Evan Haas
da3822f4c2
aro_translate_c: Translate array types 2024-07-31 09:35:07 -07:00
Evan Haas
236567de8d
aro_translate_c: Emit compile errors instead of panicking for var decls 2024-07-31 09:35:07 -07:00
Alex Rønne Petersen
653eb75355
start: Disable the gp initialization code for the self-hosted riscv64 backend. 2024-07-31 02:06:57 +02:00
Alex Rønne Petersen
982510f8d5
start: Initialize gp to __global_pointer$ on riscv. 2024-07-31 02:05:17 +02:00
YANG Xudong
a69d403cb2 std: fix long double size for loongarch. 2024-07-30 15:21:14 -07:00
YANG Xudong
2fb813c61f
std: set standard dynamic linker path for loongarch64 on linux. (#20726) 2024-07-30 15:20:56 -07:00
Alex Rønne Petersen
2e719f3239
std.os.linux.start_pie: Use a 64-bit displacement for s390x.
Not likely to be necessary ever, but might as well be 100% correct.
2024-07-30 18:02:40 +02:00
Alex Rønne Petersen
52519f79e0
std.os.linux.start_pie: Apply MIPS local GOT relocations. 2024-07-30 18:02:36 +02:00
Alex Rønne Petersen
78e581b86f
start: Copy the mips64 comment about gp to the mips32 code.
Also, don't incorrectly claim that it's only needed for dynamic linking/PIC.
2024-07-30 17:58:22 +02:00
Alex Rønne Petersen
108c682df0
start: Add POSIX csky support. 2024-07-30 17:47:46 +02:00
Marc Tiehuis
843885512d std.math.complex: fix cosh/tanh 2024-07-30 20:31:22 +12:00
Alex Rønne Petersen
c377316420
std.Target: Add tce/tcele to the comment listing omitted architectures. 2024-07-30 06:30:26 +02:00
Alex Rønne Petersen
b49b7501cf
std.Target: Remove cloudabi OS tag.
It's discontinued in favor of WASI.

https://github.com/NuxiNL/cloudlibc
2024-07-30 06:30:26 +02:00
Alex Rønne Petersen
ef06e4b6e4
std.Target: Remove ananas OS tag.
This is a fairly small hobby OS that has not seen development in 2 years. Our
current policy is that hobby OSs should use the `other` tag.

https://github.com/zhmu/ananas
2024-07-30 06:30:25 +02:00
Alex Rønne Petersen
c8ca05e93a
std.Target: Remove sparcel architecture tag.
What is `sparcel`, you might ask? Good question!

If you take a peek in the SPARC v8 manual, §2.2, it is quite explicit that SPARC
v8 is a big-endian architecture. No little-endian or mixed-endian support to be
found here.

On the other hand, the SPARC v9 manual, in §3.2.1.2, states that it has support
for mixed-endian operation, with big-endian mode being the default.

Ok, so `sparcel` must just be referring to SPARC v9 running in little-endian
mode, surely?

Nope:

* 40b4fd7a3e/llvm/lib/Target/Sparc/SparcTargetMachine.cpp (L226)
* 40b4fd7a3e/llvm/lib/Target/Sparc/SparcTargetMachine.cpp (L104)

So, `sparcel` in LLVM is referring to some sort of fantastical little-endian
SPARC v8 architecture. I've scoured the internet and I can find absolutely no
evidence that such a thing exists or has ever existed. In fact, I can find no
evidence that a little-endian implementation of SPARC v9 ever existed, either.
Or any SPARC version, actually!

The support was added here: https://reviews.llvm.org/D8741

Notably, there is no mention whatsoever of what CPU this might be referring to,
and no justification given for the "but some are little" comment added in the
patch.

My best guess is that this might have been some private exercise in creating a
little-endian version of SPARC that never saw the light of day. Given that SPARC
v8 explicitly doesn't support little-endian operation (let alone little-endian
instruction encoding!), and no CPU is known to be implemented as such, I think
it's very reasonable for us to just remove this support.
2024-07-30 06:30:25 +02:00
Alex Rønne Petersen
1e9278d718
std.Target: Remove spir/spir64 architecture tags.
These were for very old OpenCL have been long abandoned in favor of SPIR-V.

* https://github.com/KhronosGroup/SPIR
* https://github.com/KhronosGroup/SPIR-Tools
2024-07-30 06:30:25 +02:00
Marc Tiehuis
0fda2f31aa std.math.complex: tighten existing test bounds 2024-07-30 16:30:20 +12:00
Marc Tiehuis
2bd7af63d7 std.math.complex: fix acosh/atan/cosh/sqrt
Some of these are upstream changes since the original port, others are
translation errors.
2024-07-30 15:38:00 +12:00
Andrew Kelley
f219286573
Merge pull request #20852 from ziglang/init-array-start-code
start code: implement __init_array_start, __init_array_end
2024-07-29 18:40:27 -07:00
Alex Rønne Petersen
36332a4fdc
std.os.linux.tls: Add csky support. 2024-07-30 02:33:16 +02:00
Alex Rønne Petersen
9abe3aeeea
std.os.linux.tls: Add arc support. 2024-07-30 02:33:16 +02:00
Alex Rønne Petersen
e6fe7a329a
std.os.linux.tls: Add hexagon support. 2024-07-30 02:33:16 +02:00
Alex Rønne Petersen
d2b21d5823
std.os.linux.tls: Add s390x support. 2024-07-30 02:33:16 +02:00
Alex Rønne Petersen
9db992bd9b
std.os.linux.tls: Add loongarch support. 2024-07-30 02:33:15 +02:00
Alex Rønne Petersen
44d4656dfc
std.os.linux.tls: Add m68k support. 2024-07-30 02:32:55 +02:00
Alex Rønne Petersen
37275c0f69
std.os.linux.tls: Fix layout computation for the modified Variant I. 2024-07-30 02:32:32 +02:00
Alex Rønne Petersen
b52e054261
std.os.linux.tls: Refactor and improve documentation.
* Elaborate on the sub-variants of Variant I.
* Clarify the use of the TCB term.
* Rename a bunch of stuff to be more accurate/descriptive.
* Follow Zig's style around namespacing more.
* Use a structure for the ABI TCB.

No functional change intended.
2024-07-30 02:32:32 +02:00
Alex Rønne Petersen
876383cb2a
std.os.linux: Hook up newly added syscall enums. 2024-07-30 01:32:48 +02:00
Alex Rønne Petersen
7e0f9c45f2
std.os.linux: Adjust for rename of mips syscall enums. 2024-07-30 01:32:48 +02:00
Alex Rønne Petersen
e77b3ff74f
std.os.linux.syscalls: Regenerate based on Linux v6.7. 2024-07-30 01:32:48 +02:00
Alex Rønne Petersen
ce5063e188
std.os.linux.AUDIT: Rewrite ARCH in terms of std.elf.EM.
Closes #20743.
2024-07-30 01:30:35 +02:00
Alex Rønne Petersen
b2d568e813
std.elf.EM: Add missing MICROBLAZE value. 2024-07-30 01:29:38 +02:00
Alex Rønne Petersen
2386bfe854
std.os.linux.start_pie: Rewrite relocate() to avoid jump tables and libcalls.
The code would cause LLVM to emit a jump table for the switch in the loop over
the dynamic tags. That jump table was far enough away that the compiler decided
to go through the GOT, which would of course break at this early stage as we
haven't applied MIPS's local GOT relocations yet, nor can we until we've walked
through the _DYNAMIC array.

The first attempt at rewriting this used code like this:

    var sorted_dynv = [_]elf.Addr{0} ** elf.DT_NUM;

But this is also problematic as it results in a memcpy() call. Instead, we
explicitly initialize it to undefined and use a loop of volatile stores to
clear it.
2024-07-30 01:26:10 +02:00
Alex Rønne Petersen
68cebde186
std.os.linux.start_pie: Inline the getDynamicSymbol() function.
On MIPS, this call will require a relocation, which we can't do until after PIE
relocations have been applied.
2024-07-30 01:26:10 +02:00
Alex Rønne Petersen
5633767b20
std.os.linux.start_pie: Add powerpc and powerpc64 support.
Closes #20305.
2024-07-30 01:26:09 +02:00
Alex Rønne Petersen
adfbd8a98b
std.os.linux.start_pie: Add mips and mips64 support. 2024-07-30 01:24:55 +02:00
Andrew Kelley
38e0f049c5
Merge pull request #20389 from alexrp/riscv32
Some `riscv32-linux` porting work
2024-07-29 16:13:35 -07:00
Ryan Liptak
efde3ed04a Fix compile error due to GetModuleFileNameW binding change
In https://github.com/ziglang/zig/pull/19641, this binding changed from `[*]u16` to `LPWSTR` which made it a sentinel-terminated pointer. This introduced a compiler error in the `std.os.windows.GetModuleFileNameW` wrapper since it takes a `[*]u16` pointer. This commit changes the binding back to what it was before instead of introducing a breaking change to `std.os.windows.GetModuleFileNameW`

Related: https://github.com/ziglang/zig/issues/20858
2024-07-29 16:06:36 -07:00
Andrew Kelley
d60c100eb6
Merge pull request #20865 from ehaas/aro-translate-c-static-assert
Aro translate c: Render error diagnostics properly and ignore _Static_assert decls during translation
2024-07-29 15:28:31 -07:00
Alex Rønne Petersen
f7cebf21c9 c: Handle armeb and thumbeb in clone(). 2024-07-29 13:24:29 -07:00
Andrew Kelley
7342017404
Merge pull request #20822 from alexrp/start-mips-fixes
`start`: A handful of MIPS fixes
2024-07-29 12:02:59 -07:00
Andrew Kelley
3f2d1b17fc disable the new code for self-hosted riscv backend 2024-07-29 11:38:11 -07:00
Evan Haas
699e103717
aro_translate_c: Add a more helpful error message for error.StreamTooLong 2024-07-29 10:25:55 -07:00
Evan Haas
5d8e56c2eb
aro_translate_c: do not translate _Static_assert declarations
This does not completely ignore static asserts - they are validated by aro
during parsing; any failures will render an error and non-zero exit code.

Emit a warning comment that _Static_asserts are not translated - this
matches the behavior of the existing clang-based translate-c.

Aro currently does not store source locations for _Static_assert
declarations so I've hard-coded token index 0 for now.
2024-07-29 10:25:55 -07:00
Evan Haas
d7b9bbecaf
aro_translate_c: Render errors properly
The error count is not set until the diagnostics are actually rendered
2024-07-29 10:25:55 -07:00
Alex Rønne Petersen
d633b35f35
start: Always inline the call to std.os.linux.pie.relocate().
At this stage, we're not ready to make calls yet on some architectures (e.g. MIPS).
2024-07-29 10:08:34 +02:00
Alex Rønne Petersen
d6c637c36b
start: Set std.os.linux.elf_aux_maybe after PIE relocations.
Accesses to this global variable can require relocations on some platforms (e.g.
MIPS). If we do it before PIE relocations have been applied, we'll crash.
2024-07-29 10:05:28 +02:00
Alex Rønne Petersen
e33af8e902
start: Perform the posixCallMainAndExit() call with jalr on mips.
It's actually important for the ABI that r25 (t9) contains the address of the
called function, so that this standard prologue sequence works:

    lui $2, %hi(_gp_disp)
    addiu $2, $2, %lo(_gp_disp)
    addu $gp, $2, $t9

(This is a bit similar to the ToC situation on powerpc that was fixed in
7bc78967b400322a0fc5651f37a1b0428c37fb9d.)
2024-07-29 10:05:25 +02:00
Alex Rønne Petersen
77fc3b88fb
start: Set up the gp register on mips and mips64. 2024-07-29 10:04:54 +02:00
Alex Rønne Petersen
13945548fc
std.fs: Rework to always use statx() instead of fstat()/fstatat() on Linux.
statx() is strictly superior to stat() and friends. We can do this because the
standard library declares Linux 4.19 to be the minimum version supported in
std.Target. This is also necessary on riscv32 where there is only statx().

While here, I improved std.fs.File.metadata() to gather as much information as
possible when calling statx() since that is the expectation from this particular
API.
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
4e5068c35c
std: Stop supporting Linux/glibc versions older than declared in std.Target. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
6eb9cb6f28
std.os.linux.tls: Handle riscv32 in setThreadPointer(). 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
aeb3abc7e6
std.os.linux.start_pie: Handle riscv32 in getDynamicSymbol(). 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
43410cdfe9
std.os.linux: Remove the sparc64 workaround in fadvise().
This does not seem to be needed anymore, and it's unclear if it was ever truly
needed or if it was just there to deal with a QEMU/strace bug.

See: https://github.com/ziglang/zig/pull/8301#issuecomment-2184995749
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
890433e292
std.os.linux: Define timespec as kernel_timespec (64-bit) for riscv32.
This is kind of a hack because the timespec in UAPI headers is actually still
32-bit while __kernel_timespec is 64-bit. But, importantly, all the syscalls
take __kernel_timespec from the get-go (because riscv32 support is so recent).

Defining our timespec this way will allow all the syscall wrappers in
std.os.linux to do the right thing for riscv32. For other 32-bit architectures,
we have to use the 64-bit time syscalls explicitly to solve the Y2038 problem.
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
cafce8c767
std.os.linux.test: Partially skip statx() test on riscv32.
No fstatat(), so there's no point doing the rest of it.
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
7532a8a584
std.os.linux: Add riscv32 support. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
2d1ee678eb
std.os.linux: Some adjustments after syscall generation strategy changes. 2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
4e7c3cca91
std.os.linux.syscalls: Regenerate based on Linux v6.7.
loongarch64 syscalls not updated because it seems like that kernel port hasn't
been working for a year or so:

    In file included from arch/loongarch/include/uapi/asm/unistd.h:5:
    include/uapi/asm-generic/unistd.h:2:10: fatal error: 'asm/bitsperlong.h' file not found

That file is just missing from the tree. 🤷
2024-07-29 09:50:41 +02:00
Alex Rønne Petersen
a59ab5ffa5
std.Thread: Add some syscall comments to LinuxThreadImpl.ThreadCompletion.freeAndExit(). 2024-07-29 09:50:40 +02:00
Alex Rønne Petersen
b83d10214b
std.Thread: Implement LinuxThreadImpl.ThreadCompletion.freeAndExit() for riscv32. 2024-07-29 09:50:09 +02:00
Alex Rønne Petersen
b958225e68
c: Implement clone() for riscv32-linux. 2024-07-29 09:50:09 +02:00
Alex Rønne Petersen
8b176ab303
start: Implement _start() for riscv32. 2024-07-29 09:50:09 +02:00
Alex Rønne Petersen
e74c368962
std.zig.target: Set the minimum glibc for riscv32 to 2.33.
Relevant release notes:

* https://sourceware.org/legacy-ml/libc-announce/2018/msg00000.html
* https://sourceware.org/pipermail/libc-announce/2021/000030.html

Note that the supported ISAs/ABIs are explicitly listed in each, and only 2.33
actually supports the 32-bit ones.
2024-07-29 09:50:09 +02:00
Alex Rønne Petersen
c31409baa9
std.Target.Abi: Handle a few more GNU ABIs in isGnu().
Importantly, this ensures that the compiler understands that these ABIs need glibc.
2024-07-29 09:50:09 +02:00
Alex Rønne Petersen
9d23e711ef
std.atomic: Implement specialized spinLoopHint() for more architectures. 2024-07-29 09:41:47 +02:00
Alex Rønne Petersen
5b68595255
std.atomic: Define specialized cache_line values for more architectures. 2024-07-29 09:41:24 +02:00
Andrew Kelley
728024f9f3 start code: implement __init_array_start, __init_array_end 2024-07-28 23:54:49 -07:00
Andrew Kelley
390c7d84b2
Merge pull request #19833 from tealsnow/posix-INVAL
std.posix: handle INVAL in openZ, openatZ and openatWasi
2024-07-28 22:29:31 -07:00
matt ettler
ed7f11ffa7 chore: correct non-standard comments.
Comments throughout the codebase start with a space.
This commit corrects comments that do not adhere to this
norm.
2024-07-28 21:34:14 -07:00
Sammy James
00d6ea4764 Add libcpp option to test options 2024-07-28 20:40:53 -07:00
Andrew Kelley
3a0da431db
Merge pull request #20667 from jayrod246/windows-watch
Build Runner: Initial Implementation for File System Watching on Windows
2024-07-28 20:35:18 -07:00
poypoyan
939fcce5ef
std.mem.readVarInt: fix for 8-bits and below (Reloaded) (#20513) 2024-07-28 20:26:36 -07:00
Andrew Kelley
08e83fee57
Merge pull request #20297 from sno2/wtf8-conversion-buffer-overflows
std: fix buffer overflows from improper WTF encoding
2024-07-28 20:24:31 -07:00
Carter Snook
219acaa1d6 std.fs.Dir: Refactor atomicSymLink from std.fs
Deprecates std.fs.atomicSymLink and removes the allocator requirement
from the new std.fs.Dir.atomicSymLink. Replaces the two usages of this
within std.

I did not include the TODOs from the original code that were based
off of `switch (err) { ..., else => return err }` not having correct
inference that cases handled in `...` are impossible in the error
union return type because these are not specified in many places but
I can add them back if wanted.

Thank you @squeek502 for help with fixing buffer overflows!
2024-07-28 20:08:52 -07:00
Cheng Sheng
4a77c7f258
Condense and extend std.Treap's traversal functionalities. (#20002)
The core functionalities are now in two general functions
`extremeInSubtreeOnDirection()` and `nextOnDirection()` so all the other
traversing functions (`getMin()`, `getMax()`, and `InorderIterator`) are
all just trivial calls to these core functions.

The added two functions `Node.next()` and `Node.prev()` are also just
trivial calls to these.

* std.Treap traversal direction: use u1 instead of usize.

* Treap: fix getMin() and getMax(), and add tests for them.
2024-07-28 19:47:55 -07:00
Alex Rønne Petersen
d1d95294fd std.Target.Cpu.Arch: Remove the aarch64_32 tag.
This is a misfeature that we inherited from LLVM:

* https://reviews.llvm.org/D61259
* https://reviews.llvm.org/D61939

(`aarch64_32` and `arm64_32` are equivalent.)

I truly have no idea why this triple passed review in LLVM. It is, to date, the
*only* tag in the architecture component that is not, in fact, an architecture.
In reality, it is just an ILP32 ABI for AArch64 (*not* AArch32).

The triples that use `aarch64_32` look like `aarch64_32-apple-watchos`. Yes,
that triple is exactly what you think; it has no ABI component. They really,
seriously did this.

Since only Apple could come up with silliness like this, it should come as no
surprise that no one else uses `aarch64_32`. Later on, a GNU ILP32 ABI for
AArch64 was developed, and support was added to LLVM:

* https://reviews.llvm.org/D94143
* https://reviews.llvm.org/D104931

Here, sanity seems to have prevailed, and a triple using this ABI looks like
`aarch64-linux-gnu_ilp32` as you would expect.

As can be seen from the diffs in this commit, there was plenty of confusion
throughout the Zig codebase about what exactly `aarch64_32` was. So let's just
remove it. In its place, we'll use `aarch64-watchos-ilp32`,
`aarch64-linux-gnuilp32`, and so on. We'll then translate these appropriately
when talking to LLVM. Hence, this commit adds the `ilp32` ABI tag (we already
have `gnuilp32`).
2024-07-28 19:44:52 -07:00
Ketan Reynolds
0403c4b05c std.posix: handle INVAL in openatWasi
In accordance with https://github.com/ziglang/zig/pull/19833#issuecomment-2089262607
2024-07-28 19:01:55 -07:00
Ketan Reynolds
b4e7b6fdba std.posix: handle INVAL in openZ and openatZ
Contributes to #15607

Although the case is not handled in `openatWasi` (as I could not get a
working wasi environment to test the change) I have added a FIXME
addressing it and linking to the issue.
2024-07-28 19:01:55 -07:00
Matthew Ettler
d30d37e356
feat(std.os.uefi.protocol): add Serial IO 2024-07-28 12:37:53 +00:00
Jakub Konka
91c17979f1
Merge pull request #20807 from Rexicon226/riscv
riscv: more backend progress
2024-07-28 11:34:23 +02:00
Linus Groh
a84951465b translate-c: Use mangled name for local extern in condition/loop 2024-07-28 02:58:49 +03:00
Jarrod Meyer
2de0e2eca3 Watch.zig: add initial windows implementation 2024-07-27 11:32:43 -04:00
Jarrod Meyer
2b8f444dde windows: reintroduce ReadDirectoryChangesW
- additionally, introduces FileNotifyChangeFilter to improve use/readability
2024-07-27 11:32:43 -04:00