15351 Commits

Author SHA1 Message Date
David Rubin
863f74dcd2
comp: rename module to zcu 2024-08-25 15:17:21 -07:00
David Rubin
bb531759bc
coff: remove deprecated Module usages 2024-08-25 15:16:46 -07:00
David Rubin
8d2b495b2a
value: remove deprecated Module usages 2024-08-25 15:16:46 -07:00
David Rubin
80cd53d3bb
sema: clean-up {union,struct}FieldAlignment and friends
My main gripes with this design were that it was incorrectly namespaced, the naming was inconsistent and a bit wrong (`fooAlign` vs `fooAlignment`).

This commit moves all the logic from `PerThread.zig` to use the zcu + tid system that the previous couple commits introduce.
I've organized and merged the functions to be a bit more specific to their own purpose.

- `fieldAlignment` takes a struct or union type, an index, and a Zcu (or the Sema version which takes a Pt), and gives you the alignment of the field at the index.
- `structFieldAlignment` takes the field type itself, and provides the logic to handle special cases, such as externs.

A design goal I had in mind was to avoid using the word 'struct' in the function name, when it worked for things that aren't structs, such as unions.
2024-08-25 15:16:46 -07:00
David Rubin
b4bb64ce78
sema: rework type resolution to use Zcu when possible 2024-08-25 15:16:42 -07:00
Andrew Kelley
849c31a6cc
Merge pull request #21177 from alexrp/elf-coff-conv
`std.{coff,elf}`: Remove the `{MachineType,EM}.toTargetCpuArch()` functions.
2024-08-25 14:49:53 -07:00
mlugg
7d54c62c8a incremental: fix adding/removing aggregate fields
I don't recall why I put these checks here -- they aren't correct. We
can freely recreate a type even if its fields have changed, because we
are going to re-do all type resolution.

The only conditions for recreations are (a) the ZIR index must not be
lost and (b) the number of captures must be the same. These conditions
are permissible because if either is violated, we can guarantee that
analysis of a valid `zirStructDecl` (etc) will never reference this
type (since the ZIR index has just been tracked, and the captures have
just been created based on the ZIR).

Adds a corresponding test case.

Resolves: #21185
2024-08-24 20:30:52 +01:00
Alex Rønne Petersen
5dd2bb525d glibc: Define _IO_stdin_used in start code and reference it in stub asm.
This is necessary to inform the real, non-stub glibc that a program built with
Zig is using a modern `FILE` structure, i.e. glibc 2.1+. This is particularly
important on lesser-used architectures where the legacy code is poorly tested;
for example, glibc 2.40 introduced a regression for the legacy case in the
libio cleanup code, causing all Zig-compiled MIPS binaries to crash on exit.
2024-08-23 11:09:20 -07:00
Alex Rønne Petersen
fb6f5a30b2
link: Rename InvalidCpuArch error to InvalidMachineType. 2024-08-23 19:56:29 +02:00
Alex Rønne Petersen
a69f55a7cc
std.{coff,elf}: Remove the {MachineType,EM}.toTargetCpuArch() functions.
These are fundamentally incapable of producing accurate information for reasons
I've laid out in #20771. Since our only use of these functions is to check that
object files have the correct machine type, and since #21020 made
`std.Target.to{Coff,Elf}Machine()` more accurate, just switch these checks over
to that and compare the machine type tags instead.

Closes #20771.
2024-08-23 19:56:24 +02:00
Alex Rønne Petersen
3fb6e46f6e glibc: Pass -Qunused-arguments when building libc_nonshared.a.
For some platforms, the math-related flags are ignored and produce warnings.
There's nothing we can do about that, so just silence them.
2024-08-23 00:59:06 -07:00
Jacob Young
0a52914355 Elf: all dwarf relocs need to become linker relocs 2024-08-22 20:08:05 -04:00
Jacob Young
17171cdb07 Dwarf: fix big and zero enum values 2024-08-22 20:08:05 -04:00
Jacob Young
f47e1e148e Dwarf: add more childless special cases 2024-08-22 20:08:05 -04:00
Jacob Young
874ad98f7a Dwarf: fix treating big int limbs as signed 2024-08-22 20:08:04 -04:00
Jacob Young
4a132d4bce Type: fix inconsistency between zig fmt and @typeName 2024-08-22 20:08:04 -04:00
Jacob Young
cbaff43b2a Dwarf: add missing var args info on function decls 2024-08-22 19:53:04 -04:00
Jacob Young
31220b50b5 Dwarf: cleanup emitted debug info
* reduce iteration cost by not tracking unused entries
 * avoid emitting unused abbrevs to `.debug_abbrev`
 * get the compiler executable passing `llvm-dwarfdump --verify`
 * make it possible to skip `.debug_line` padding much more quickly
