32127 Commits

Author SHA1 Message Date
Andrew Kelley
da25ed95fc macho linker conforms to explicit error sets, again 2025-01-15 15:11:35 -08:00
Andrew Kelley
6235cc3da4 remove "FIXME" from codebase
See #363. Please file issues rather than making TODO comments.
2025-01-15 15:11:35 -08:00
Andrew Kelley
16180f525a macho linker: conform to explicit error sets
Makes linker functions have small error sets, required to report
diagnostics properly rather than having a massive error set that has a
lot of codes.

Other linker implementations are not ported yet.

Also the branch is not passing semantic analysis yet.
2025-01-15 15:11:35 -08:00
Andrew Kelley
795e7c64d5 wasm linker: aggressive DODification
The goals of this branch are to:
* compile faster when using the wasm linker and backend
* enable saving compiler state by directly copying in-memory linker
  state to disk.
* more efficient compiler memory utilization
* introduce integer type safety to wasm linker code
* generate better WebAssembly code
* fully participate in incremental compilation
* do as much work as possible outside of flush(), while continuing to do
  linker garbage collection.
* avoid unnecessary heap allocations
* avoid unnecessary indirect function calls

In order to accomplish this goals, this removes the ZigObject
abstraction, as well as Symbol and Atom. These abstractions resulted
in overly generic code, doing unnecessary work, and needless
complications that simply go away by creating a better in-memory data
model and emitting more things lazily.

For example, this makes wasm codegen emit MIR which is then lowered to
wasm code during linking, with optimal function indexes etc, or
relocations are emitted if outputting an object. Previously, this would
always emit relocations, which are fully unnecessary when emitting an
executable, and required all function calls to use the maximum size LEB
encoding.

This branch introduces the concept of the "prelink" phase which occurs
after all object files have been parsed, but before any Zcu updates are
sent to the linker. This allows the linker to fully parse all objects
into a compact memory model, which is guaranteed to be complete when Zcu
code is generated.

This commit is not a complete implementation of all these goals; it is
not even passing semantic analysis.
2025-01-15 15:11:35 -08:00
mlugg
77273103a8 print_value: fix crash on undefined slice ptr
Resolves: #22418
2025-01-15 21:13:51 +00:00
mlugg
4b910e525d Sema: more validation for builtin decl types
Also improve the source locations when this validation fails.

Resolves: #22465
2025-01-14 22:44:18 +00:00
mlugg
5322459a0b Sema: fix UB in error reporting
And add test coverage for the compile error in question.
2025-01-14 21:17:46 +00:00
mlugg
27274d4fde Type: struct {} does not have a well-defined layout
`Type.hasWellDefinedLayout` was in disagreement with pointer loading
logic about auto-layout structs with zero fields, `struct {}`. For
consistency, these types should not have a well-defined layout.

