31900 Commits

Author SHA1 Message Date
mlugg
3aab81b0ab Builtin: clean up formatting of generated code
This commit simply tweaks the generated `builtin.zig` source code to be
more consistent and in line with current conventions.
2024-12-09 17:35:10 -05:00
Alex Rønne Petersen
b94bb6f96f std.Target: Remove our broken support for the ancient and obsolete Arm OABI.
NetBSD has long since migrated to the EABI and doesn't officially support the
OABI anymore. The ABI selection logic in LLVM only actually picks OABI for
NetBSD as a last resort if the EABI isn't selected. That fallback is likely to
be removed in the future. So just remove this support in Zig entirely.

While here, I also removed some leftover 32-bit Arm and 32-bit x86 code for
Apple targets, which are long dead and unsupported by Zig.
2024-12-09 10:47:18 +01:00
Alex Rønne Petersen
7cd2c1ce87
Merge pull request #22191 from alexrp/wasi-libc-names
`std.zig.target`: Teach `isLibCLibName()` about emulated wasi-libc libraries
2024-12-09 10:46:56 +01:00
Alex Rønne Petersen
589f4e9170
Merge pull request #22190 from alexrp/cc-args
`Compilation`: Don't rely on Clang defaults for options that are user-facing.
2024-12-09 10:46:31 +01:00
Alex Rønne Petersen
c9e74bb9aa
std.zig.target: Teach isLibCLibName() about emulated wasi-libc libraries. 2024-12-08 20:23:58 +01:00
Alex Rønne Petersen
f283791a5e
compiler: Link libc when we're asked to link to an emulated wasi-libc library. 2024-12-08 20:22:13 +01:00
Alex Rønne Petersen
1e095024a7
compiler: Check for wasi-libc emulated libraries before libc libraries.
This will become useful when we update wasi-libc and get the emulated libdl.
2024-12-08 20:20:54 +01:00
Alex Rønne Petersen
92117d9bef
std.zig.target: Remove duplicate libc check for macOS in isLibCLibName(). 2024-12-08 20:18:01 +01:00
wooster0
a221b2fbf2 Sema: fix use of Zcu.LazySrcLoc in error message
It currently prints as:

:3:18: error: untagged union 'Zcu.LazySrcLoc{ .base_node_inst = InternPool.TrackedInst.Index(104), .offset = Zcu.LazySrcLoc.Offset{ .node_offset = Zcu.LazySrcLoc.Offset.TracedOffset{ .x = -2, .trace = (value tracing disabled) } } }' cannot be converted to integer
2024-12-08 17:23:57 +00:00
Alex Rønne Petersen
6951ee43bf
Compilation: Don't rely on Clang defaults for options that are user-facing. 2024-12-08 16:53:55 +01:00
Alex Rønne Petersen
8d9ff8353d
compiler: Update the list of targets that have a red zone. 2024-12-08 16:52:44 +01:00
Alex Rønne Petersen
e62aac3ec4 compiler: Only omit frame pointers by default for ReleaseSmall.
Frame pointers make both debugging and profiling work better, and the overhead
is reportedly 1% or less for typical programs [0]. I think the pros outweigh the
cons here. People who *really* care about that 1% can simply use the
-fomit-frame-pointer option to reclaim it. For ReleaseSmall, though, it makes
sense to omit frame pointers by default for the sake of code size, as we already
strip the binary in this case anyway.

Closes #22161.

[0] https://www.brendangregg.com/blog/2024-03-17/the-return-of-the-frame-pointers.html
2024-12-08 04:18:12 -05:00
Alex Rønne Petersen
ba37a4369b std.zig.WindowsSdk: Support cross-arch SDK lookups.
This makes e.g. cross-compiling for x86-windows-msvc on a x86_64-windows-msvc
system work properly.

Closes #11926.
2024-12-08 04:53:28 +01:00
Alex Rønne Petersen
1f95e3d9cd build.zig: Also set code model for loongarch32.
This issue applies to both loongarch32 and loongarch64.
2024-12-07 22:21:35 +01:00
Alex Rønne Petersen
4894ac4bcb
Merge pull request #22130 from alexrp/zig-h-portability
Some portability improvements and cleanups in `zig.h`
2024-12-07 12:11:57 +01:00
Andrew Kelley
eb9c9a38f2
Merge pull request #22167 from alexrp/compiler-rt-names
compiler: Classify various compiler-rt and libunwind names accurately and satisfy them
2024-12-06 19:04:39 -05:00
Alex Rønne Petersen
ca069244b2 std.Target: Fix charSignedness() for hexagon. 2024-12-06 18:15:29 +01:00
Alex Rønne Petersen
8f27fc6c07
compiler: Classify libssp as an alias for compiler-rt.
This is a GCC library providing symbols with stack smashing protection. We
provide (most of) these symbols in our compiler-rt.
2024-12-06 15:10:37 +01:00
Alex Rønne Petersen
65cfc91836
std.zig.target: Consider libsupc++ to be a libc++ library name.
This is, roughly, GCC's equivalent of libc++abi.
2024-12-06 15:08:43 +01:00
Alex Rønne Petersen
da794ec7a3
compiler: Remove warning about superfluous compiler-rt libraries.
* This warning's wording is actually inaccurate when using the -fno-compiler-rt
  or -rtlib=none options.
