mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
Clean fix for undefined symbol for allocator functions
This commit is contained in:
parent
64b30d344c
commit
e91ec42e33
@ -1031,7 +1031,7 @@ where
|
||||
&"always",
|
||||
&"--stage",
|
||||
&"0",
|
||||
&format!("tests/{}/codegen/virtual-function-elimination.rs", test_type),
|
||||
&format!("tests/{}", test_type),
|
||||
&"--compiletest-rustc-args",
|
||||
&rustc_args,
|
||||
],
|
||||
|
@ -1,6 +1,6 @@
|
||||
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
|
||||
#[cfg(feature = "master")]
|
||||
use gccjit::{FnAttribute, VarAttribute};
|
||||
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
|
||||
use rustc_ast::expand::allocator::{
|
||||
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
|
||||
alloc_error_handler_name, default_fn_name, global_fn_name,
|
||||
@ -9,8 +9,9 @@ use rustc_middle::bug;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::OomStrategy;
|
||||
|
||||
use crate::base::symbol_visibility_to_gcc;
|
||||
use crate::GccContext;
|
||||
#[cfg(feature = "master")]
|
||||
use crate::base::symbol_visibility_to_gcc;
|
||||
|
||||
pub(crate) unsafe fn codegen(
|
||||
tcx: TyCtxt<'_>,
|
||||
@ -72,7 +73,9 @@ pub(crate) unsafe fn codegen(
|
||||
let name = OomStrategy::SYMBOL.to_string();
|
||||
let global = context.new_global(None, GlobalKind::Exported, i8, name);
|
||||
#[cfg(feature = "master")]
|
||||
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
|
||||
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
|
||||
tcx.sess.default_visibility(),
|
||||
)));
|
||||
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
|
||||
let value = context.new_rvalue_from_int(i8, value as i32);
|
||||
global.global_set_initializer_rvalue(value);
|
||||
@ -80,7 +83,9 @@ pub(crate) unsafe fn codegen(
|
||||
let name = NO_ALLOC_SHIM_IS_UNSTABLE.to_string();
|
||||
let global = context.new_global(None, GlobalKind::Exported, i8, name);
|
||||
#[cfg(feature = "master")]
|
||||
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
|
||||
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
|
||||
tcx.sess.default_visibility(),
|
||||
)));
|
||||
let value = context.new_rvalue_from_int(i8, 0);
|
||||
global.global_set_initializer_rvalue(value);
|
||||
}
|
||||
@ -109,10 +114,10 @@ fn create_wrapper_function(
|
||||
false,
|
||||
);
|
||||
|
||||
println!("{} -> {}: {:?}", from_name, to_name, tcx.sess.default_visibility());
|
||||
|
||||
#[cfg(feature = "master")]
|
||||
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
|
||||
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
|
||||
tcx.sess.default_visibility(),
|
||||
)));
|
||||
|
||||
if tcx.sess.must_emit_unwind_tables() {
|
||||
// TODO(antoyo): emit unwind tables.
|
||||
|
@ -21,7 +21,7 @@ use std::fs::{self, File};
|
||||
use std::path::{Path, PathBuf};
|
||||
use std::sync::Arc;
|
||||
|
||||
use gccjit::{Context, FnAttribute, FunctionType, GlobalKind, OutputKind};
|
||||
use gccjit::{Context, OutputKind};
|
||||
use object::read::archive::ArchiveFile;
|
||||
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
|
||||
use rustc_codegen_ssa::back::symbol_export;
|
||||
@ -50,7 +50,7 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
|
||||
|
||||
struct LtoData {
|
||||
// TODO(antoyo): use symbols_below_threshold.
|
||||
symbols_below_threshold: Vec<String>,
|
||||
//symbols_below_threshold: Vec<String>,
|
||||
upstream_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
|
||||
tmp_path: TempDir,
|
||||
}
|
||||
@ -85,15 +85,12 @@ fn prepare_lto(
|
||||
}
|
||||
};
|
||||
let exported_symbols = cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
|
||||
//println!("1. {:?}", exported_symbols);
|
||||
let mut symbols_below_threshold = {
|
||||
let _timer = cgcx.prof.generic_activity("GCC_lto_generate_symbols_below_threshold");
|
||||
exported_symbols[&LOCAL_CRATE].iter().filter_map(symbol_filter).collect::<Vec<String>>()
|
||||
};
|
||||
info!("{} symbols to preserve in this crate", symbols_below_threshold.len());
|
||||
|
||||
//println!("2. {:?}", symbols_below_threshold);
|
||||
|
||||
// If we're performing LTO for the entire crate graph, then for each of our
|
||||
// upstream dependencies, find the corresponding rlib and load the bitcode
|
||||
// from the archive.
|
||||
@ -122,7 +119,6 @@ fn prepare_lto(
|
||||
for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
|
||||
let exported_symbols =
|
||||
cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
|
||||
//println!("3. {:?}", exported_symbols);
|
||||
{
|
||||
let _timer = cgcx.prof.generic_activity("GCC_lto_generate_symbols_below_threshold");
|
||||
symbols_below_threshold
|
||||
@ -159,12 +155,7 @@ fn prepare_lto(
|
||||
}
|
||||
}
|
||||
|
||||
println!("**** 4. {:?}", symbols_below_threshold);
|
||||
Ok(LtoData {
|
||||
symbols_below_threshold,
|
||||
upstream_modules,
|
||||
tmp_path,
|
||||
})
|
||||
Ok(LtoData { upstream_modules, tmp_path })
|
||||
}
|
||||
|
||||
fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
|
||||
@ -192,7 +183,7 @@ pub(crate) fn run_fat(
|
||||
cached_modules,
|
||||
lto_data.upstream_modules,
|
||||
lto_data.tmp_path,
|
||||
<o_data.symbols_below_threshold,
|
||||
//<o_data.symbols_below_threshold,
|
||||
)
|
||||
}
|
||||
|
||||
@ -203,7 +194,7 @@ fn fat_lto(
|
||||
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
|
||||
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
|
||||
tmp_path: TempDir,
|
||||
symbols_below_threshold: &[String],
|
||||
//symbols_below_threshold: &[String],
|
||||
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
|
||||
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
|
||||
info!("going for a fat lto");
|
||||
@ -328,14 +319,7 @@ fn fat_lto(
|
||||
ptr as *const *const libc::c_char,
|
||||
symbols_below_threshold.len() as libc::size_t,
|
||||
);*/
|
||||
let int_type = module.module_llvm.context.new_type::<i32>();
|
||||
for symbol in symbols_below_threshold {
|
||||
println!("*** Keeping symbol: {}", symbol);
|
||||
module.module_llvm.context.new_global(None, GlobalKind::Imported, int_type, symbol);
|
||||
}
|
||||
let void_type = module.module_llvm.context.new_type::<()>();
|
||||
let func = module.module_llvm.context.new_function(None, FunctionType::Extern, void_type, &[], "__rust_alloc", false);
|
||||
func.add_attribute(FnAttribute::Used);
|
||||
|
||||
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
|
||||
//}
|
||||
}
|
||||
@ -385,7 +369,7 @@ pub(crate) fn run_thin(
|
||||
lto_data.upstream_modules,
|
||||
lto_data.tmp_path,
|
||||
cached_modules,
|
||||
<o_data.symbols_below_threshold,
|
||||
//<o_data.symbols_below_threshold,
|
||||
)
|
||||
}
|
||||
|
||||
@ -436,10 +420,8 @@ fn thin_lto(
|
||||
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
|
||||
tmp_path: TempDir,
|
||||
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
|
||||
symbols_below_threshold: &[String],
|
||||
//_symbols_below_threshold: &[String],
|
||||
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
|
||||
println!("********* Thin LTO");
|
||||
|
||||
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
|
||||
info!("going for that thin, thin LTO");
|
||||
|
||||
@ -509,12 +491,6 @@ fn thin_lto(
|
||||
}
|
||||
}
|
||||
|
||||
/*for symbol in symbols_below_threshold {
|
||||
module.module_llvm.context.new_global(symbol);
|
||||
}*/
|
||||
|
||||
println!("**** Name: {:?}\n******", name);
|
||||
|
||||
serialized.push(module);
|
||||
module_names.push(name);
|
||||
}
|
||||
|
@ -15,7 +15,9 @@ use rustc_middle::mir::mono::Visibility;
|
||||
use rustc_middle::ty::TyCtxt;
|
||||
use rustc_session::config::DebugInfo;
|
||||
use rustc_span::Symbol;
|
||||
use rustc_target::spec::{PanicStrategy, SymbolVisibility};
|
||||
use rustc_target::spec::PanicStrategy;
|
||||
#[cfg(feature = "master")]
|
||||
use rustc_target::spec::SymbolVisibility;
|
||||
|
||||
use crate::builder::Builder;
|
||||
use crate::context::CodegenCx;
|
||||
|
Loading…
Reference in New Issue
Block a user