Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9ec6a02

Browse files
committedJun 30, 2024·
Merge commit '49cd5dd454d0115cfbe9e39102a8b3ba4616aa40' into sync_cg_clif-2024-06-30
2 parents 716752e + 49cd5dd commit 9ec6a02

File tree

23 files changed

+440
-291
lines changed

23 files changed

+440
-291
lines changed
 

‎compiler/rustc_codegen_cranelift/.github/workflows/abi-cafe.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,6 @@ jobs:
5555
if: matrix.os == 'macos-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-apple-darwin'
5656
run: rustup set default-host x86_64-apple-darwin
5757

58-
- name: Select XCode version
59-
if: matrix.os == 'macos-latest'
60-
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
61-
6258
- name: Prepare dependencies
6359
run: ./y.sh prepare
6460

‎compiler/rustc_codegen_cranelift/.github/workflows/main.yml

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,9 @@ jobs:
6666
env:
6767
TARGET_TRIPLE: aarch64-unknown-linux-gnu
6868
apt_deps: gcc-aarch64-linux-gnu qemu-user
69+
- os: macos-latest
70+
env:
71+
TARGET_TRIPLE: aarch64-apple-darwin
6972
- os: ubuntu-latest
7073
env:
7174
TARGET_TRIPLE: s390x-unknown-linux-gnu
@@ -108,10 +111,6 @@ jobs:
108111
sudo apt-get update
109112
sudo apt-get install -y ${{ matrix.apt_deps }}
110113
111-
- name: Select XCode version
112-
if: matrix.os == 'macos-latest'
113-
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
114-
115114
- name: Prepare dependencies
116115
run: ./y.sh prepare
117116

@@ -214,6 +213,9 @@ jobs:
214213
- os: macos-latest
215214
env:
216215
TARGET_TRIPLE: x86_64-apple-darwin
216+
- os: macos-latest
217+
env:
218+
TARGET_TRIPLE: aarch64-apple-darwin
217219
# cross-compile from Linux to Windows using mingw
218220
- os: ubuntu-latest
219221
env:
@@ -248,10 +250,6 @@ jobs:
248250
sudo apt-get update
249251
sudo apt-get install -y gcc-mingw-w64-x86-64
250252
251-
- name: Select XCode version
252-
if: matrix.os == 'macos-latest'
253-
run: sudo xcode-select -s /Applications/Xcode_14.3.1.app
254-
255253
- name: Prepare dependencies
256254
run: ./y.sh prepare
257255

@@ -282,7 +280,8 @@ jobs:
282280
runs-on: ubuntu-latest
283281
timeout-minutes: 10
284282
if: ${{ github.ref == 'refs/heads/master' }}
285-
needs: [rustfmt, test, bench, dist]
283+
# FIXME add the bench job back to the dependency list once rust-lang/rust#125493 gets merged
284+
needs: [rustfmt, test, dist]
286285

287286
permissions:
288287
contents: write # for creating the dev tag and release

‎compiler/rustc_codegen_cranelift/Cargo.lock

Lines changed: 30 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,18 @@ checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
4646

4747
[[package]]
4848
name = "cranelift-bforest"
49-
version = "0.107.0"
49+
version = "0.109.0"
5050
source = "registry+https://github.com/rust-lang/crates.io-index"
51-
checksum = "79b27922a6879b5b5361d0a084cb0b1941bf109a98540addcb932da13b68bed4"
51+
checksum = "0b6b33d7e757a887989eb18b35712b2a67d96171ec3149d1bfb657b29b7b367c"
5252
dependencies = [
5353
"cranelift-entity",
5454
]
5555