* It's not all that helpful; it's already understood that these libraries are
  part of the compiler, so printing a warning is just noise. In practice, this
  warning would always happen when building upstream musl, for example.
* We don't warn when we satisfy -lunwind using our bundled libunwind either, or
  various libc libraries using our bundled libc, or when providing libc++, etc.
  So I really don't think we should be warning here either.
2024-12-06 14:57:22 +01:00
Alex Rønne Petersen
a879c3ea0b
compiler: Classify libgcc as an alias for compiler-rt.
This is GCC's equivalent to compiler-rt. The two libraries have a huge overlap
in exported symbols, so we may as well satisfy it this way to increase
compatibility with build systems in the wild.
2024-12-06 14:57:22 +01:00
Alex Rønne Petersen
e7169e9d4d
compiler: Classify libgcc_eh as an alias for libunwind.
This is GCC's take on libunwind. We can satisfy it by way of our bundled LLVM
libunwind implementation.

Closes #17268.
2024-12-06 14:57:22 +01:00
Alex Rønne Petersen
37a34b54af
compiler: Recognize libgcc_s regardless of target ABI.
The real libgcc_s is a compiler-provided library; it works just fine with both
glibc and musl. There's no reason that I can see for this check to be limited to
glibc-based targets.
2024-12-06 14:57:19 +01:00
Alex Rønne Petersen
f8372d030e
compiler: Classify libatomic as an alias for compiler-rt.
This is a library that ships with GCC and provides fallback implementations of
atomic intrinsics where necessary. Since we do the same in our compiler-rt
implementation, and since some build systems insist on passing -latomic even
for Clang (which zig cc masquerades as), just satisfy this dependency by way of
compiler-rt.

