15199 Commits

Author SHA1 Message Date
Alex Rønne Petersen
6316fd9535 std.Target: Add goff and xcoff to ObjectFormat.
Also improve the docs a bit, and handle driverkit and dxil in default().
2024-08-11 20:21:28 -07:00
mlugg
153e7d6235
frontend: give all container types namespaces
Eliding the namespace when a container type has no decls was an
experiment in saving memory, but it ended up causing more trouble than
it was worth in various places. So, take the small memory hit for
reified types, and just give every container type a namespace.
2024-08-11 07:30:21 +01:00
mlugg
548a087faf
compiler: split Decl into Nav and Cau
The type `Zcu.Decl` in the compiler is problematic: over time it has
gained many responsibilities. Every source declaration, container type,
generic instantiation, and `@extern` has a `Decl`. The functions of
these `Decl`s are in some cases entirely disjoint.

After careful analysis, I determined that the two main responsibilities
of `Decl` are as follows:
* A `Decl` acts as the "subject" of semantic analysis at comptime. A
  single unit of analysis is either a runtime function body, or a
  `Decl`. It registers incremental dependencies, tracks analysis errors,
  etc.
* A `Decl` acts as a "global variable": a pointer to it is consistent,
  and it may be lowered to a specific symbol by the codegen backend.

This commit eliminates `Decl` and introduces new types to model these
responsibilities: `Cau` (Comptime Analysis Unit) and `Nav` (Named
Addressable Value).

Every source declaration, and every container type requiring resolution
(so *not* including `opaque`), has a `Cau`. For a source declaration,
this `Cau` performs the resolution of its value. (When #131 is
implemented, it is unsolved whether type and value resolution will share
a `Cau` or have two distinct `Cau`s.) For a type, this `Cau` is the
context in which type resolution occurs.

Every non-`comptime` source declaration, every generic instantiation,
and every distinct `extern` has a `Nav`. These are sent to codegen/link:
the backends by definition do not care about `Cau`s.

This commit has some minor technically-breaking changes surrounding
`usingnamespace`. I don't think they'll impact anyone, since the changes
are fixes around semantics which were previously inconsistent (the
behavior changed depending on hashmap iteration order!).

Aside from that, this changeset has no significant user-facing changes.
Instead, it is an internal refactor which makes it easier to correctly
model the responsibilities of different objects, particularly regarding
incremental compilation. The performance impact should be negligible,
but I will take measurements before merging this work into `master`.

