34846 Commits

Author SHA1 Message Date
Jakub Konka
801f038c2c elf: do not pad placeholders coming from input object files
This is currently not entirely accurate since no padding will affect
the last-most atom of ZigObject that should be padded.
2024-09-04 13:34:26 +02:00
Jakub Konka
eeec50d251 elf: misc .eh_frame management fixes 2024-09-04 13:34:26 +02:00
Jakub Konka
fca92fd7c0 elf: copy existing data when allocating other alloc sections in relocatable mode 2024-09-04 13:34:26 +02:00
Jakub Konka
5cdad186fe elf: do not create .eh_frame section if ZigObject already did so in relocatable mode 2024-09-04 13:34:26 +02:00
Jakub Konka
88e0d49feb elf: init rela sections in a separate pass for ZigObject 2024-09-04 13:34:26 +02:00
Jakub Konka
2ef3e30e2d elf: emit relocs for self-hosted generated .eh_frame section 2024-09-04 13:34:26 +02:00
Jakub Konka
5cb51c10de elf: fix relocatable mode 2024-09-04 13:34:26 +02:00
Jakub Konka
6b53dc9461 elf: actually allocate atoms within each section chunk 2024-09-04 13:34:26 +02:00
Jakub Konka
6a50a0f0ed elf: update osec index for section chunks in objects 2024-09-04 13:34:26 +02:00
Jakub Konka
f87a7251a3 elf: actually write allocated atoms in object files 2024-09-04 13:34:26 +02:00
Jakub Konka
874ef6308e elf: do not create .eh_frame section if ZigObject already did so 2024-09-04 13:34:26 +02:00
Jakub Konka
45e46f0fb9 elf: allocate atom chunks using allocateChunk mechanics in objects 2024-09-04 13:34:25 +02:00
Jakub Konka
1ef96f05eb elf: introduce SectionChunk - a container of atoms per object file 2024-09-04 13:34:25 +02:00
Jakub Konka
6ec5df3898 elf: allocate .tdata and .tbss using allocateAtom mechanics 2024-09-04 13:34:25 +02:00
Jakub Konka
3e100c5dab dwarf: make Section.off a function 2024-09-04 13:34:25 +02:00
Jakub Konka
da60159d85 elf+dwarf: refer sections via section symbols 2024-09-04 13:34:25 +02:00
Jakub Konka
acb91f4b30 elf: fix emitting correct .rela. sections in -r mode 2024-09-04 13:34:25 +02:00
Jakub Konka
25fa092bb1 elf: fix a typo in setting ZigObject.data_relro_index 2024-09-04 13:34:25 +02:00
Jakub Konka
bc39bddd5f elf: remove isDebugSection helper 2024-09-04 13:34:25 +02:00
Jakub Konka
ef6ee90ff8 elf: remove now unused number_of_zig_segments 2024-09-04 13:34:25 +02:00
Jakub Konka
2d0f4fc9c0 elf: allocate .text in ZigObject similarly to .eh_frame 2024-09-04 13:34:25 +02:00
Jakub Konka
848535535d elf: allocate .data.rel.ro and .rodata in ZigObject similarly to .eh_frame 2024-09-04 13:34:25 +02:00
Jakub Konka
0b92404ddf elf: allocate .data in ZigObject similarly to .eh_frame 2024-09-04 13:34:25 +02:00
Jakub Konka
37a1f0e7f2 elf: allocate .bss in ZigObject similarly to .eh_frame 2024-09-04 13:34:25 +02:00
Jakub Konka
8f1ce3c85b elf: shuffle some stages to make it clear what needs what 2024-09-04 13:34:25 +02:00
Jakub Konka
d32af9ea2a elf: move initOutputSection into Elf from Object 2024-09-04 13:34:25 +02:00
Jakub Konka
b44dd599ad elf: split Atom.allocate into Atom-independent parts 2024-09-04 13:34:25 +02:00
Arwalk
f87dd43c12
stdlib : base64 encode to writer (#20961) 2024-09-04 08:10:12 +00:00
Alex Rønne Petersen
e5ee9c1e43 std.elf: Bring the EM enum up to date.
Based on:

* `include/elf/common.h` in binutils
* `include/uapi/linux/elf-em.h` in Linux
* https://www.sco.com/developers/gabi/latest/ch4.eheader.html

I opted to use the tag naming of binutils because it seems to be by far the most
complete and authoritative source at this point in time.
2024-09-03 17:44:01 -07:00
Alex Rønne Petersen
290ccb160e glibc: Avoid building and linking stub libraries that were emptied in 2.34.
Closes #20919.
2024-09-03 17:33:23 -07:00
Michael Dusan
7a4d69983a AstGen: update @errorCast to maybe eval to err
Consequently, `AstGen.ret()` now passes the error code to
`.defer_error_code`. Previously, the error union value was passed.

closes #20371
2024-09-03 22:56:23 +01:00
Andrew Kelley
242d268a06
Merge pull request #21277 from antlilja/llvm-module-flags
LLVM: Set module flags through Builder instead of LLVM API bindings
2024-09-02 17:57:27 -07:00
Alex Rønne Petersen
9bcb0e938c
std.crypto.ml_kem: Reduce test iteration counts from 100 to 10. (#21285)
Closes #21255.
2024-09-02 23:20:48 +00:00
fdfdjfk3
a670f55195
std.fmt.fmtIntSize*: document when precision is ignored 2024-09-02 14:21:59 +03:00
Jeremy Hertel
13da34955c std.hash_map: fix error message in getAutoHashFn 2024-09-02 12:09:10 +03:00
Matthew Lugg
6d2945f1fe
Merge pull request #21264 from mlugg/decl-literals
compiler: implement decl literals
2024-09-02 00:44:11 +01:00
Jeremy Hertel
227fb4875f std.math: rename make_f80 to F80.toFloat and break_f80 to F80.fromFloat 2024-09-02 00:10:22 +03:00
mlugg
289c704b60
cbe: don't emit 'x = x' in switch dispatch loop 2024-09-01 20:31:01 +01:00
David Rubin
0d295d7635
riscv: implement switch_dispatch & loop_switch_br 2024-09-01 18:31:01 +01:00
David Rubin
97ed239203
riscv: implement repeat and the new switch_br 2024-09-01 18:31:01 +01:00
Jacob Young
d5b01df3c8
x86_64: implement loop_switch_br and switch_dispatch 2024-09-01 18:31:01 +01:00
mlugg
2b9af9e825
AstGen: error on unused switch label 2024-09-01 18:31:01 +01:00
mlugg
b7a55cd6c3
AstGen: allow breaking from labeled switch
Also, don't use the special switch lowering for errors if the switch
is labeled; this isn't currently supported. Related: #20627.
2024-09-01 18:31:01 +01:00
mlugg
fd70d9db99
x86_64: un-regress loop and switch_br
This does *not* yet implement the new `loop_switch_br` instruction.
2024-09-01 18:30:32 +01:00
mlugg
cb68c0917a
wasm: un-regress loop and switch_br
`.loop` is also a block, so the block_depth must be stored *after* block
creation, ensuring a correct block_depth to jump back to when receiving
`.repeat`.

This also un-regresses `switch_br` which now correctly handles ranges
within cases. It supports it for both jump tables as well as regular
conditional branches.
2024-09-01 18:30:31 +01:00
mlugg
3b52e5a221
std.zig.render: fix switch rendering 2024-09-01 18:30:31 +01:00
mlugg
0cc8435a83
std.zig: resolve syntactic ambiguity
The parse of `fn foo(a: switch (...) { ... })` was previously handled
incorrectly; `a` was treated as both the parameter name and a label.

The same issue exists for `for` and `while` expressions -- they should
be fixed too, and the grammar amended appropriately. This commit does
not do this: it only aims to avoid introducing regressions from labeled
switch syntax.
2024-09-01 18:30:31 +01:00
mlugg
5e12ca9fe3
compiler: implement labeled switch/continue 2024-09-01 18:30:31 +01:00
mlugg
5fb4a7df38
Air: add explicit repeat instruction to repeat loops
This commit introduces a new AIR instruction, `repeat`, which causes
control flow to move back to the start of a given AIR loop. `loop`
instructions will no longer automatically perform this operation after
control flow reaches the end of the body.

The motivation for making this change now was really just consistency
with the upcoming implementation of #8220: it wouldn't make sense to
have this feature work significantly differently. However, there were
already some TODOs kicking around which wanted this feature. It's useful
for two key reasons:

* It allows loops over AIR instruction bodies to loop precisely until
  they reach a `noreturn` instruction. This allows for tail calling a
  few things, and avoiding a range check on each iteration of a hot
  path, plus gives a nice assertion that validates AIR structure a
  little. This is a very minor benefit, which this commit does apply to
  the LLVM and C backends.

* It should allow for more compact ZIR and AIR to be emitted by having
  AstGen emit `repeat` instructions more often rather than having
  `continue` statements `break` to a `block` which is *followed* by a
  `repeat`. This is done in status quo because `repeat` instructions
  only ever cause the direct parent block to repeat. Now that AIR is
  more flexible, this flexibility can be pretty trivially extended to
  ZIR, and we can then emit better ZIR. This commit does not implement
  this.

Support for this feature is currently regressed on all self-hosted
native backends, including x86_64. This support will be added where
necessary before this branch is merged.
2024-09-01 18:30:31 +01:00
mlugg
1b000b90c9
Air: direct representation of ranges in switch cases
This commit modifies the representation of the AIR `switch_br`
instruction to represent ranges in cases. Previously, Sema emitted
different AIR in the case of a range, where the `else` branch of the
`switch_br` contained a simple `cond_br` for each such case which did a
simple range check (`x > a and x < b`). Not only does this add
complexity to Sema, which we would like to minimize, but it also gets in
the way of the implementation of #8220. That proposal turns certain
`switch` statements into a looping construct, and for optimization
purposes, we want to lower this to AIR fairly directly (i.e. without
involving a `loop` instruction). That means we would ideally like a
single instruction to represent the entire `switch` statement, so that
we can dispatch back to it with a different operand as in #8220. This is
not really possible to do correctly under the status quo system.

This commit implements lowering of this new `switch_br` usage in the
LLVM and C backends. The C backend just turns any case containing ranges
entirely into conditionals, as before. The LLVM backend is a little
smarter, and puts scalar items into the `switch` instruction, only using
conditionals for the range cases (which direct to the same bb). All
remaining self-hosted backends are temporarily regressed in the presence
of switch range cases. This functionality will be restored for at least
the x86_64 backend before merge.
2024-09-01 18:30:31 +01:00