Closes #22165.
2024-12-06 14:51:22 +01:00
Alex Rønne Petersen
cbc05e0b1d Compilation: Consider *.rlib files to be static libraries.
These are produced by rustc: https://rustc-dev-guide.rust-lang.org/backend/libs-and-metadata.html#rlib
2024-12-05 15:05:55 +01:00
Alex Rønne Petersen
d70be200d8
Merge pull request #22141 from alexrp/target-remove-bridgeos
`std.Target`: Remove `Os.Tag.bridgeos`
2024-12-05 15:05:25 +01:00
Frank Denis
c9d6f8b505
Remove parallel variants of AEGIS-MAC (#22146)
The construction is likely to change before standardization
2024-12-04 22:45:07 +00:00
Alex Rønne Petersen
4e29c67eed
llvm: Remove dead targetArch() and targetOs() functions.
These were leftovers from when we used the LLVM API to create modules.
2024-12-03 20:43:20 +01:00
Alex Rønne Petersen
09b39f77b7
std.Target: Remove Os.Tag.bridgeos.
It doesn't appear that targeting bridgeOS is meaningfully supported by Apple.
Even LLVM/Clang appear to have incomplete support for it, suggesting that Apple
never bothered to upstream that support. So there's really no sense in us
pretending to support this.
2024-12-03 20:43:15 +01:00
Alex Kladov
6188cb8e50 sema: add a missing errdefer
This fix doesn't matter at all in the grand scheme of things, but I
think the story behind it is perhaps curious, as it might point at a
design flaw in the Sema's error reporting API. So, a story:

On lobsters, there's a rather heated discussion on the merits on RAII vs
defer. I don't really like participating in heating discussions, but
also sort of can't stop thinking about this.

My own personal experience with Zig's defer and errdefer is that they
are fiddly to get right consistency --- if a program has a lot of
resource management to do, I _always_ mess up at least one
defer/errdefer. I've found my internal peace by just avoiding
spread-out, "pox" resource management, and instead centralizing resource
ownership under one of the following patterns:

* Either the thing is acquired and released in main
* Or main allocates N instances of thing, and then the rest of the code
  explicitly juggles this finite pool of N. Notably, this juggling
  typically doesn't involve defer/errdefer at all, as, at this level of
  precision, there are no `try`s left, so you only code the happy path
* Or there's some sort of arena thing, where a bunch of resources have a
  single owner, the user's don' bother cleaning up their resources, and
  instead the owner does it once at the end.

So I wanted to make a lobster.rs comment in the vein of "yeah, if your
program is mostly about resource management, then Zig could be kinda a
pain, but that's friction tells you something: perhaps your program
shouldn't be about resource management, and instead it should be doing
what it is supposed to do?". And, as an evidence for my claim, I wanted
to point out some large body of Zig code which doesn't have a lot of
errdefers.

So, I cracked opened Sema.zig, `ctrl+f` for `defer`, saw whopping 400
something occupancies, and my heart skipped a bit. Looking at the
occurrences, _some_ of them were non-resource-related usages of defer.
But a lot of them were the following pattern:

```zig
const msg = try sema.errMsg(src, "comptime control flow inside runtime block", .{});
errdefer msg.destroy(sema.gpa);
```

This is exactly the thing that I know _I_ can't get right consistently!
So, at this point, I made a prediction that at least one of `errdefer`s
is missing. So, I looked at the first few `const msg = try` and of
course found one without `errdefer`.

I am at 0.8 that, even with this PR applied, the claim will still stand
--- there will be `errdefer` missing. So it feels like some API
re-design is in order, to make sure individual error messages are not
resources.

Could Sema just own all partially-constructed error messages, and, at a
few known safe-points:

* if the control flow is normal, assert that there are no in-progress
  error messages
* if we are throwing an error, go and release messages immediately?

I am unlikely to do the actual refactor here, but I think it's worth
highlighting the overall pattern here.

PS: I am only 0.9 sure that what I've found is indeed a bug! I don't
understand the code, I did a dumb text search, so I _could_ have made a
fool of myself here :P
2024-12-03 14:18:26 -05:00
Alex Rønne Petersen
c27488a387
zig.h: Add zig_gnuc_asm macro to indicate availability of GNU-style inline asm. 2024-12-03 12:11:05 +01:00
Alex Rønne Petersen
f058b147d3
zig.h: Introduce operating system macros. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
084ec97811
zig.h: Introduce object format macros. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
ace8396076
zig.h: Move some macros and includes closer to where they're used. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
0e934c7df1
zig.h: Use C99/C11 headers if available regardless of language standard.
If present, these headers are usable even when compiling for older C language
versions.

Most notably, this enables zig.h atomics to work with slimcc and TinyCC in C99
mode (and earlier).
2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
1c43c2c209
zig.h: Remove duplicate and unguarded stdint.h include.
We already do this for C99 only later in the file.
2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
125bf05c27
zig.h: Implement zig_unreachable() with __assume(0) for MSVC. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
062feb6c82
zig.h: Implement zig_frame_address() with _AddressOfReturnAddress() for MSVC. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
37538f19cd
zig.h: Use zig_*_windows_teb() inline assembly with TinyCC and slimcc. 2024-12-03 12:07:34 +01:00
Alex Rønne Petersen
204df19d79
zig.h: Avoid depending on cpuid.h for zig_x86_cpuid().
Just use inline assembly instead, which is what that header does. Also make sure
we have a dummy implementation when inline assembly is unavailable.
2024-12-03 12:07:32 +01:00
Alex Rønne Petersen
24b57f4d30
zig.h: Introduce architecture macros to simplify checks throughout. 2024-12-03 11:57:21 +01:00
Alex Rønne Petersen
ba66814185
zig.h: Don't use __debugbreak() for MinGW.
It seems like only Clang supports this in MinGW mode, and Clang will already
take the __builtin_debugtrap() path anyway.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
d19e1919da
zig.h: Define zig_gnuc for both GCC and Clang and stop using __GNUC__.
There's only one spot in the header where we want to handle GCC but not Clang,
so just add an extra check there.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
dd1d9cce3c
zig.h: Add a zig_msvc macro to be used instead of _MSC_VER. 2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
f29daebd90
zig.h: Use __thread for slimcc in pre-C11 mode. 2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
fa6946f645
zig.h: Add support for C23 keywords.
The old spellings from C11 are deprecated in C23.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
023a7fefb1
zig.h: Add TinyCC support where appropriate.
tcc doesn't have __has_attribute and __has_builtin, so we need to manually check
for tcc in these preprocessor paths.
2024-12-03 11:57:20 +01:00
Alex Rønne Petersen
43a1b88bc8
zig.h: Use __BYTE_ORDER__ instead of __LITTLE_ENDIAN__ for endianness check.
The former is supported by most compilers while the latter is Clang-only.
2024-12-03 11:57:20 +01:00
Andrew Kelley
4e09e363cd
Merge pull request #21720 from kubkon/macho-dwarf-v5
macho: add basic handling of DWARFv5
2024-12-03 02:28:22 -05:00
Jakub Konka
29c7f6810f macho: fix 32bit builds 2024-12-02 22:05:21 -05:00