30867 Commits

Author SHA1 Message Date
Alex Rønne Petersen
6364995d3f
std.os.linux: Also use kernel_timespec for riscv32 when libc is linked.
Both glibc and musl use time64 as the base ABI for riscv32. This fixes the
`sleep` test in `std.time` hanging forever due to the libc functions reading
bogus values.
2024-08-31 03:31:58 +02:00
Alex Rønne Petersen
537cb49eb2
std.os.linux: Define the Stat struct for riscv32.
The kernel does define the struct, it just doesn't use it. Yet both glibc and
musl expose it directly as their public stat struct, and std.c takes it from
std.os.linux. So just define it after all.
2024-08-31 03:31:58 +02:00
Andrew Kelley
e084c46ed6 fix invisible merge conflict 2024-08-30 14:55:28 -07:00
Alex Rønne Petersen
cb0e6d8aa6 std.os.linux: Fix syscall6() when building for PIC/PIE.
LLVM would run out of registers due to the edi usage. Just extend what we're
already doing for ebp to edi as well.
2024-08-30 14:48:17 -07:00
Andrew Kelley
e4e91a1314
Merge pull request #21224 from alexrp/mips-gnu-fixes
Fix MIPS PIC level and work around an LLVM bug for `mips(el)-linux-gnueabi(hf)`
2024-08-30 14:47:43 -07:00
Andrew Kelley
5d08b7f054
Merge pull request #21178 from alexrp/glibc-thumb
`std.zig.target`: Remove `thumb*-linux-gnueabi*` target triples.
2024-08-30 14:35:30 -07:00
Andrew Kelley
a4cc43c42b
Merge pull request #21174 from alexrp/win-arm
Change `arm-windows-gnu` to `thumb-windows-gnu`, plus some initial port work
2024-08-30 14:34:53 -07:00
Alex Rønne Petersen
5723fcaac1 llvm: Pass EmitOptions to libzigcpp by pointer.
Passing it by value means that bringup on new architectures is harder for no
real benefit. Passing it by pointer allows to get the compiler running without
needing to figure out the C calling convention details first. This manifested in
practice on LoongArch, for example.
2024-08-30 11:02:12 -07:00
Jakub Konka
aaca4ff74d
Merge pull request #21254 from jacobly0/fix-dwarf
Dwarf: fix issues with emitted debug info
2024-08-30 19:07:36 +02:00
Jacob Young
a1a9d7440c Elf: fix reference from eh_frame_hdr to eh_frame 2024-08-30 09:24:32 -04:00
Jacob Young
7305184203 dwarf: share and use std.dwarf.EH_PE constants 2024-08-30 09:24:32 -04:00
Jacob Young
f0c0f697a6 Dwarf: fix zir inst index comparison not checking the file 2024-08-30 08:21:24 -04:00
Matthew Lugg
d997ddaa10
Merge pull request #21231 from mlugg/field-decl-name-conflict
AstGen: disallow fields and decls from sharing names
2024-08-30 03:06:52 +01:00
mlugg
c3fb30803f
behavior: avoid field/decl name conflicts 2024-08-29 23:43:52 +01:00
mlugg
605f2a0978
cases: update for new error wording, add coverage for field/decl name conflict 2024-08-29 23:43:52 +01:00
mlugg
c62487da76
compiler: avoid field/decl name conflicts
Most of the required renames here are net wins for readaibility, I'd
say. The ones in `arch` are a little more verbose, but I think better. I
didn't bother renaming the non-conflicting functions in
`arch/arm/bits.zig` and `arch/aarch64/bits.zig`, since these backends
are pretty bit-rotted anyway AIUI.
2024-08-29 23:43:52 +01:00
mlugg
ba8d3f69ca
std.pdb: obey naming conventions
These names aren't matching any formal specification; they're mostly
just ripped from LLVM code. Therefore, we should definitely follow Zig
naming conventions here.
2024-08-29 23:43:52 +01:00
mlugg
4330c40596
std: avoid field/decl name conflicts
Most of these changes seem like improvements. The PDB thing had a TODO
saying it used to crash; I anticipate it works now, we'll see what CI
does.

