Commit Graph

202 Commits

Author SHA1 Message Date
王宇逸
f5f09d2f4b Add cygwin support
Co-authored-by: Ookiineko <chiisaineko@protonmail.com>
2025-03-05 01:17:50 -05:00
Nikita Popov
ececfaba78 Don't build out of line atomics support code for uefi
https://github.com/llvm/llvm-project/pull/116706 added Windows
support to cpu_model. Compiling for UEFI also goes through that
code path, because we treat it as a windows target. However,
including windows.h is not actually going to work (and the used
API would not be available in an UEFI environment).

Disable building of cpu_model on UEFI to fix this.
2025-01-28 14:06:54 -06:00
Trevor Gross
83a61e67fd Account for optimization levels other than numbers
The build script currently panics with `opt-level=z` or `opt-level=s`.
Account for this here.

This is the `compiler-builtins` version of [1].

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

[1]: https://github.com/rust-lang/libm/pull/417
2025-01-07 18:13:04 -05:00
Trevor Gross
f4f942c3e9 Update the libm submodule 2025-01-06 19:17:41 -05:00
Trevor Gross
fbd6907358 Add integer to f128 conversions 2024-10-30 12:25:24 -05:00
Alan Wu
3f70601e3c Allow implicit function decl on A64
Testing in <https://github.com/rust-lang/rust/pull/131221>, we found
that <https://github.com/rust-lang/compiler-builtins/pull/627> is
unusable with the current LLVM version.
2024-10-04 12:33:16 -04:00
Alan Wu
edc6f80dcc Build with -Werror=implicit-function-declaration
To prevent fail-fast in situations like
https://github.com/rust-lang/rust/issues/125619, where an upstream
source compiles but creates a link error way downstream.
2024-10-03 11:24:49 -04:00
Trevor Gross
606d971958 Add support for f128 integer exponentiation
Create the symbol `__powitf2`.
2024-09-28 11:06:33 -04:00
Trevor Gross
764a177497 Add f128 division
Use the new generic division algorithm to expose `__divtf3` and
`__divkf3`.
2024-09-24 18:32:58 +02:00
Trevor Gross
db9debf096 Apply fixes to build.rs files
Make the following changes:

- Add `rerun-if-changed` to the new `configure.rs`, it seems this was
  causing incorrect caching.
- Change from matching `i686` to `x86`. The target triple starts with
  `i686` so that is what we were checking before, but the architecture
  is `x86`. This change should have been made when we added `struct
  Target`, update it now instead.
2024-08-19 07:04:07 -05:00
Kleis Auke Wolthuizen
13cc7daf05 Fix CI for targets that conditionally disable f16 or f128 support 2024-08-12 14:56:59 +02:00
Kleis Auke Wolthuizen
5dad727bdc Configure f16 and f128 support for WebAssembly 2024-08-11 17:25:55 +02:00
Guillaume Gomez
145143a0b7 Activate force-soft-floats feature in build.rs 2024-08-08 14:09:07 +02:00
Trevor Gross
5a4ccab866 Fix emscripten as os rather than env.
b7af6078 ("Switch to a target structure...") is checking whether the
target environment is emscripten, but it seems emscripten is the OS. Fix
this, which should resolve the issue in
<https://github.com/rust-lang/rust/pull/128691#issuecomment-2269933428>.
2024-08-05 16:26:27 -05:00
Trevor Gross
b168f56dd4 Configure which platforms get f16 and f128 enabled by default
By moving the logic for which platforms get symbols to
`compiler_builtins` rather than rust-lang/rust, we can control where
symbols get enabled without relying on Cargo features. Using Cargo
features turned out to be a problem in [1].

This will help resolve errors like [2].

[1]: https://github.com/rust-lang/rust/issues/128358
[2]: https://github.com/rust-lang/rust/issues/128401
2024-08-03 02:02:44 -04:00
Trevor Gross
22e4aa37da Switch to a target structure in build.rs 2024-08-03 02:02:41 -04:00
Andrey Turkin
adabbe73d9 Implement __ctz*i2 intrinsics 2024-07-25 19:26:02 +03:00
Andrey Turkin
cc64c7978e Never use C version of clz builtins 2024-07-24 12:50:04 +01:00
Andrey Turkin
a5c7a17d55 Implement remaining __clz*i2 intrinsics 2024-07-24 12:50:04 +01:00
Andrey Turkin
45465cc488 Implement __bswap[sdt]i2 intrinsics
These can be emitted by gcc, at least if requested specifically via __builtin_bswap{32,64,128}.
2024-07-06 11:51:52 +02:00
Andrey Turkin
98195c0348 Get rid of a warning 2024-07-06 05:19:37 +03:00
Quentin Perez
2fa55c4ef5 Add Apple visionOS support 2024-05-22 09:49:08 +02:00
Trevor Gross
ccd179b231 Add f128 float to integer conversion functions
Add the following:

