Skip to content

Commit 5372fc9

Browse files
committed
Auto merge of #149586 - tgross35:update-builtins, r=tgross35
compiler-builtins subtree update Subtree update of `compiler-builtins` to rust-lang/compiler-builtins@acb3a00. Created using https://github.com/rust-lang/josh-sync. r? `@ghost`
2 parents b1b08cd + 55c229b commit 5372fc9

File tree

25 files changed

+315
-83
lines changed

25 files changed

+315
-83
lines changed

library/compiler-builtins/.github/workflows/main.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ env:
1313
RUSTDOCFLAGS: -Dwarnings
1414
RUSTFLAGS: -Dwarnings
1515
RUST_BACKTRACE: full
16-
BENCHMARK_RUSTC: nightly-2025-05-28 # Pin the toolchain for reproducable results
16+
BENCHMARK_RUSTC: nightly-2025-12-01 # Pin the toolchain for reproducable results
1717

1818
jobs:
1919
# Determine which tests should be run based on changed files.
@@ -132,10 +132,7 @@ jobs:
132132
rustup default "$channel"
133133
rustup target add "${{ matrix.target }}"
134134
135-
# Our scripts use nextest if possible. This is skipped on the native ppc
136-
# and s390x runners since install-action doesn't support them.
137135
- uses: taiki-e/install-action@nextest
138-
if: "!(matrix.os == 'ubuntu-24.04-ppc64le' || matrix.os == 'ubuntu-24.04-s390x')"
139136

140137
- uses: Swatinem/rust-cache@v2
141138
with:

library/compiler-builtins/compiler-builtins/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ Miscellaneous functionality that is not used by Rust.
374374
- ~~i386/fp_mode.c~~
375375
- ~~int_util.c~~
376376
- ~~loongarch/fp_mode.c~~
377-
- ~~os_version_check.c~~
377+
- ~~os_version_check.c~~ (implemented in `std` instead)
378378
- ~~riscv/fp_mode.c~~
379379
- ~~riscv/restore.S~~ (callee-saved registers)
380380
- ~~riscv/save.S~~ (callee-saved registers)

