Commit Graph

85 Commits

Author SHA1 Message Date
The rustc-josh-sync Cronjob Bot
e36d827a4e Merge ref 'd36f96412516' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: d36f964125
Filtered ref: 92461731ae79cfe5044e4826160665b77c0363a2

This merge was created using https://github.com/rust-lang/josh-sync.
2025-08-28 04:13:43 +00:00
Paul Murphy
64cbe52849 Allow linking a prebuilt optimized compiler-rt builtins library
Extend the <target>.optimized-compiler-builtins bootstrap option to accept a
path to a prebuilt compiler-rt builtins library, and update compiler-builtins
to enable optimized builtins without building compiler-rt builtins.
2025-08-25 16:08:35 -05:00
Stefan Schindler
ca7a0aff74 Fix some typos 2025-08-19 23:03:18 +00:00
Trevor Gross
ba5def8a85 Add __addhf3, __subhf3, __mulhf3, __{eq,ge,gt,le,lt,ne,unord}hf2
LLVM does not currently emit these, but it is being discussed as an
option on platforms where `f32` is not hardware supported. Glibc/libgcc
also has the comparison functions [1] already.

The generic implementations for addition, subtraction, and
multiplication work for f16 without any complications, as do
comparisons, so add them here.

[1]: https://sourceware.org/git/?p=glibc.git;a=commit;h=6ec6c77867af4ddfec7323e0ac6ede89effca852
2025-08-09 15:47:10 -05:00
The rustc-josh-sync Cronjob Bot
bf8487827d Merge ref 'ffb9d94dcf4a' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: ffb9d94dcf
Filtered ref: 2f31646593733abae36e4c05b5a54acfb9f1f6bc

This merge was created using https://github.com/rust-lang/josh-sync.
2025-08-09 01:55:44 +00:00
Trevor Gross
0a1e0c65ec Rollup merge of #144974 - tgross35:update-builtins, r=tgross35
compiler-builtins subtree update

Subtree update of `compiler-builtins` to 87a66ec969.

Created using https://github.com/rust-lang/josh-sync.

r? ``@ghost``
2025-08-07 19:36:37 -05:00
Trevor Gross
36ec648e0a Remove instances of allow(improper_ctypes)
i128/u128 haven't flagged `improper_ctypes` for a while, and this just
made it to stable [1]. Remove the `allow`s as they are no longer needed.

[1]: https://blog.rust-lang.org/2025/08/07/Rust-1.89.0/#i128-and-u128-in-extern-c-functions
2025-08-07 12:31:22 -05:00
Trevor Gross
fbc700f92b configure: Use CARGO_CFG_*_{F16,F128} rather than invoking rustc
Currently we run the `rustc` from the `RUSTC` environment variable to
figure out whether or not to enable `f16` and `f128`, based on the
`target_has_reliable_{f16,f128}` config. However, this does not know
about the codegen backend used, and the backend isn't trivial to check
in a build script (usually it gets set via `RUSTFLAGS`).

It turns out we don't actually need to run `rustc` here: Cargo
unconditionally emits all config from the relevant compiler as
`CARGO_CFG_*` variables, regardless of whether or not they are known
options. Switch to checking these for setting config rather than
invoking `rustc`.

As an added advantage, this will work with target.json files without any
special handling.

Fixes: ed17b95715dd ("Use the compiler to determine whether or not to enable `f16` and `f128`")
2025-08-05 21:17:03 +00:00
Paul Murphy
3b50253b57 compiler-builtins: plumb LSE support for aarch64 on linux
Add dynamic support for aarch64 LSE atomic ops on linux targets
when optimized-compiler-builtins is not enabled.

A hook, __enable_rust_lse, is provided for the runtime to enable
them if available. A future patch will use this to enable them
if available.

