7724 Commits

Author SHA1 Message Date
Jacob Young
d652dd0658 x86_64: rewrite @abs for scalar floats 2025-01-21 06:39:24 -05:00
Andrew Kelley
f5485a52bc reject crti.o/crtn.o, embrace the future
crti.o/crtn.o is a legacy strategy for calling constructor functions
upon object loading that has been superseded by the
init_array/fini_array mechanism.

Zig code depends on neither, since the language intentionally has no way
to initialize data at runtime, but alas the Zig linker still must
support this feature since popular languages depend on it.

Anyway, the way it works is that crti.o has the machine code prelude of
two functions called _init and _fini, each in their own section with the
respective name. crtn.o has the machine code instructions comprising the
exitlude for each function. In between, objects use the .init and .fini
link section to populate the function body.

This function is then expected to be called upon object initialization
and deinitialization.

This mechanism is depended on by libc, for example musl and glibc, but
only for older ISAs. By the time the libcs gained support for newer
ISAs, they had moved on to the init_array/fini_array mechanism instead.

For the Zig linker, we are trying to move the linker towards
order-independent objects which is incompatible with the legacy
crti/crtn mechanism.

Therefore, this commit drops support entirely for crti/crtn mechanism,
which is necessary since the other commits in this branch make it
nondeterministic in which order the libc objects and the other link
inputs are sent to the linker.

The linker is still expected to produce a deterministic output, however,
by ignoring object input order for the purposes of symbol resolution.
2025-01-20 20:59:52 -08:00
mlugg
0ec6b2dd88 compiler: simplify generic functions, fix issues with inline calls
The original motivation here was to fix regressions caused by #22414.
However, while working on this, I ended up discussing a language
simplification with Andrew, which changes things a little from how they
worked before #22414.

The main user-facing change here is that any reference to a prior
function parameter, even if potentially comptime-known at the usage
site or even not analyzed, now makes a function generic. This applies
even if the parameter being referenced is not a `comptime` parameter,
since it could still be populated when performing an inline call. This
is a breaking language change.

The detection of this is done in AstGen; when evaluating a parameter
type or return type, we track whether it referenced any prior parameter,
and if so, we mark this type as being "generic" in ZIR. This will cause
Sema to not evaluate it until the time of instantiation or inline call.

A lovely consequence of this from an implementation perspective is that
it eliminates the need for most of the "generic poison" system. In
particular, `error.GenericPoison` is now completely unnecessary, because
we identify generic expressions earlier in the pipeline; this simplifies
the compiler and avoids redundant work. This also entirely eliminates
the concept of the "generic poison value". The only remnant of this
system is the "generic poison type" (`Type.generic_poison` and
`InternPool.Index.generic_poison_type`). This type is used in two
places:

* During semantic analysis, to represent an unknown result type.
* When storing generic function types, to represent a generic parameter/return type.

It's possible that these use cases should instead use `.none`, but I
leave that investigation to a future adventurer.

One last thing. Prior to #22414, inline calls were a little inefficient,
because they re-evaluated even non-generic parameter types whenever they
were called. Changing this behavior is what ultimately led to #22538.
Well, because the new logic will mark a type expression as generic if
there is any change its resolved type could differ in an inline call,
this redundant work is unnecessary! So, this is another way in which the
new design reduces redundant work and complexity.

Resolves: #22494
Resolves: #22532
Resolves: #22538
2025-01-21 02:41:42 +00:00
Andrew Kelley
216e0f3730
Merge pull request #22548 from mlugg/fix-broken-pipe
Wait for reported spawn success or failure before trying to write to the stdio pipe in the build runner.

Hopefully fixes `error.BrokenPipe` failures
2025-01-20 21:40:04 -05:00
mlugg
8bcb578507 Sema: fix is_non_null_ptr handling for runtime-known pointers
We can still often determine a comptime result based on the type, even
if the pointer is runtime-known.

