Skip to content

Commit 52bd4f2

Browse files
committed
Add a limit_rdylib_exports option and disable it for Solaris
1 parent 185dceb commit 52bd4f2

File tree

6 files changed

+18
-7
lines changed

6 files changed

+18
-7
lines changed

Diff for: src/librustc_codegen_ssa/back/linker.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -381,15 +381,12 @@ impl<'a> Linker for GccLinker<'a> {
381381
// The object files have far more public symbols than we actually want to export,
382382
// so we hide them all here.
383383

384-
if crate_type == CrateType::ProcMacro {
385-
return
384+
if !self.sess.target.target.options.limit_rdylib_exports {
385+
return;
386386
}
387387

388-
// Symbol visibility takes care of this for the WebAssembly.
389-
// Additionally the only known linker, LLD, doesn't support the script
390-
// arguments just yet
391-
if self.sess.target.target.arch == "wasm32" {
392-
return;
388+
if crate_type == CrateType::ProcMacro {
389+
return
393390
}
394391

395392
let mut arg = OsString::new();

Diff for: src/librustc_target/spec/mod.rs

+6
Original file line numberDiff line numberDiff line change
@@ -748,6 +748,9 @@ pub struct TargetOptions {
748748
/// wasm32 where the whole program either has simd or not.
749749
pub simd_types_indirect: bool,
750750

751+
/// Pass a list of symbol which should be exported in the dylib to the linker.
752+
pub limit_rdylib_exports: bool,
753+
751754
/// If set, have the linker export exactly these symbols, instead of using
752755
/// the usual logic to figure this out from the crate itself.
753756
pub override_export_symbols: Option<Vec<String>>,
@@ -843,6 +846,7 @@ impl Default for TargetOptions {
843846
emit_debug_gdb_scripts: true,
844847
requires_uwtable: false,
845848
simd_types_indirect: true,
849+
limit_rdylib_exports: true,
846850
override_export_symbols: None,
847851
merge_functions: MergeFunctions::Aliases,
848852
target_mcount: "mcount".to_string(),
@@ -1149,6 +1153,7 @@ impl Target {
11491153
key!(emit_debug_gdb_scripts, bool);
11501154
key!(requires_uwtable, bool);
11511155
key!(simd_types_indirect, bool);
1156+
key!(limit_rdylib_exports, bool);
11521157
key!(override_export_symbols, opt_list);
11531158
key!(merge_functions, MergeFunctions)?;
11541159
key!(target_mcount);
@@ -1364,6 +1369,7 @@ impl ToJson for Target {
13641369
target_option_val!(emit_debug_gdb_scripts);
13651370
target_option_val!(requires_uwtable);
13661371
target_option_val!(simd_types_indirect);
1372+
target_option_val!(limit_rdylib_exports);
13671373
target_option_val!(override_export_symbols);
13681374
target_option_val!(merge_functions);
13691375
target_option_val!(target_mcount);

Diff for: src/librustc_target/spec/solaris_base.rs

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions {
88
has_rpath: true,
99
target_family: Some("unix".to_string()),
1010
is_like_solaris: true,
11+
limit_rdylib_exports: false, // Linker doesn't support this
1112

1213
.. Default::default()
1314
}

Diff for: src/librustc_target/spec/wasm32_base.rs

+5
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,11 @@ pub fn options() -> TargetOptions {
106106
// no dynamic linking, no need for default visibility!
107107
default_hidden_visibility: true,
108108

109+
// Symbol visibility takes care of this for the WebAssembly.
110+
// Additionally the only known linker, LLD, doesn't support the script
111+
// arguments just yet
112+
limit_rdylib_exports: false,
113+
109114
// we use the LLD shipped with the Rust toolchain by default
110115
linker: Some("rust-lld".to_owned()),
111116
lld_flavor: LldFlavor::Wasm,

Diff for: src/librustc_target/spec/wasm32_experimental_emscripten.rs

+1
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ pub fn target() -> Result<Target, String> {
2424
is_like_emscripten: true,
2525
max_atomic_width: Some(32),
2626
post_link_args,
27+
limit_rdylib_exports: false,
2728
target_family: Some("unix".to_string()),
2829
.. Default::default()
2930
};

Diff for: src/librustc_target/spec/wasm32_unknown_emscripten.rs

+1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ pub fn target() -> Result<Target, String> {
2626
is_like_emscripten: true,
2727
max_atomic_width: Some(32),
2828
post_link_args,
29+
limit_rdylib_exports: false,
2930
target_family: Some("unix".to_string()),
3031
codegen_backend: "emscripten".to_string(),
3132
.. Default::default()

0 commit comments

Comments
 (0)