Skip to content

Commit fc8e79f

Browse files
antoyocjgillotmichaelwoeristerAmanieuJohnTitor
authored
Sync from rust (rust-lang#107)
* Rebase fallout. * Move rustc_middle::middle::cstore to rustc_session. * Create more accurate debuginfo for vtables. Before this commit all vtables would have the same name "vtable" in debuginfo. Now they get a name that identifies the implementing type and the trait that is being implemented. * Remove alloc::prelude As per the libs team decision in rust-lang#58935. Closes rust-lang#58935 * Make hash_result an Option. * Properly check `target_features` not to trigger an assertion * Add LLVM CFI support to the Rust compiler This commit adds LLVM Control Flow Integrity (CFI) support to the Rust compiler. It initially provides forward-edge control flow protection for Rust-compiled code only by aggregating function pointers in groups identified by their number of arguments. Forward-edge control flow protection for C or C++ and Rust -compiled code "mixed binaries" (i.e., for when C or C++ and Rust -compiled code share the same virtual address space) will be provided in later work as part of this project by defining and using compatible type identifiers (see Type metadata in the design document in the tracking issue rust-lang#89653). LLVM CFI can be enabled with -Zsanitizer=cfi and requires LTO (i.e., -Clto). * Update to nightly-2021-10-30 * Add deduplication of constant values as rustc relies on LLVM doing that Co-authored-by: Camille GILLOT <[email protected]> Co-authored-by: Michael Woerister <michaelwoerister@posteo> Co-authored-by: Amanieu d'Antras <[email protected]> Co-authored-by: Yuki Okushi <[email protected]> Co-authored-by: Ramon de C Valle <[email protected]>
1 parent 1d064f1 commit fc8e79f

File tree

10 files changed

+40
-16
lines changed

10 files changed

+40
-16
lines changed

example/alloc_example.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
#![feature(start, box_syntax, core_intrinsics, alloc_prelude, alloc_error_handler)]
1+
#![feature(start, box_syntax, core_intrinsics, alloc_error_handler)]
22
#![no_std]
33

44
extern crate alloc;
55
extern crate alloc_system;
66

7-
use alloc::prelude::v1::*;
7+
use alloc::boxed::Box;
88

99
use alloc_system::System;
1010

rust-toolchain

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
nightly-2021-09-28
1+
nightly-2021-10-30

src/archive.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::fs::File;
22
use std::path::{Path, PathBuf};
33

4-
use rustc_session::Session;
54
use rustc_codegen_ssa::back::archive::ArchiveBuilder;
5+
use rustc_session::Session;
66

77
use rustc_data_structures::temp_dir::MaybeTempDir;
8-
use rustc_middle::middle::cstore::DllImport;
9-
8+
use rustc_session::cstore::DllImport;
109

1110
struct ArchiveConfig<'a> {
1211
sess: &'a Session,

src/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl<'a, 'gcc, 'tcx> AsmBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
118118
true
119119
}
120120

121-
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, _span: &[Span]) {
121+
fn codegen_inline_asm(&mut self, template: &[InlineAsmTemplatePiece], rust_operands: &[InlineAsmOperandRef<'tcx, Self>], options: InlineAsmOptions, _span: &[Span], _instance: Instance<'_>) {
122122
let asm_arch = self.tcx.sess.asm_arch.unwrap();
123123
let is_x86 = matches!(asm_arch, InlineAsmArch::X86 | InlineAsmArch::X86_64);
124124
let att_dialect = is_x86 && options.contains(InlineAsmOptions::ATT_SYNTAX);

src/base.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ use gccjit::{
77
GlobalKind,
88
};
99
use rustc_middle::dep_graph;
10-
use rustc_middle::middle::cstore::EncodedMetadata;
1110
use rustc_middle::middle::exported_symbols;
1211
use rustc_middle::ty::TyCtxt;
1312
use rustc_middle::mir::mono::Linkage;
1413
use rustc_codegen_ssa::{ModuleCodegen, ModuleKind};
1514
use rustc_codegen_ssa::base::maybe_create_entry_wrapper;
1615
use rustc_codegen_ssa::mono_item::MonoItemExt;
1716
use rustc_codegen_ssa::traits::DebugInfoMethods;
17+
use rustc_metadata::EncodedMetadata;
1818
use rustc_session::config::DebugInfo;
1919
use rustc_span::Symbol;
2020

@@ -59,7 +59,13 @@ pub fn compile_codegen_unit<'tcx>(tcx: TyCtxt<'tcx>, cgu_name: Symbol) -> (Modul
5959
let start_time = Instant::now();
6060

6161
let dep_node = tcx.codegen_unit(cgu_name).codegen_dep_node(tcx);
62-
let (module, _) = tcx.dep_graph.with_task(dep_node, tcx, cgu_name, module_codegen, dep_graph::hash_result);
62+
let (module, _) = tcx.dep_graph.with_task(
63+
dep_node,
64+
tcx,
65+
cgu_name,
66+
module_codegen,
67+
Some(dep_graph::hash_result),
68+
);
6369
let time_to_codegen = start_time.elapsed();
6470
drop(prof_timer);
6571

@@ -152,7 +158,7 @@ pub fn write_compressed_metadata<'tcx>(tcx: TyCtxt<'tcx>, metadata: &EncodedMeta
152158

153159
let context = &gcc_module.context;
154160
let mut compressed = rustc_metadata::METADATA_HEADER.to_vec();
155-
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data).unwrap();
161+
FrameEncoder::new(&mut compressed).write_all(&metadata.raw_data()).unwrap();
156162

157163
let name = exported_symbols::metadata_symbol_name(tcx);
158164
let typ = context.new_array_type(None, context.new_type::<u8>(), compressed.len() as i32);

src/builder.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -910,6 +910,16 @@ impl<'a, 'gcc, 'tcx> BuilderMethods<'a, 'tcx> for Builder<'a, 'gcc, 'tcx> {
910910
// TODO(antoyo)
911911
}
912912

913+
fn type_metadata(&mut self, _function: RValue<'gcc>, _typeid: String) {
914+
// Unsupported.
915+
}
916+
917+
fn typeid_metadata(&mut self, _typeid: String) -> RValue<'gcc> {
918+
// Unsupported.
919+
self.context.new_rvalue_from_int(self.int_type, 0)
920+
}
921+
922+
913923
fn store(&mut self, val: RValue<'gcc>, ptr: RValue<'gcc>, align: Align) -> RValue<'gcc> {
914924
self.store_with_flags(val, ptr, align, MemFlags::empty())
915925
}