Also, we previously used load -> is non null instead of AIR
`is_non_null_ptr` if the pointer is comptime-known, but that's a bad
heuristic. Instead, we should check for the pointer to be
comptime-known, *and* for the load to be comptime-known, and only in
that case should we call `Sema.analyzeIsNonNull`.

Resolves: #22556
2025-01-21 00:33:32 +00:00
Jacob Young
b9198b708f x86_64: rewrite @abs 2025-01-20 14:47:07 -05:00
Alex Rønne Petersen
d5db02728c
Merge pull request #22530 from alexrp/omit-unwind-tables
Fix building the standard library without CFI directives
2025-01-20 07:24:12 +01:00
mlugg
b8e568504e
std.Build: extend test_runner option to specify whether runner uses std.zig.Server
The previous logic here was trying to assume that custom test runners
never used `std.zig.Server` to communicate with the build runner;
however, it was flawed, because modifying the `test_runner` field on
`Step.Compile` would not update this flag. That might have been
intentional (allowing a way for the user to specify a custom test runner
which *does* use the compiler server protocol), but if so, it was a
flawed API, since it was too easy to update one field without updating
the other.

Instead, bundle these two pieces of state into a new type
`std.Build.Step.Compile.TestRunner`. When passing a custom test runner,
you are now *provided* to specify whether it is a "simple" runner, or
whether it uses the compiler server protocol.

This is a breaking change, but is unlikely to affect many people, since
custom test runners are seldom used in the wild.
2025-01-20 00:14:58 +00:00
Alex Rønne Petersen
45bb4f955c
test: Add a standalone test for omitting CFI directives. 2025-01-19 02:15:30 +01:00
mlugg
3b6e5ba490
Sema: don't try to initialize global union pointer at comptime
Resolves: #19832
2025-01-18 14:30:06 +00:00
mlugg
f7b9f84df2
incremental: fix enum resolution bugs 2025-01-18 14:30:06 +00:00
Jacob Young
8c8dfb35f3 x86_64: fix crashes compiling the compiler and tests 2025-01-16 20:47:30 -05:00
Jacob Young
c3d33440f0 x86_64: pass more behavior tests 2025-01-16 20:47:30 -05:00
Jacob Young
666d76d85c x86_64: implement load and store 2025-01-16 20:47:30 -05:00
Jacob Young
63730441d0 x86_64: implement union access 2025-01-16 20:47:30 -05:00
Jacob Young
3240adfa16 x86_64: implement pointer addition and subtraction 2025-01-16 20:47:30 -05:00
Jacob Young
0d9079f466 x86_64: implement element access 2025-01-16 20:47:30 -05:00
Jacob Young
e5d5a8bc4e x86_64: implement switch jump tables 2025-01-16 20:42:08 -05:00
Jacob Young
ac1a975f9b x86_64: implement clz and not 2025-01-16 20:42:08 -05:00
Jacob Young
a1828ebcda x86_64: demolish the old 2025-01-16 20:42:08 -05:00
Jacob Young
73a42953c9 x86_64: 2 means better 2025-01-16 20:42:08 -05:00
Jacob Young
b9c4400776 x86_64: implement fallback for pcmpeqq 2025-01-16 20:42:08 -05:00
Jacob Young
c4b93555b0 x86_64: testing 2025-01-16 20:42:08 -05:00
Jacob Young
257054a146 Revert "disable flaky incremental compilation tests"
This reverts commit 133abdeda2994886c3476a3faf53f8a911513b32 but keeps
the tests disabled for the wasm target, which is the only configuration
that seems to fail, even though the error looks like a frontend error.
2025-01-16 20:02:49 -05:00
Matthew Lugg
4d8c24c6c5
Merge pull request #22505 from mlugg/easier-modify-builtin
std.builtin.Type renames, and make it easier to modify std.builtin
2025-01-16 22:20:02 +00:00
Andrew Kelley
133abdeda2 disable flaky incremental compilation tests
tracking issue #22510
2025-01-16 13:13:11 -08:00
mlugg
9804cc8bc6
all: update to std.builtin.Type.{Pointer,Array,StructField} field renames 2025-01-16 12:49:58 +00:00
mlugg
d00e05f186
all: update to std.builtin.Type.Pointer.Size field renames
This was done by regex substitution with `sed`. I then manually went
over the entire diff and fixed any incorrect changes.

