Skip to content

Commit 2ffa3c8

Browse files
committed
Auto merge of rust-lang#122599 - bjorn3:sync_cg_clif-2024-03-16, r=bjorn3
Subtree sync for rustc_codegen_cranelift The main highlight this time is a fix for a recently introduced ICE. Fixes rust-lang#122399 r? `@ghost` `@rustbot` label +A-codegen +A-cranelift +T-compiler
2 parents 22e241e + 6697186 commit 2ffa3c8

File tree

7 files changed

+83
-30
lines changed

7 files changed

+83
-30
lines changed

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

+19-11
Original file line numberDiff line numberDiff line change
@@ -44,10 +44,9 @@ jobs:
4444
env:
4545
TARGET_TRIPLE: x86_64-apple-darwin
4646
# cross-compile from Linux to Windows using mingw
47-
# FIXME The wine version in Ubuntu 22.04 is missing ProcessPrng
48-
#- os: ubuntu-latest
49-
# env:
50-
# TARGET_TRIPLE: x86_64-pc-windows-gnu
47+
- os: ubuntu-latest
48+
env:
49+
TARGET_TRIPLE: x86_64-pc-windows-gnu
5150
- os: ubuntu-latest
5251
env:
5352
TARGET_TRIPLE: aarch64-unknown-linux-gnu
@@ -81,11 +80,11 @@ jobs:
8180
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
8281
run: rustup set default-host x86_64-pc-windows-gnu
8382

84-
#- name: Install MinGW toolchain and wine
85-
# if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
86-
# run: |
87-
# sudo apt-get update
88-
# sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
83+
- name: Install MinGW toolchain and wine
84+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
85+
run: |
86+
sudo apt-get update
87+
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
8988
9089
- name: Install AArch64 toolchain and qemu
9190
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
@@ -108,6 +107,15 @@ jobs:
108107
- name: Prepare dependencies
109108
run: ./y.sh prepare
110109

110+
# The Wine version shipped with Ubuntu 22.04 doesn't implement bcryptprimitives.dll
111+
- name: Build bcryptprimitives.dll shim for Wine
112+
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
113+
run: |
114+
rustup target add x86_64-pc-windows-gnu
115+
mkdir wine_shims
116+
rustc patches/bcryptprimitives.rs -Copt-level=3 -Clto=fat --out-dir wine_shims --target x86_64-pc-windows-gnu
117+
echo "WINEPATH=$(pwd)/wine_shims" >> $GITHUB_ENV
118+
111119
- name: Build
112120
run: ./y.sh build --sysroot none
113121

@@ -234,11 +242,11 @@ jobs:
234242
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
235243
run: rustup set default-host x86_64-pc-windows-gnu
236244

237-
- name: Install MinGW toolchain and wine
245+
- name: Install MinGW toolchain
238246
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
239247
run: |
240248
sudo apt-get update
241-
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
249+
sudo apt-get install -y gcc-mingw-w64-x86-64
242250
243251
- name: Prepare dependencies
244252
run: ./y.sh prepare

compiler/rustc_codegen_cranelift/example/std_example.rs

+8
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,14 @@ fn main() {
167167
transmute_fat_pointer();
168168

169169
rust_call_abi();
170+
171+
const fn no_str() -> Option<Box<str>> {
172+
None
173+
}
174+
175+
static STATIC_WITH_MAYBE_NESTED_BOX: &Option<Box<str>> = &no_str();
176+
177+
println!("{:?}", STATIC_WITH_MAYBE_NESTED_BOX);
170178
}
171179

172180
fn panic(_: u128) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Shim for bcryptprimitives.dll. The Wine version shipped with Ubuntu 22.04
2+
// doesn't support it yet. Authored by @ChrisDenton
3+
4+
#![crate_type = "cdylib"]
5+
#![allow(nonstandard_style)]
6+
7+
#[no_mangle]
8+
pub unsafe extern "system" fn ProcessPrng(mut pbData: *mut u8, mut cbData: usize) -> i32 {
9+
while cbData > 0 {
10+
let size = core::cmp::min(cbData, u32::MAX as usize);
11+
RtlGenRandom(pbData, size as u32);
12+
cbData -= size;
13+
pbData = pbData.add(size);
14+
}
15+
1
16+
}
17+
18+
#[link(name = "advapi32")]
19+
extern "system" {
20+
#[link_name = "SystemFunction036"]
21+
pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8;
22+
}

compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml

+2-5
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"
4242

4343
[[package]]
4444
name = "cc"
45-
version = "1.0.83"
45+
version = "1.0.90"
4646
source = "registry+https://github.com/rust-lang/crates.io-index"
47-
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
48-
dependencies = [
49-
"libc",
50-
]
47+
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"
5148