- `__fixtfsi`
- `__fixtfdi`
- `__fixtfti`
- `__fixunstfsi`
- `__fixunstfdi`
- `__fixunstfti`
2024-05-20 20:01:33 -04:00
Trevor Gross
191c1b88cd Implement f128 multiplication 2024-05-15 07:19:17 -05:00
Trevor Gross
2755f457f8 Implement f128 addition and subtraction 2024-05-15 07:19:17 -05:00
theKidOfArcrania
0ccdd076ae Merge branch 'master' of https://github.com/rust-lang/compiler-builtins 2024-05-14 15:50:50 -07:00
theKidOfArcrania
a5779e5d37 Fix paths for Windows arm64 build 2024-05-13 11:17:07 -07:00
Trevor Gross
f52b4a268f Remove the undocumented and unused rustbuild feature
See
<https://github.com/rust-lang/compiler-builtins/pull/603#discussion_r1590747361>
2024-05-11 09:56:55 +02:00
Trevor Gross
286944e479 Emit directives for cargo-check-cfg 2024-05-11 09:56:55 +02:00
beetrees
229babb1d0 Add builtins for f16/f128 float conversions 2024-05-02 13:49:24 +02:00
Trevor Gross
a55604fd8c Add a way to run tests on non-linux machines
Allow using the `rust-lang/rust:nightly` docker image to run tests in
cases where the host rust and cargo cannot be used, such as non-linux
hosts.
2024-04-19 11:49:23 -04:00
Daniel Paoliello
30182128c9 Add support for arm64ec 2024-03-28 09:20:13 -07:00
WANG Rui
75624cc8ae Add compiler-rt fallbacks on loongarch64-musl 2024-03-28 14:12:16 +00:00
Nikita Popov
168bc9ecd7 Also don't build floatdixf and floatundixf 2024-02-02 10:04:55 +01:00
Nikita Popov
2f8b08f9e3 Remove 80-bit builtins entirely
It turns out that these also don't build on x86 + MSVC. Rather
than fixing up the condition, I'm just deleting them entirely.
As far as I know, Rust does not support 80-bit floats and has
no plan to support them, so we shouldn't need them.
2024-01-31 17:37:26 +01:00
trevyn
f4dbd52ed5
Merge branch 'master' into wasm 2024-01-28 07:20:27 -08:00
Tyler Mandry
45a113effb Handle move of cpu_model.c
This happened in https://github.com/llvm/llvm-project/pull/75635/files
and shows up when building against a recent commit of LLVM.
2024-01-28 11:20:12 +00:00
Nikita Popov
105f0d834d Only add 80-bit long double source on x86
These no longer build on other architectures with LLVM 18. In
previous versions they used an incorrect float layout.
2024-01-22 13:04:44 +01:00
trevyn
d9065480c7
Merge branch 'master' into wasm 2024-01-18 09:36:53 +04:00
trevyn
0808cdeb67 build: Allow building C compiler-rt fallbacks for wasm 2024-01-09 02:11:00 +04:00
Alistair Francis
e898296fd9 build: Allow building C compiler-rt fallbacks for RISC-V
Now that https://github.com/rust-lang/rust/pull/117654 has been merged
the rust-lang/rust distribution containers contain RISC-V C compilers.

This means that we can now enable the "c" feature fallback.

Resolves: https://github.com/rust-lang/compiler-builtins/issues/350
Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
2023-12-20 09:47:37 +10:00
Sebastian Imlay
25fa91e1b2 Add tvOS to build script 2023-10-06 17:35:20 -04:00
James Farrell
6595f36317 Generate outlined_atomics.rs in a deterministic order.
Also add a missing newline.
2023-08-28 22:14:18 +00:00
Sean Cross
10df3f61ad build: compile memory intrinsics on xous
Like SGX, Xous does not have any libc to link against. As a result,
memory intrinsics need to be available as part of `compiler_builtins`

