15237 Commits

Author SHA1 Message Date
Jakub Konka
f26573fddf elf: re-use old atom slot for a trampoline to that atom
This is the initial implementation of Jacob Young's idea of
re-using old function slots as trampolines for new function's
location. This way the trampoline is guaranteed to be aligned
to the function's alignment.

The only edge case is if an incremental update further overaligns
the function in which case we skip/delete the trampoline and
re-evaluate all references.
2024-08-14 12:10:40 +02:00
Jakub Konka
1bd54a55fa fix compile errors in other codegen backends 2024-08-13 21:52:40 +02:00
Jakub Konka
97ab420dcf elf: do not emit zig jump table in relocatables 2024-08-13 13:30:24 +02:00
Jakub Konka
49d78cc793 elf: only apply zig jump table indirection to function calls (PLT32) 2024-08-13 13:30:24 +02:00
Jakub Konka
9daf5e81c4 elf: commit non-indirected symbol address to symtab 2024-08-13 13:30:24 +02:00
Jakub Konka
df80ccf760 elf: pretty print alingment when pretty printing atoms 2024-08-13 13:30:24 +02:00
Jakub Konka
39ee346681 elf: make .text.zig bigger now that jump table is part of it 2024-08-13 13:30:24 +02:00
Jakub Konka
afaec5c3e4 x86_64: fix generating lazy symbol refs 2024-08-13 13:30:24 +02:00
Jakub Konka
edd72c75eb elf: fix circular dep loop in zig jump table 2024-08-13 13:30:24 +02:00
Jakub Konka
57f7209508 elf: replace use of linker_extern_fn with more generic Immediate.reloc 2024-08-13 13:30:24 +02:00
Jakub Konka
ce8886d57d elf: make zig jump table indirection implicit via Symbol.address 2024-08-13 13:30:24 +02:00
Jakub Konka
d25c93a868 x86_64: emit call rel32 for near calls with linker reloc 2024-08-13 13:30:24 +02:00
Jakub Konka
ffcf0478fe x86_64: remove handling of .call since it's unused for now 2024-08-13 13:30:24 +02:00
Jakub Konka
78b1c73602 elf: rename OffsetTable to JumpTable 2024-08-13 13:30:24 +02:00
Jakub Konka
e1ce9a7065 elf: add poorman's reporting tool for unallocated NAVs/UAVs 2024-08-13 13:30:24 +02:00
Jakub Konka
e3f6ebaea9 x86_64+elf: fix jump table indirection for functions 2024-08-13 13:30:24 +02:00
Jakub Konka
16abf51cee x86_64: handle lea_symbol returned by genNavRef 2024-08-13 13:30:24 +02:00
Jakub Konka
f968dd0cb1 comp: actually report codegen errors 2024-08-13 13:30:24 +02:00
Jakub Konka
5fd53dc36f x86_64: start converting away from .got.zig knowledge 2024-08-13 13:30:24 +02:00
Jakub Konka
d7c5fbce92 elf: emit a jump table in place of offset table for functions 2024-08-13 13:30:24 +02:00
Jakub Konka
d328140858 elf: nuke ZigGotSection from existence 2024-08-13 13:30:24 +02:00
Jakub Konka
4c2b34e8ab elf: relax R_X86_64_32 into jump table indirection if zig_offset_table set 2024-08-13 13:30:24 +02:00
Jakub Konka
7556b32840 elf: indirect via offset table in the linker away from backend 2024-08-13 13:30:24 +02:00
Jakub Konka
97a65ea0d5 elf: dirty offset table entry on moving Atom in off/addr space 2024-08-13 13:30:24 +02:00
Jakub Konka
24b915c9f2 elf: write offset table entry if dirty 2024-08-13 13:30:24 +02:00
Jakub Konka
67e703dc71 elf: allocate new offset table via Atom.allocate mechanism 2024-08-13 13:30:23 +02:00
Jakub Konka
27e1e63671 elf: introduce OffsetTable in ZigObject for funcs only 2024-08-13 13:30:23 +02:00
Alex Rønne Petersen
d6f9972594 all: Handle spirv in addition to spirv(32,64) where applicable.
Some of this is arbitrary since spirv (as opposed to spirv32/spirv64) refers to
the version with logical memory layout, i.e. no 'real' pointers. This change at
least matches what clang does.
2024-08-12 16:08:28 -07:00
Andrew Kelley
f988cea825
Merge pull request #21019 from alexrp/target-os-cleanup
`std.Target`: Remove `minix` and `liteos`, rename `glsl450` to `opengl`, and some minor housekeeping
2024-08-12 16:06:57 -07:00
Alex Rønne Petersen
82b0f44721 llvm: Disable lowering to f16 on s390x.
https://github.com/llvm/llvm-project/issues/50374
2024-08-12 16:01:59 -07:00
Alex Rønne Petersen
a1a823f69c llvm: Disable lowering to f128 on sparc32.
efc6b50d2d/llvm/lib/Target/Sparc/SparcISelLowering.cpp (L561-L562)
2024-08-12 16:01:34 -07:00
Alex Rønne Petersen
9f1fb45201
llvm: Move some OS selection prongs for clarity.
This makes it clearer which OSs are not known to or supported by LLVM at all vs
the ones where we're intentionally passing choosing "unknown".
2024-08-12 09:03:08 +02:00
Alex Rønne Petersen
8af4d65108
std.Target: Remove liteos OS tag.
It has not seen development in 4 years.

https://github.com/LiteOS/LiteOS/commits/master
2024-08-12 08:59:49 +02:00
Alex Rønne Petersen
e211dce6fc
std.Target: Remove minix OS tag.
It has not seen development in 6 years. RIP.

* https://github.com/Stichting-MINIX-Research-Foundation/minix/commits/master
* https://groups.google.com/g/minix3/c/nUG1NwxXXkg
2024-08-12 08:59:49 +02:00
Alex Rønne Petersen
eb4539a27d
std.Target: Rename glsl450 Arch tag to opengl.
Versions can simply use the normal version range mechanism, or alternatively an
Abi tag if that makes more sense. For now, we only care about 4.5 anyway.
2024-08-12 08:59:47 +02:00
Andrew Kelley
61dac74128
Merge pull request #20985 from alexrp/gpu-nonsense
Follow-up on `std.Target` GPU changes in #20960
2024-08-11 20:23:28 -07:00
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