The resulting asm should exactly match that of LLVM's compiler-rt
builtins, though the symbol naming for the support function and
global does not.
2025-08-05 10:30:38 -05:00
Trevor Gross
16cb37c957 Remove no-asm gating when there is no alternative implementation
Assembly-related configuration was added in 1621c6dbf9eb ("Use
`specialized-div-rem` 1.0.0 for division algorithms") to account for
Cranelift not yet supporting assembly. This hasn't been relevant for a
while, so we no longer need to gate `asm!` behind this configuration.
Thus, remove `cfg(not(feature = "no-asm"))` in places where there is no
generic fallback.

There are other cases, however, where setting the `no-asm` configuration
enables testing of generic version of builtins when there are platform-
specific implementations available; these cases are left unchanged. This
could be improved in the future by exposing both versions for testing
rather than using a configuration and running the entire testsuite
twice.

This is the compiler-builtins portion of
https://github.com/rust-lang/rust/pull/144471.
2025-07-27 16:39:31 -05:00
Trevor Gross
9dad77f337 Use x86_no_sse configuration in more places
Emit `x86_no_sse` in the compiler-builtins (and builtins-test) build
script, and use it to simplify `all(target_arch = "x86",
not(target_fefature = "sse))` configuration.
2025-07-24 19:37:45 +00:00
The rustc-josh-sync Cronjob Bot
3f04631ce0 Merge ref '82310651b93a' from rust-lang/rust
Pull recent changes from https://github.com/rust-lang/rust via Josh.

Upstream ref: 82310651b9
Filtered ref: e13c0be8f13737c64082b89ce834546079767ac4

This merge was created using https://github.com/rust-lang/josh-sync.
2025-07-18 19:06:49 +00:00
Julien THILLARD
6b87978169 Change the memcmp and bcmp return type to c_int
Fix the return type of `memcmp` and `bcmp` builtin functions on targets
with a `c_int` other than `i32`.

Linked issue: https://github.com/rust-lang/rust/issues/144076
2025-07-18 18:19:13 +00:00
Trevor Gross
7dacaef5d3 mem: Use core::ffi::c_int
This alias was added in 9897bfb8a ("Fix memset arguments for MSP430
target"), which predates `core::ffi`. Now that it exists we can just use
`core::ffi::c_int`.
2025-07-18 17:35:57 +00:00
Matthias Krüger
6c4502d97d Rollup merge of #143660 - cuviper:lib-doc-false, r=tgross35
Disable docs for `compiler-builtins` and `sysroot`

Bootstrap already had a manual doc filter for the `sysroot` crate, but
other library crates keep themselves out of the public docs by setting
`[lib] doc = false` in their manifest. This seems like a better solution
to hide `compiler-builtins` docs, and removes the `sysroot` hack too.

Fixes rust-lang/rust#143215 (after backport)
```@rustbot``` label beta-nominated
2025-07-10 20:28:50 +02:00
Josh Stone
87e7539fcd Disable docs for compiler-builtins and sysroot
Bootstrap already had a manual doc filter for the `sysroot` crate, but
other library crates keep themselves out of the public docs by setting
`[lib] doc = false` in their manifest. This seems like a better solution
to hide `compiler-builtins` docs, and removes the `sysroot` hack too.
2025-07-08 16:59:44 -07:00
Trevor Gross
016bc61312 Test building custom targets and resolve an issue probing rustc
The `rustc` probe done in our build scripts needs to pass `--target` to
get the correct configuration, which usually comes from the `TARGET`
environment variable. However, for targets specified via a `target.json`
file, `TARGET` gets set to the file name without an extension or path.
`rustc` will check a search path to attempt to locate the file, but this
is likely to fail since the directory where Cargo invokes build scripts
(and hence where those scripts invoke `rustc`) might not have any
relation to the JSON spec file.

Resolve this for now by leaving `f16` and `f128` disabled if the `rustc`
command fails. Result of the discussion at CARGO-14208 may eventually
provide a better solution.

A CI test is also added since custom JSON files are an edge case that
could fail in other ways. I verified this fails without the fix here.
The JSON file is the output for `thumbv7em-none-eabi`, just renamed so
`rustc` doesn't identify it.
2025-07-04 21:09:56 -05:00
Trevor Gross
be35d37d8b Use the compiler to determine whether or not to enable f16 and f128
Currently we whether or not to build and test `f16` and `f128` support
mostly based on the target triple. This isn't always accurate, however,
since support also varies by backend and the backend version.

Since recently, `rustc` is aware of this with the unstable config option
`target_has_reliable_{f16,f128}`, which better represents when the types
are actually expected to be available and usable. Switch our
compiler-builtins and libm configuration to use this by probing `rustc`
for the target's settings.

A few small `cfg` fixes are needed with this.
2025-07-02 01:18:54 -05:00
Folkert de Vries
962ff16101 Use asm_cfg in probestack
cc https://www.github.com/rust-lang/rust/issues/140364
2025-06-24 14:40:08 -04:00
Folkert de Vries
a413cca7d3 use extern "custom" on naked functions with a custom calling convention 2025-06-14 18:17:23 +00:00
Folkert de Vries
3dc3017691 use is_multiple_of to check if an addr is aligned 2025-06-14 13:10:25 -04:00
Trevor Gross
7222fa6f34 Work around out-of-tree testing with a shim crate
Out-of-tree testing is broken with the most recent update from
rust-lang/rust because it makes `compiler-builtins` depend on `core` by
path, which isn't usually available. In order to enable testing outside
of rust-lang/rust, add a new crate `builtins-shim` that uses the same
source as `compiler-builtins` but drops the `core` dependency. This has
replaced `compiler-builtins` as the workspace member and entrypoint for
tests.
2025-06-14 06:56:18 +00:00
Trevor Gross
c1cd1ef5fc Merge ref 'd087f112b7d1:/library/compiler-builtins' from https://github.com/rust-lang/rust
Pull recent changes from rust-lang/rust via Josh.

Upstream ref: d087f112b7
Filtered ref: 2d43ce8ac022170e5383f7e5a188b55564b6566a
2025-06-14 06:56:04 +00:00
Trevor Gross
19b47ae1f4 Mark compiler-builtins as publish = false
Now that this repository is a subtree, we have no need to continue
publishing `compiler-builtins`.
2025-06-13 18:15:18 +00:00
Trevor Gross
509b8f2291 Clean up and sort manifest keys
Use a consistent ordering for top-level manifest keys, and remove those
that are now redundant (`homapage` isn't supposed to be the same as
`repository`, and `documentation` automatically points to docs.rs now).
2025-06-13 17:35:21 +00:00
qinghon
013e06c5ff Eliminate build.rs-generated Aarch64 atomic macros (#951)
Replace `build.rs` Rust generation with macros, using the unstable
`${concat(...)}`.

Fixes: https://github.com/rust-lang/compiler-builtins/issues/947
2025-06-13 01:27:47 -04:00
Folkert de Vries
b030442eb6 indent the probestack inline assembly 2025-06-10 10:09:00 +02:00
Folkert de Vries
45d649e2ea merge the sgx/fortanix __rust_probestack into the general x86_64 one 2025-06-10 10:09:00 +02:00
Folkert de Vries
b6eb4f9c3a use #[naked] for __rust_probestack 2025-06-10 10:08:57 +02:00
Folkert de Vries
f3af86010b add a fixme to use extern_custom when available 2025-06-10 10:08:08 +02:00
Trevor Gross
3497619ec1 compiler-builtins: Remove unused lints.rust table
The unexpected configs are now unused or known to `rustc` in our CI.
2025-06-10 06:49:28 +00:00
Trevor Gross
fc71544932 compiler-builtins: Emit rustc-check-cfg earlier
The `build.rs` entrypoint returns early for some targets, so emscripten
and OpenBSD were not getting check-cfg set. Emit these earlier to avoid
the `unexpected_cfgs` lint.
2025-06-09 04:46:54 +00:00
Trevor Gross
f131c2fa47 compiler-builtins: Specify :r registers for usize
On the ILP32 `x86_64-unknown-linux-gnux32` target, `usize` is 32 bits so
there is a sub-register alignment warning. Specify the 64-bit `r`
registers, which matches the current default as well as the size of the
other operands in the routines.
2025-06-09 04:46:54 +00:00
Trevor Gross
58bef69b81 compiler-builtins: Resolve unsafe_op_in_unsafe_fn on Arm32 Android
There are a few places that violate this lint, which showed up in
rust-lang/rust CI (the relevent module is gated behind
`kernel_user_helpers` which is only set for `armv4t`, `armv5te`, and
`arm-linux-androideabi`; none of these are tested in compiler-builtins
CI). Add new `unsafe { /* ... */ }` blocks where needed to address this.

Some blocks should get a more thorough review of their preconditions, so
their safety comments are left as `FIXME`s.
2025-06-09 04:46:52 +00:00
Trevor Gross
f43bb2ac99 compiler-builtins: Fix a rustdoc::bare-urls error 2025-06-08 02:36:58 +00:00
Trevor Gross
cc3e57147e Use the in-tree compiler-builtins
Many of `std`'s dependency have a dependency on the crates.io
`compiler-builtins` when used with the feature
`rustc-std-workspace-core`. Use a Cargo patch to select the in-tree
version instead.

`compiler-builtins` is also added as a dependency of
`rustc-std-workspace-core` so these crates can remove their crates.io
dependency in the future.
2025-06-08 02:36:58 +00:00
Trevor Gross
ab453db3c4 panic-handler: Remove the no_core feature
This was introduced before `#[panic_handler]` was stable, but should no
longer be needed. Additionally, we only need it for
`builtins-test-intrinsics`, not as a dependency of `compiler-builtins`.
2025-06-04 21:27:00 +00:00
Trevor Gross
1599091459 Merge ref 'df8102fe5f24:/library/compiler-builtins' from https://github.com/rust-lang/rust
Pull recent changes from rust-lang/rust via Josh.

Upstream ref: df8102fe5f
Filtered ref: 3c30d8cb1ec24e0b8a88a5cedcf6b9bece0117d7
2025-06-04 18:10:09 +00:00
Trevor Gross
aff21f659f compiler-builtins: Eliminate symlinks
compiler-builtins has a symlink to the `libm` source directory so the
two crates can share files but still act as two separate crates. This
causes problems with some sysroot-related tooling, however, since
directory symlinks seem to not be supported.

The reason this was a symlink in the first place is that there isn't an
easy for Cargo to publish two crates that share source (building works
fine but publishing rejects `include`d files from parent directories, as
well as nested package roots). However, after the switch to a subtree,
we no longer need to publish compiler-builtins; this means that we can
eliminate the link and just use `#[path]`.

Similarly, the LICENSE file was symlinked so it could live in the
repository root but be included in the package. This is also removed as
it caused problems with the dist job (error from bootstrap's
`tarball.rs`, "generated a symlink in a tarball").

If we need to publish compiler-builtins again for any reason, it would
be easy to revert these changes in a preprocess step.
2025-06-02 23:59:11 +00:00
Trevor Gross
0a7e59265a Upgrade all dependencies to the latest available version
In particular, this includes a fix to `iai-callgrind` that will allow us
to simplify our benchmark runner.
2025-06-01 19:57:14 +00:00
github-actions[bot]
3c35505fe9 chore: release 2025-05-30 15:18:27 +00:00
Trevor Gross
151b1cb047 Change compiler-builtins to edition 2024
Do the same for `builtins-test-intrinsics`. Mostly this means updating
`extern` to `unsafe extern`, and fixing a few new Clippy lints.
2025-05-29 16:12:33 +00:00
Trevor Gross
97c0bebdf7 Remove unneeded C symbols
These are now provided by `compiler-builtins`, so there is no need to
also build the C versions. This was detected by checking for duplicate
symbols and not excluding weak symbols (like CI currently does).
2025-05-29 15:38:10 +00:00
Trevor Gross
877feef541 Reuse libm's Caat and CastFrom in compiler-builtins 2025-05-29 03:56:08 +00:00
Trevor Gross
851aa05aa0 cleanup: Reuse MinInt and Int from libm in compiler-builtins
Since the two crates are now in the same repo, it is easier to share
code. Begin some deduplication with the integer traits.
2025-05-29 03:04:59 +00:00
Trevor Gross
4c264c96ae Update CmpResult to use a pointer-sized return type
As seen at [1], LLVM uses `long long` on LLP64 (to get a 64-bit integer
matching pointer size) and `long` on everything else, with exceptions
for AArch64 and AVR. Our current logic always uses an `i32`. This
happens to work because LLVM uses 32-bit instructions to check the
output on x86-64, but the GCC checks the full 64-bit register so garbage
in the upper half leads to incorrect results.

Update our return type to be `isize`, with exceptions for AArch64 and
AVR.

Fixes: https://github.com/rust-lang/compiler-builtins/issues/919

[1]: 0cf3c437c1/compiler-rt/lib/builtins/fp_compare_impl.inc (L11-L27)
2025-05-28 02:58:42 -04:00
beetrees
11c1522955 Enable __powitf2 on MSVC 2025-05-21 19:24:24 +02:00
Tobias Decking
d16c82dba1 Fix i256::MAX 2025-05-13 15:01:51 +02:00
github-actions[bot]
65663b538f chore(compiler_builtins): release v0.1.159 2025-05-12 16:37:12 +02:00
nora
c4c7f25c4c Remove cfg(bootstrap)
Foe the  bootstrap bump
2025-05-12 16:26:35 +02:00