about summary refs log tree commit diff
path: root/src/test/compile-fail
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2015-04-12 01:26:53 +0000
committerbors <bors@rust-lang.org>2015-04-12 01:26:53 +0000
commit5afa2704a6fdee62b267a5df9ca0934350dfc3d1 (patch)
tree834dd80c3e70e530ba79a54b4e047610d9b33c19 /src/test/compile-fail
parent6790b0e51967b1487728d155e0800a1ed03a30d3 (diff)
parent000db3841e49048c73ba61a0a2480b7878b6807f (diff)
downloadrust-5afa2704a6fdee62b267a5df9ca0934350dfc3d1.tar.gz
rust-5afa2704a6fdee62b267a5df9ca0934350dfc3d1.zip
Auto merge of #23011 - nagisa:the-war-of-symbol-and-symbol, r=pnkfelix
We provide tools to tell what exact symbols to emit for any fn or static, but
don’t quite check if that won’t cause any issues later on. Some of the issues
include LLVM mangling our names again and our names pointing to wrong locations,
us generating dumb foreign call wrappers, linker errors, extern functions
resolving to different symbols altogether (`extern {fn fail();} fail();` in some
cases calling `fail1()`), etc.

Before the commit we had a function called `note_unique_llvm_symbol`, so it is
clear somebody was aware of the issue at some point, but the function was barely
used, mostly in irrelevant locations.

Along with working on it I took liberty to start refactoring trans/base into
a few smaller modules. The refactoring is incomplete and I hope I will find some
motivation to carry on with it.

This is possibly a [breaking-change] because it makes dumbly written code
properly invalid.

This fixes all those issues about incorrect use of #[no_mangle] being not reported/misreported/ICEd by the compiler.

NB. This PR does not attempt to tackle the parallel codegen issue that was mentioned in https://github.com/rust-lang/rust/pull/22811, but I believe it should be very straightforward in a follow up PR by modifying `trans::declare::get_defined_value` to look at all the contexts.

cc @alexcrichton @huonw @nrc because you commented on the original RFC issue.

EDIT: wow, this became much bigger than I initially intended.
Diffstat (limited to 'src/test/compile-fail')
-rw-r--r--src/test/compile-fail/dupe-symbols-1.rs21
-rw-r--r--src/test/compile-fail/dupe-symbols-2.rs25
-rw-r--r--src/test/compile-fail/dupe-symbols-3.rs21
-rw-r--r--src/test/compile-fail/dupe-symbols-4.rs31
-rw-r--r--src/test/compile-fail/dupe-symbols-5.rs20
-rw-r--r--src/test/compile-fail/dupe-symbols-6.rs18
-rw-r--r--src/test/compile-fail/dupe-symbols-7.rs15
7 files changed, 151 insertions, 0 deletions
diff --git a/src/test/compile-fail/dupe-symbols-1.rs b/src/test/compile-fail/dupe-symbols-1.rs
new file mode 100644
index 00000000000..9fa4eafcad0
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-1.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+#[export_name="fail"]
+pub fn a() {
+}
+
+#[export_name="fail"]
+pub fn b() {
+//~^ symbol `fail` is already defined
+}
diff --git a/src/test/compile-fail/dupe-symbols-2.rs b/src/test/compile-fail/dupe-symbols-2.rs
new file mode 100644
index 00000000000..976a65589b8
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-2.rs
@@ -0,0 +1,25 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+mod a {
+    #[no_mangle]
+    pub extern fn fail() {
+    }
+}
+
+mod b {
+    #[no_mangle]
+    pub extern fn fail() {
+    //~^ symbol `fail` is already defined
+    }
+}
diff --git a/src/test/compile-fail/dupe-symbols-3.rs b/src/test/compile-fail/dupe-symbols-3.rs
new file mode 100644
index 00000000000..98a61c33c58
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-3.rs
@@ -0,0 +1,21 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+#[export_name="fail"]
+pub fn a() {
+}
+
+#[no_mangle]
+pub fn fail() {
+//~^ symbol `fail` is already defined
+}
diff --git a/src/test/compile-fail/dupe-symbols-4.rs b/src/test/compile-fail/dupe-symbols-4.rs
new file mode 100644
index 00000000000..9e730699d25
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-4.rs
@@ -0,0 +1,31 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+// error-pattern: symbol `fail` is already defined
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+
+pub trait A {
+    fn fail(self);
+}
+
+struct B;
+struct C;
+
+impl A for B {
+    #[no_mangle]
+    fn fail(self) {}
+}
+
+impl A for C {
+    #[no_mangle]
+    fn fail(self) {}
+}
diff --git a/src/test/compile-fail/dupe-symbols-5.rs b/src/test/compile-fail/dupe-symbols-5.rs
new file mode 100644
index 00000000000..eb4b50d03ca
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-5.rs
@@ -0,0 +1,20 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+#[export_name="fail"]
+static HELLO: u8 = 0;
+
+#[export_name="fail"]
+pub fn b() {
+//~^ symbol `fail` is already defined
+}
diff --git a/src/test/compile-fail/dupe-symbols-6.rs b/src/test/compile-fail/dupe-symbols-6.rs
new file mode 100644
index 00000000000..6f412d9a0de
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-6.rs
@@ -0,0 +1,18 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+#![crate_type="rlib"]
+#![allow(warnings)]
+
+#[export_name="fail"]
+static HELLO: u8 = 0;
+
+#[export_name="fail"]
+static HELLO_TWICE: u16 = 0;
+//~^ symbol `fail` is already defined
diff --git a/src/test/compile-fail/dupe-symbols-7.rs b/src/test/compile-fail/dupe-symbols-7.rs
new file mode 100644
index 00000000000..c2880ba6f51
--- /dev/null
+++ b/src/test/compile-fail/dupe-symbols-7.rs
@@ -0,0 +1,15 @@
+// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
+// file at the top-level directory of this distribution and at
+// http://rust-lang.org/COPYRIGHT.
+//
+// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
+// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
+// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
+// option. This file may not be copied, modified, or distributed
+// except according to those terms.
+//
+// error-pattern: entry symbol `main` defined multiple times
+#![allow(warnings)]
+
+#[no_mangle]
+fn main(){}