5656
[[package]]
5757
name = "cranelift-codegen"
58-
version = "0.107.0"
58+
version = "0.109.0"
5959
source = "registry+https://github.com/rust-lang/crates.io-index"
60-
checksum = "304c455b28bf56372729acb356afbb55d622f2b0f2f7837aa5e57c138acaac4d"
60+
checksum = "b9acf15cb22be42d07c3b57d7856329cb228b7315d385346149df2566ad5e4aa"
6161
dependencies = [
6262
"bumpalo",
6363
"cranelift-bforest",
@@ -70,45 +70,46 @@ dependencies = [
7070
"hashbrown 0.14.3",
7171
"log",
7272
"regalloc2",
73+
"rustc-hash",
7374
"smallvec",
7475
"target-lexicon",
7576
]
7677

7778
[[package]]
7879
name = "cranelift-codegen-meta"
79-
version = "0.107.0"
80+
version = "0.109.0"
8081
source = "registry+https://github.com/rust-lang/crates.io-index"
81-
checksum = "1653c56b99591d07f67c5ca7f9f25888948af3f4b97186bff838d687d666f613"
82+
checksum = "e934d301392b73b3f8b0540391fb82465a0f179a3cee7c726482ac4727efcc97"
8283
dependencies = [
8384
"cranelift-codegen-shared",
8485
]
8586

8687
[[package]]
8788
name = "cranelift-codegen-shared"
88-
version = "0.107.0"
89+
version = "0.109.0"
8990
source = "registry+https://github.com/rust-lang/crates.io-index"
90-
checksum = "f5b6a9cf6b6eb820ee3f973a0db313c05dc12d370f37b4fe9630286e1672573f"
91+
checksum = "8afb2a2566b3d54b854dfb288b3b187f6d3d17d6f762c92898207eba302931da"
9192

9293
[[package]]
9394
name = "cranelift-control"
94-
version = "0.107.0"
95+
version = "0.109.0"
9596
source = "registry+https://github.com/rust-lang/crates.io-index"
96-
checksum = "d9d06e6bf30075fb6bed9e034ec046475093392eea1aff90eb5c44c4a033d19a"
97+
checksum = "0100f33b704cdacd01ad66ff41f8c5030d57cbff078e2a4e49ab1822591299fa"
9798
dependencies = [
9899
"arbitrary",
99100
]
100101

101102
[[package]]
102103
name = "cranelift-entity"
103-
version = "0.107.0"
104+
version = "0.109.0"
104105
source = "registry+https://github.com/rust-lang/crates.io-index"
105-
checksum = "29be04f931b73cdb9694874a295027471817f26f26d2f0ebe5454153176b6e3a"
106+
checksum = "a8cfdc315e5d18997093e040a8d234bea1ac1e118a716d3e30f40d449e78207b"
106107

107108
[[package]]
108109
name = "cranelift-frontend"
109-
version = "0.107.0"
110+
version = "0.109.0"
110111
source = "registry+https://github.com/rust-lang/crates.io-index"
111-
checksum = "a07fd7393041d7faa2f37426f5dc7fc04003b70988810e8c063beefeff1cd8f9"
112+
checksum = "0f74b84f16af2e982b0c0c72233503d9d55cbfe3865dbe807ca28dc6642a28b5"
112113
dependencies = [
113114
"cranelift-codegen",
114115
"log",
@@ -118,15 +119,15 @@ dependencies = [
118119

119120
[[package]]
120121
name = "cranelift-isle"
121-
version = "0.107.0"
122+
version = "0.109.0"
122123
source = "registry+https://github.com/rust-lang/crates.io-index"
123-
checksum = "f341d7938caa6dff8149dac05bb2b53fc680323826b83b4cf175ab9f5139a3c9"
124+
checksum = "adf306d3dde705fb94bd48082f01d38c4ededc74293a4c007805f610bf08bc6e"
124125

125126
[[package]]
126127
name = "cranelift-jit"
127-
version = "0.107.0"
128+
version = "0.109.0"
128129
source = "registry+https://github.com/rust-lang/crates.io-index"
129-
checksum = "42733555e06433f1461570e09dbd756dafc228b4dac75c597cdbdc518de07522"
130+
checksum = "f5c5cfb8bbd3339cd25cca30e7516ff8fe5cb1feeddde6980cc4d5ef34df97bb"
130131
dependencies = [
131132
"anyhow",
132133
"cranelift-codegen",
@@ -144,9 +145,9 @@ dependencies = [
144145

145146
[[package]]
146147
name = "cranelift-module"
147-
version = "0.107.0"
148+
version = "0.109.0"
148149
source = "registry+https://github.com/rust-lang/crates.io-index"
149-
checksum = "84950af02bb85f3da764d53a953b43bb29a732e793d4fe24637a61591be9a024"
150+
checksum = "7c9b0d4269b36fd858e6d8f20cd4938941186fb831488c361888cb2d6b33a9a6"
150151
dependencies = [
151152
"anyhow",
152153
"cranelift-codegen",
@@ -155,9 +156,9 @@ dependencies = [
155156

156157
[[package]]
157158
name = "cranelift-native"
158-
version = "0.107.0"
159+
version = "0.109.0"
159160
source = "registry+https://github.com/rust-lang/crates.io-index"
160-
checksum = "82af6066e6448d26eeabb7aa26a43f7ff79f8217b06bade4ee6ef230aecc8880"
161+
checksum = "1ea0ebdef7aff4a79bcbc8b6495f31315f16b3bf311152f472eaa8d679352581"
161162
dependencies = [
162163
"cranelift-codegen",
163164
"libc",
@@ -166,9 +167,9 @@ dependencies = [
166167

167168
[[package]]
168169
name = "cranelift-object"
169-
version = "0.107.0"
170+
version = "0.109.0"
170171
source = "registry+https://github.com/rust-lang/crates.io-index"
171-
checksum = "00af56107039ed150391df6f753298c7b08f2b6a2e0727d216b5fa599d684d8b"
172+
checksum = "19e33439ec20db058bc7cc3410f9748ab1ad90a35cef713d625c736f43e3820d"
172173
dependencies = [
173174
"anyhow",
174175
"cranelift-codegen",
@@ -278,9 +279,9 @@ checksum = "6c8640c5d730cb13ebd907d8d04b52f55ac9a2eec55b440c8892f40d56c76c1d"
278279

279280
[[package]]
280281
name = "object"
281-
version = "0.33.0"
282+
version = "0.36.1"
282283
source = "registry+https://github.com/rust-lang/crates.io-index"
283-
checksum = "d8dd6c0cdf9429bce006e1362bfce61fa1bfd8c898a643ed8d2b471934701d3d"
284+
checksum = "081b846d1d56ddfc18fdf1a922e4f6e07a11768ea1b92dec44e42b72712ccfce"
284285
dependencies = [
285286
"crc32fast",
286287
"hashbrown 0.14.3",
@@ -410,10 +411,11 @@ checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
410411

411412
[[package]]
412413
name = "wasmtime-jit-icache-coherence"
413-
version = "20.0.0"
414+
version = "22.0.0"
414415
source = "registry+https://github.com/rust-lang/crates.io-index"
415-
checksum = "7a9f93a3289057b26dc75eb84d6e60d7694f7d169c7c09597495de6e016a13ff"
416+
checksum = "5afe2f0499542f9a4bcfa1b55bfdda803b6ade4e7c93c6b99e0f39dba44b0a91"
416417
dependencies = [
418+
"anyhow",
417419
"cfg-if",
418420
"libc",
419421
"windows-sys",

‎compiler/rustc_codegen_cranelift/Cargo.toml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ crate-type = ["dylib"]
88

99
[dependencies]
1010
# These have to be in sync with each other
11-
cranelift-codegen = { version = "0.107.0", default-features = false, features = ["std", "unwind", "all-arch"] }
12-
cranelift-frontend = { version = "0.107.0" }
13-
cranelift-module = { version = "0.107.0" }
14-
cranelift-native = { version = "0.107.0" }
15-
cranelift-jit = { version = "0.107.0", optional = true }
16-
cranelift-object = { version = "0.107.0" }
11+
cranelift-codegen = { version = "0.109.0", default-features = false, features = ["std", "unwind", "all-arch"] }
12+
cranelift-frontend = { version = "0.109.0" }
13+
cranelift-module = { version = "0.109.0" }
14+
cranelift-native = { version = "0.109.0" }
15+
cranelift-jit = { version = "0.109.0", optional = true }
16+
cranelift-object = { version = "0.109.0" }
1717
target-lexicon = "0.12.0"
1818
gimli = { version = "0.28", default-features = false, features = ["write"]}
19-
object = { version = "0.33", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
19+
object = { version = "0.36", default-features = false, features = ["std", "read_core", "write", "archive", "coff", "elf", "macho", "pe"] }
2020

2121
indexmap = "2.0.0"
2222
libloading = { version = "0.8.0", optional = true }

‎compiler/rustc_codegen_cranelift/Readme.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ For more docs on how to build and test see [build_system/usage.txt](build_system
7070
|FreeBSD|[^no-rustup]||||
7171
|AIX|[^xcoff]|N/A|N/A|[^xcoff]|
7272
|Other unixes|||||
73-
|macOS||[^apple-silicon]|N/A|N/A|
73+
|macOS||[^no-rustup]|N/A|N/A|
7474
|Windows|[^no-rustup]||N/A|N/A|
7575

7676
✅: Fully supported and tested
@@ -80,7 +80,6 @@ For more docs on how to build and test see [build_system/usage.txt](build_system
8080
Not all targets are available as rustup component for nightly. See notes in the platform support matrix.
8181

8282
[^xcoff]: XCOFF object file format is not supported.
83-
[^apple-silicon]: Tracked in [#1248](https://github.com/rust-lang/rustc_codegen_cranelift/issues/1248).
8483
[^no-rustup]: Not available as rustup component for nightly. You can build it yourself.
8584

8685
## Usage

‎compiler/rustc_codegen_cranelift/build_system/build_sysroot.rs

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,6 @@ fn build_clif_sysroot_for_triple(
267267
prefix.to_str().unwrap()
268268
));
269269
}
270-
rustflags.push("-Zunstable-options".to_owned());
271-
for (name, values) in EXTRA_CHECK_CFGS {
272-
rustflags.push(check_cfg_arg(name, *values));
273-
}
274270
compiler.rustflags.extend(rustflags);
275271
let mut build_cmd = STANDARD_LIBRARY.build(&compiler, dirs);
276272
if channel == "release" {
@@ -330,34 +326,3 @@ fn build_rtstartup(dirs: &Dirs, compiler: &Compiler) -> Option<SysrootTarget> {
330326

331327
Some(target_libs)
332328
}
333-
334-
// Copied from https://github.com/rust-lang/rust/blob/4fd98a4b1b100f5329c6efae18031791f64372d2/src/bootstrap/src/utils/helpers.rs#L569-L585
335-
/// Create a `--check-cfg` argument invocation for a given name
336-
/// and it's values.
337-
fn check_cfg_arg(name: &str, values: Option<&[&str]>) -> String {
338-
// Creating a string of the values by concatenating each value:
339-
// ',values("tvos","watchos")' or '' (nothing) when there are no values.
340-
let next = match values {
341-
Some(values) => {
342-
let mut tmp = values.iter().flat_map(|val| [",", "\"", val, "\""]).collect::<String>();
343-
344-
tmp.insert_str(1, "values(");
345-
tmp.push(')');
346-
tmp
347-
}
348-
None => "".to_string(),
349-
};
350-
format!("--check-cfg=cfg({name}{next})")
351-
}
352-
353-
const EXTRA_CHECK_CFGS: &[(&str, Option<&[&str]>)] = &[
354-
("bootstrap", None),
355-
("stdarch_intel_sde", None),
356-
("no_fp_fmt_parse", None),
357-
("no_global_oom_handling", None),
358-
("no_rc", None),
359-
("no_sync", None),
360-
("netbsd10", None),
361-
("backtrace_in_libstd", None),
362-
("target_arch", Some(&["xtensa"])),
363-
];

‎compiler/rustc_codegen_cranelift/build_system/tests.rs

Lines changed: 4 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,6 @@ pub(crate) fn run_tests(
329329
struct TestRunner<'a> {
330330
is_native: bool,
331331
jit_supported: bool,
332-
use_unstable_features: bool,
333332
skip_tests: &'a [&'a str],
334333
dirs: Dirs,
335334
target_compiler: Compiler,
@@ -361,15 +360,7 @@ impl<'a> TestRunner<'a> {
361360
&& target_compiler.triple.contains("x86_64")
362361
&& !target_compiler.triple.contains("windows");
363362

364-
Self {
365-
is_native,
366-
jit_supported,
367-
use_unstable_features,
368-
skip_tests,
369-
dirs,
370-
target_compiler,
371-
stdlib_source,
372-
}
363+
Self { is_native, jit_supported, skip_tests, dirs, target_compiler, stdlib_source }
373364
}
374365

375366
fn run_testsuite(&self, tests: &[TestCase]) {
@@ -393,31 +384,13 @@ impl<'a> TestRunner<'a> {
393384
match *cmd {
394385
TestCaseCmd::Custom { func } => func(self),
395386
TestCaseCmd::BuildLib { source, crate_types } => {
396-
if self.use_unstable_features {
397-
self.run_rustc([source, "--crate-type", crate_types]);
398-
} else {
399-
self.run_rustc([
400-
source,
401-
"--crate-type",
402-
crate_types,
403-
"--cfg",
404-
"no_unstable_features",
405-
]);
406-
}
387+
self.run_rustc([source, "--crate-type", crate_types]);
407388
}
408389
TestCaseCmd::BuildBin { source } => {
409-
if self.use_unstable_features {
410-
self.run_rustc([source]);
411-
} else {
412-
self.run_rustc([source, "--cfg", "no_unstable_features"]);
413-
}
390+
self.run_rustc([source]);
414391
}
415392
TestCaseCmd::BuildBinAndRun { source, args } => {
416-
if self.use_unstable_features {
417-
self.run_rustc([source]);
418-
} else {
419-
self.run_rustc([source, "--cfg", "no_unstable_features"]);
420-
}
393+
self.run_rustc([source]);
421394
self.run_out_command(
422395
source.split('/').last().unwrap().split('.').next().unwrap(),
423396
args,
@@ -472,7 +445,6 @@ impl<'a> TestRunner<'a> {
472445
cmd.arg(&self.target_compiler.triple);
473446
cmd.arg("-Cpanic=abort");
474447
cmd.arg("-Zunstable-options");
475-
cmd.arg("--check-cfg=cfg(no_unstable_features)");
476448
cmd.arg("--check-cfg=cfg(jit)");
477449
cmd.args(args);
478450
cmd

‎compiler/rustc_codegen_cranelift/example/mini_core_hello_world.rs

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -333,12 +333,7 @@ fn main() {
333333
#[cfg(all(not(jit), not(all(windows, target_env = "gnu"))))]
334334
test_tls();
335335

336-
#[cfg(all(
337-
not(jit),
338-
not(no_unstable_features),
339-
target_arch = "x86_64",
340-
any(target_os = "linux", target_os = "macos")
341-
))]
336+
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
342337
unsafe {
343338
global_asm_test();
344339
naked_test();
@@ -367,17 +362,12 @@ fn stack_val_align() {
367362
assert_eq!(&a as *const Foo as usize % 8192, 0);
368363
}
369364

370-
#[cfg(all(
371-
not(jit),
372-
not(no_unstable_features),
373-
target_arch = "x86_64",
374-
any(target_os = "linux", target_os = "macos")
375-
))]
365+
#[cfg(all(not(jit), target_arch = "x86_64", any(target_os = "linux", target_os = "macos")))]
376366
extern "C" {
377367
fn global_asm_test();
378368
}
379369

380-
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "linux"))]
370+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "linux"))]
381371
global_asm! {
382372
"
383373
.global global_asm_test
@@ -387,7 +377,7 @@ global_asm! {
387377
"
388378
}
389379

390-
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64", target_os = "macos"))]
380+
#[cfg(all(not(jit), target_arch = "x86_64", target_os = "macos"))]
391381
global_asm! {
392382
"
393383
.global _global_asm_test
@@ -397,7 +387,7 @@ global_asm! {
397387
"
398388
}
399389

400-
#[cfg(all(not(jit), not(no_unstable_features), target_arch = "x86_64"))]
390+
#[cfg(all(not(jit), target_arch = "x86_64"))]
401391
#[naked]
402392
extern "C" fn naked_test() {
403393
unsafe {

‎compiler/rustc_codegen_cranelift/example/std_example.rs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,9 @@ unsafe fn test_simd() {
251251
test_mm_add_epi8();
252252
test_mm_add_pd();
253253
test_mm_cvtepi8_epi16();
254+
#[cfg(not(jit))]
255+
test_mm_cvtps_epi32();
256+
test_mm_cvttps_epi32();
254257
test_mm_cvtsi128_si64();
255258

256259
test_mm_extract_epi8();
@@ -476,6 +479,41 @@ unsafe fn test_mm256_permutevar8x32_epi32() {
476479
assert_eq_m256i(r, e);
477480
}
478481

482+
#[cfg(target_arch = "x86_64")]
483+
#[target_feature(enable = "avx2")]
484+
#[cfg(not(jit))]
485+
unsafe fn test_mm_cvtps_epi32() {
486+
let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN];
487+
488+
let float_vec = _mm_loadu_ps(floats.as_ptr());
489+
let int_vec = _mm_cvtps_epi32(float_vec);
490+
491+
let mut ints: [i32; 4] = [0; 4];
492+
_mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec);
493+
494+
// this is very different from `floats.map(|f| f as i32)`!
495+
let expected_ints: [i32; 4] = [2, -2, i32::MIN, i32::MIN];
496+
497+
assert_eq!(ints, expected_ints);
498+
}
499+
500+
#[cfg(target_arch = "x86_64")]
501+
#[target_feature(enable = "avx2")]
502+
unsafe fn test_mm_cvttps_epi32() {
503+
let floats: [f32; 4] = [1.5, -2.5, i32::MAX as f32 + 1.0, f32::NAN];
504+
505+
let float_vec = _mm_loadu_ps(floats.as_ptr());
506+
let int_vec = _mm_cvttps_epi32(float_vec);
507+
508+
let mut ints: [i32; 4] = [0; 4];
509+
_mm_storeu_si128(ints.as_mut_ptr() as *mut __m128i, int_vec);
510+
511+
// this is very different from `floats.map(|f| f as i32)`!
512+
let expected_ints: [i32; 4] = [1, -2, i32::MIN, i32::MIN];
513+
514+
assert_eq!(ints, expected_ints);
515+
}
516+
479517
fn test_checked_mul() {
480518
let u: Option<u8> = u8::from_str_radix("1000", 10).ok();
481519
assert_eq!(u, None);

‎compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@ version = 3
44

55
[[package]]
66
name = "addr2line"
7-
version = "0.21.0"
7+
version = "0.22.0"
88
source = "registry+https://github.com/rust-lang/crates.io-index"
9-
checksum = "8a30b2e23b9e17a9f90641c7ab1549cd9b44f296d3ccbf309d2863cfe398a0cb"
9+
checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678"
1010
dependencies = [
1111
"compiler_builtins",
12-
"gimli",
12+
"gimli 0.29.0",
1313
"rustc-std-workspace-alloc",
1414
"rustc-std-workspace-core",
1515
]
@@ -133,6 +133,17 @@ dependencies = [
133133
"rustc-std-workspace-core",
134134
]
135135

136+
[[package]]
137+
name = "gimli"
138+
version = "0.29.0"
139+
source = "registry+https://github.com/rust-lang/crates.io-index"
140+
checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd"
141+
dependencies = [
142+
"compiler_builtins",
143+
"rustc-std-workspace-alloc",
144+
"rustc-std-workspace-core",
145+
]
146+
136147
[[package]]
137148
name = "hashbrown"
138149
version = "0.14.3"
@@ -147,9 +158,9 @@ dependencies = [
147158

148159
[[package]]
149160
name = "hermit-abi"
150-
version = "0.3.9"
161+
version = "0.4.0"
151162
source = "registry+https://github.com/rust-lang/crates.io-index"
152-
checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024"
163+
checksum = "fbf6a919d6cf397374f7dfeeea91d974c7c0a7221d0d0f4f20d859d329e53fcc"
153164
dependencies = [
154165
"compiler_builtins",
155166
"rustc-std-workspace-alloc",
@@ -189,9 +200,9 @@ dependencies = [
189200

190201
[[package]]
191202
name = "object"
192-
version = "0.32.1"
203+
version = "0.36.0"
193204
source = "registry+https://github.com/rust-lang/crates.io-index"
194-
checksum = "9cf5f9dd3933bd50a9e1f149ec995f39ae2c496d31fd772c1fd45ebc27e902b0"
205+
checksum = "576dfe1fc8f9df304abb159d767a29d0476f7750fbf8aa7ad07816004a207434"
195206
dependencies = [
196207
"compiler_builtins",
197208
"memchr",
@@ -286,9 +297,9 @@ dependencies = [
286297

287298
[[package]]
288299
name = "rustc-demangle"
289-
version = "0.1.23"
300+
version = "0.1.24"
290301
source = "registry+https://github.com/rust-lang/crates.io-index"
291-
checksum = "d626bb9dae77e28219937af045c257c28bfd3f69333c512553507f5f9798cb76"
302+
checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f"
292303
dependencies = [
293304
"compiler_builtins",
294305
"rustc-std-workspace-core",
@@ -396,8 +407,6 @@ dependencies = [
396407
"core",
397408
"getopts",
398409
"libc",
399-
"panic_abort",
400-
"panic_unwind",
401410
"std",
402411
]
403412

@@ -430,7 +439,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
430439
checksum = "37a19a21a537f635c16c7576f22d0f2f7d63353c1337ad4ce0d8001c7952a25b"
431440
dependencies = [
432441
"compiler_builtins",
433-
"gimli",
442+
"gimli 0.28.1",
434443
"rustc-std-workspace-core",
435444
]
436445

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-05-13"
2+
channel = "nightly-2024-06-30"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

‎compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ rm tests/ui/parser/unclosed-delimiter-in-dep.rs # submodule contains //~ERROR
3636
rm tests/ui/asm/x86_64/evex512-implicit-feature.rs # unimplemented AVX512 x86 vendor intrinsic
3737

3838
# exotic linkages
39-
rm tests/ui/issues/issue-33992.rs # unsupported linkages
40-
rm tests/incremental/hashes/function_interfaces.rs # same
41-
rm tests/incremental/hashes/statics.rs # same
39+
rm tests/incremental/hashes/function_interfaces.rs
40+
rm tests/incremental/hashes/statics.rs
4241

4342
# variadic arguments
4443
rm tests/ui/abi/mir/mir_codegen_calls_variadic.rs # requires float varargs
@@ -60,20 +59,28 @@ rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported
6059

6160
# requires LTO
6261
rm -r tests/run-make/cdylib
63-
rm -r tests/run-make/issue-14500
64-
rm -r tests/run-make/issue-64153
6562
rm -r tests/run-make/codegen-options-parsing
6663
rm -r tests/run-make/lto-*
6764
rm -r tests/run-make/reproducible-build-2
6865
rm -r tests/run-make/issue-109934-lto-debuginfo
6966
rm -r tests/run-make/no-builtins-lto
67+
rm -r tests/run-make/reachable-extern-fn-available-lto
68+
69+
# coverage instrumentation
70+
rm tests/ui/consts/precise-drop-with-coverage.rs
71+
rm tests/ui/issues/issue-85461.rs
72+
rm -r tests/ui/instrument-coverage/
73+
74+
# missing f16/f128 support
75+
rm tests/ui/half-open-range-patterns/half-open-range-pats-semantics.rs
7076

7177
# optimization tests
7278
# ==================
7379
rm tests/ui/codegen/issue-28950.rs # depends on stack size optimizations
7480
rm tests/ui/codegen/init-large-type.rs # same
7581
rm tests/ui/issues/issue-40883.rs # same
7682
rm -r tests/run-make/fmt-write-bloat/ # tests an optimization
83+
rm tests/ui/statics/const_generics.rs # same
7784

7885
# backend specific tests
7986
# ======================
@@ -85,6 +92,7 @@ rm -r tests/run-make/sepcomp-cci-copies # same
8592
rm -r tests/run-make/volatile-intrinsics # same
8693
rm -r tests/run-make/llvm-ident # same
8794
rm -r tests/run-make/no-builtins-attribute # same
95+
rm -r tests/run-make/pgo-gen-no-imp-symbols # same
8896
rm tests/ui/abi/stack-protector.rs # requires stack protector support
8997
rm -r tests/run-make/emit-stack-sizes # requires support for -Z emit-stack-sizes
9098
rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific
@@ -93,13 +101,14 @@ rm -r tests/run-make/print-to-output # requires --print relocation-models
93101
# requires asm, llvm-ir and/or llvm-bc emit support
94102
# =============================================
95103
rm -r tests/run-make/emit-named-files
96-
rm -r tests/run-make/issue-30063
97104
rm -r tests/run-make/multiple-emits
98105
rm -r tests/run-make/output-type-permutations
99106
rm -r tests/run-make/emit-to-stdout
100107
rm -r tests/run-make/compressed-debuginfo
101108
rm -r tests/run-make/symbols-include-type-name
102-
109+
rm -r tests/run-make/notify-all-emit-artifacts
110+
rm -r tests/run-make/reset-codegen-1
111+
rm -r tests/run-make/inline-always-many-cgu
103112

104113
# giving different but possibly correct results
105114
# =============================================
@@ -118,6 +127,7 @@ rm -r tests/run-make/compiler-builtins # Expects lib/rustlib/src/rust to contain
118127
# ============
119128
rm -r tests/run-make/extern-fn-explicit-align # argument alignment not yet supported
120129
rm -r tests/run-make/panic-abort-eh_frame # .eh_frame emitted with panic=abort
130+
rm tests/ui/deprecation/deprecated_inline_threshold.rs # missing deprecation warning for -Cinline-threshold
121131

122132
# bugs in the test suite
123133
# ======================
@@ -148,12 +158,12 @@ index 9607ff02f96..b7d97caf9a2 100644
148158
--- a/src/tools/run-make-support/src/rustdoc.rs
149159
+++ b/src/tools/run-make-support/src/rustdoc.rs
150160
@@ -34,8 +34,6 @@ pub fn bare() -> Self {
151-
/// Construct a \`rustdoc\` invocation with \`-L \$(TARGET_RPATH_DIR)\` set.
161+
#[track_caller]
152162
pub fn new() -> Self {
153163
let mut cmd = setup_common();
154-
- let target_rpath_dir = env::var_os("TARGET_RPATH_DIR").unwrap();
164+
- let target_rpath_dir = env_var_os("TARGET_RPATH_DIR");
155165
- cmd.arg(format!("-L{}", target_rpath_dir.to_string_lossy()));
156-
Self { cmd, stdin: None }
166+
Self { cmd }
157167
}
158168
159169
EOF

‎compiler/rustc_codegen_cranelift/src/abi/mod.rs

Lines changed: 104 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ mod pass_mode;
55
mod returning;
66

77
use std::borrow::Cow;
8+
use std::mem;
89

9-
use cranelift_codegen::ir::SigRef;
10+
use cranelift_codegen::ir::{ArgumentPurpose, SigRef};
1011
use cranelift_codegen::isa::CallConv;
1112
use cranelift_module::ModuleError;
1213
use rustc_codegen_ssa::errors::CompilerBuiltinsCannotCall;
@@ -17,7 +18,7 @@ use rustc_middle::ty::TypeVisitableExt;
1718
use rustc_monomorphize::is_call_from_compiler_builtins_to_upstream_monomorphization;
1819
use rustc_session::Session;
1920
use rustc_span::source_map::Spanned;
20-
use rustc_target::abi::call::{Conv, FnAbi};
21+
use rustc_target::abi::call::{Conv, FnAbi, PassMode};
2122
use rustc_target::spec::abi::Abi;
2223

2324
use self::pass_mode::*;
@@ -487,6 +488,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
487488
let args = args;
488489
assert_eq!(fn_abi.args.len(), args.len());
489490

491+
#[derive(Copy, Clone)]
490492
enum CallTarget {
491493
Direct(FuncRef),
492494
Indirect(SigRef, Value),
@@ -532,7 +534,7 @@ pub(crate) fn codegen_terminator_call<'tcx>(
532534
};
533535

534536
self::returning::codegen_with_call_return_arg(fx, &fn_abi.ret, ret_place, |fx, return_ptr| {
535-
let call_args = return_ptr
537+
let mut call_args = return_ptr
536538
.into_iter()
537539
.chain(first_arg_override.into_iter())
538540
.chain(
@@ -545,47 +547,118 @@ pub(crate) fn codegen_terminator_call<'tcx>(
545547
)
546548
.collect::<Vec<Value>>();
547549

548-
let call_inst = match func_ref {
550+
// FIXME: Find a cleaner way to support varargs.
551+
if fn_abi.c_variadic {
552+
adjust_call_for_c_variadic(fx, &fn_abi, source_info, func_ref, &mut call_args);
553+
}
554+
555+
match func_ref {
549556
CallTarget::Direct(func_ref) => fx.bcx.ins().call(func_ref, &call_args),
550557
CallTarget::Indirect(sig, func_ptr) => {
551558
fx.bcx.ins().call_indirect(sig, func_ptr, &call_args)
552559
}
560+
}
561+
});
562+
563+
if let Some(dest) = target {
564+
let ret_block = fx.get_block(dest);
565+
fx.bcx.ins().jump(ret_block, &[]);
566+
} else {
567+
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
568+
}
569+
570+
fn adjust_call_for_c_variadic<'tcx>(
571+
fx: &mut FunctionCx<'_, '_, 'tcx>,
572+
fn_abi: &FnAbi<'tcx, Ty<'tcx>>,
573+
source_info: mir::SourceInfo,
574+
target: CallTarget,
575+
call_args: &mut Vec<Value>,
576+
) {
577+
if fn_abi.conv != Conv::C {
578+
fx.tcx.dcx().span_fatal(
579+
source_info.span,
580+
format!("Variadic call for non-C abi {:?}", fn_abi.conv),
581+
);
582+
}
583+
let sig_ref = match target {
584+
CallTarget::Direct(func_ref) => fx.bcx.func.dfg.ext_funcs[func_ref].signature,
585+
CallTarget::Indirect(sig_ref, _) => sig_ref,
553586
};
587+
// `mem::take()` the `params` so that `fx.bcx` can be used below.
588+
let mut abi_params = mem::take(&mut fx.bcx.func.dfg.signatures[sig_ref].params);
589+
590+
// Recalculate the parameters in the signature to ensure the signature contains the variadic arguments.
591+
let has_return_arg = matches!(fn_abi.ret.mode, PassMode::Indirect { .. });
592+
// Drop everything except the return argument (if there is one).
593+
abi_params.truncate(if has_return_arg { 1 } else { 0 });
594+
// Add the fixed arguments.
595+
abi_params.extend(
596+
fn_abi.args[..fn_abi.fixed_count as usize]
597+
.iter()
598+
.flat_map(|arg_abi| arg_abi.get_abi_param(fx.tcx).into_iter()),
599+
);
600+
let fixed_arg_count = abi_params.len();
601+
// Add the variadic arguments.
602+
abi_params.extend(
603+
fn_abi.args[fn_abi.fixed_count as usize..]
604+
.iter()
605+
.flat_map(|arg_abi| arg_abi.get_abi_param(fx.tcx).into_iter()),
606+
);
554607

555-
// FIXME find a cleaner way to support varargs
556-
if fn_sig.c_variadic() {
557-
if !matches!(fn_sig.abi(), Abi::C { .. }) {
608+
if fx.tcx.sess.target.is_like_osx && fx.tcx.sess.target.arch == "aarch64" {
609+
// Add any padding arguments needed for Apple AArch64.
610+
// There's no need to pad the argument list unless variadic arguments are actually being
611+
// passed.
612+
if abi_params.len() > fixed_arg_count {
613+
// 128-bit integers take 2 registers, and everything else takes 1.
614+
// FIXME: Add support for non-integer types
615+
// This relies on the checks below to ensure all arguments are integer types and
616+
// that the ABI is "C".
617+
// The return argument isn't counted as it goes in its own dedicated register.
618+
let integer_registers_used: usize = abi_params
619+
[if has_return_arg { 1 } else { 0 }..fixed_arg_count]
620+
.iter()
621+
.map(|arg| if arg.value_type.bits() == 128 { 2 } else { 1 })
622+
.sum();
623+
// The ABI uses 8 registers before it starts pushing arguments to the stack. Pad out
624+
// the registers if needed to ensure the variadic arguments are passed on the stack.
625+
if integer_registers_used < 8 {
626+
abi_params.splice(
627+
fixed_arg_count..fixed_arg_count,
628+
(integer_registers_used..8).map(|_| AbiParam::new(types::I64)),
629+
);
630+
call_args.splice(
631+
fixed_arg_count..fixed_arg_count,
632+
(integer_registers_used..8).map(|_| fx.bcx.ins().iconst(types::I64, 0)),
633+
);
634+
}
635+
}
636+
637+
// `StructArgument` is not currently used by the `aarch64` ABI, and is therefore not
638+
// handled when calculating how many padding arguments to use. Assert that this remains
639+
// the case.
640+
assert!(abi_params.iter().all(|param| matches!(
641+
param.purpose,
642+
// The only purposes used are `Normal` and `StructReturn`.
643+
ArgumentPurpose::Normal | ArgumentPurpose::StructReturn
644+
)));
645+
}
646+
647+
// Check all parameters are integers.
648+
for param in abi_params.iter() {
649+
if !param.value_type.is_int() {
650+
// FIXME: Set %al to upperbound on float args once floats are supported.
558651
fx.tcx.dcx().span_fatal(
559652
source_info.span,
560-
format!("Variadic call for non-C abi {:?}", fn_sig.abi()),
653+
format!("Non int ty {:?} for variadic call", param.value_type),
561654
);
562655
}
563-
let sig_ref = fx.bcx.func.dfg.call_signature(call_inst).unwrap();
564-
let abi_params = call_args
565-
.into_iter()
566-
.map(|arg| {
567-
let ty = fx.bcx.func.dfg.value_type(arg);
568-
if !ty.is_int() {
569-
// FIXME set %al to upperbound on float args once floats are supported
570-
fx.tcx.dcx().span_fatal(
571-
source_info.span,
572-
format!("Non int ty {:?} for variadic call", ty),
573-
);
574-
}
575-
AbiParam::new(ty)
576-
})
577-
.collect::<Vec<AbiParam>>();
578-
fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
579656
}
580657

581-
call_inst
582-
});
658+
assert_eq!(abi_params.len(), call_args.len());
583659

584-
if let Some(dest) = target {
585-
let ret_block = fx.get_block(dest);
586-
fx.bcx.ins().jump(ret_block, &[]);
587-
} else {
588-
fx.bcx.ins().trap(TrapCode::UnreachableCodeReached);
660+
// Put the `AbiParam`s back in the signature.
661+
fx.bcx.func.dfg.signatures[sig_ref].params = abi_params;
589662
}
590663
}
591664

‎compiler/rustc_codegen_cranelift/src/allocator.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,10 @@ use rustc_session::config::OomStrategy;
1111
use crate::prelude::*;
1212

1313
/// Returns whether an allocator shim was created
14-
pub(crate) fn codegen(
15-
tcx: TyCtxt<'_>,
16-
module: &mut impl Module,
17-
unwind_context: &mut UnwindContext,
18-
) -> bool {
14+
pub(crate) fn codegen(tcx: TyCtxt<'_>, module: &mut dyn Module) -> bool {
1915
let Some(kind) = allocator_kind_for_codegen(tcx) else { return false };
2016
codegen_inner(
2117
module,
22-
unwind_context,
2318
kind,
2419
tcx.alloc_error_handler_kind(()).unwrap(),
2520
tcx.sess.opts.unstable_opts.oom,
@@ -28,8 +23,7 @@ pub(crate) fn codegen(
2823
}
2924

3025
fn codegen_inner(
31-
module: &mut impl Module,
32-
unwind_context: &mut UnwindContext,
26+
module: &mut dyn Module,
3327
kind: AllocatorKind,
3428
alloc_error_handler_kind: AllocatorKind,
3529
oom_strategy: OomStrategy,
@@ -67,7 +61,6 @@ fn codegen_inner(
6761
};
6862
crate::common::create_wrapper_function(
6963
module,
70-
unwind_context,
7164
sig,
7265
&global_fn_name(method.name),
7366
&default_fn_name(method.name),
@@ -82,7 +75,6 @@ fn codegen_inner(
8275
};
8376
crate::common::create_wrapper_function(
8477
module,
85-
unwind_context,
8678
sig,
8779
"__rust_alloc_error_handler",
8880
&alloc_error_handler_name(alloc_error_handler_kind),

‎compiler/rustc_codegen_cranelift/src/base.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -249,9 +249,7 @@ pub(crate) fn compile_fn(
249249
}
250250

251251
// Define debuginfo for function
252-
let isa = module.isa();
253252
let debug_context = &mut cx.debug_context;
254-
let unwind_context = &mut cx.unwind_context;
255253
cx.profiler.generic_activity("generate debug info").run(|| {
256254
if let Some(debug_context) = debug_context {
257255
codegened_func.func_debug_cx.unwrap().finalize(
@@ -260,7 +258,6 @@ pub(crate) fn compile_fn(
260258
context,
261259
);
262260
}
263-
unwind_context.add_function(codegened_func.func_id, &context, isa);
264261
});
265262
}
266263

@@ -909,7 +906,7 @@ fn codegen_stmt<'tcx>(
909906
| StatementKind::PlaceMention(..)
910907
| StatementKind::AscribeUserType(..) => {}
911908

912-
StatementKind::Coverage { .. } => fx.tcx.dcx().fatal("-Zcoverage is unimplemented"),
909+
StatementKind::Coverage { .. } => unreachable!(),
913910
StatementKind::Intrinsic(ref intrinsic) => match &**intrinsic {
914911
// We ignore `assume` intrinsics, they are only useful for optimizations
915912
NonDivergingIntrinsic::Assume(_) => {}

‎compiler/rustc_codegen_cranelift/src/common.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,6 @@ pub(crate) fn type_sign(ty: Ty<'_>) -> bool {
247247

248248
pub(crate) fn create_wrapper_function(
249249
module: &mut dyn Module,
250-
unwind_context: &mut UnwindContext,
251250
sig: Signature,
252251
wrapper_name: &str,
253252
callee_name: &str,
@@ -280,7 +279,6 @@ pub(crate) fn create_wrapper_function(
280279
bcx.finalize();
281280
}
282281
module.define_function(wrapper_func_id, &mut ctx).unwrap();
283-
unwind_context.add_function(wrapper_func_id, &ctx, module.isa());
284282
}
285283

286284
pub(crate) struct FunctionCx<'m, 'clif, 'tcx: 'm> {
@@ -395,6 +393,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
395393
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
396394
// a way to specify stack slot alignment.
397395
size: (size + abi_align - 1) / abi_align * abi_align,
396+
align_shift: 4,
398397
});
399398
Pointer::stack_slot(stack_slot)
400399
} else {
@@ -405,6 +404,7 @@ impl<'tcx> FunctionCx<'_, '_, 'tcx> {
405404
// FIXME Don't force the size to a multiple of <abi_align> bytes once Cranelift gets
406405
// a way to specify stack slot alignment.
407406
size: (size + align) / abi_align * abi_align,
407+
align_shift: 4,
408408
});
409409
let base_ptr = self.bcx.ins().stack_addr(self.pointer_type, stack_slot, 0);
410410
let misalign_offset = self.bcx.ins().urem_imm(base_ptr, i64::from(align));

‎compiler/rustc_codegen_cranelift/src/driver/aot.rs

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use rustc_session::Session;
2626
use crate::concurrency_limiter::{ConcurrencyLimiter, ConcurrencyLimiterToken};
2727
use crate::debuginfo::TypeDebugContext;
2828
use crate::global_asm::GlobalAsmConfig;
29+
use crate::unwind_module::UnwindModule;
2930
use crate::{prelude::*, BackendConfig};
3031

3132
struct ModuleCodegenResult {
@@ -318,7 +319,11 @@ fn produce_final_output_artifacts(
318319
// These are used in linking steps and will be cleaned up afterward.
319320
}
320321

321-
fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) -> ObjectModule {
322+
fn make_module(
323+
sess: &Session,
324+
backend_config: &BackendConfig,
325+
name: String,
326+
) -> UnwindModule<ObjectModule> {
322327
let isa = crate::build_isa(sess, backend_config);
323328

324329
let mut builder =
@@ -327,16 +332,15 @@ fn make_module(sess: &Session, backend_config: &BackendConfig, name: String) ->
327332
// is important, while cg_clif cares more about compilation times. Enabling -Zfunction-sections
328333
// can easily double the amount of time necessary to perform linking.
329334
builder.per_function_section(sess.opts.unstable_opts.function_sections.unwrap_or(false));
330-
ObjectModule::new(builder)
335+
UnwindModule::new(ObjectModule::new(builder), true)
331336
}
332337

333338
fn emit_cgu(
334339
output_filenames: &OutputFilenames,
335340
prof: &SelfProfilerRef,
336341
name: String,
337-
module: ObjectModule,
342+
module: UnwindModule<ObjectModule>,
338343
debug: Option<DebugContext>,
339-
unwind_context: UnwindContext,
340344
global_asm_object_file: Option<PathBuf>,
341345
producer: &str,
342346
) -> Result<ModuleCodegenResult, String> {
@@ -346,8 +350,6 @@ fn emit_cgu(
346350
debug.emit(&mut product);
347351
}
348352

349-
unwind_context.emit(&mut product);
350-
351353
let module_regular = emit_module(
352354
output_filenames,
353355
prof,
@@ -494,7 +496,6 @@ fn module_codegen(
494496

495497
let mut cx = crate::CodegenCx::new(
496498
tcx,
497-
backend_config.clone(),
498499
module.isa(),
499500
tcx.sess.opts.debuginfo != DebugInfo::None,
500501
cgu_name,
@@ -531,13 +532,7 @@ fn module_codegen(
531532
}
532533
}
533534
}
534-
crate::main_shim::maybe_create_entry_wrapper(
535-
tcx,
536-
&mut module,
537-
&mut cx.unwind_context,
538-
false,
539-
cgu.is_primary(),
540-
);
535+
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut module, false, cgu.is_primary());
541536

542537
let cgu_name = cgu.name().as_str().to_owned();
543538

@@ -571,7 +566,6 @@ fn module_codegen(
571566
cgu_name,
572567
module,
573568
cx.debug_context,
574-
cx.unwind_context,
575569
global_asm_object_file,
576570
&producer,
577571
)
@@ -665,13 +659,10 @@ pub(crate) fn run_aot(
665659
});
666660

667661
let mut allocator_module = make_module(tcx.sess, &backend_config, "allocator_shim".to_string());
668-
let mut allocator_unwind_context = UnwindContext::new(allocator_module.isa(), true);
669-
let created_alloc_shim =
670-
crate::allocator::codegen(tcx, &mut allocator_module, &mut allocator_unwind_context);
662+
let created_alloc_shim = crate::allocator::codegen(tcx, &mut allocator_module);
671663

672664
let allocator_module = if created_alloc_shim {
673-
let mut product = allocator_module.finish();
674-
allocator_unwind_context.emit(&mut product);
665+
let product = allocator_module.finish();
675666

676667
match emit_module(
677668
tcx.output_filenames(()),

‎compiler/rustc_codegen_cranelift/src/driver/jit.rs

Lines changed: 17 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ use rustc_session::Session;
1414
use rustc_span::Symbol;
1515

1616
use crate::debuginfo::TypeDebugContext;
17+
use crate::unwind_module::UnwindModule;
1718
use crate::{prelude::*, BackendConfig};
1819
use crate::{CodegenCx, CodegenMode};
1920

2021
struct JitState {
21-
backend_config: BackendConfig,
22-
jit_module: JITModule,
22+
jit_module: UnwindModule<JITModule>,
2323
}
2424

2525
thread_local! {
@@ -63,7 +63,7 @@ fn create_jit_module(
6363
tcx: TyCtxt<'_>,
6464
backend_config: &BackendConfig,
6565
hotswap: bool,
66-
) -> (JITModule, CodegenCx) {
66+
) -> (UnwindModule<JITModule>, CodegenCx) {
6767
let crate_info = CrateInfo::new(tcx, "dummy_target_cpu".to_string());
6868

6969
let isa = crate::build_isa(tcx.sess, backend_config);
@@ -72,17 +72,11 @@ fn create_jit_module(
7272
crate::compiler_builtins::register_functions_for_jit(&mut jit_builder);
7373
jit_builder.symbol_lookup_fn(dep_symbol_lookup_fn(tcx.sess, crate_info));
7474
jit_builder.symbol("__clif_jit_fn", clif_jit_fn as *const u8);
75-
let mut jit_module = JITModule::new(jit_builder);
75+
let mut jit_module = UnwindModule::new(JITModule::new(jit_builder), false);
7676

77-
let mut cx = crate::CodegenCx::new(
78-
tcx,
79-
backend_config.clone(),
80-
jit_module.isa(),
81-
false,
82-
Symbol::intern("dummy_cgu_name"),
83-
);
77+
let cx = crate::CodegenCx::new(tcx, jit_module.isa(), false, Symbol::intern("dummy_cgu_name"));
8478

85-
crate::allocator::codegen(tcx, &mut jit_module, &mut cx.unwind_context);
79+
crate::allocator::codegen(tcx, &mut jit_module);
8680

8781
(jit_module, cx)
8882
}
@@ -128,7 +122,7 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
128122
);
129123
}
130124
CodegenMode::JitLazy => {
131-
codegen_shim(tcx, &mut cx, &mut cached_context, &mut jit_module, inst)
125+
codegen_shim(tcx, &mut cached_context, &mut jit_module, inst)
132126
}
133127
},
134128
MonoItem::Static(def_id) => {
@@ -146,18 +140,11 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
146140
tcx.dcx().fatal("Inline asm is not supported in JIT mode");
147141
}
148142

149-
crate::main_shim::maybe_create_entry_wrapper(
150-
tcx,
151-
&mut jit_module,
152-
&mut cx.unwind_context,
153-
true,
154-
true,
155-
);
143+
crate::main_shim::maybe_create_entry_wrapper(tcx, &mut jit_module, true, true);
156144

157145
tcx.dcx().abort_if_errors();
158146

159-
jit_module.finalize_definitions().unwrap();
160-
unsafe { cx.unwind_context.register_jit(&jit_module) };
147+
jit_module.finalize_definitions();
161148

162149
println!(
163150
"Rustc codegen cranelift will JIT run the executable, because -Cllvm-args=mode=jit was passed"
@@ -177,12 +164,12 @@ pub(crate) fn run_jit(tcx: TyCtxt<'_>, backend_config: BackendConfig) -> ! {
177164
call_conv: jit_module.target_config().default_call_conv,
178165
};
179166
let start_func_id = jit_module.declare_function("main", Linkage::Import, &start_sig).unwrap();
180-
let finalized_start: *const u8 = jit_module.get_finalized_function(start_func_id);
167+
let finalized_start: *const u8 = jit_module.module.get_finalized_function(start_func_id);
181168

182169
LAZY_JIT_STATE.with(|lazy_jit_state| {
183170
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
184171
assert!(lazy_jit_state.is_none());
185-
*lazy_jit_state = Some(JitState { backend_config, jit_module });
172+
*lazy_jit_state = Some(JitState { jit_module });
186173
});
187174

188175
let f: extern "C" fn(c_int, *const *const c_char) -> c_int =
@@ -268,7 +255,6 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
268255
let mut lazy_jit_state = lazy_jit_state.borrow_mut();
269256
let lazy_jit_state = lazy_jit_state.as_mut().unwrap();
270257
let jit_module = &mut lazy_jit_state.jit_module;
271-
let backend_config = lazy_jit_state.backend_config.clone();
272258

273259
let name = tcx.symbol_name(instance).name;
274260
let sig = crate::abi::get_function_sig(
@@ -278,7 +264,7 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
278264
);
279265
let func_id = jit_module.declare_function(name, Linkage::Export, &sig).unwrap();
280266

281-
let current_ptr = jit_module.read_got_entry(func_id);
267+
let current_ptr = jit_module.module.read_got_entry(func_id);
282268

283269
// If the function's GOT entry has already been updated to point at something other
284270
// than the shim trampoline, don't re-jit but just return the new pointer instead.
@@ -288,29 +274,27 @@ fn jit_fn(instance_ptr: *const Instance<'static>, trampoline_ptr: *const u8) ->
288274
return current_ptr;
289275
}
290276

291-
jit_module.prepare_for_function_redefine(func_id).unwrap();
277+
jit_module.module.prepare_for_function_redefine(func_id).unwrap();
292278

293279
let mut cx = crate::CodegenCx::new(
294280
tcx,
295-
backend_config,
296281
jit_module.isa(),
297282
false,
298283
Symbol::intern("dummy_cgu_name"),
299284
);
300285
codegen_and_compile_fn(tcx, &mut cx, &mut Context::new(), jit_module, instance);
301286

302287
assert!(cx.global_asm.is_empty());
303-
jit_module.finalize_definitions().unwrap();
304-
unsafe { cx.unwind_context.register_jit(&jit_module) };
305-
jit_module.get_finalized_function(func_id)
288+
jit_module.finalize_definitions();
289+
jit_module.module.get_finalized_function(func_id)
306290
})
307291
})
308292
}
309293

310294
fn dep_symbol_lookup_fn(
311295
sess: &Session,
312296
crate_info: CrateInfo,
313-
) -> Box<dyn Fn(&str) -> Option<*const u8>> {
297+
) -> Box<dyn Fn(&str) -> Option<*const u8> + Send> {
314298
use rustc_middle::middle::dependency_format::Linkage;
315299

316300
let mut dylib_paths = Vec::new();
@@ -362,9 +346,8 @@ fn dep_symbol_lookup_fn(
362346

363347
fn codegen_shim<'tcx>(
364348
tcx: TyCtxt<'tcx>,
365-
cx: &mut CodegenCx,
366349
cached_context: &mut Context,
367-
module: &mut JITModule,
350+
module: &mut UnwindModule<JITModule>,
368351
inst: Instance<'tcx>,
369352
) {
370353
let pointer_type = module.target_config().pointer_type();
@@ -413,5 +396,4 @@ fn codegen_shim<'tcx>(
413396
trampoline_builder.ins().return_(&ret_vals);
414397

415398
module.define_function(func_id, context).unwrap();
416-
cx.unwind_context.add_function(func_id, context, module.isa());
417399
}

‎compiler/rustc_codegen_cranelift/src/inline_asm.rs

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -113,13 +113,7 @@ pub(crate) fn codegen_inline_asm_terminator<'tcx>(
113113
);
114114
let sig =
115115
get_function_sig(fx.tcx, fx.target_config.default_call_conv, instance);
116-
create_wrapper_function(
117-
fx.module,
118-
&mut fx.cx.unwind_context,
119-
sig,
120-
&wrapper_name,
121-
symbol.name,
122-
);
116+
create_wrapper_function(fx.module, sig, &wrapper_name, symbol.name);
123117

124118
CInlineAsmOperand::Symbol { symbol: wrapper_name }
125119
} else {
@@ -283,13 +277,7 @@ pub(crate) fn codegen_naked_asm<'tcx>(
283277
);
284278
let sig =
285279
get_function_sig(tcx, module.target_config().default_call_conv, instance);
286-
create_wrapper_function(
287-
module,
288-
&mut cx.unwind_context,
289-
sig,
290-
&wrapper_name,
291-
symbol.name,
292-
);
280+
create_wrapper_function(module, sig, &wrapper_name, symbol.name);
293281

294282
CInlineAsmOperand::Symbol { symbol: wrapper_name }
295283
} else {

‎compiler/rustc_codegen_cranelift/src/intrinsics/llvm_x86.rs

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,11 +459,20 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
459459
intrinsic_args!(fx, args => (a); intrinsic);
460460
let a = a.load_scalar(fx);
461461

462+
let value = fx.bcx.ins().x86_cvtt2dq(types::I32X4, a);
463+
let cvalue = CValue::by_val(value, ret.layout());
464+
ret.write_cvalue(fx, cvalue);
465+
}
466+
"llvm.x86.sse2.cvtps2dq" => {
467+
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_mm_cvtps_epi32
468+
intrinsic_args!(fx, args => (a); intrinsic);
469+
let a = a.load_scalar(fx);
470+
462471
// Using inline asm instead of fcvt_to_sint_sat as unrepresentable values are turned
463472
// into 0x80000000 for which Cranelift doesn't have a native instruction.
464473
codegen_inline_asm_inner(
465474
fx,
466-
&[InlineAsmTemplatePiece::String(format!("cvttps2dq xmm0, xmm0"))],
475+
&[InlineAsmTemplatePiece::String(format!("cvtps2dq xmm0, xmm0"))],
467476
&[CInlineAsmOperand::InOut {
468477
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::xmm0)),
469478
_late: true,
@@ -1416,6 +1425,36 @@ pub(crate) fn codegen_x86_llvm_intrinsic_call<'tcx>(
14161425
ret.write_cvalue(fx, res);
14171426
}
14181427

1428+
"llvm.x86.rdtsc" => {
1429+
// https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html#text=_rdtsc&ig_expand=5273
1430+
1431+
let res_place = CPlace::new_stack_slot(
1432+
fx,
1433+
fx.layout_of(Ty::new_tup(fx.tcx, &[fx.tcx.types.u32, fx.tcx.types.u32])),
1434+
);
1435+
let eax_place = res_place.place_field(fx, FieldIdx::new(0));
1436+
let edx_place = res_place.place_field(fx, FieldIdx::new(1));
1437+
codegen_inline_asm_inner(
1438+
fx,
1439+
&[InlineAsmTemplatePiece::String("rdtsc".to_string())],
1440+
&[
1441+
CInlineAsmOperand::Out {
1442+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::ax)),
1443+
late: true,
1444+
place: Some(eax_place),
1445+
},
1446+
CInlineAsmOperand::Out {
1447+
reg: InlineAsmRegOrRegClass::Reg(InlineAsmReg::X86(X86InlineAsmReg::dx)),
1448+
late: true,
1449+
place: Some(edx_place),
1450+
},
1451+
],
1452+
InlineAsmOptions::NOSTACK | InlineAsmOptions::NOMEM,
1453+
);
1454+
let res = res_place.to_cvalue(fx);
1455+
ret.write_cvalue_transmute(fx, res);
1456+
}
1457+
14191458
_ => {
14201459
fx.tcx
14211460
.dcx()

‎compiler/rustc_codegen_cranelift/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ mod pretty_clif;
7979
mod toolchain;
8080
mod trap;
8181
mod unsize;
82+
mod unwind_module;
8283
mod value_and_place;
8384
mod vtable;
8485

@@ -130,22 +131,13 @@ struct CodegenCx {
130131
global_asm: String,
131132
inline_asm_index: Cell<usize>,
132133
debug_context: Option<DebugContext>,
133-
unwind_context: UnwindContext,
134134
cgu_name: Symbol,
135135
}
136136

137137
impl CodegenCx {
138-
fn new(
139-
tcx: TyCtxt<'_>,
140-
backend_config: BackendConfig,
141-
isa: &dyn TargetIsa,
142-
debug_info: bool,
143-
cgu_name: Symbol,
144-
) -> Self {
138+
fn new(tcx: TyCtxt<'_>, isa: &dyn TargetIsa, debug_info: bool, cgu_name: Symbol) -> Self {
145139
assert_eq!(pointer_ty(tcx), isa.pointer_type());
146140

147-
let unwind_context =
148-
UnwindContext::new(isa, matches!(backend_config.codegen_mode, CodegenMode::Aot));
149141
let debug_context = if debug_info && !tcx.sess.target.options.is_like_windows {
150142
Some(DebugContext::new(tcx, isa, cgu_name.as_str()))
151143
} else {
@@ -158,7 +150,6 @@ impl CodegenCx {
158150
global_asm: String::new(),
159151
inline_asm_index: Cell::new(0),
160152
debug_context,
161-
unwind_context,
162153
cgu_name,
163154
}
164155
}
@@ -175,14 +166,19 @@ impl CodegenBackend for CraneliftCodegenBackend {
175166
}
176167

177168
fn init(&self, sess: &Session) {
178-
use rustc_session::config::Lto;
169+
use rustc_session::config::{InstrumentCoverage, Lto};
179170
match sess.lto() {
180171
Lto::No | Lto::ThinLocal => {}
181172
Lto::Thin | Lto::Fat => {
182173
sess.dcx().warn("LTO is not supported. You may get a linker error.")
183174
}
184175
}
185176

177+
if sess.opts.cg.instrument_coverage() != InstrumentCoverage::No {
178+
sess.dcx()
179+
.fatal("`-Cinstrument-coverage` is LLVM specific and not supported by Cranelift");
180+
}
181+
186182
let mut config = self.config.borrow_mut();
187183
if config.is_none() {
188184
let new_config = BackendConfig::from_opts(&sess.opts.cg.llvm_args)

‎compiler/rustc_codegen_cranelift/src/main_shim.rs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@ use crate::prelude::*;
1111
/// users main function.
1212
pub(crate) fn maybe_create_entry_wrapper(
1313
tcx: TyCtxt<'_>,
14-
module: &mut impl Module,
15-
unwind_context: &mut UnwindContext,
14+
module: &mut dyn Module,
1615
is_jit: bool,
1716
is_primary_cgu: bool,
1817
) {
@@ -36,12 +35,11 @@ pub(crate) fn maybe_create_entry_wrapper(
3635
return;
3736
}
3837

39-
create_entry_fn(tcx, module, unwind_context, main_def_id, is_jit, is_main_fn, sigpipe);
38+
create_entry_fn(tcx, module, main_def_id, is_jit, is_main_fn, sigpipe);
4039

4140
fn create_entry_fn(
4241
tcx: TyCtxt<'_>,
43-
m: &mut impl Module,
44-
unwind_context: &mut UnwindContext,
42+
m: &mut dyn Module,
4543
rust_main_def_id: DefId,
4644
ignore_lang_start_wrapper: bool,
4745
is_main_fn: bool,
@@ -170,7 +168,5 @@ pub(crate) fn maybe_create_entry_wrapper(
170168
if let Err(err) = m.define_function(cmain_func_id, &mut ctx) {
171169
tcx.dcx().fatal(format!("entry symbol `{entry_name}` defined multiple times: {err}"));
172170
}
173-
174-
unwind_context.add_function(cmain_func_id, &ctx, m.isa());
175171
}
176172
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
use cranelift_codegen::control::ControlPlane;
2+
use cranelift_codegen::ir::{Function, Signature};
3+
use cranelift_codegen::isa::{TargetFrontendConfig, TargetIsa};
4+
use cranelift_codegen::{Context, FinalizedMachReloc};
5+
use cranelift_module::{
6+
DataDescription, DataId, FuncId, FuncOrDataId, Linkage, Module, ModuleDeclarations,
7+
ModuleResult,
8+
};
9+
use cranelift_object::{ObjectModule, ObjectProduct};
10+
11+
use crate::UnwindContext;
12+
13+
/// A wrapper around a [Module] which adds any defined function to the [UnwindContext].
14+
pub(crate) struct UnwindModule<T> {
15+
pub(crate) module: T,
16+
unwind_context: UnwindContext,
17+
}
18+
19+
impl<T: Module> UnwindModule<T> {
20+
pub(crate) fn new(module: T, pic_eh_frame: bool) -> Self {
21+
let unwind_context = UnwindContext::new(module.isa(), pic_eh_frame);
22+
UnwindModule { module, unwind_context }
23+
}
24+
}
25+
26+
impl UnwindModule<ObjectModule> {
27+
pub(crate) fn finish(self) -> ObjectProduct {
28+
let mut product = self.module.finish();
29+
self.unwind_context.emit(&mut product);
30+
product
31+
}
32+
}
33+
34+
#[cfg(feature = "jit")]
35+
impl UnwindModule<cranelift_jit::JITModule> {
36+
pub(crate) fn finalize_definitions(&mut self) {
37+
self.module.finalize_definitions().unwrap();
38+
let prev_unwind_context = std::mem::replace(
39+
&mut self.unwind_context,
40+
UnwindContext::new(self.module.isa(), false),
41+
);
42+
unsafe { prev_unwind_context.register_jit(&self.module) };
43+
}
44+
}
45+
46+
impl<T: Module> Module for UnwindModule<T> {
47+
fn isa(&self) -> &dyn TargetIsa {
48+
self.module.isa()
49+
}
50+
51+
fn declarations(&self) -> &ModuleDeclarations {
52+
self.module.declarations()
53+
}
54+
55+
fn get_name(&self, name: &str) -> Option<FuncOrDataId> {
56+
self.module.get_name(name)
57+
}
58+
59+
fn target_config(&self) -> TargetFrontendConfig {
60+
self.module.target_config()
61+
}
62+
63+
fn declare_function(
64+
&mut self,
65+
name: &str,
66+
linkage: Linkage,
67+
signature: &Signature,
68+
) -> ModuleResult<FuncId> {
69+
self.module.declare_function(name, linkage, signature)
70+
}
71+
72+
fn declare_anonymous_function(&mut self, signature: &Signature) -> ModuleResult<FuncId> {
73+
self.module.declare_anonymous_function(signature)
74+
}
75+
76+
fn declare_data(
77+
&mut self,
78+
name: &str,
79+
linkage: Linkage,
80+
writable: bool,
81+
tls: bool,
82+
) -> ModuleResult<DataId> {
83+
self.module.declare_data(name, linkage, writable, tls)
84+
}
85+
86+
fn declare_anonymous_data(&mut self, writable: bool, tls: bool) -> ModuleResult<DataId> {
87+
self.module.declare_anonymous_data(writable, tls)
88+
}
89+
90+
fn define_function_with_control_plane(
91+
&mut self,
92+
func: FuncId,
93+
ctx: &mut Context,
94+
ctrl_plane: &mut ControlPlane,
95+
) -> ModuleResult<()> {
96+
self.module.define_function_with_control_plane(func, ctx, ctrl_plane)?;
97+
self.unwind_context.add_function(func, ctx, self.module.isa());
98+
Ok(())
99+
}
100+
101+
fn define_function_bytes(
102+
&mut self,
103+
_func_id: FuncId,
104+
_func: &Function,
105+
_alignment: u64,
106+
_bytes: &[u8],
107+
_relocs: &[FinalizedMachReloc],
108+
) -> ModuleResult<()> {
109+
unimplemented!()
110+
}
111+
112+
fn define_data(&mut self, data_id: DataId, data: &DataDescription) -> ModuleResult<()> {
113+
self.module.define_data(data_id, data)
114+
}
115+
}

0 commit comments

Comments
 (0)
Please sign in to comment.