2024-08-22 08:44:08 +02:00
Jakub Konka
7cd1c882c9
Merge pull request #21160 from ziglang/link-thunks-test 2024-08-22 06:59:45 +02:00
Jakub Konka
cbb8093455 macho: emit local symbols for thunks 2024-08-22 00:34:58 +02:00
mlugg
4f437e4d24
translate-c: populate file system inputs on error
Resolves: #20648
2024-08-21 19:13:26 +01:00
mlugg
7bbbbf8ffa compiler: fix losing ZIR instructions in main_struct_inst fields 2024-08-21 16:24:57 +01:00
Jakub Konka
e79ac14ef3 elf: refactor tracking debug section sizes 2024-08-21 10:28:31 +02:00
Jacob Young
db48a78963 Dwarf: ensure stale relocations are deleted 2024-08-21 01:43:22 -04:00
Jakub Konka
b17bbf9e6c elf: fixes after rebase 2024-08-21 01:43:21 -04:00
Jakub Konka
6c731be3a1 elf: allow for concatenating atoms to merge sections 2024-08-21 01:43:21 -04:00
Jakub Konka
6a86a1041c elf: remove obsolete call to Dwarf.resolveRelocs 2024-08-21 01:43:21 -04:00
Jakub Konka
fe6dfd5090 elf: fix emitting cross-section relocs for .debug* sections 2024-08-21 01:43:21 -04:00
Jakub Konka
c4d820b3f1 elf: emit DTPOFF32/DTPOFF64 relocation for .debug* sections 2024-08-21 01:43:21 -04:00
Jakub Konka
d388d555d5 elf: parse and emit Elf relocs for cross section refs for .debug* sections 2024-08-21 01:43:21 -04:00
Jakub Konka
d3d5ed992c elf: emit .rela.debug* sections for relocatable if required 2024-08-21 01:43:21 -04:00
Jakub Konka
517721bbcc elf: start unraveling Dwarf relocs into Elf relocs 2024-08-21 01:43:21 -04:00
Jakub Konka
56e1ae21e4 elf: populate debug atoms on the linker side after Dwarf.flushModule 2024-08-21 01:43:21 -04:00
Jakub Konka
41f2302865 elf: create section symbols and atoms per each ZigObject debug section 2024-08-21 01:43:21 -04:00
Jakub Konka
84105be4df elf: remove unused code 2024-08-21 01:43:21 -04:00
mlugg
a99ad52b36
Sema: register correct dependencies for inline calls
And add a corresponding test case.
2024-08-21 01:30:46 +01:00
mlugg
95fbfde9da
Sema: delete bootstrap compiler bug workaround 2024-08-21 01:30:44 +01:00
mlugg
9cf8a7661f
compiler: handle eval branch quota in memoized calls
In a `memoized_call`, store how many backwards braches the call
performs. Add this to `sema.branch_count` when using a memoized call. If
this exceeds the quota, perform a non-memoized call to get a correct
"exceeded X backwards branches" error.

Also, do not memoize calls which do `@setEvalBranchQuota` or similar, as
this affects global state which must apply to the caller.

Change some eval branch quotas so that the compiler itself still builds correctly.

