From 185dcebbff7f3c18fb94be82f76bdfd620cfb096 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sat, 6 Apr 2019 18:07:53 +0200 Subject: [PATCH 1/3] Limit dylib symbols --- src/librustc_codegen_ssa/back/linker.rs | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index 260c07a7b62..eee9533535f 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -377,15 +377,11 @@ fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) { return; } - // If we're compiling a dylib, then we let symbol visibility in object - // files to take care of whether they're exported or not. - // - // If we're compiling a cdylib, however, we manually create a list of - // exported symbols to ensure we don't expose any more. The object files - // have far more public symbols than we actually want to export, so we - // hide them all here. - if crate_type == CrateType::Dylib || - crate_type == CrateType::ProcMacro { + // We manually create a list of exported symbols to ensure we don't expose any more. + // The object files have far more public symbols than we actually want to export, + // so we hide them all here. + + if crate_type == CrateType::ProcMacro { return } From 52bd4f263b57faf987dc32d40642403e313e175a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Sun, 14 Apr 2019 19:05:21 +0200 Subject: [PATCH 2/3] Add a limit_rdylib_exports option and disable it for Solaris --- src/librustc_codegen_ssa/back/linker.rs | 11 ++++------- src/librustc_target/spec/mod.rs | 6 ++++++ src/librustc_target/spec/solaris_base.rs | 1 + src/librustc_target/spec/wasm32_base.rs | 5 +++++ .../spec/wasm32_experimental_emscripten.rs | 1 + src/librustc_target/spec/wasm32_unknown_emscripten.rs | 1 + 6 files changed, 18 insertions(+), 7 deletions(-) diff --git a/src/librustc_codegen_ssa/back/linker.rs b/src/librustc_codegen_ssa/back/linker.rs index eee9533535f..39ccf4f46b7 100644 --- a/src/librustc_codegen_ssa/back/linker.rs +++ b/src/librustc_codegen_ssa/back/linker.rs @@ -381,15 +381,12 @@ fn export_symbols(&mut self, tmpdir: &Path, crate_type: CrateType) { // The object files have far more public symbols than we actually want to export, // so we hide them all here. - if crate_type == CrateType::ProcMacro { - return + if !self.sess.target.target.options.limit_rdylib_exports { + return; } - // Symbol visibility takes care of this for the WebAssembly. - // Additionally the only known linker, LLD, doesn't support the script - // arguments just yet - if self.sess.target.target.arch == "wasm32" { - return; + if crate_type == CrateType::ProcMacro { + return } let mut arg = OsString::new(); diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 844edbb946a..329d3f2b2f3 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -748,6 +748,9 @@ pub struct TargetOptions { /// wasm32 where the whole program either has simd or not. pub simd_types_indirect: bool, + /// Pass a list of symbol which should be exported in the dylib to the linker. + pub limit_rdylib_exports: bool, + /// If set, have the linker export exactly these symbols, instead of using /// the usual logic to figure this out from the crate itself. pub override_export_symbols: Option>, @@ -843,6 +846,7 @@ fn default() -> TargetOptions { emit_debug_gdb_scripts: true, requires_uwtable: false, simd_types_indirect: true, + limit_rdylib_exports: true, override_export_symbols: None, merge_functions: MergeFunctions::Aliases, target_mcount: "mcount".to_string(), @@ -1149,6 +1153,7 @@ macro_rules! key { key!(emit_debug_gdb_scripts, bool); key!(requires_uwtable, bool); key!(simd_types_indirect, bool); + key!(limit_rdylib_exports, bool); key!(override_export_symbols, opt_list); key!(merge_functions, MergeFunctions)?; key!(target_mcount); @@ -1364,6 +1369,7 @@ macro_rules! target_option_val { target_option_val!(emit_debug_gdb_scripts); target_option_val!(requires_uwtable); target_option_val!(simd_types_indirect); + target_option_val!(limit_rdylib_exports); target_option_val!(override_export_symbols); target_option_val!(merge_functions); target_option_val!(target_mcount); diff --git a/src/librustc_target/spec/solaris_base.rs b/src/librustc_target/spec/solaris_base.rs index 0dfbb13b773..9e7eda03773 100644 --- a/src/librustc_target/spec/solaris_base.rs +++ b/src/librustc_target/spec/solaris_base.rs @@ -8,6 +8,7 @@ pub fn opts() -> TargetOptions { has_rpath: true, target_family: Some("unix".to_string()), is_like_solaris: true, + limit_rdylib_exports: false, // Linker doesn't support this .. Default::default() } diff --git a/src/librustc_target/spec/wasm32_base.rs b/src/librustc_target/spec/wasm32_base.rs index edaf902c130..39a8ce92825 100644 --- a/src/librustc_target/spec/wasm32_base.rs +++ b/src/librustc_target/spec/wasm32_base.rs @@ -106,6 +106,11 @@ pub fn options() -> TargetOptions { // no dynamic linking, no need for default visibility! default_hidden_visibility: true, + // Symbol visibility takes care of this for the WebAssembly. + // Additionally the only known linker, LLD, doesn't support the script + // arguments just yet + limit_rdylib_exports: false, + // we use the LLD shipped with the Rust toolchain by default linker: Some("rust-lld".to_owned()), lld_flavor: LldFlavor::Wasm, diff --git a/src/librustc_target/spec/wasm32_experimental_emscripten.rs b/src/librustc_target/spec/wasm32_experimental_emscripten.rs index 5ecd66306d0..b802bee25ae 100644 --- a/src/librustc_target/spec/wasm32_experimental_emscripten.rs +++ b/src/librustc_target/spec/wasm32_experimental_emscripten.rs @@ -24,6 +24,7 @@ pub fn target() -> Result { is_like_emscripten: true, max_atomic_width: Some(32), post_link_args, + limit_rdylib_exports: false, target_family: Some("unix".to_string()), .. Default::default() }; diff --git a/src/librustc_target/spec/wasm32_unknown_emscripten.rs b/src/librustc_target/spec/wasm32_unknown_emscripten.rs index a6e9340ce28..e0df36884bf 100644 --- a/src/librustc_target/spec/wasm32_unknown_emscripten.rs +++ b/src/librustc_target/spec/wasm32_unknown_emscripten.rs @@ -26,6 +26,7 @@ pub fn target() -> Result { is_like_emscripten: true, max_atomic_width: Some(32), post_link_args, + limit_rdylib_exports: false, target_family: Some("unix".to_string()), codegen_backend: "emscripten".to_string(), .. Default::default() From f8f9a2869cce570c994d96afb82f4162b1b44cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?John=20K=C3=A5re=20Alsaker?= Date: Wed, 12 Jun 2019 23:09:08 +0200 Subject: [PATCH 3/3] Ignore NVPTX tests --- src/ci/docker/test-various/Dockerfile | 4 ---- src/test/assembly/nvptx-arch-default.rs | 1 + src/test/assembly/nvptx-arch-emit-asm.rs | 1 + src/test/assembly/nvptx-arch-link-arg.rs | 1 + src/test/assembly/nvptx-arch-target-cpu.rs | 1 + src/test/assembly/nvptx-atomics.rs | 1 + src/test/assembly/nvptx-internalizing.rs | 1 + src/test/assembly/nvptx-linking-binary.rs | 1 + src/test/assembly/nvptx-linking-cdylib.rs | 1 + src/test/assembly/nvptx-safe-naming.rs | 1 + 10 files changed, 9 insertions(+), 4 deletions(-) diff --git a/src/ci/docker/test-various/Dockerfile b/src/ci/docker/test-various/Dockerfile index 611a24a69bd..c45b1a9a0f1 100644 --- a/src/ci/docker/test-various/Dockerfile +++ b/src/ci/docker/test-various/Dockerfile @@ -15,10 +15,6 @@ RUN apt-get update && apt-get install -y --no-install-recommends \ wget \ patch -# FIXME: build the `ptx-linker` instead. -RUN curl -sL https://github.com/denzp/rust-ptx-linker/releases/download/v0.9.0-alpha.2/rust-ptx-linker.linux64.tar.gz | \ - tar -xzvC /usr/bin - RUN curl -sL https://nodejs.org/dist/v9.2.0/node-v9.2.0-linux-x64.tar.xz | \ tar -xJ diff --git a/src/test/assembly/nvptx-arch-default.rs b/src/test/assembly/nvptx-arch-default.rs index 7fe71c33521..8a71a6370f1 100644 --- a/src/test/assembly/nvptx-arch-default.rs +++ b/src/test/assembly/nvptx-arch-default.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib // only-nvptx64 +// ignore-nvptx64 #![no_std] diff --git a/src/test/assembly/nvptx-arch-emit-asm.rs b/src/test/assembly/nvptx-arch-emit-asm.rs index 0ca17729c02..b252b450fa7 100644 --- a/src/test/assembly/nvptx-arch-emit-asm.rs +++ b/src/test/assembly/nvptx-arch-emit-asm.rs @@ -1,6 +1,7 @@ // assembly-output: emit-asm // compile-flags: --crate-type rlib // only-nvptx64 +// ignore-nvptx64 #![no_std] diff --git a/src/test/assembly/nvptx-arch-link-arg.rs b/src/test/assembly/nvptx-arch-link-arg.rs index f6b6e8ccaa1..025a9ad4987 100644 --- a/src/test/assembly/nvptx-arch-link-arg.rs +++ b/src/test/assembly/nvptx-arch-link-arg.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib -C link-arg=--arch=sm_60 // only-nvptx64 +// ignore-nvptx64 #![no_std] diff --git a/src/test/assembly/nvptx-arch-target-cpu.rs b/src/test/assembly/nvptx-arch-target-cpu.rs index 08a7a193bbd..824ee9cd897 100644 --- a/src/test/assembly/nvptx-arch-target-cpu.rs +++ b/src/test/assembly/nvptx-arch-target-cpu.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib -C target-cpu=sm_50 // only-nvptx64 +// ignore-nvptx64 #![no_std] diff --git a/src/test/assembly/nvptx-atomics.rs b/src/test/assembly/nvptx-atomics.rs index 3bbd7b3d12d..f9639806449 100644 --- a/src/test/assembly/nvptx-atomics.rs +++ b/src/test/assembly/nvptx-atomics.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib // only-nvptx64 +// ignore-nvptx64 #![feature(abi_ptx, core_intrinsics)] #![no_std] diff --git a/src/test/assembly/nvptx-internalizing.rs b/src/test/assembly/nvptx-internalizing.rs index c9edc386959..0004fcea7a2 100644 --- a/src/test/assembly/nvptx-internalizing.rs +++ b/src/test/assembly/nvptx-internalizing.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib // only-nvptx64 +// ignore-nvptx64 #![feature(abi_ptx)] #![no_std] diff --git a/src/test/assembly/nvptx-linking-binary.rs b/src/test/assembly/nvptx-linking-binary.rs index d88ed9139ca..64b9c2f17aa 100644 --- a/src/test/assembly/nvptx-linking-binary.rs +++ b/src/test/assembly/nvptx-linking-binary.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type bin // only-nvptx64 +// ignore-nvptx64 #![feature(abi_ptx)] #![no_main] diff --git a/src/test/assembly/nvptx-linking-cdylib.rs b/src/test/assembly/nvptx-linking-cdylib.rs index 1145f567d8c..bdbc30ea97f 100644 --- a/src/test/assembly/nvptx-linking-cdylib.rs +++ b/src/test/assembly/nvptx-linking-cdylib.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib // only-nvptx64 +// ignore-nvptx64 #![feature(abi_ptx)] #![no_std] diff --git a/src/test/assembly/nvptx-safe-naming.rs b/src/test/assembly/nvptx-safe-naming.rs index ab6f91423aa..80bb04fc0f2 100644 --- a/src/test/assembly/nvptx-safe-naming.rs +++ b/src/test/assembly/nvptx-safe-naming.rs @@ -1,6 +1,7 @@ // assembly-output: ptx-linker // compile-flags: --crate-type cdylib // only-nvptx64 +// ignore-nvptx64 #![feature(abi_ptx)] #![no_std]