5249
[[package]]
5350
name = "cfg-if"
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
[toolchain]
2-
channel = "nightly-2024-03-08"
2+
channel = "nightly-2024-03-16"
33
components = ["rust-src", "rustc-dev", "llvm-tools"]

compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh

+2
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported
8383
rm -r tests/run-make/target-specs # i686 not supported by Cranelift
8484
rm -r tests/run-make/mismatching-target-triples # same
8585
rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't work entirely correctly
86+
rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported
8687

8788
# requires LTO
8889
rm -r tests/run-make/cdylib
@@ -121,6 +122,7 @@ rm -r tests/run-make/optimization-remarks-dir # remarks are LLVM specific
121122
rm tests/ui/mir/mir_misc_casts.rs # depends on deduplication of constants
122123
rm tests/ui/mir/mir_raw_fat_ptr.rs # same
123124
rm tests/ui/consts/issue-33537.rs # same
125+
rm tests/ui/consts/const-mut-refs-crate.rs # same
124126

125127
# rustdoc-clif passes extra args, suppressing the help message when no args are passed
126128
rm -r tests/run-make/issue-88756-default-output

compiler/rustc_codegen_cranelift/src/constant.rs

+29-13
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,11 @@ pub(crate) fn codegen_tls_ref<'tcx>(
5353
let call = fx.bcx.ins().call(func_ref, &[]);
5454
fx.bcx.func.dfg.first_result(call)
5555
} else {
56-
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
56+
let data_id = data_id_for_static(
57+
fx.tcx, fx.module, def_id, false,
58+
// For a declaration the stated mutability doesn't matter.
59+
false,
60+
);
5761
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
5862
if fx.clif_comments.enabled() {
5963
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
@@ -164,7 +168,11 @@ pub(crate) fn codegen_const_value<'tcx>(
164168
}
165169
GlobalAlloc::Static(def_id) => {
166170
assert!(fx.tcx.is_static(def_id));
167-
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
171+
let data_id = data_id_for_static(
172+
fx.tcx, fx.module, def_id, false,
173+
// For a declaration the stated mutability doesn't matter.
174+
false,
175+
);
168176
let local_data_id =
169177
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
170178
if fx.clif_comments.enabled() {
@@ -232,21 +240,19 @@ fn data_id_for_static(
232240
module: &mut dyn Module,
233241
def_id: DefId,
234242
definition: bool,
243+
definition_writable: bool,
235244
) -> DataId {
236245
let attrs = tcx.codegen_fn_attrs(def_id);
237246

238247
let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
239248
let symbol_name = tcx.symbol_name(instance).name;
240-
let ty = instance.ty(tcx, ParamEnv::reveal_all());
241-
let is_mutable = if tcx.is_mutable_static(def_id) {
242-
true
243-
} else {
244-
!ty.is_freeze(tcx, ParamEnv::reveal_all())
245-
};
246-
let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();
247249

248250
if let Some(import_linkage) = attrs.import_linkage {
249251
assert!(!definition);
252+
assert!(!tcx.is_mutable_static(def_id));
253+
254+
let ty = instance.ty(tcx, ParamEnv::reveal_all());
255+
let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();
250256

251257
let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak
252258
|| import_linkage == rustc_middle::mir::mono::Linkage::WeakAny
@@ -259,7 +265,7 @@ fn data_id_for_static(
259265
let data_id = match module.declare_data(
260266
symbol_name,
261267
linkage,
262-
is_mutable,
268+
false,
263269
attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
264270
) {
265271
Ok(data_id) => data_id,
@@ -307,7 +313,7 @@ fn data_id_for_static(
307313
let data_id = match module.declare_data(
308314
symbol_name,
309315
linkage,
310-
is_mutable,
316+
definition_writable,
311317
attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
312318
) {
313319
Ok(data_id) => data_id,
@@ -341,7 +347,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
341347

342348
let alloc = tcx.eval_static_initializer(def_id).unwrap();
343349

344-
let data_id = data_id_for_static(tcx, module, def_id, true);
350+
let data_id = data_id_for_static(
351+
tcx,
352+
module,
353+
def_id,
354+
true,
355+
alloc.inner().mutability == Mutability::Mut,
356+
);
345357
(data_id, alloc, section_name)
346358
}
347359
};
@@ -421,7 +433,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
421433
// Don't push a `TodoItem::Static` here, as it will cause statics used by
422434
// multiple crates to be duplicated between them. It isn't necessary anyway,
423435
// as it will get pushed by `codegen_static` when necessary.
424-
data_id_for_static(tcx, module, def_id, false)
436+
data_id_for_static(
437+
tcx, module, def_id, false,
438+
// For a declaration the stated mutability doesn't matter.
439+
false,
440+
)
425441
}
426442
};
427443

0 commit comments

Comments
 (0)