The `std.os.uefi` field renames are a notable breaking change.
2024-08-29 20:39:11 +01:00
mlugg
401910a2ca
AstGen: disallow fields and decls from sharing names
This is a mini-proposal which is accepted as part of #9938.

This compiler and standard library need some changes to obey this rule.
2024-08-29 20:39:11 +01:00
Andrew Kelley
e9a00ba7f4
Merge pull request #21236 from ziglang/fuzz
exclude unreachable code paths from having coverage instrumentation
2024-08-28 23:20:21 -07:00
Andrew Kelley
13b5cee4cc fuzzing: fix entry address logic
* the pcs list is unsorted
* use the function address

Fixes entry points in ReleaseSafe mode.
2024-08-28 18:07:13 -07:00
Andrew Kelley
c81219c573 LLVM: use @llvm.used instead of @llvm.compiler.used
because it marks the linker section, preventing garbage collection.

Also, name the members because that is required by this intrinsic.

Also, enable the StackDepth option in the sancov pass as a workaround
for https://github.com/llvm/llvm-project/pull/106464, otherwise, LLVM
enables TracePCGuard even though we explicitly disable it.
2024-08-28 18:07:13 -07:00
Andrew Kelley
9e11c4f60e LLVM: put sancov globals into llvm.compiler.used
This matches what LLVM's sancov pass does and is required so that
optimization passes do not delete the instrumentation.

However, this is currently triggering an error: "members of
llvm.compiler.used must be named" so the next commit will add names to
those globals.
2024-08-28 18:07:13 -07:00
Andrew Kelley
1bec824cad LLVM: disable inline 8-bit counters when using trace pc guard 2024-08-28 18:07:13 -07:00
Andrew Kelley
88bba4c154 LLVM: enable sancov pass partially
It's useful to have TraceCmp based on the results of LLVM optimizations,
while the code coverage bits were emitted by Zig manually, allowing more
careful correlation to points of interest in the source code.

This re-enables the sancov pass in `-ffuzz` mode, but only TraceCmp.

Notably, IndirectCalls is off, which needs to be implemented manually in
the LLVM backend, and StackDepth remains off, because it is not used by
libfuzzer or AFL either.

If stack depth is re-introduced, it can be done with better performance
characteristics by being function call graph aware, and only lowered in
call graph cycles, where its heuristic properties come in useful.

Fixes the fuzzing regression.
2024-08-28 18:07:13 -07:00
Andrew Kelley
b8d99a3323 implement code coverage instrumentation manually
instead of relying on the LLVM sancov pass. The LLVM pass is still
executed if trace_pc_guard is requested, disabled otherwise. The LLVM
backend emits the instrumentation directly.

It uses `__sancov_pcs1` symbol name instead of `__sancov_pcs` because
each element is 1 usize instead of 2.

AIR: add CoveragePoint to branch hints which indicates whether those
branches are interesting for code coverage purposes.

Update libfuzzer to use the new instrumentation. It's simplified since
we no longer need the constructor and the pcs are now in a continguous
list.

This is a regression in the fuzzing functionality because the
instrumentation for comparisons is no longer emitted, resulting in worse
fuzzer inputs generated. A future commit will add that instrumentation
back.
2024-08-28 18:07:13 -07:00
Andrew Kelley
43dc8db068 print_air: print cond_br branch hints 2024-08-28 18:07:13 -07:00
Andrew Kelley
a3d622bdd6 llvm.Builder: revert adding !nosanitize API
It's not actually useful after all.
2024-08-28 18:07:13 -07:00
Andrew Kelley
df52073681 llvm.Builder: add !nosanitize API
see #20992

Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
2024-08-28 18:07:13 -07:00
Jacob Young
6a21875ddb
Merge pull request #21230 from jacobly0/stack-trace
Dwarf: fix self-hosted stack traces
2024-08-28 17:39:35 -04:00
Andrew Kelley
31fef6f110
Merge pull request #21225 from mlugg/std-builtin-type
std: update `std.builtin.Type` fields to follow naming conventions
2024-08-28 10:49:31 -07:00
Jacob Young
12275cf4b9 Dwarf: fix parsing self-hosted debug info for stack traces 2024-08-28 06:45:17 -04:00
Jacob Young
4cc16fd6f7 Dwarf: fix and test inline function bugs 2024-08-28 04:25:08 -04:00
sobolevn
9a12905a2d Only set contents: read permission in GitHub Action 2024-08-28 00:45:22 -07:00
mlugg
aaa7e73983
link.Dwarf: skip tests in updateComptimeNav
These won't live in the parent namespace as decls which causes problems
later in this function, and tests are guaranteed not to be referenced at
comptime anyway, so there's actually no need to run this logic.
2024-08-28 08:39:59 +01:00
mlugg
0fe3fd01dd
std: update std.builtin.Type fields to follow naming conventions
The compiler actually doesn't need any functional changes for this: Sema
does reification based on the tag indices of `std.builtin.Type` already!
So, no zig1.wasm update is necessary.

