Skip to content

Commit e91ec42

Browse files
committed
Clean fix for undefined symbol for allocator functions
1 parent 64b30d3 commit e91ec42

File tree

4 files changed

+24
-41
lines changed

4 files changed

+24
-41
lines changed

build_system/src/test.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1031,7 +1031,7 @@ where
10311031
&"always",
10321032
&"--stage",
10331033
&"0",
1034-
&format!("tests/{}/codegen/virtual-function-elimination.rs", test_type),
1034+
&format!("tests/{}", test_type),
10351035
&"--compiletest-rustc-args",
10361036
&rustc_args,
10371037
],

src/allocator.rs

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1+
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
12
#[cfg(feature = "master")]
23
use gccjit::{FnAttribute, VarAttribute};
3-
use gccjit::{Context, FunctionType, GlobalKind, ToRValue, Type};
44
use rustc_ast::expand::allocator::{
55
ALLOCATOR_METHODS, AllocatorKind, AllocatorTy, NO_ALLOC_SHIM_IS_UNSTABLE,
66
alloc_error_handler_name, default_fn_name, global_fn_name,
@@ -9,8 +9,9 @@ use rustc_middle::bug;
99
use rustc_middle::ty::TyCtxt;
1010
use rustc_session::config::OomStrategy;
1111

12-
use crate::base::symbol_visibility_to_gcc;
1312
use crate::GccContext;
13+
#[cfg(feature = "master")]
14+
use crate::base::symbol_visibility_to_gcc;
1415

1516
pub(crate) unsafe fn codegen(
1617
tcx: TyCtxt<'_>,
@@ -72,15 +73,19 @@ pub(crate) unsafe fn codegen(
7273
let name = OomStrategy::SYMBOL.to_string();
7374
let global = context.new_global(None, GlobalKind::Exported, i8, name);
7475
#[cfg(feature = "master")]
75-
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
76+
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
77+
tcx.sess.default_visibility(),
78+
)));
7679
let value = tcx.sess.opts.unstable_opts.oom.should_panic();
7780
let value = context.new_rvalue_from_int(i8, value as i32);
7881
global.global_set_initializer_rvalue(value);
7982

8083
let name = NO_ALLOC_SHIM_IS_UNSTABLE.to_string();
8184
let global = context.new_global(None, GlobalKind::Exported, i8, name);
8285
#[cfg(feature = "master")]
83-
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
86+
global.add_attribute(VarAttribute::Visibility(symbol_visibility_to_gcc(
87+
tcx.sess.default_visibility(),
88+
)));
8489
let value = context.new_rvalue_from_int(i8, 0);
8590
global.global_set_initializer_rvalue(value);
8691
}
@@ -109,10 +114,10 @@ fn create_wrapper_function(
109114
false,
110115
);
111116

112-
println!("{} -> {}: {:?}", from_name, to_name, tcx.sess.default_visibility());
113-
114117
#[cfg(feature = "master")]
115-
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(tcx.sess.default_visibility())));
118+
func.add_attribute(FnAttribute::Visibility(symbol_visibility_to_gcc(
119+
tcx.sess.default_visibility(),
120+
)));
116121

