Provide reasoning for skips, and enable thumb since this seems to work.
Also, change wasm32-unknown-unknown to be a proper build-only target.
The mentioned failures on MinGW are cases like:
thread 'musl_edge_case_expf' (1728) panicked at libm-test\tests\compare_built_musl.rs:26:50:
called `Result::unwrap()` on an `Err` value:
input: (0.0,)
as hex: (+0x0p+0,)
as bits: (0x00000000,)
expected: 0.0 +0x0p+0 0x00000000
actual: 1.0 +0x1.000000p+0 0x3f800000
thread 'musl_edge_case_ceil' (1964) panicked at libm-test\tests\compare_built_musl.rs:26:50:
called `Result::unwrap()` on an `Err` value:
input: (1.0000000000000002,)
as hex: (+0x1.0000000000001p+0,)
as bits: (0x3ff0000000000001,)
expected: 1.0 +0x1.0000000000000p+0 0x3ff0000000000000
actual: 2.0 +0x1.0000000000000p+1 0x4000000000000000
Our libm's results are correct, for some reason musl is off (something
about the fp environment on x86, or a different FLT_EVAL_MODE?)
This was needed while some codegen backends did not support inline
assembly, or ran into circular issues using vector intrinsics. All such
issues have since been resolved with the in-tree backends. The remaining
need was to be able to toggle these features in tests, which we can do
via the enabled-by-default `arch` feature. Since there aren't any cases
requiring `force-soft-float`, remove its functionality and deprecate it.
It is possible that future codegen backends may have a similar need to
disable inline assembly until pairity with the LLVM backend can be
reached. In these cases rather than having `force-soft-float`, it would
be better to have rustc provide a `cfg(target_supports_inline_asm)`.
`build.rs` can then do something like:
let nightly = cfg!(feature = "compiler-builtins") || cfg!(feature = "unstable");
let asm_support = env::var("CARGO_CFG_TARGET_SUPPORTS_INLINE_ASM").is_ok();
let arch_enabled = cfg!(feature = "arch") && (!nightly || (nightly && asm_support));
set_cfg("arch_enabled", arch_enabled);
This is about what we have now with `cfg(target_has_reliable_f16)` and
`cfg(target_has_reliable_f128)` being set by rustc, which is
significantly easier to use than the `feature = "no-f16-f128"` that it
replaced. Having rustc directly tell us what it supports means we don't
need to bubble subtractive options up to bootstrap via a chain of Cargo
features that aren't really meant to support disabling things.
I'm sketching this out for future reference since it seems likely that
the need comes back up eventually.
Make `libm` and `compiler-builtins` use the same configuration:
* By default there is an `arch` feature which allows `core::arch` and
inline assembly.
* Disabling the `arch` feature turns these off.
Positive feature flags are easier to reason about than negative, so this
will allow for some build script cleanup as well.
The .dockerenv check was a workaround for Docker CI where the
checkout is mounted read-only. However, its presence does not reliably
indicate that the filesystem is unwritable.
Use CARGO_TARGET_DIR as the condition instead, which directly
captures when a custom writable target directory is in use and avoids
false assumptions.
Implement the following logic:
* For elf executable binaries, check for PT_GNU_STACK with PF_X. This
combination tells the kernel to make the stack executable.
* For elf intermediate objects, check for `.note.GNU-stack` with
SHF_EXECINSTR. This combination in an object file tells the linker to
give the final binary PT_GNU_STACK PF_X.
* For elf intermediate objects with no `.note.GNU-stack`, assume the
legacy behavior that assumes an executable stack is required.
* For non-elf binaries, don't check anything. In a follow up it may be
possible to check for `MH_ALLOW_STACK_EXECUTION` on Mach-O binaries,
but it doesn't seem possible to get the latest compiler to emit this.
This appears to match what is done by `scanelf` to emit `!WX` [1], which
seems to be the tool used to create the output in the issue. The ld
manpage [2] also has some useful notes about these flags, as does the
presentation at [3].
Closes: https://github.com/rust-lang/compiler-builtins/issues/183
[1]: 9ef54b472e/scanelf.c
[2]: https://man7.org/linux/man-pages/man1/ld.1.html
[3]: https://www.ndss-symposium.org/wp-content/uploads/6D-s0924-ye.pdf
It would be nice to support a few more flags here, but the current
implementation is a bit limited. Switch to `getopts` which should make
things a bit easier in the future.
This option was used to gate `f16` and `f128` when support across
backends and targets was inconsistent. We now have the rustc builtin cfg
`target_has_reliable{f16,f128}` which has taken over this usecase.
Remove no-f16-f128 since it is now unused and redundant.
Rather than setting an environment variable in the workflow job based on
whether or not the environment is non-MinGW Windows, we can just check
this in the ci script.
This was originally added in b0f19660f0 ("Add tests for UNC paths on
windows builds") and its followup commits.
Many contributions to compiler-builtins don't have any need to touch
libm, and could get by with the few minutes of CI for compiler-builtins
rather than the ~30 minutes for libm. We already have some scripts that
handle changed file detection, so expand its use to skip libm CI if it
doesn't need to run.
Update `run.sh` to start testing `libm`. Currently this is somewhat
inefficient because `builtins-test` gets run more than once on some
targets; this can be cleaned up later.
This crate doesn't need to be a default member since it requires the
opposite settings from everything else. Exclude it from the workspace
and run it only when explicitly requested.
This also makes `cargo t --no-default-features` work without additional
qualifiers. `--no-default-features` still needs to be passed to ensure
`#![compiler_builtins]` does not get set.
compiler-builtins needs doctests disabled in order for everything to
work correctly, since this causes an error running rustdoc that is
unrelated to features (our `compiler_builtins` is getting into the crate
graph before that from the sysroot, but `#![compiler_builtins]` is not
set).
We can also remove `test = false` and `doctest = false` in
`builtins-test` since these no longer cause issues. This is unlikely to
be used but it is better to not quietly skip if anything ever gets added
by accident.
Apply a handful of changes to reduce the diff between the two:
* Cancel running jobs on new pushes
* Enable log color and backtraces
* Add timeouts
* Specify CI runner versions
* Add an armv7 job
* Replace the name NO_STD with BUILD_ONLY
* Update the extension to the canonical .yaml
* Set AR_ and CC_ environments in docker
* Install requirements to build MPFR
The current setup has the `Cargo.toml` for `compiler-builtins` at the
repository root, which means all support crates and other files are
located within the package root. This works for now but is not the
cleanest setup since files that should or shouldn't be included in the
package need to be configured in `Cargo.toml`. If we eventually merge
`libm` development into this repository, it would be nice to make this
separation more straightforward.
Begin cleaning things up by moving the crate source to a new
`compiler-builtins` directory and adding a virtual manifest. For now the
`libm` submodule is also moved, but in the future it can likely move
back to the top level (ideally `compiler-builtins/src` would contain a
symlink to `libm/src/math`, but unfortunately it seems like Cargo does
not like something about the submodule + symlink combination).
Currently there is an interesting situation with the way features get
enabled; `testcrate` enables `mangled-names`, but the `intrinsics.rs`
example requires this feature be disabled (otherwise the test fails with
missing symbols, as expected). This is also the reason that `testcrate`
is not a default workspace member, meaning `cargo test` doesn't actually
run `testcrate`'s tests; making it a default member would mean that
`compiler-builtins/mangled-names` gets enabled when
`examples/intrinsics.rs` gets built, due to the way features get
unified.
Simplify the situation by making moving the example to its own crate as
`builtins-test-intrinsics`. This also means `testcrate` can become a
default member so it is included in `cargo check` or `cargo test` when
run at the workspace root.
`testcrate` and `builtins-test-intrinsics` still can't be built at the
same time since there isn't a straightforward way to have Cargo build
`compiler-builtins` twice with different features. This is a side effect
of us using non-additive features, but there isn't really a better
option since enabling both mangled and unmangled names would render
`builtins-test-intrinsics` useless.
This adds comparisons among the compiler-builtins function, system
functions if available, and optionally handwritten assembly.
These also help us identify inconsistencies between this crate and
system functions, which may otherwise go unnoticed if intrinsics get
lowered to inline operations rather than library calls.