This change is necessary to disallow name clashes between fields and
decls on a type, which is a prerequisite of #9938.
2024-08-28 08:39:59 +01:00
Alex Rønne Petersen
a2e691d589
Revert "add a workaround for miscompilation regarding alignment"
This reverts commit 149aa9afb7b57340c5dd7be8032b843fe439b668.
2024-08-28 06:24:05 +02:00
Alex Rønne Petersen
e585103306
llvm: Disable FastISel on MIPS as a workaround for #21215.
Until llvm/llvm-project#106231 trickles down.
2024-08-28 06:19:01 +02:00
Alex Rønne Petersen
7d9edff11d
llvm: Set PIC level 1 for MIPS.
For hysterical raisins, MIPS always uses 1, regardless of `-fpic` vs `-fPIC`.
2024-08-28 06:18:06 +02:00
Alex Rønne Petersen
832f74876e
std.builtin: Define VaList for arm, armeb, and thumbeb too. 2024-08-28 03:13:01 +02:00
Alex Rønne Petersen
34c6482403
std.debug: Fix a bitness portability issue in walkStackWindows(). 2024-08-28 03:13:01 +02:00
Alex Rønne Petersen
d702a21bbc
std.os.windows: Define CONTEXT, RUNTIME_FUNCTION, and KNONVOLATILE_CONTEXT_POINTERS for thumb. 2024-08-28 03:13:01 +02:00
Alex Rønne Petersen
2e2441a89d
std.os.windows: Implement teb() for thumb.
6e15604c48/include/winnt.h (L2503)

Closes #4645.
2024-08-28 03:13:01 +02:00
Alex Rønne Petersen
f02b93002c
compiler_rt: Export arm div helpers with correct names for thumb-linux-gnu. 2024-08-28 03:13:00 +02:00
Alex Rønne Petersen
3106998412
compiler_rt: Implement __chkstk() for thumb-windows-gnu.
ad435bcc14/compiler-rt/lib/builtins/arm/chkstk.S
2024-08-28 03:10:43 +02:00
Alex Rønne Petersen
338730d2fa
link.Coff: Set default image base correctly for thumb. 2024-08-28 03:08:10 +02:00
Alex Rønne Petersen
6d15dc1ab8
mingw: Fix various target checks to check for thumb.
Also remove mentions of arm, armeb, thumbeb, and aarch64_be; none of these are
relevant for Windows.
2024-08-28 03:08:10 +02:00
Alex Rønne Petersen
a3990a950d
std.zig.WindowsSdk: Fix various target checks to check for thumb.
Also remove mentions of arm and armeb; these are not relevant for Windows.
2024-08-28 03:08:10 +02:00
Alex Rønne Petersen
1c6642552e
std.zig.target: Change arm-windows-gnu triple to thumb-linux-gnu.
Windows on 32-bit Arm only operates in Thumb-2 mode: https://devblogs.microsoft.com/oldnewthing/20210601-00/?p=105267

Trying to compile for arm-windows-gnu fails in all sorts of ways as neither
LLVM nor MinGW-w64 expect it.
2024-08-28 03:08:10 +02:00
Alex Rønne Petersen
694004ed40 glibc: Remove mentions of thumb.
We no longer expose `thumb*-linux-gnueabi*` target triples in std.zig.target.
2024-08-28 02:57:31 +02:00