This commit manually changes a file in Aro which is automatically
generated. The sources which generate the file are not in this repo.
Upstream Aro should make the suitable changes on their end before the
next sync of Aro sources into the Zig repo.
2024-08-21 01:26:55 +01:00
Jacob Young
55864e98e0 x86_64: support more dwarf locations 2024-08-20 15:08:23 -04:00
Jacob Young
eaa227449c Dwarf: fix issues with inline call sites 2024-08-20 15:08:23 -04:00
Jacob Young
62f7276501 Dwarf: emit info about inline call sites 2024-08-20 08:09:33 -04:00
Jacob Young
ef90eb0d4d Dwarf: delete incorrect logic that also has the possibility of crashing 2024-08-20 08:09:33 -04:00
Jacob Young
78dec0a3da Compilation: fix crash saving incremental state 2024-08-20 08:09:33 -04:00
Ian Johnson
0a70455095 Fix handling of empty XDG environment variables
Closes #21132

According to the XDG Base Directory specification
(https://specifications.freedesktop.org/basedir-spec/latest/#variables),
empty values for these environment variables should be treated the same
as if they are unset. Specifically, for the instances changed in this
commit,

> $XDG_DATA_HOME defines the base directory relative to which
> user-specific data files should be stored. If $XDG_DATA_HOME is either
> not set **or empty**, a default equal to $HOME/.local/share should be
> used.

and

> $XDG_CACHE_HOME defines the base directory relative to which
> user-specific non-essential data files should be stored. If
> $XDG_CACHE_HOME is either not set **or empty**, a default equal to
> $HOME/.cache should be used.

(emphasis mine)

In addition to the case mentioned in the linked issue, all other uses of
XDG environment variables were corrected.
2024-08-19 23:30:14 -07:00
Robin Voetter
b4343074d2
replace Compilation.Emit with std.Build.Cache.Path
This type is exactly the same as std.Build.Cache.Path, except for
one function which is not used anymore. Therefore we can replace
it without consequences.
2024-08-19 19:09:12 +02:00
Robin Voetter
43f73af359
fix various issues related to Path handling in the compiler and std
A compilation build step for which the binary is not required could not
be compiled previously. There were 2 issues that caused this:

- The compiler communicated only the results of the emitted binary and
  did not properly communicate the result if the binary was not emitted.

  This is fixed by communicating the final hash of the artifact path (the
  hash of the corresponding /o/<hash> directory) and communicating this
  instead of the entire path. This changes the zig build --listen protocol
  to communicate hashes instead of paths, and emit_bin_path is accordingly
  renamed to emit_digest.

- There was an error related to the default llvm object path when
  CacheUse.Whole was selected. I'm not really sure why this didn't manifest
  when the binary is also emitted.

  This was fixed by improving the path handling related to flush() and
  emitLlvmObject().

In general, this commit also improves some of the path handling throughout
the compiler and standard library.
2024-08-19 19:09:11 +02:00
Matthew Lugg
54e48f7b7d
Merge pull request #21128 from mlugg/incremental
incremental: more progress
2024-08-19 06:30:54 +01:00
Andrew Kelley
c6677be53b llvm: disable instrumentation in naked functions
closes #21130
2024-08-18 20:36:27 -07:00
mlugg
de49a9a173
Zir: add instructions to fetch std.builtin types
This replaces the constant `Zir.Inst.Ref` tags (and the analagous tags
in `Air.Inst.Ref`, `InternPool.Index`) referring to types in
`std.builtin` with a ZIR instruction `extended(builtin_type(...))` which
instructs Sema to fetch such a type, effectively as if it were a
shorthand for the ZIR for `@import("std").builtin.xyz`.

Previously, this was achieved through constant tags in `Ref`. The
analagous `InternPool` indices began as `simple_type` values, and were
later rewritten to the correct type information. This system was kind of
brittle, and more importantly, isn't compatible with incremental
compilation of std, since incremental compilation relies on the ability
to recreate types at different indices when they change. Replacing the
old system with this instruction slightly increases the size of ZIR, but
it simplifies logic and allows incremental compilation to work correctly
on the standard library.

This shouldn't have a significant impact on ZIR size or compiler
performance, but I will take measurements in the PR to confirm this.
2024-08-18 18:10:59 +01:00
mlugg
b745fee1f8
frontend: handle incremental updates of replaced runtime functions 2024-08-18 18:10:59 +01:00