Skip to content

Commit

Permalink
Fix compilation for libgccjit12
Browse files Browse the repository at this point in the history
  • Loading branch information
antoyo committed Jul 13, 2023
1 parent c4e86b6 commit bb6bb84
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 22 deletions.
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,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'
Expand Down
2 changes: 1 addition & 1 deletion build_sysroot/build_sysroot.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
RUSTFLAGS="$RUSTFLAGS -Cembed-bitcode=no -Clto=no" cargo build --target $TARGET_TRIPLE --features compiler_builtins/c
fi

# Copy files to sysroot
Expand Down
8 changes: 7 additions & 1 deletion src/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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;

Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion src/builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
69 changes: 51 additions & 18 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ extern crate rustc_middle;
extern crate rustc_session;
extern crate rustc_span;
extern crate rustc_target;
extern crate tempfile;

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --mini-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --std-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-rand-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, sde -future -rtm_mode full --)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-example-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-failing-rustc)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, sde -future -rtm_mode full --)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --extended-regex-tests)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 0)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit_without_int128.so, master-without-128bit-integers, --test-successful-rustc --nb-...

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-libcore)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

Check warning on line 38 in src/lib.rs

View workflow job for this annotation

GitHub Actions / build (libgccjit.so, master, --test-successful-rustc --nb-parts 2 --current-part 1)

unused extern crate

// This prevents duplicating functions and statics that are already part of the host rustc process.
#[allow(unused_extern_crates)]
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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<dyn CodegenBackend> {
// 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,
Expand Down Expand Up @@ -314,15 +354,8 @@ pub fn target_features(sess: &Session, allow_unstable: bool, target_info: &Arc<T
if sess.is_nightly_build() || allow_unstable || gate.is_none() { Some(feature) } else { None }
},
)
.filter(|_feature| {
#[cfg(feature="master")]
{
target_info.cpu_supports(_feature)
}
#[cfg(not(feature="master"))]
{
false
}
.filter(|feature| {
target_info.cpu_supports(feature)
/*
adx, aes, avx, avx2, avx512bf16, avx512bitalg, avx512bw, avx512cd, avx512dq, avx512er, avx512f, avx512ifma,
avx512pf, avx512vbmi, avx512vbmi2, avx512vl, avx512vnni, avx512vp2intersect, avx512vpopcntdq,
Expand Down

0 comments on commit bb6bb84

Please sign in to comment.