Skip to content

Subtree sync for rustc_codegen_cranelift #122599

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 20 commits into from
Mar 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
98dcd85
Change InlineAsm to allow multiple targets instead
nbdd0121 Dec 26, 2023
8cec998
Implement asm goto in MIR and MIR lowering
nbdd0121 Dec 26, 2023
a11756c
Forbid implementing `Freeze` even if the trait is stabilized
oli-obk Feb 23, 2024
5ffd498
Rollup merge of #119365 - nbdd0121:asm-goto, r=Amanieu
matthiaskrgr Mar 8, 2024
5ec45d3
Merge commit '54cbb6e7531f95e086d5c3dd0d5e73bfbe3545ba' into sync_cg_…
bjorn3 Mar 8, 2024
77dae8c
Merge branch 'sync_from_rust'
bjorn3 Mar 8, 2024
127c232
Distinguish between library and lang UB in assert_unsafe_precondition
saethlin Feb 27, 2024
f5a192b
Rustup to rustc 1.78.0-nightly (46b180ec2 2024-03-08)
bjorn3 Mar 9, 2024
e18201d
Fix rustc test suite
bjorn3 Mar 9, 2024
0763382
Add bcryptprimitives.dll shim for wine
bjorn3 Mar 9, 2024
ef862a7
Auto merge of #121662 - saethlin:precondition-unification, r=RalfJung
bors Mar 10, 2024
01affeb
use Instance::expect_resolve() instead of unwraping Instance::resolve()
RalfJung Mar 10, 2024
fe7be63
add comments explaining where post-mono const eval errors abort compi…
RalfJung Mar 10, 2024
221402e
Rollup merge of #121840 - oli-obk:freeze, r=dtolnay
jhpratt Mar 11, 2024
47abd3a
Rollup merge of #122287 - RalfJung:simd-static-assert, r=pnkfelix
matthiaskrgr Mar 14, 2024
0000db5
Sync from rust c67326b063bd27ed04f306ba2e372cd92e0a8751
bjorn3 Mar 16, 2024
9f162c4
Rustup to rustc 1.78.0-nightly (c67326b06 2024-03-15)
bjorn3 Mar 16, 2024
e775fdc
Don't try to get a ty for a nested allocation
bjorn3 Mar 16, 2024
4cf4ffc
Fix rustc test suite
bjorn3 Mar 16, 2024
6697186
Merge commit '4cf4ffc6ba514f171b3f52d1c731063e4fc45be3' into sync_cg_…
bjorn3 Mar 16, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 19 additions & 11 deletions compiler/rustc_codegen_cranelift/.github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,9 @@ jobs:
env:
TARGET_TRIPLE: x86_64-apple-darwin
# cross-compile from Linux to Windows using mingw
# FIXME The wine version in Ubuntu 22.04 is missing ProcessPrng
#- os: ubuntu-latest
# env:
# TARGET_TRIPLE: x86_64-pc-windows-gnu
- os: ubuntu-latest
env:
TARGET_TRIPLE: x86_64-pc-windows-gnu
- os: ubuntu-latest
env:
TARGET_TRIPLE: aarch64-unknown-linux-gnu
Expand Down Expand Up @@ -81,11 +80,11 @@ jobs:
if: matrix.os == 'windows-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: rustup set default-host x86_64-pc-windows-gnu

#- name: Install MinGW toolchain and wine
# if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
# run: |
# sudo apt-get update
# sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
- name: Install MinGW toolchain and wine
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable

- name: Install AArch64 toolchain and qemu
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'aarch64-unknown-linux-gnu'
Expand All @@ -108,6 +107,15 @@ jobs:
- name: Prepare dependencies
run: ./y.sh prepare

# The Wine version shipped with Ubuntu 22.04 doesn't implement bcryptprimitives.dll
- name: Build bcryptprimitives.dll shim for Wine
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: |
rustup target add x86_64-pc-windows-gnu
mkdir wine_shims
rustc patches/bcryptprimitives.rs -Copt-level=3 -Clto=fat --out-dir wine_shims --target x86_64-pc-windows-gnu
echo "WINEPATH=$(pwd)/wine_shims" >> $GITHUB_ENV

- name: Build
run: ./y.sh build --sysroot none

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

- name: Install MinGW toolchain and wine
- name: Install MinGW toolchain
if: matrix.os == 'ubuntu-latest' && matrix.env.TARGET_TRIPLE == 'x86_64-pc-windows-gnu'
run: |
sudo apt-get update
sudo apt-get install -y gcc-mingw-w64-x86-64 wine-stable
sudo apt-get install -y gcc-mingw-w64-x86-64

- name: Prepare dependencies
run: ./y.sh prepare
Expand Down
8 changes: 8 additions & 0 deletions compiler/rustc_codegen_cranelift/example/std_example.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ fn main() {
transmute_fat_pointer();

rust_call_abi();

const fn no_str() -> Option<Box<str>> {
None
}

static STATIC_WITH_MAYBE_NESTED_BOX: &Option<Box<str>> = &no_str();

println!("{:?}", STATIC_WITH_MAYBE_NESTED_BOX);
}

