Skip to content

Commit 4c52745

Browse files
committed
rip out link guards
As discussed in #32293 (comment), adding link guards are a heuristic that is causing undue complications: - the link guards inject extra public symbols, which is not always OK. - link guards as implemented could be a non-trivial performance hit, because no attempt is made to "de-duplicate" the dependency graph, so at worst you have O(N!) calls to the link guard functions. Nonetheless, link guards are very helpful in detecting errors, so it may be worth adding them back in some modified form in the future.
1 parent b385ce1 commit 4c52745

File tree

4 files changed

+0
-162
lines changed

4 files changed

+0
-162
lines changed

src/librustc_trans/back/linker.rs

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ use session::config::CrateTypeDylib;
2323
use session::config;
2424
use syntax::ast;
2525
use trans::CrateTranslation;
26-
use trans::link_guard;
2726

2827
/// Linker abstraction used by back::link to build up the command to invoke a
2928
/// linker.
@@ -361,25 +360,6 @@ impl<'a> Linker for MsvcLinker<'a> {
361360
writeln!(f, " {}", symbol)?;
362361
}
363362

364-
// Add link-guard symbols
365-
{
366-
// local crate
367-
let symbol = link_guard::link_guard_name(&trans.link.crate_name[..],
368-
&trans.link.crate_hash);
369-
try!(writeln!(f, " {}", symbol));
370-
}
371-
// statically linked dependencies
372-
for (i, format) in formats[&CrateTypeDylib].iter().enumerate() {
373-
if *format == Linkage::Static {
374-
let cnum = (i + 1) as ast::CrateNum;
375-
let crate_name = cstore.original_crate_name(cnum);
376-
let svh = cstore.crate_hash(cnum);
377-
378-
let symbol = link_guard::link_guard_name(&crate_name[..], &svh);
379-
try!(writeln!(f, " {}", symbol));
380-
}
381-
}
382-
383363
Ok(())
384364
})();
385365
if let Err(e) = res {

src/librustc_trans/trans/base.rs

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ use trans::expr;
7979
use trans::glue;
8080
use trans::inline;
8181
use trans::intrinsic;
82-
use trans::link_guard;
8382
use trans::machine;
8483
use trans::machine::{llalign_of_min, llsize_of, llsize_of_real};
8584
use trans::meth;
@@ -2384,7 +2383,6 @@ pub fn create_entry_wrapper(ccx: &CrateContext, sp: Span, main_llfn: ValueRef) {
23842383
unsafe {
23852384
llvm::LLVMPositionBuilderAtEnd(bld, llbb);
23862385

2387-
link_guard::insert_reference_to_link_guard(ccx, llbb);
23882386
debuginfo::gdb::insert_reference_to_gdb_debug_scripts_section_global(ccx);
23892387

23902388
let (start_fn, args) = if use_start_lang_item {
@@ -2763,8 +2761,6 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27632761
symbol_names_test::report_symbol_names(&ccx);
27642762
}
27652763

2766-
emit_link_guard_if_necessary(&shared_ccx);
2767-
27682764
for ccx in shared_ccx.iter() {
27692765
if ccx.sess().opts.debuginfo != NoDebugInfo {
27702766
debuginfo::finalize(&ccx);
@@ -2825,8 +2821,6 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
28252821
if sess.entry_fn.borrow().is_some() {
28262822
reachable_symbols.push("main".to_string());
28272823
}
2828-
reachable_symbols.push(link_guard::link_guard_name(&link_meta.crate_name,
2829-
&link_meta.crate_hash));
28302824

28312825
// For the purposes of LTO, we add to the reachable set all of the upstream
28322826
// reachable extern fns. These functions are all part of the public ABI of
@@ -2870,24 +2864,6 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
28702864
}
28712865
}
28722866

2873-
fn emit_link_guard_if_necessary(shared_ccx: &SharedCrateContext) {
2874-
let link_meta = shared_ccx.link_meta();
2875-
let link_guard_name = link_guard::link_guard_name(&link_meta.crate_name,
2876-
&link_meta.crate_hash);
2877-
let link_guard_name = CString::new(link_guard_name).unwrap();
2878-
2879-
// Check if the link-guard has already been emitted in a codegen unit
2880-
let link_guard_already_emitted = shared_ccx.iter().any(|ccx| {
2881-
let link_guard = unsafe { llvm::LLVMGetNamedValue(ccx.llmod(),
2882-
link_guard_name.as_ptr()) };
2883-
!link_guard.is_null()
2884-
});
2885-
2886-
if !link_guard_already_emitted {
2887-
link_guard::get_or_insert_link_guard(&shared_ccx.get_ccx(0));
2888-
}
2889-
}
2890-
28912867
/// We visit all the items in the krate and translate them. We do
28922868
/// this in two walks. The first walk just finds module items. It then
28932869
/// walks the full contents of those module items and translates all

src/librustc_trans/trans/link_guard.rs

Lines changed: 0 additions & 117 deletions
This file was deleted.

src/librustc_trans/trans/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@ mod expr;
5353
mod glue;
5454
mod inline;
5555
mod intrinsic;
56-
pub mod link_guard;
5756
mod machine;
5857
mod _match;
5958
mod meth;

0 commit comments

Comments
 (0)