Skip to content

Commit d6e35d1

Browse files
authored
Rollup merge of #66018 - pnkfelix:issue-64872-revert-64324, r=alexcrichton
Revert PR 64324: dylibs export generics again (for now) As discussed on PR #65781, this is a targeted attempt to undo the main semantic change from PR #64324, by putting `dylib` back in the set of crate types that export generic symbols. The main reason to do this is that PR #64324 had unanticipated side-effects that caused bugs like #64872, and in the opinion of @alexcrichton and myself, the impact of #64872 is worse than #64319. In other words, it is better for us, in the short term, to reopen #64319 as currently unfixed for now than to introduce new bugs like #64872. Fix #64872 Reopen #64319
2 parents 81505e7 + 6457914 commit d6e35d1

File tree

12 files changed

+79
-92
lines changed

12 files changed

+79
-92
lines changed

src/librustc/ty/context.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -1514,8 +1514,14 @@ impl<'tcx> TyCtxt<'tcx> {
15141514
CrateType::Executable |
15151515
CrateType::Staticlib |
15161516
CrateType::ProcMacro |
1517-
CrateType::Dylib |
15181517
CrateType::Cdylib => false,
1518+
1519+
// FIXME rust-lang/rust#64319, rust-lang/rust#64872:
1520+
// We want to block export of generics from dylibs,
1521+
// but we must fix rust-lang/rust#65890 before we can
1522+
// do that robustly.
1523+
CrateType::Dylib => true,
1524+
15191525
CrateType::Rlib => true,
15201526
}
15211527
})

src/librustc_codegen_ssa/back/linker.rs

+4-15
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ use rustc::middle::dependency_format::Linkage;
1414
use rustc::session::Session;
1515
use rustc::session::config::{self, CrateType, OptLevel, DebugInfo,
1616
LinkerPluginLto, Lto};
17-
use rustc::middle::exported_symbols::ExportedSymbol;
1817
use rustc::ty::TyCtxt;
1918
use rustc_target::spec::{LinkerFlavor, LldFlavor};
2019
use rustc_serialize::{json, Encoder};
@@ -1112,20 +1111,10 @@ fn exported_symbols(tcx: TyCtxt<'_>, crate_type: CrateType) -> Vec<String> {
11121111
continue;
11131112
}
11141113

1115-
// Do not export generic symbols from upstream crates in linked
1116-
// artifact (notably the `dylib` crate type). The main reason
1117-
// for this is that `symbol_name` is actually wrong for generic
1118-
// symbols because it guesses the name we'd give them locally
1119-
// rather than the name it has upstream (depending on
1120-
// `share_generics` settings and such).
1121-
//
1122-
// To fix that issue we just say that linked artifacts, aka
1123-
// `dylib`s, never export generic symbols and they aren't
1124-
// available to downstream crates. (the not available part is
1125-
// handled elsewhere).
1126-
if let ExportedSymbol::Generic(..) = symbol {
1127-
continue;
1128-
}
1114+
// FIXME rust-lang/rust#64319, rust-lang/rust#64872:
1115+
// We want to block export of generics from dylibs,
1116+
// but we must fix rust-lang/rust#65890 before we can
1117+
// do that robustly.
11291118

11301119
symbols.push(symbol.symbol_name(tcx).to_string());
11311120
}

src/librustc_metadata/cstore_impl.rs

