diff options
| author | Antoni Boucher <bouanto@zoho.com> | 2024-12-14 16:23:37 -0500 |
|---|---|---|
| committer | Antoni Boucher <bouanto@zoho.com> | 2024-12-14 16:23:37 -0500 |
| commit | e91ec42e3343698cd66aa6d97f62fa7de172eb74 (patch) | |
| tree | 3ce6344cde75e99bd084913da31cd4a92a316ed7 /src | |
| parent | 64b30d344ce54f8ee496cb3590b4c7cf3cb30447 (diff) | |
| download | rust-e91ec42e3343698cd66aa6d97f62fa7de172eb74.tar.gz rust-e91ec42e3343698cd66aa6d97f62fa7de172eb74.zip | |
Clean fix for undefined symbol for allocator functions
Diffstat (limited to 'src')
| -rw-r--r-- | src/allocator.rs | 19 | ||||
| -rw-r--r-- | src/back/lto.rs | 40 | ||||
| -rw-r--r-- | src/base.rs | 4 |
3 files changed, 23 insertions, 40 deletions
diff --git a/src/allocator.rs b/src/allocator.rs index 6df56693ce1..416f3231a13 100644 --- a/src/allocator.rs +++ b/src/allocator.rs @@ -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. diff --git a/src/back/lto.rs b/src/back/lto.rs index b0b89bf588b..aecb4c42408 100644 --- a/src/back/lto.rs +++ b/src/back/lto.rs @@ -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); } diff --git a/src/base.rs b/src/base.rs index 76699da3275..c92dbc98195 100644 --- a/src/base.rs +++ b/src/base.rs @@ -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; |