src/consts.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,13 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
3131

3232
impl<'gcc, 'tcx> StaticMethods for CodegenCx<'gcc, 'tcx> {
3333
fn static_addr_of(&self, cv: RValue<'gcc>, align: Align, kind: Option<&str>) -> RValue<'gcc> {
34-
if let Some(global_value) = self.const_globals.borrow().get(&cv) {
35-
// TODO(antoyo): upgrade alignment.
36-
return *global_value;
34+
// TODO(antoyo): implement a proper rvalue comparison in libgccjit instead of doing the
35+
// following:
36+
for (value, variable) in &*self.const_globals.borrow() {
37+
if format!("{:?}", value) == format!("{:?}", cv) {
38+
// TODO(antoyo): upgrade alignment.
39+
return *variable;
40+
}
3741
}
3842
let global_value = self.static_addr_of_mut(cv, align, kind);
3943
// TODO(antoyo): set global constant.

src/debuginfo.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use gccjit::RValue;
22
use rustc_codegen_ssa::mir::debuginfo::{FunctionDebugContext, VariableKind};
33
use rustc_codegen_ssa::traits::{DebugInfoBuilderMethods, DebugInfoMethods};
44
use rustc_middle::mir;
5-
use rustc_middle::ty::{Instance, Ty};
5+
use rustc_middle::ty::{Instance, PolyExistentialTraitRef, Ty};
66
use rustc_span::{SourceFile, Span, Symbol};
77
use rustc_target::abi::Size;
88
use rustc_target::abi::call::FnAbi;
@@ -31,7 +31,7 @@ impl<'a, 'gcc, 'tcx> DebugInfoBuilderMethods for Builder<'a, 'gcc, 'tcx> {
3131
}
3232

3333
impl<'gcc, 'tcx> DebugInfoMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
34-
fn create_vtable_metadata(&self, _ty: Ty<'tcx>, _vtable: Self::Value) {
34+
fn create_vtable_metadata(&self, _ty: Ty<'tcx>, _trait_ref: Option<PolyExistentialTraitRef<'tcx>>, _vtable: Self::Value) {
3535
// TODO(antoyo)
3636
}
3737

src/intrinsic/mod.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,6 +367,11 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
367367
// TODO(antoyo)
368368
}
369369

370+
fn type_test(&mut self, _pointer: Self::Value, _typeid: Self::Value) -> Self::Value {
371+
// Unsupported.
372+
self.context.new_rvalue_from_int(self.int_type, 0)
373+
}
374+
370375
fn va_start(&mut self, _va_list: RValue<'gcc>) -> RValue<'gcc> {
371376
unimplemented!();
372377
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ use rustc_codegen_ssa::target_features::supported_target_features;
6060
use rustc_codegen_ssa::traits::{CodegenBackend, ExtraBackendMethods, ModuleBufferMethods, ThinBufferMethods, WriteBackendMethods};
6161
use rustc_data_structures::fx::FxHashMap;
6262
use rustc_errors::{ErrorReported, Handler};
63+
use rustc_metadata::EncodedMetadata;
6364
use rustc_middle::dep_graph::{WorkProduct, WorkProductId};
64-
use rustc_middle::middle::cstore::EncodedMetadata;
6565
use rustc_middle::ty::TyCtxt;
6666
use rustc_session::config::{Lto, OptLevel, OutputFilenames};
6767
use rustc_session::Session;

0 commit comments

Comments
 (0)