+5-21
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ use rustc::ty::query::QueryConfig;
99
use rustc::middle::cstore::{CrateSource, CrateStore, DepKind, EncodedMetadata, NativeLibraryKind};
1010
use rustc::middle::exported_symbols::ExportedSymbol;
1111
use rustc::middle::stability::DeprecationEntry;
12-
use rustc::middle::dependency_format::Linkage;
1312
use rustc::hir::def;
1413
use rustc::hir;
1514
use rustc::session::{CrateDisambiguator, Session};
@@ -235,26 +234,11 @@ provide! { <'tcx> tcx, def_id, other, cdata,
235234
used_crate_source => { Lrc::new(cdata.source.clone()) }
236235

237236
exported_symbols => {
238-
let mut syms = cdata.exported_symbols(tcx);
239-
240-
// When linked into a dylib crates don't export their generic symbols,
241-
// so if that's happening then we can't load upstream monomorphizations
242-
// from this crate.
243-
let formats = tcx.dependency_formats(LOCAL_CRATE);
244-
let remove_generics = formats.iter().any(|(_ty, list)| {
245-
match list.get(def_id.krate.as_usize() - 1) {
246-
Some(Linkage::IncludedFromDylib) | Some(Linkage::Dynamic) => true,
247-
_ => false,
248-
}
249-
});
250-
if remove_generics {
251-
syms.retain(|(sym, _threshold)| {
252-
match sym {
253-
ExportedSymbol::Generic(..) => false,
254-
_ => return true,
255-
}
256-
});
257-
}
237+
let syms = cdata.exported_symbols(tcx);
238+
239+
// FIXME rust-lang/rust#64319, rust-lang/rust#64872: We want
240+
// to block export of generics from dylibs, but we must fix
241+
// rust-lang/rust#65890 before we can do that robustly.
258242

259243
Arc::new(syms)
260244
}

src/test/run-make-fulldeps/issue-64319/Makefile

-39
This file was deleted.

src/test/run-make-fulldeps/issue-64319/bar.rs

-5
This file was deleted.

src/test/run-make-fulldeps/issue-64319/foo.rs

-9
This file was deleted.

src/test/run-make-fulldeps/symbol-visibility/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,12 @@ all:
7979
# Check that a Rust dylib exports its monomorphic functions, including generics this time
8080
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rust_dylib)" -eq "1" ]
8181
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rust_dylib)" -eq "1" ]
82-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "0" ]
82+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rust_dylib)" -eq "1" ]
8383

8484
# Check that a Rust dylib exports the monomorphic functions from its dependencies
8585
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_c_function_from_rlib)" -eq "1" ]
8686
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_rust_function_from_rlib)" -eq "1" ]
87-
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "0" ]
87+
[ "$$($(NM) $(TMPDIR)/$(RDYLIB_NAME) | grep -c public_generic_function_from_rlib)" -eq "1" ]
8888

8989
# Check that an executable does not export any dynamic symbols
9090
[ "$$($(NM) $(TMPDIR)/$(EXE_NAME) | grep -c public_c_function_from_rlib)" -eq "0" ]
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// compile-flags: -C debuginfo=2
2+
3+
// no-prefer-dynamic
4+
#![crate_type = "rlib"]
5+
6+
pub trait Object { fn method(&self) { } }
7+
8+
impl Object for u32 { }
9+
impl Object for () { }
10+
impl<T> Object for &T { }
11+
12+
pub fn unused() {
13+
let ref u = 0_u32;
14+
let _d = &u as &dyn crate::Object;
15+
_d.method()
16+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
// compile-flags: -C debuginfo=2 -C prefer-dynamic
2+
3+
#![crate_type="dylib"]
4+
5+
extern crate a_def_obj;
6+
7+
pub use a_def_obj::Object;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// no-prefer-dynamic
2+
// compile-flags: -C debuginfo=2
3+
#![crate_type="rlib"]
4+
5+
extern crate b_reexport_obj;
6+
use b_reexport_obj::Object;
7+
8+
pub fn another_dyn_debug() {
9+
let ref u = 1_u32;
10+
let _d = &u as &dyn crate::Object;
11+
_d.method()
12+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
// compile-flags: -C debuginfo=2 -C prefer-dynamic
2+
3+
#![crate_type="rlib"]
4+
5+
extern crate c_another_vtable_for_obj;
6+
7+
pub fn chain() {
8+
c_another_vtable_for_obj::another_dyn_debug();
9+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
// run-pass
2+
3+
// note that these aux-build directives must be in this order: the
4+
// later crates depend on the earlier ones. (The particular bug that
5+
// is being exercised here used to exhibit itself during the build of
6+
// `chain_of_rlibs_and_dylibs.dylib`)
7+
8+
// aux-build:a_def_obj.rs
9+
// aux-build:b_reexport_obj.rs
10+
// aux-build:c_another_vtable_for_obj.rs
11+
// aux-build:d_chain_of_rlibs_and_dylibs.rs
12+
13+
extern crate d_chain_of_rlibs_and_dylibs;
14+
15+
pub fn main() {
16+
d_chain_of_rlibs_and_dylibs::chain();
17+
}

0 commit comments

Comments
 (0)