Skip to content

Commit dbebcee

Browse files
committed
Auto merge of #59752 - Zoxc:dylib-fix, r=alexcrichton
Limit dylib symbols This makes `windows-gnu` match the behavior of `windows-msvc`. It probably doesn't make sense to export these symbols on other platforms either.
2 parents 9f8cd9d + f8f9a28 commit dbebcee

16 files changed

+31
-19
lines changed

src/ci/docker/test-various/Dockerfile

-4
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
1515
wget \
1616
patch
1717

18-
# FIXME: build the `ptx-linker` instead.
19-
RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-alpha.2/rust-ptx-linker.linux64.tar.gz | \
20-
tar -xzvC /usr/bin
21-
2218
RUN curl -sL https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.xz | \
2319
tar -xJ
2420

src/librustc_codegen_ssa/back/linker.rs

+8-15
Original file line numberDiff line numberDiff line change
@@ -377,25 +377,18 @@ impl<'a> Linker for GccLinker<'a> {
377377
return;
378378
}
379379

380-
// If we're compiling a dylib, then we let symbol visibility in object
381-
// files to take care of whether they're exported or not.
382-
//
383-
// If we're compiling a cdylib, however, we manually create a list of
384-
// exported symbols to ensure we don't expose any more. The object files
385-
// have far more public symbols than we actually want to export, so we
386-
// hide them all here.
387-
if crate_type == CrateType::Dylib ||
388-
crate_type == CrateType::ProcMacro {
389-
return
390-
}
380+
// We manually create a list of exported symbols to ensure we don't expose any more.
381+
// The object files have far more public symbols than we actually want to export,
382+
// so we hide them all here.
391383

392-
// Symbol visibility takes care of this for the WebAssembly.
393-
// Additionally the only known linker, LLD, doesn't support the script
394-
// arguments just yet
395-
if self.sess.target.target.arch == "wasm32" {
384+
if !self.sess.target.target.options.limit_rdylib_exports {
396385
return;
397386
}
398387

388+
if crate_type == CrateType::ProcMacro {
389+
return
390+
}
391+
399392
let mut arg = OsString::new();
400393
let path = tmpdir.join("list");
401394

src/librustc_target/spec/mod.rs

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

753+
/// Pass a list of symbol which should be exported in the dylib to the linker.
754+
pub limit_rdylib_exports: bool,
755+
753756
/// If set, have the linker export exactly these symbols, instead of using
754757
/// the usual logic to figure this out from the crate itself.
755758
pub override_export_symbols: Option<Vec<String>>,
@@ -845,6 +848,7 @@ impl Default for TargetOptions {
845848
emit_debug_gdb_scripts: true,
846849
requires_uwtable: false,
847850
simd_types_indirect: true,
851+
limit_rdylib_exports: true,
848852
override_export_symbols: None,
849853
merge_functions: MergeFunctions::Aliases,
850854
target_mcount: "mcount".to_string(),
@@ -1151,6 +1155,7 @@ impl Target {
11511155
key!(emit_debug_gdb_scripts, bool);
11521156
key!(requires_uwtable, bool);
11531157
key!(simd_types_indirect, bool);
1158+
key!(limit_rdylib_exports, bool);
11541159
key!(override_export_symbols, opt_list);
11551160
key!(merge_functions, MergeFunctions)?;
11561161
key!(target_mcount);
@@ -1366,6 +1371,7 @@ impl ToJson for Target {
13661371
target_option_val!(emit_debug_gdb_scripts);
13671372
target_option_val!(requires_uwtable);
13681373
target_option_val!(simd_types_indirect);
1374+
target_option_val!(limit_rdylib_exports);
13691375
target_option_val!(override_export_symbols);
13701376
target_option_val!(merge_functions);
13711377
target_option_val!(target_mcount);

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
}

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,

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
};

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()

src/test/assembly/nvptx-arch-default.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![no_std]
67

src/test/assembly/nvptx-arch-emit-asm.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: emit-asm
22
// compile-flags: --crate-type rlib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![no_std]
67

src/test/assembly/nvptx-arch-link-arg.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib -C link-arg=--arch=sm_60
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![no_std]
67

src/test/assembly/nvptx-arch-target-cpu.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib -C target-cpu=sm_50
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![no_std]
67

src/test/assembly/nvptx-atomics.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![feature(abi_ptx, core_intrinsics)]
67
#![no_std]

src/test/assembly/nvptx-internalizing.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![feature(abi_ptx)]
67
#![no_std]

src/test/assembly/nvptx-linking-binary.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type bin
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![feature(abi_ptx)]
67
#![no_main]

src/test/assembly/nvptx-linking-cdylib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![feature(abi_ptx)]
67
#![no_std]

src/test/assembly/nvptx-safe-naming.rs

+1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// assembly-output: ptx-linker
22
// compile-flags: --crate-type cdylib
33
// only-nvptx64
4+
// ignore-nvptx64
45

56
#![feature(abi_ptx)]
67
#![no_std]

0 commit comments

Comments
 (0)