Co-authored-by: Jacob Young <jacobly0@users.noreply.github.com>
Co-authored-by: Jakub Konka <kubkon@jakubkonka.com>
2024-08-11 07:29:41 +01:00
Jakub Konka
5dffd8cb7b Wasm: handle ref to an extern in getDeclVAddr 2024-08-10 22:32:06 +02:00
Jakub Konka
62fad66d64 Coff: handle ref to an extern in getDeclVAddr 2024-08-10 22:26:02 +02:00
Jakub Konka
8f82a66019 MachO/ZigObject: handle ref to an extern in getDeclVAddr 2024-08-10 22:25:57 +02:00
Jakub Konka
5d6e49d065 Elf/ZigObject: handle ref to an extern in getDeclVAddr
Prior to this change, we would unconditionally create a symbol and atom
pair for a Decl that could point to an extern, in which case no atom
can be created.
2024-08-10 22:23:24 +02:00
Jakub Konka
421b105d85 macho: ensure we only ever put named symbols in the symtab 2024-08-10 17:19:37 +02:00
Jakub Konka
3f2a0c3de4 elf: ensure we only ever put named symbols in the symtab 2024-08-10 17:18:48 +02:00
sin-ack
2cfad20204 Compilation: Mark .c++ files as having C++ extension
Some projects, such as Cap'n Proto, use .c++ as their filenames. Without
this, compiling them fails because zig c++ will fall back to using the
linker.
2024-08-08 17:42:11 -07:00
Andrew Kelley
cf87a1a7cf language: add module name field to @src
closes #20963
2024-08-08 07:47:14 -07:00
Jan Hendrik Farr
ca012e5b69 std.posix: read on timerfd can return error.Canceled 2024-08-08 01:12:26 -07:00
Andrew Kelley
61fbdebd61
Merge pull request #20969 from alexrp/llvm-unsup-targets
`llvm`: Fix hasLlvmSupport() for dxil, spirv[32,64], and kalimba.
2024-08-07 22:50:08 -07:00
Jakub Konka
cfe6ff4301
Merge pull request #20971 from ziglang/elf-ownership-2
elf: move ownership of symbols into owning objects
2024-08-08 00:27:36 +02:00
YANG Xudong
b8705ed652
loongarch: various architecture specific fixes (#20912) 2024-08-07 13:06:29 -07:00
Andrew Kelley
87e8fc1ade
Merge pull request #20512 from aikawayataro/add-v-linker-arg
zig ld: handle -v linker arg
2024-08-07 13:01:12 -07:00
Andrew Kelley
0e99f517f2
Merge pull request #20958 from ziglang/fuzz
introduce a fuzz testing web interface
2024-08-07 11:55:30 -07:00
Jakub Konka
b058545970 elf: remove stale code 2024-08-07 10:21:03 +02:00
Jakub Konka
90c4037819 elf: fix off-by-one direct access to symbol resolver in ZigObject 2024-08-07 10:21:03 +02:00
Jakub Konka
128289fda1 elf: actually init symbol resolvers array in ZigObject 2024-08-07 10:21:03 +02:00
Jakub Konka
668fd7aca6 elf: handle SHN_UNDEF explicitly in ZigObject.resolveSymbols 2024-08-07 10:21:03 +02:00
Jakub Konka
02f38d7749 codegen: fix Elf symbol refs 2024-08-07 10:21:03 +02:00
Jakub Konka
89db24ec6d elf: fix .eh_frame calc in relocatable mode 2024-08-07 10:21:03 +02:00
Jakub Konka
e99818c602 elf: start-stop resolution has to come after init output sections 2024-08-07 10:21:03 +02:00
Jakub Konka
835f1fc03f elf: fix off-by-one when referring to resolved table directly 2024-08-07 10:21:02 +02:00
Jakub Konka
0a198789f1 elf: scan LinkerDefined obj for symbol indirection too 2024-08-07 10:21:02 +02:00
Jakub Konka
137d43c0ea elf: get hello-world glibc working again 2024-08-07 10:21:02 +02:00
Jakub Konka
26da7c8207 elf: fix symbol resolution for Objects 2024-08-07 10:21:02 +02:00
Jakub Konka
04f8f8ad3e elf: do not re-init Symbol when initializing 2024-08-07 10:21:02 +02:00
Jakub Konka
8ca809d928 elf: move getStartStopBasename into Object 2024-08-07 10:21:02 +02:00
Jakub Konka
41e9b8b6c8 elf: fix compile errors 2024-08-07 10:21:02 +02:00
Jakub Konka
deeaa1bb0c elf: redo symbol mgmt and ownership in ZigObject 2024-08-07 10:21:02 +02:00
Jakub Konka
de80e4fec2 elf: move symbol ownership to LinkerDefined 2024-08-07 10:21:02 +02:00
Jakub Konka
9fe69cc0b5 elf: move symbol ownership to SharedObject 2024-08-07 10:21:02 +02:00
Jakub Konka
d0367b0219 elf: move symbol ownership to Object 2024-08-07 10:21:02 +02:00
Jakub Konka
9ec415d4de elf: null symbol is obsolete 2024-08-07 10:21:02 +02:00
Jakub Konka
518c7908f0 elf: always create symbol extra 2024-08-07 10:21:02 +02:00
Andrew Kelley
cd5f673cae
Merge pull request #20909 from alexrp/glibc-riscv
Support building glibc for riscv32/riscv64
2024-08-07 01:14:54 -07:00
Andrew Kelley
b071b10ce8
Merge pull request #20894 from alexrp/target-cleanup-4
`std.Target`: Minor rework to some `isArch()` functions, fix some related issues throughout `std`
2024-08-07 01:08:44 -07:00
Ryan Liptak
304519da27 Make Type.intAbiAlignment match LLVM alignment for x86-windows target
During the LLVM 18 upgrade, two changes were made that changed `@alignOf(u64)` to 4 for the x86-windows target:

- `Type.maxIntAlignment` was made to return 16 for x86 (200e06b). Before that commit, `maxIntAlignment` was 8 for windows/uefi and 4 for everything else
- `Type.intAbiAlignment` was made to return 4 for 33...64 (7e1cba7 + e89d6fc). Before those commits, `intAbiAlignment` would return 8, since the maxIntAlignment for x86-windows was 8 (and for other targets, the `maxIntAlignment` of 4 would clamp the `intAbiAlignment` to 4)

`src/codegen/llvm.zig` has its own alignment calculations that no longer match the values returned from the `Type` functions. For the x86-windows target, this loop:

ddcb7b1c11/src/codegen/llvm.zig (L558-L567)

when the `size` is 64 will set `abi` and `pref` to 64 (meaning an align of 8 bytes), which doesn't match the `Type` alignment of 4.

This commit makes `Type.intAbiAlignment` match the alignment calculated in `codegen/llvm.zig`.

Fixes #20047
Fixes #20466
Fixes #20469
2024-08-07 00:59:46 -07:00
Andrew Kelley
904fcda736 Compilation: fix -femit-docs 2024-08-07 00:48:32 -07:00
Andrew Kelley
ff503edc04 Compilation: fix not showing sub-errors for autodocs 2024-08-07 00:48:32 -07:00
Alex Rønne Petersen
746f20d21f
llvm: Use unreachable in targetTriple() for targets without LLVM support. 2024-08-07 09:39:42 +02:00
Alex Rønne Petersen
a9f68410d0
llvm: Clarify in initializeLLVMTarget() that there's no kalimba backend. 2024-08-07 09:39:42 +02:00
Alex Rønne Petersen
650785c718
target: Fix hasLlvmSupport() for dxil, spirv[32,64], and kalimba. 2024-08-07 09:39:39 +02:00
Alex Rønne Petersen
e9b5377b8e musl: Disable warnings in all compilations.
This is what upstream's configure does.

Previously, we only disabled warnings in some musl compilations, with `rcrt1.o`
notably being one for which we didn't. This resulted in a warning in `dlstart.c`
which is included in `rcrt1.c`. So let's just be consistent and disable warnings
for all musl code.

Closes #13385.
2024-08-06 15:00:47 -07:00
Andrew Kelley
d6945eeba9 Revert "glibc: Add a temporary hack in abilists loading due to sparcel removal."
This reverts commit 62a01851d9c433ea3f2e98cc986e75d32aece443.

No longer needed with the abilists update.
2024-08-05 09:53:37 -07:00
Alex Rønne Petersen
f407778e83
glibc: Set -frounding-math like upstream.
~Same thing as b03a04c7fca587af0f1caf59881def3c91596728.
2024-08-02 09:54:08 +02:00
Alex Rønne Petersen
923f114bdb
glibc: Define NO_INITFINI for non-legacy architectures. 2024-08-02 09:54:08 +02:00
Alex Rønne Petersen
635a3d87de
glibc: Change riscv32-linux-gnuilp32 target triple to riscv32-linux-gnu.
This target triple was weird on multiple levels:

* The `ilp32` ABI is the soft float ABI. This is not the main ABI we want to
  support on RISC-V; rather, we want `ilp32d`.
* `gnuilp32` is a bespoke tag that was introduced in Zig. The rest of the world
  just uses `gnu` for RISC-V target triples.
* `gnu_ilp32` is already the name of an ILP32 ABI used on AArch64. `gnuilp32` is
  too easy to confuse with this.
* We don't use this convention for `riscv64-linux-gnu`.
* Supporting all RISC-V ABIs with this convention will result in combinatorial
  explosion; see #20690.
2024-08-02 09:54:08 +02:00