Signed-off-by: Sean Cross <sean@xobs.io>
2023-08-12 07:50:26 +03:00
Taiki Endo
716d2064f0 Fix build error on aarch64_be linux 2023-07-08 14:18:27 +09:00
Joshua Nelson
6242fd629e address review comments and fix CI
- implement CAS 16
- remove useless commented out symbol name
- support `feature("no-asm")`
- fix warnings when `feature("c")` is enabled
- rustfmt
2023-06-26 15:09:37 +00:00
Joshua Nelson
21c821c6c9 Port outline-atomics to rust
This has a very long history, summarized in
https://github.com/rust-lang/rust/issues/109064. This port is a very
minimal subset of `aarch64/lse.S` from LLVM's compiler-rt. In
particular, it is missing the following:

1. Any form of runtime dispatch between LL/SC and LSE.

Determining which version of the intrinsics to use
requires one of the following:

  i) `getauxval` from glibc. It's unclear whether `compiler_builtins` is
allowed to depend on libc at all, and musl doesn't even support
getauxval. Don't enshrine the requirement "de-facto" by making it
required for outline-atomics.

  ii) kernel support. Linux and FreeBSD have limited support, but it
requires an extremely recent kernel version and doesn't work at all under QEMU (https://github.com/rust-lang/rust/issues/109064#issuecomment-1494939904).

Instead, we hard-code LL/SC intrinsics. Users who want LSE support
should use the LLVM compiler-rt (if you're building from source in
rust-lang/rust, make sure you have `src/llvm-project` checked out
locally. the goal is to soon add a new `optimized-compiler-builtins`
option so this is easier to discover).

2. The global `___aarch64_have_lse_atomics` CTOR, required to do runtime
   dispatch. Thom Chiviolani has this to say about global CTORs:

> static ctors are problems because we are pretty eager about dead code elim
> in general if you have a module that isnt directly reference we will probably not have its static ctors
> also, while llvm has a super robust way to have a static ctor (theres s special "appending global" to use for c++), we dont use that and just have people make a #[used] static in a special section
> 1. the robust way kinda requires rust knowing that the argument is a static ctor (maybe a #[rustc_static_ctor] attribute). it also would be... finnicky, since on windows we actually care beyond being a static ctor, that we run as part in a specific group of ctors, which means a very specific section (one for TLS and the other for, uh, i dont remember)
> 2. we still actually have to codegen the cgu that isn't referenced. but maybe we could remember that it has that attribute and use that

So while this is possible in theory, it's decidedly non-trivial, and
needs invasive changes to rust itself. In any case, it doesn't matter
until we decide the story around libc.

3. The 16-byte (i128) version of compare_and_swap. This wouldn't be
   *too* hard to add, but it would be hard to test. The way I tested the
existing code was not just with unit tests but also by loading it as a
path dependency and running `x test core` - the latter caught several
bugs the unit tests didn't catch (because I originally wrote the tests
wrong). So I am slightly nervous about adding a 16-byte version that is
much more poorly tested than the other intrinsics.
2023-06-26 05:56:08 +00:00
Amanieu d'Antras
20fb963ab6 Add emutls.c for OpenHarmony 2023-03-10 19:59:23 +00:00
Nicholas Bishop
ebaca42a41 Use a stub stdlib.h when compiling for UEFI targets
int_util.c includes stdlib.h if `_WIN32` is defined. When compiling
the UEFI targets with clang they are treated as Windows targets (e.g. if
the Rust target is x86_64-unknown-uefi, the clang target is
x86_64-unknown-windows-gnu). So stdlib.h gets included, even though we
are compilling with `-ffreestanding` and don't want stdlib.h to be
used. That file may not be present, or an incompatible version might be
installed leading to typedef redefinition errors.

The contents of stdlib.h aren't actually needed for these targets anyway
(due to `__STDC_HOSTED__` being 0), so create a minimal stdlib.h in
`build.rs` when `target_os == uefi` and add it to the include path.
2022-11-17 21:16:01 -05:00
Nicholas Bishop
98b3454d3d Skip assembly implementations on the UEFI targets
The UEFI targets link with `/SAFESEH`. That requires that objects have a
symbol called [`@feat.00`]. Clang adds that symbol for COFF targets if
the input is a C file, but not if the input is an ASM file. That doesn't
prevent compiler_builtins or rustc from building, but using the
resulting rustc to compile something that references one of the objects
lacking `@feat.00` will result in a linker error.

Fix by removing all the `.S` implementations when `target_os == uefi`.

[`@feat.00`]: https://learn.microsoft.com/en-us/windows/win32/debug/pe-format#the-sxdata-section
2022-11-16 13:16:42 -05:00