This diff also changes a lot of `callconv(.C)` to `callconv(.c)`, since
my regex happened to also trigger here. I opted to leave these changes
in, since they *are* a correct migration, even if they're not the one I
was trying to do!
2025-01-16 12:46:29 +00:00
Andrew Kelley
24bdb42a23 test/link/wasm/shared-memory: update to better linker behavior
now it's smarter about omitting tls stuff if there end up being no
TLS data sections
2025-01-15 19:44:20 -08:00
Andrew Kelley
744bb5d16a wasm linker: change rules about symbol visibility
export by default means export, as expected. if you want hidden
visibility then use hidden visibility.
2025-01-15 18:31:44 -08:00
Andrew Kelley
9dd6efb7e4 wasm linker: fix TLS data segments
fix calculation of alignment and size

include __tls_align and __tls_size globals along with __tls_base

include them only if the TLS segment is emitted

add missing reloc logic for memory_addr_tls_sleb

fix name of data segments to include only the prefix
2025-01-15 18:17:37 -08:00
Andrew Kelley
204e689bdb tests: remove dead code 2025-01-15 15:11:37 -08:00
Andrew Kelley
42602dc96b test/link/wasm/export-data: update expected behavior
Object being linked has neither functions nor globals named "foo" or
"bar" and so these names correctly fail to be exported when creating an
executable.
2025-01-15 15:11:37 -08:00
Andrew Kelley
50d053f31c test/wasm/infer-features: update to expected behavior
I intentionally simplified the target features functionality to use the
target features that are explicitly specified to the linker and ignore
the "tooling conventions"

this makes the wasm linker behave the same as ELF, COFF, and MachO.
2025-01-15 15:11:37 -08:00
Andrew Kelley
ec5fc6a2a8 test/link/wasm/function-table: delete bad test
this tests for importing a function table, but the example source does
not try to use an imported table, so it's a useless check. it's unclear
what the behavior is even supposed to do in this case.

the other two cases are left alone.
2025-01-15 15:11:37 -08:00
Andrew Kelley
ae119e395a test/link/wasm/segment: delete bad test
- doesn't run the exe
- checks for data segment named .rodata which is not a thing
- checks for data segment named .bss which is not needed
2025-01-15 15:11:37 -08:00
Andrew Kelley
c565191f30 test/link/wasm/type: remove redundant tests
This test passes now, but let's not run it for the other optimization
modes since they don't affect linker behavior.
2025-01-15 15:11:36 -08:00
Andrew Kelley
9143575ec3 test/wasm/export: delete redundant tests
the other optimization modes don't affect linking
2025-01-15 15:11:36 -08:00
Andrew Kelley
7ae2f21e2b delete bad linker test: bss
The purpose of this test is unclear. It checks for the existence of bss
section which is completely unnecessary since those zeroes can be
omitted from the binary.

Furthermore the code generated for __wasm_init_memory looks wrong.
Finally, the CheckObject DSL is brittle, it only checks for exact
matches of entire lines in an ad-hoc text format. Conclusion, it's a bad
test, delete it.
2025-01-15 15:11:36 -08:00
Andrew Kelley
c535422423 wasm linker: implement hidden visibility 2025-01-15 15:11:36 -08:00
Andrew Kelley
9285f91ccc wasm linker: incremental test coverage 2025-01-15 15:11:36 -08:00
Andrew Kelley
1afa6e260e build: respect -Duse-llvm option when doing behavior tests 2025-01-15 15:11:36 -08:00
Andrew Kelley
fbdcb2289b wasm linker: don't pretend it's possible to export data symbols 2025-01-15 15:11:36 -08: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
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