fn panic(_: u128) {
Expand Down
22 changes: 22 additions & 0 deletions compiler/rustc_codegen_cranelift/patches/bcryptprimitives.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Shim for bcryptprimitives.dll. The Wine version shipped with Ubuntu 22.04
// doesn't support it yet. Authored by @ChrisDenton

#![crate_type = "cdylib"]
#![allow(nonstandard_style)]

#[no_mangle]
pub unsafe extern "system" fn ProcessPrng(mut pbData: *mut u8, mut cbData: usize) -> i32 {
while cbData > 0 {
let size = core::cmp::min(cbData, u32::MAX as usize);
RtlGenRandom(pbData, size as u32);
cbData -= size;
pbData = pbData.add(size);
}
1
}

#[link(name = "advapi32")]
extern "system" {
#[link_name = "SystemFunction036"]
pub fn RtlGenRandom(RandomBuffer: *mut u8, RandomBufferLength: u32) -> u8;
}
7 changes: 2 additions & 5 deletions compiler/rustc_codegen_cranelift/patches/stdlib-lock.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,9 @@ checksum = "0942ffc6dcaadf03badf6e6a2d0228460359d5e34b57ccdc720b7382dfbd5ec5"

[[package]]
name = "cc"
version = "1.0.83"
version = "1.0.90"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f1174fb0b6ec23863f8b971027804a42614e347eafb0a95bf0b12cdae21fc4d0"
dependencies = [
"libc",
]
checksum = "8cd6604a82acf3039f1144f54b8eb34e91ffba622051189e71b781822d5ee1f5"

[[package]]
name = "cfg-if"
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_codegen_cranelift/rust-toolchain
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "nightly-2024-03-08"
channel = "nightly-2024-03-16"
components = ["rust-src", "rustc-dev", "llvm-tools"]
2 changes: 2 additions & 0 deletions compiler/rustc_codegen_cranelift/scripts/test_rustc_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ rm -r tests/run-make/symbols-include-type-name # --emit=asm not supported
rm -r tests/run-make/target-specs # i686 not supported by Cranelift
rm -r tests/run-make/mismatching-target-triples # same
rm tests/ui/asm/x86_64/issue-96797.rs # const and sym inline asm operands don't work entirely correctly
rm tests/ui/asm/x86_64/goto.rs # inline asm labels not supported

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

# rustdoc-clif passes extra args, suppressing the help message when no args are passed
rm -r tests/run-make/issue-88756-default-output
Expand Down
42 changes: 29 additions & 13 deletions compiler/rustc_codegen_cranelift/src/constant.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,11 @@ pub(crate) fn codegen_tls_ref<'tcx>(
let call = fx.bcx.ins().call(func_ref, &[]);
fx.bcx.func.dfg.first_result(call)
} else {
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
let data_id = data_id_for_static(
fx.tcx, fx.module, def_id, false,
// For a declaration the stated mutability doesn't matter.
false,
);
let local_data_id = fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
if fx.clif_comments.enabled() {
fx.add_comment(local_data_id, format!("tls {:?}", def_id));
Expand Down Expand Up @@ -164,7 +168,11 @@ pub(crate) fn codegen_const_value<'tcx>(
}
GlobalAlloc::Static(def_id) => {
assert!(fx.tcx.is_static(def_id));
let data_id = data_id_for_static(fx.tcx, fx.module, def_id, false);
let data_id = data_id_for_static(
fx.tcx, fx.module, def_id, false,
// For a declaration the stated mutability doesn't matter.
false,
);
let local_data_id =
fx.module.declare_data_in_func(data_id, &mut fx.bcx.func);
if fx.clif_comments.enabled() {
Expand Down Expand Up @@ -232,21 +240,19 @@ fn data_id_for_static(
module: &mut dyn Module,
def_id: DefId,
definition: bool,
definition_writable: bool,
) -> DataId {
let attrs = tcx.codegen_fn_attrs(def_id);

let instance = Instance::mono(tcx, def_id).polymorphize(tcx);
let symbol_name = tcx.symbol_name(instance).name;
let ty = instance.ty(tcx, ParamEnv::reveal_all());
let is_mutable = if tcx.is_mutable_static(def_id) {
true
} else {
!ty.is_freeze(tcx, ParamEnv::reveal_all())
};
let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();

if let Some(import_linkage) = attrs.import_linkage {
assert!(!definition);
assert!(!tcx.is_mutable_static(def_id));

let ty = instance.ty(tcx, ParamEnv::reveal_all());
let align = tcx.layout_of(ParamEnv::reveal_all().and(ty)).unwrap().align.pref.bytes();

let linkage = if import_linkage == rustc_middle::mir::mono::Linkage::ExternalWeak
|| import_linkage == rustc_middle::mir::mono::Linkage::WeakAny
Expand All @@ -259,7 +265,7 @@ fn data_id_for_static(
let data_id = match module.declare_data(
symbol_name,
linkage,
is_mutable,
false,
attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
) {
Ok(data_id) => data_id,
Expand Down Expand Up @@ -307,7 +313,7 @@ fn data_id_for_static(
let data_id = match module.declare_data(
symbol_name,
linkage,
is_mutable,
definition_writable,
attrs.flags.contains(CodegenFnAttrFlags::THREAD_LOCAL),
) {
Ok(data_id) => data_id,
Expand Down Expand Up @@ -341,7 +347,13 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant

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

let data_id = data_id_for_static(tcx, module, def_id, true);
let data_id = data_id_for_static(
tcx,
module,
def_id,
true,
alloc.inner().mutability == Mutability::Mut,
);
(data_id, alloc, section_name)
}
};
Expand Down Expand Up @@ -421,7 +433,11 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut dyn Module, cx: &mut Constant
// Don't push a `TodoItem::Static` here, as it will cause statics used by
// multiple crates to be duplicated between them. It isn't necessary anyway,
// as it will get pushed by `codegen_static` when necessary.
data_id_for_static(tcx, module, def_id, false)
data_id_for_static(
tcx, module, def_id, false,
// For a declaration the stated mutability doesn't matter.
false,
)
}
};

Expand Down
Loading