This is technically a breaking change.
2025-01-14 20:27:49 +00:00
wooster0
affe45b31f Coff msdos-stub: replace with documented byte array
This replaces the msdos-stub binary with a fully documented
byte array with inline comments to make it easy to understand what
every byte actually means.
2025-01-14 16:34:59 +00:00
Alex Rønne Petersen
8019694e17 mingw: Add upstream RtlSecureZeroMemory implementation.
Closes #22475.
2025-01-14 05:31:14 +01:00
xdBronch
fb43e91b22
Sema: disallow non scalar sentinels in array types and reified types (#22473) 2025-01-13 05:28:53 +00:00
Jacob Young
5de880c288 Dwarf: emit debug info for extern globals 2025-01-12 23:40:57 -05:00
Andrew Kelley
fb7be4e074 behavior: referencing an extern means depending on it 2025-01-12 22:57:27 -05:00
mlugg
f78f9388fe Sema: allow tail calls of function pointers
Resolves: #22474
2025-01-13 02:57:15 +00:00
Ben Grant
15fe999572 std.atomic: fix cache line size for RISC-V 2025-01-12 04:51:00 +01:00
mlugg
04c9f50aec compiler: improve "... contains reference to comptime var" errors
`Sema.explainWhyValueContainsReferenceToComptimeVar` (concise name!)
adds notes to an error explaining how to get from a given `Value` to a
pointer to some `comptime var` (or a comptime field). Previously, this
error could be very opaque in any case where it wasn't obvious where the
comptime var pointer came from; particularly for type captures. Now, the
error notes explain this to the user.
2025-01-11 08:54:47 +00:00
Jacob Young
6cfc9c0e02
Merge pull request #22459 from jacobly0/fix-miscomps
cbe/x86_64: fix more miscomps
2025-01-10 15:36:21 -05:00
Jacob Young
02692ad78c cbe: fix miscomps of the compiler 2025-01-10 06:10:15 -05:00
Jacob Young
4e581427d1 x86_64: fix miscomp where in use register is marked as free 2025-01-10 06:10:15 -05:00
Andrew Kelley
b36ea592b8 build.zig: make unit tests not use the full matrix 2025-01-10 06:03:57 -05:00
Matthew Lugg
bc846c3799
Merge pull request #22414 from mlugg/better-analyze-call
Sema: rewrite semantic analysis of function calls
2025-01-10 10:43:31 +00:00
Michael Dusan
80a9f0b942 bsd: fix stage3 linking on freebsd and dragonfly 2025-01-10 09:38:31 +01:00
mlugg
6a837e64cf
compiler: bump stack size 32 MiB -> 46 MiB
Before the prior commit, the maximum comptime recursion depth on my
system was 4062. After the prior commit, it decreased to 2854. This
commit increases the compiler's stack size enough so that the recursion
depth limit is no less than it was before the `Sema.analyzeCall`
rewrite, preventing this from being a breaking change. Specifically,
this stack size increases my observed maximum comptime recursion depth
to 4105.
2025-01-10 05:41:21 +00:00
mlugg
e9bd2d45d4
Sema: rewrite semantic analysis of function calls
This rewrite improves some error messages, hugely simplifies the logic,
and fixes several bugs. One of these bugs is technically a new rule
which Andrew and I agreed on: if a parameter has a comptime-only type
but is not declared `comptime`, then the corresponding call argument
should not be *evaluated* at comptime; only resolved. Implementing this
required changing how function types work a little, which in turn
required allowing a new kind of function coercion for some generic use
cases: function coercions are now allowed to implicitly *remove*
`comptime` annotations from parameters with comptime-only types. This is
okay because removing the annotation affects only the call site.

Resolves: #22262
2025-01-09 06:46:47 +00:00
Jacob Young
3f95003d4c cbe: fix miscomps of x86_64 backend 2025-01-08 19:33:45 -05:00
Jacob Young
5b5c60f433 Dwarf: fix assertion failure
I'm not entirely sure how this happens.
2025-01-08 11:10:28 -05:00
Des-Nerger
6a21d18adf -fwine: allow 32-bit .exe's be run on backward-compatible 64-bit arches
Closes #22361.
2025-01-07 19:03:40 +01:00
David Rubin
40f5eac79c Sema: fix invalid AIR from array concat 2025-01-07 06:17:40 -05:00
Alex Rønne Petersen
23281704dc test: Enable long calls for all thumb/thumbeb module tests.
The relocation range issues will happen eventually as we add more code to the
standard library and test suites, so we may as well just deal with this now.
@MasonRemaley ran into this in #20271, for example.
2025-01-07 08:44:45 +01:00
David Rubin
fc28a71d9f Target: update the extra features before resolving the dynamic linker 2025-01-07 02:58:10 +01:00
Jacob Young
7aa95bc7f6 Dwarf: fix abbrev code being overwritten with the wrong empty variant 2025-01-06 17:08:47 -05:00
Reuben Dunnington
f34ef39af1 remove wasm from redzone targets list 2025-01-06 22:10:11 +01:00
Alex Rønne Petersen
0fb80b0633
Merge pull request #22430 from alexrp/thumbeb
Some QEMU fixes + disable some tests for `thumbeb` in addition to `armeb`
2025-01-06 21:51:56 +01:00
Alex Rønne Petersen
03ac40d570
std: Disable some tests affected by #22060 for thumbeb too. 2025-01-06 16:47:40 +01:00
Alex Rønne Petersen
c1ae99efb3
test: Disable align(N) on functions and @alignCast functions for thumbeb too. 2025-01-06 16:31:32 +01:00
Alex Rønne Petersen
52e9fd7c3c
test: Disable vector behavior tests affected by #22060 for thumbeb too. 2025-01-06 16:20:27 +01:00
Reuben Dunnington
a7a5f3506b fix win32 manifest ID for DLLs
* MSDN documentation page covering what resource IDs manifests should have:
  https://learn.microsoft.com/en-us/windows/win32/sbscs/using-side-by-side-assemblies-as-a-resource
* This change ensures shared libraries that embed win32 manifests use the
  proper ID of 2 instead of 1, which is only allowed for .exes. If the manifest
  uses the wrong ID, it will not be found and is essentially ignored.
2025-01-06 15:56:21 +01:00
Alex Rønne Petersen
f54f58b60f
std.zig.system: Handle thumb/thumbeb for QEMU in getExternalExecutor(). 2025-01-06 15:37:25 +01:00
Alex Rønne Petersen
749e67dee8
std.zig.system: Reject x32 for QEMU in getExternalExecutor(). 2025-01-06 15:37:23 +01:00
cdeler
745d3ed0ac
Remove strict verifyContext invocation from hash_map implementation. (#22370)
Fixes #19640

Co-authored-by: Andrew Kelley <andrew@ziglang.org>
2025-01-06 13:37:30 +00:00
Jacob Young
0bf44c3093 x86_64: fix @errorName data
The final offset was clobbering the first error name, which is revealed
by an out of bounds when the global error set is empty.

Closes #22362
2025-01-05 17:15:56 -05:00
mlugg
137787edbb Sema: fix incorrect type in optional_payload instruction
Resolves: #22417
2025-01-05 19:38:19 +00:00
Travis Lange
82e7f23c49 Added support for thin lto 2025-01-05 18:08:11 +01:00
mlugg
da1ffae7d2 std: fix undefined value in Target.Query
This is an RLS footgun.

Resolves: #21834
2025-01-05 16:26:21 +00:00
Matthew Lugg
41786fabfc
Merge pull request #22412 from mlugg/line-number-incremental
incremental: debug line number updates
2025-01-05 11:48:58 +00:00
mlugg
b039a8b615 compiler: slightly simplify builtin decl memoization
Rather than `Zcu.BuiltinDecl.Memoized` being a struct with fields, it
can instead just be an array, indexed by the enum. This allows runtime
indexing, avoiding a few now-unnecessary `inline` switch cases.
2025-01-05 05:52:02 +00:00
Jacob Young
dde3116e50
Dwarf: implement new incremental line number update API 2025-01-05 02:20:56 +00:00
mlugg
065e10c95c
link: new incremental line number update API 2025-01-05 02:20:56 +00:00
Matthew Lugg
136c5a916e
Merge pull request #22403 from mlugg/incremental
incremental: fixes
2025-01-05 00:28:06 +00:00
axel escalada
ff4f2753e4
Improve first() documentation for split iterators
* remove  from doc., add explicit info when panic

* match convention for assert documentation, avoiding to use panic here
2025-01-04 13:45:12 +00:00