diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index d2b7724a221..d0cbff40b9c 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -22,6 +22,7 @@ jobs: - { gcc: "libgccjit.so", extra: "", env_extra: "", artifacts_branch: "master" } - { gcc: "libgccjit_without_int128.so", extra: "", env_extra: "", artifacts_branch: "master-without-128bit-integers" } - { gcc: "libgccjit12.so", extra: "--no-default-features", env_extra: "TEST_FLAGS='-Cpanic=abort -Zpanic-abort-tests'", artifacts_branch: "gcc12" } + #- { gcc: "libgccjit12.so", extra: "--no-default-features", env_extra: "TEST_FLAGS='-Cpanic=abort -Zpanic-abort-tests' CG_RUSTFLAGS='-Clink-arg=-fno-use-linker-plugin'", artifacts_branch: "gcc12" } commands: [ "--mini-tests", "--std-tests", @@ -46,7 +47,9 @@ jobs: - name: Install packages # `llvm-14-tools` is needed to install the `FileCheck` binary which is used for asm tests. - run: sudo apt-get install ninja-build ripgrep llvm-14-tools + run: | + sudo apt-get update + sudo apt-get install ninja-build ripgrep llvm-14-tools - name: Install libgccjit12 if: matrix.libgccjit_version.gcc == 'libgccjit12.so' diff --git a/build_sysroot/build_sysroot.sh b/build_sysroot/build_sysroot.sh index 9d692d599f6..973c45d2eeb 100755 --- a/build_sysroot/build_sysroot.sh +++ b/build_sysroot/build_sysroot.sh @@ -22,7 +22,7 @@ if [[ "$1" == "--release" ]]; then RUSTFLAGS="$RUSTFLAGS -Zmir-opt-level=3" cargo build --target $TARGET_TRIPLE --release else sysroot_channel='debug' - cargo build --target $TARGET_TRIPLE --features compiler_builtins/c + GCC_EXEC_PREFIX=/usr/lib/gcc/x86_64-linux-gnu/ cargo build --target $TARGET_TRIPLE --features compiler_builtins/c fi # Copy files to sysroot diff --git a/src/base.rs b/src/base.rs index 82669aa99cf..b87a73fc5c9 100644 --- a/src/base.rs +++ b/src/base.rs @@ -6,8 +6,10 @@ use std::time::Instant; use gccjit::{ Context, FunctionType, - GlobalKind, TargetInfo, + GlobalKind, }; +#[cfg(feature="master")] +use gccjit::TargetInfo; use rustc_middle::dep_graph; use rustc_middle::ty::TyCtxt; #[cfg(feature="master")] @@ -21,6 +23,8 @@ use rustc_session::config::DebugInfo; use rustc_span::Symbol; use crate::GccContext; +#[cfg(not(feature="master"))] +use crate::TargetInfo; use crate::builder::Builder; use crate::context::CodegenCx; @@ -89,6 +93,8 @@ pub fn compile_codegen_unit(tcx: TyCtxt<'_>, cgu_name: Symbol, target_info: Arc< // Instantiate monomorphizations without filling out definitions yet... //let llvm_module = ModuleLlvm::new(tcx, &cgu_name.as_str()); let context = Context::default(); + //context.add_driver_option("-v"); + //context.add_driver_option("-fno-use-linker-plugin"); context.add_command_line_option("-fexceptions"); context.add_driver_option("-fexceptions"); diff --git a/src/builder.rs b/src/builder.rs index 43d0aafbd50..0d5b15bef52 100644 --- a/src/builder.rs +++ b/src/builder.rs @@ -501,7 +501,7 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> { } #[cfg(not(feature="master"))] - fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: &CodegenFnAttrs, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> { + fn invoke(&mut self, typ: Type<'gcc>, fn_attrs: Option<&CodegenFnAttrs>, fn_abi: Option<&FnAbi<'tcx, Ty<'tcx>>>, func: RValue<'gcc>, args: &[RValue<'gcc>], then: Block<'gcc>, catch: Block<'gcc>, _funclet: Option<&Funclet>) -> RValue<'gcc> { let call_site = self.call(typ, fn_attrs, None, func, args, None); let condition = self.context.new_rvalue_from_int(self.bool_type, 1); self.llbb().end_with_conditional(None, condition, then, catch); diff --git a/src/lib.rs b/src/lib.rs index 4e9c2f91be5..a29ecec8c96 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -35,6 +35,7 @@ extern crate rustc_middle; extern crate rustc_session; extern crate rustc_span; extern crate rustc_target; +extern crate tempfile; // This prevents duplicating functions and statics that are already part of the host rustc process. #[allow(unused_extern_crates)] @@ -66,7 +67,9 @@ use std::any::Any; use std::sync::Arc; use crate::errors::LTONotSupported; -use gccjit::{Context, OptimizationLevel, TargetInfo}; +use gccjit::{Context, OptimizationLevel}; +#[cfg(feature="master")] +use gccjit::TargetInfo; use rustc_ast::expand::allocator::AllocatorKind; use rustc_codegen_ssa::{CodegenResults, CompiledModule, ModuleCodegen}; use rustc_codegen_ssa::base::codegen_crate; @@ -259,17 +262,54 @@ impl WriteBackendMethods for GccCodegenBackend { } } +#[cfg(not(feature="master"))] +#[derive(Debug)] +pub struct TargetInfo { + supports_128bit_integers: bool, +} + +#[cfg(not(feature="master"))] +impl TargetInfo { + fn cpu_supports(&self, _feature: &str) -> bool { + false + } + + fn supports_128bit_int(&self) -> bool { + self.supports_128bit_integers + } +} + /// This is the entrypoint for a hot plugged rustc_codegen_gccjit #[no_mangle] pub fn __rustc_codegen_backend() -> Box { - // Get the native arch and check whether the target supports 128-bit integers. - let context = Context::default(); - let arch = context.get_target_info().arch().unwrap(); - - // Get the second TargetInfo with the correct CPU features by setting the arch. - let context = Context::default(); - context.add_driver_option(&format!("-march={}", arch.to_str().unwrap())); - let target_info = Arc::new(context.get_target_info()); + #[cfg(feature="master")] + let target_info = { + // Get the native arch and check whether the target supports 128-bit integers. + let context = Context::default(); + let arch = context.get_target_info().arch().unwrap(); + + // Get the second TargetInfo with the correct CPU features by setting the arch. + let context = Context::default(); + context.add_driver_option(&format!("-march={}", arch.to_str().unwrap())); + Arc::new(context.get_target_info()) + }; + + #[cfg(not(feature="master"))] + let target_info = { + use gccjit::CType; + use tempfile::TempDir; + + let temp_dir = TempDir::new().expect("cannot create temporary directory"); + let temp_file = temp_dir.into_path().join("result.asm"); + let check_context = Context::default(); + check_context.set_print_errors_to_stderr(false); + let _int128_ty = check_context.new_c_type(CType::UInt128t); + // NOTE: we cannot just call compile() as this would require other files than libgccjit.so. + check_context.compile_to_file(gccjit::OutputKind::Assembler, temp_file.to_str().expect("path to str")); + Arc::new(TargetInfo { + supports_128bit_integers: check_context.get_last_error() == Ok(None), + }) + }; Box::new(GccCodegenBackend { target_info, @@ -314,15 +354,8 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Arc