library/compiler-builtins/crates/musl-math-sys/build.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ fn main() {
4646
let cfg = Config::from_env();
4747

4848
if cfg.target_env == "msvc"
49-
|| cfg.target_family == "wasm"
49+
|| cfg.target_families.iter().any(|f| f == "wasm")
5050
|| cfg.target_features.iter().any(|f| f == "thumb-mode")
5151
{
5252
println!(
@@ -69,7 +69,7 @@ struct Config {
6969
musl_arch: String,
7070
target_arch: String,
7171
target_env: String,
72-
target_family: String,
72+
target_families: Vec<String>,
7373
target_os: String,
7474
target_string: String,
7575
target_vendor: String,
@@ -79,6 +79,9 @@ struct Config {
7979
impl Config {
8080
fn from_env() -> Self {
8181
let manifest_dir = PathBuf::from(env::var("CARGO_MANIFEST_DIR").unwrap());
82+
let target_families = env::var("CARGO_CFG_TARGET_FAMILY")
83+
.map(|feats| feats.split(',').map(ToOwned::to_owned).collect())
84+
.unwrap_or_default();
8285
let target_features = env::var("CARGO_CFG_TARGET_FEATURE")
8386
.map(|feats| feats.split(',').map(ToOwned::to_owned).collect())
8487
.unwrap_or_default();
@@ -104,7 +107,7 @@ impl Config {
104107
musl_arch,
105108
target_arch,
106109
target_env: env::var("CARGO_CFG_TARGET_ENV").unwrap(),
107-
target_family: env::var("CARGO_CFG_TARGET_FAMILY").unwrap(),
110+
target_families,
108111
target_os: env::var("CARGO_CFG_TARGET_OS").unwrap(),
109112
target_string: env::var("TARGET").unwrap(),
110113
target_vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(),

library/compiler-builtins/crates/symbol-check/src/main.rs

Lines changed: 69 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ use std::io::{BufRead, BufReader};
77
use std::path::{Path, PathBuf};
88
use std::process::{Command, Stdio};
99

10-
use object::read::archive::{ArchiveFile, ArchiveMember};
10+
use object::read::archive::ArchiveFile;
1111
use object::{
12-
File as ObjFile, Object, ObjectSection, ObjectSymbol, Symbol, SymbolKind, SymbolScope,
12+
File as ObjFile, Object, ObjectSection, ObjectSymbol, Result as ObjResult, Symbol, SymbolKind,
13+
SymbolScope,
1314
};
1415
use serde_json::Value;
1516

@@ -24,6 +25,11 @@ Cargo will get invoked with `CARGO_ARGS` and the specified target. All output
2425
`compiler_builtins*.rlib` files will be checked.
2526
2627
If TARGET is not specified, the host target is used.
28+
29+
check PATHS ...
30+
31+
Run the same checks on the given set of paths, without invoking Cargo. Paths
32+
may be either archives or object files.
2733
";
2834

2935
fn main() {
@@ -33,12 +39,14 @@ fn main() {
3339

3440
match &args_ref[1..] {
3541
["build-and-check", target, "--", args @ ..] if !args.is_empty() => {
36-
check_cargo_args(args);
3742
run_build_and_check(target, args);
3843
}
3944
["build-and-check", "--", args @ ..] if !args.is_empty() => {
40-
check_cargo_args(args);
41-
run_build_and_check(&host_target(), args);
45+
let target = &host_target();
46+
run_build_and_check(target, args);
47+
}
48+
["check", paths @ ..] if !paths.is_empty() => {
49+
check_paths(paths);
4250
}
4351
_ => {
4452
println!("{USAGE}");
@@ -47,22 +55,25 @@ fn main() {
4755
}
4856
}
4957

50-
/// Make sure `--target` isn't passed to avoid confusion (since it should be proivded only once,
51-
/// positionally).
52-
fn check_cargo_args(args: &[&str]) {
58+
fn run_build_and_check(target: &str, args: &[&str]) {
59+
// Make sure `--target` isn't passed to avoid confusion (since it should be
60+
// proivded only once, positionally).
5361
for arg in args {
5462
assert!(
5563
!arg.contains("--target"),
5664
"target must be passed positionally. {USAGE}"
5765
);
5866
}
59-
}
6067

61-
fn run_build_and_check(target: &str, args: &[&str]) {
6268
let paths = exec_cargo_with_args(target, args);
69+
check_paths(&paths);
70+
}
71+
72+
fn check_paths<P: AsRef<Path>>(paths: &[P]) {
6373
for path in paths {
74+
let path = path.as_ref();
6475
println!("Checking {}", path.display());
65-
let archive = Archive::from_path(&path);
76+
let archive = BinFile::from_path(path);
6677

6778
verify_no_duplicates(&archive);
6879
verify_core_symbols(&archive);
@@ -165,7 +176,7 @@ struct SymInfo {
165176
}
166177

167178
impl SymInfo {
168-
fn new(sym: &Symbol, obj: &ObjFile, member: &ArchiveMember) -> Self {
179+
fn new(sym: &Symbol, obj: &ObjFile, obj_path: &str) -> Self {
169180
// Include the section name if possible. Fall back to the `Section` debug impl if not.
170181
let section = sym.section();
171182
let section_name = sym
@@ -187,7 +198,7 @@ impl SymInfo {
187198
is_weak: sym.is_weak(),
188199
is_common: sym.is_common(),
189200
address: sym.address(),
190-
object: String::from_utf8_lossy(member.name()).into_owned(),
201+
object: obj_path.to_owned(),
191202
}
192203
}
193204
}
@@ -197,7 +208,7 @@ impl SymInfo {
197208
/// Note that this will also locate cases where a symbol is weakly defined in more than one place.
198209
/// Technically there are no linker errors that will come from this, but it keeps our binary more
199210
/// straightforward and saves some distribution size.
200-
fn verify_no_duplicates(archive: &Archive) {
211+
fn verify_no_duplicates(archive: &BinFile) {
201212
let mut syms = BTreeMap::<String, SymInfo>::new();
202213
let mut dups = Vec::new();
203214
let mut found_any = false;
@@ -254,7 +265,7 @@ fn verify_no_duplicates(archive: &Archive) {
254265
}
255266

256267
/// Ensure that there are no references to symbols from `core` that aren't also (somehow) defined.
257-
fn verify_core_symbols(archive: &Archive) {
268+
fn verify_core_symbols(archive: &BinFile) {
258269
let mut defined = BTreeSet::new();
259270
let mut undefined = Vec::new();
260271
let mut has_symbols = false;
@@ -289,39 +300,63 @@ fn verify_core_symbols(archive: &Archive) {
289300
}
290301

291302
/// Thin wrapper for owning data used by `object`.
292-
struct Archive {
303+
struct BinFile {
304+
path: PathBuf,
293305
data: Vec<u8>,
294306
}
295307

296-
impl Archive {
308+
impl BinFile {
297309
fn from_path(path: &Path) -> Self {
298310
Self {
311+
path: path.to_owned(),
299312
data: fs::read(path).expect("reading file failed"),
300313
}
301314
}
302315

303-
fn file(&self) -> ArchiveFile<'_> {
304-
ArchiveFile::parse(self.data.as_slice()).expect("archive parse failed")
316+
fn as_archive_file(&self) -> ObjResult<ArchiveFile<'_>> {
317+
ArchiveFile::parse(self.data.as_slice())
305318
}
306319

307-
/// For a given archive, do something with each object file.
308-
fn for_each_object(&self, mut f: impl FnMut(ObjFile, &ArchiveMember)) {
309-
let archive = self.file();
310-
311-
for member in archive.members() {
312-
let member = member.expect("failed to access member");
313-
let obj_data = member
314-
.data(self.data.as_slice())
315-
.expect("failed to access object");
316-
let obj = ObjFile::parse(obj_data).expect("failed to parse object");
317-
f(obj, &member);
320+
fn as_obj_file(&self) -> ObjResult<ObjFile<'_>> {
321+
ObjFile::parse(self.data.as_slice())
322+
}
323+
324+
/// For a given archive, do something with each object file. For an object file, do
325+
/// something once.
326+
fn for_each_object(&self, mut f: impl FnMut(ObjFile, &str)) {
327+
// Try as an archive first.
328+
let as_archive = self.as_archive_file();
329+
if let Ok(archive) = as_archive {
330+
for member in archive.members() {
331+
let member = member.expect("failed to access member");
332+
let obj_data = member
333+
.data(self.data.as_slice())
334+
.expect("failed to access object");
335+
let obj = ObjFile::parse(obj_data).expect("failed to parse object");
336+
f(obj, &String::from_utf8_lossy(member.name()));
337+
}
338+
339+
return;
318340
}
341+
342+
// Fall back to parsing as an object file.
343+
let as_obj = self.as_obj_file();
344+
if let Ok(obj) = as_obj {
345+
f(obj, &self.path.to_string_lossy());
346+
return;
347+
}
348+
349+
panic!(
350+
"failed to parse as either archive or object file: {:?}, {:?}",
351+
as_archive.unwrap_err(),
352+
as_obj.unwrap_err(),
353+
);
319354
}
320355

321-
/// For a given archive, do something with each symbol.
322-
fn for_each_symbol(&self, mut f: impl FnMut(Symbol, &ObjFile, &ArchiveMember)) {
323-
self.for_each_object(|obj, member| {
324-
obj.symbols().for_each(|sym| f(sym, &obj, member));
356+
/// D something with each symbol in an archive or object file.
357+
fn for_each_symbol(&self, mut f: impl FnMut(Symbol, &ObjFile, &str)) {
358+
self.for_each_object(|obj, obj_path| {
359+
obj.symbols().for_each(|sym| f(sym, &obj, obj_path));
325360
});
326361
}
327362
}

library/compiler-builtins/libm-test/benches/icount.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,17 @@ fn icount_bench_u128_widen_mul(cases: Vec<(u128, u128)>) {
111111
}
112112
}
113113

114+
#[library_benchmark]
115+
#[bench::linspace(setup_u128_mul())]
116+
fn icount_bench_u256_narrowing_div(cases: Vec<(u128, u128)>) {
117+
use libm::support::NarrowingDiv;
118+
for (x, y) in cases.iter().copied() {
119+
let x = black_box(x.widen_hi());
120+
let y = black_box(y);
121+
black_box(x.checked_narrowing_div_rem(y));
122+
}
123+
}
124+
114125
#[library_benchmark]
115126
#[bench::linspace(setup_u256_add())]
116127
fn icount_bench_u256_add(cases: Vec<(u256, u256)>) {
@@ -145,7 +156,7 @@ fn icount_bench_u256_shr(cases: Vec<(u256, u32)>) {
145156

146157
library_benchmark_group!(
147158
name = icount_bench_u128_group;
148-
benchmarks = icount_bench_u128_widen_mul, icount_bench_u256_add, icount_bench_u256_sub, icount_bench_u256_shl, icount_bench_u256_shr
159+
benchmarks = icount_bench_u128_widen_mul, icount_bench_u256_narrowing_div, icount_bench_u256_add, icount_bench_u256_sub, icount_bench_u256_shl, icount_bench_u256_shr
149160
);
150161

151162
#[library_benchmark]

library/compiler-builtins/libm-test/src/precision.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
//! Configuration for skipping or changing the result for individual test cases (inputs) rather
22
//! than ignoring entire tests.
33
4-
use core::f32;
5-
64
use CheckBasis::{Mpfr, Musl};
75
use libm::support::CastFrom;
86
use {BaseName as Bn, Identifier as Id};

library/compiler-builtins/libm/configure.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Config {
1313
pub target_triple: String,
1414
pub target_arch: String,
1515
pub target_env: String,
16-
pub target_family: Option<String>,
16+
pub target_families: Vec<String>,
1717
pub target_os: String,
1818
pub target_string: String,
1919
pub target_vendor: String,
@@ -25,6 +25,9 @@ pub struct Config {
2525
impl Config {
2626
pub fn from_env() -> Self {
2727
let target_triple = env::var("TARGET").unwrap();
28+
let target_families = env::var("CARGO_CFG_TARGET_FAMILY")
29+
.map(|feats| feats.split(',').map(ToOwned::to_owned).collect())
30+
.unwrap_or_default();
2831
let target_features = env::var("CARGO_CFG_TARGET_FEATURE")
2932
.map(|feats| feats.split(',').map(ToOwned::to_owned).collect())
3033
.unwrap_or_default();
@@ -41,7 +44,7 @@ impl Config {
4144
cargo_features,
4245
target_arch: env::var("CARGO_CFG_TARGET_ARCH").unwrap(),
4346
target_env: env::var("CARGO_CFG_TARGET_ENV").unwrap(),
44-
target_family: env::var("CARGO_CFG_TARGET_FAMILY").ok(),
47+
target_families,
4548
target_os: env::var("CARGO_CFG_TARGET_OS").unwrap(),
4649
target_string: env::var("TARGET").unwrap(),
4750
target_vendor: env::var("CARGO_CFG_TARGET_VENDOR").unwrap(),

library/compiler-builtins/libm/src/math/atan.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,6 @@
2929
* to produce the hexadecimal values shown.
3030
*/
3131

32-
use core::f64;
33-
3432
use super::fabs;
3533

3634
const ATANHI: [f64; 4] = [
@@ -134,19 +132,19 @@ pub fn atan(x: f64) -> f64 {
134132

135133
#[cfg(test)]
136134
mod tests {
137-
use core::f64;
135+
use core::f64::consts;
138136

139137
use super::atan;
140138

141139
#[test]
142140
fn sanity_check() {
143141
for (input, answer) in [
144-
(3.0_f64.sqrt() / 3.0, f64::consts::FRAC_PI_6),
145-
(1.0, f64::consts::FRAC_PI_4),
146-
(3.0_f64.sqrt(), f64::consts::FRAC_PI_3),
147-
(-3.0_f64.sqrt() / 3.0, -f64::consts::FRAC_PI_6),
148-
(-1.0, -f64::consts::FRAC_PI_4),
149-
(-3.0_f64.sqrt(), -f64::consts::FRAC_PI_3),
142+
(3.0_f64.sqrt() / 3.0, consts::FRAC_PI_6),
143+
(1.0, consts::FRAC_PI_4),
144+
(3.0_f64.sqrt(), consts::FRAC_PI_3),
145+
(-3.0_f64.sqrt() / 3.0, -consts::FRAC_PI_6),
146+
(-1.0, -consts::FRAC_PI_4),
147+
(-3.0_f64.sqrt(), -consts::FRAC_PI_3),
150148
]
151149
.iter()
152150
{
@@ -167,12 +165,12 @@ mod tests {
167165

168166
#[test]
169167
fn infinity() {
170-
assert_eq!(atan(f64::INFINITY), f64::consts::FRAC_PI_2);
168+
assert_eq!(atan(f64::INFINITY), consts::FRAC_PI_2);
171169
}
172170

173171
#[test]
174172
fn minus_infinity() {
175-
assert_eq!(atan(f64::NEG_INFINITY), -f64::consts::FRAC_PI_2);
173+
assert_eq!(atan(f64::NEG_INFINITY), -consts::FRAC_PI_2);
176174
}
177175

178176
#[test]

library/compiler-builtins/libm/src/math/cbrtf.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@
1717
* Return cube root of x
1818
*/
1919

20-
use core::f32;
21-
2220
const B1: u32 = 709958130; /* B1 = (127-127.0/3-0.03306235651)*2**23 */
2321
const B2: u32 = 642849266; /* B2 = (127-127.0/3-24/3-0.03306235651)*2**23 */
2422

library/compiler-builtins/libm/src/math/expm1.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
* ====================================================
1111
*/
1212

13-
use core::f64;
14-
1513
const O_THRESHOLD: f64 = 7.09782712893383973096e+02; /* 0x40862E42, 0xFEFA39EF */
1614
const LN2_HI: f64 = 6.93147180369123816490e-01; /* 0x3fe62e42, 0xfee00000 */
1715
const LN2_LO: f64 = 1.90821492927058770002e-10; /* 0x3dea39ef, 0x35793c76 */

0 commit comments

Comments
 (0)