117122
if tcx.sess.must_emit_unwind_tables() {
118123
// TODO(antoyo): emit unwind tables.

src/back/lto.rs

Lines changed: 8 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ use std::fs::{self, File};
2121
use std::path::{Path, PathBuf};
2222
use std::sync::Arc;
2323

24-
use gccjit::{Context, FnAttribute, FunctionType, GlobalKind, OutputKind};
24+
use gccjit::{Context, OutputKind};
2525
use object::read::archive::ArchiveFile;
2626
use rustc_codegen_ssa::back::lto::{LtoModuleCodegen, SerializedModule, ThinModule, ThinShared};
2727
use rustc_codegen_ssa::back::symbol_export;
@@ -50,7 +50,7 @@ pub fn crate_type_allows_lto(crate_type: CrateType) -> bool {
5050

5151
struct LtoData {
5252
// TODO(antoyo): use symbols_below_threshold.
53-
symbols_below_threshold: Vec<String>,
53+
//symbols_below_threshold: Vec<String>,
5454
upstream_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
5555
tmp_path: TempDir,
5656
}
@@ -85,15 +85,12 @@ fn prepare_lto(
8585
}
8686
};
8787
let exported_symbols = cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
88-
//println!("1. {:?}", exported_symbols);
8988
let mut symbols_below_threshold = {
9089
let _timer = cgcx.prof.generic_activity("GCC_lto_generate_symbols_below_threshold");
9190
exported_symbols[&LOCAL_CRATE].iter().filter_map(symbol_filter).collect::<Vec<String>>()
9291
};
9392
info!("{} symbols to preserve in this crate", symbols_below_threshold.len());
9493

95-
//println!("2. {:?}", symbols_below_threshold);
96-
9794
// If we're performing LTO for the entire crate graph, then for each of our
9895
// upstream dependencies, find the corresponding rlib and load the bitcode
9996
// from the archive.
@@ -122,7 +119,6 @@ fn prepare_lto(
122119
for &(cnum, ref path) in cgcx.each_linked_rlib_for_lto.iter() {
123120
let exported_symbols =
124121
cgcx.exported_symbols.as_ref().expect("needs exported symbols for LTO");
125-
//println!("3. {:?}", exported_symbols);
126122
{
127123
let _timer = cgcx.prof.generic_activity("GCC_lto_generate_symbols_below_threshold");
128124
symbols_below_threshold
@@ -159,12 +155,7 @@ fn prepare_lto(
159155
}
160156
}
161157

162-
println!("**** 4. {:?}", symbols_below_threshold);
163-
Ok(LtoData {
164-
symbols_below_threshold,
165-
upstream_modules,
166-
tmp_path,
167-
})
158+
Ok(LtoData { upstream_modules, tmp_path })
168159
}
169160

170161
fn save_as_file(obj: &[u8], path: &Path) -> Result<(), LtoBitcodeFromRlib> {
@@ -192,7 +183,7 @@ pub(crate) fn run_fat(
192183
cached_modules,
193184
lto_data.upstream_modules,
194185
lto_data.tmp_path,
195-
&lto_data.symbols_below_threshold,
186+
//&lto_data.symbols_below_threshold,
196187
)
197188
}
198189

@@ -203,7 +194,7 @@ fn fat_lto(
203194
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
204195
mut serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
205196
tmp_path: TempDir,
206-
symbols_below_threshold: &[String],
197+
//symbols_below_threshold: &[String],
207198
) -> Result<LtoModuleCodegen<GccCodegenBackend>, FatalError> {
208199
let _timer = cgcx.prof.generic_activity("GCC_fat_lto_build_monolithic_module");
209200
info!("going for a fat lto");
@@ -328,14 +319,7 @@ fn fat_lto(
328319
ptr as *const *const libc::c_char,
329320
symbols_below_threshold.len() as libc::size_t,
330321
);*/
331-
let int_type = module.module_llvm.context.new_type::<i32>();
332-
for symbol in symbols_below_threshold {
333-
println!("*** Keeping symbol: {}", symbol);
334-
module.module_llvm.context.new_global(None, GlobalKind::Imported, int_type, symbol);
335-
}
336-
let void_type = module.module_llvm.context.new_type::<()>();
337-
let func = module.module_llvm.context.new_function(None, FunctionType::Extern, void_type, &[], "__rust_alloc", false);
338-
func.add_attribute(FnAttribute::Used);
322+
339323
save_temp_bitcode(cgcx, &module, "lto.after-restriction");
340324
//}
341325
}
@@ -385,7 +369,7 @@ pub(crate) fn run_thin(
385369
lto_data.upstream_modules,
386370
lto_data.tmp_path,
387371
cached_modules,
388-
&lto_data.symbols_below_threshold,
372+
//&lto_data.symbols_below_threshold,
389373
)
390374
}
391375

@@ -436,10 +420,8 @@ fn thin_lto(
436420
serialized_modules: Vec<(SerializedModule<ModuleBuffer>, CString)>,
437421
tmp_path: TempDir,
438422
cached_modules: Vec<(SerializedModule<ModuleBuffer>, WorkProduct)>,
439-
symbols_below_threshold: &[String],
423+
//_symbols_below_threshold: &[String],
440424
) -> Result<(Vec<LtoModuleCodegen<GccCodegenBackend>>, Vec<WorkProduct>), FatalError> {
441-
println!("********* Thin LTO");
442-
443425
let _timer = cgcx.prof.generic_activity("LLVM_thin_lto_global_analysis");
444426
info!("going for that thin, thin LTO");
445427

@@ -509,12 +491,6 @@ fn thin_lto(
509491
}
510492
}
511493

512-
/*for symbol in symbols_below_threshold {
513-
module.module_llvm.context.new_global(symbol);
514-
}*/
515-
516-
println!("**** Name: {:?}\n******", name);
517-
518494
serialized.push(module);
519495
module_names.push(name);
520496
}

src/base.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ use rustc_middle::mir::mono::Visibility;
1515
use rustc_middle::ty::TyCtxt;
1616
use rustc_session::config::DebugInfo;
1717
use rustc_span::Symbol;
18-
use rustc_target::spec::{PanicStrategy, SymbolVisibility};
18+
use rustc_target::spec::PanicStrategy;
19+
#[cfg(feature = "master")]
20+
use rustc_target::spec::SymbolVisibility;
1921

2022
use crate::builder::Builder;
2123
use crate::context::CodegenCx;

0 commit comments

Comments
 (0)