summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbors-servo <lbergstrom+bors@mozilla.com>2017-07-18 00:29:12 -0700
committerGitHub <noreply@github.com>2017-07-18 00:29:12 -0700
commit63de24e68dc5659de1c3451b4424068628c6edc7 (patch)
treec08b5ab97c0a7bdd3abc256271b883489c1b511c
parent75c587571f38746e98f18f56c29dd7ae8884680c (diff)
parent4f8de62f4585ce40c9b10b3ddc9f9f99b681549b (diff)
Auto merge of #822 - upsuper:mangling-fix, r=emilio
Stop Rust from prepending underscore before '?' for win32 This fixes #819. It also includes tests for different platforms which are not supposed to be affected, so that we won't regress them in the future either. The prefix `\x01` char is necessary for Win32. See also [msvc32_symbolify function in regen_atoms.py](https://github.com/servo/servo/blob/1b6d29e31996c87218352b825aa93e01909a6a24/components/style/gecko/regen_atoms.py#L35-L38).
-rw-r--r--src/ir/function.rs9
-rw-r--r--tests/expectations/tests/mangling-linux32.rs28
-rw-r--r--tests/expectations/tests/mangling-linux64.rs28
-rw-r--r--tests/expectations/tests/mangling-macos.rs19
-rw-r--r--tests/expectations/tests/mangling-win32.rs19
-rw-r--r--tests/expectations/tests/mangling-win64.rs28
-rw-r--r--tests/headers/mangling-linux32.hpp7
-rw-r--r--tests/headers/mangling-linux64.hpp7
-rw-r--r--tests/headers/mangling-macos.h3
-rw-r--r--tests/headers/mangling-macos.hpp7
-rw-r--r--tests/headers/mangling-win32.h3
-rw-r--r--tests/headers/mangling-win32.hpp7
-rw-r--r--tests/headers/mangling-win64.hpp7
13 files changed, 165 insertions, 7 deletions
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 9865997d..5fa95203 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -130,7 +130,14 @@ fn get_abi(cc: CXCallingConv) -> Abi {
fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) {
if ctx.needs_mangling_hack() {
- symbol.remove(0);
+ match symbol.chars().next().unwrap() {
+ // Stripping leading underscore for all names on Darwin and
+ // C linkage functions on Win32.
+ '_' => { symbol.remove(0); }
+ // Stop Rust from prepending underscore for variables on Win32.
+ '?' => { symbol.insert(0, '\x01'); }
+ _ => {}
+ }
}
}
diff --git a/tests/expectations/tests/mangling-linux32.rs b/tests/expectations/tests/mangling-linux32.rs
new file mode 100644
index 00000000..5aa7bd55
--- /dev/null
+++ b/tests/expectations/tests/mangling-linux32.rs
@@ -0,0 +1,28 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+extern "C" {
+ pub fn foo();
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN3Foo4sBarE"]
+ pub static mut Foo_sBar: bool;
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/mangling-linux64.rs b/tests/expectations/tests/mangling-linux64.rs
new file mode 100644
index 00000000..5aa7bd55
--- /dev/null
+++ b/tests/expectations/tests/mangling-linux64.rs
@@ -0,0 +1,28 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+extern "C" {
+ pub fn foo();
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN3Foo4sBarE"]
+ pub static mut Foo_sBar: bool;
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/mangling-macos.rs b/tests/expectations/tests/mangling-macos.rs
index 87df5e4a..5aa7bd55 100644
--- a/tests/expectations/tests/mangling-macos.rs
+++ b/tests/expectations/tests/mangling-macos.rs
@@ -7,3 +7,22 @@
extern "C" {
pub fn foo();
}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "_ZN3Foo4sBarE"]
+ pub static mut Foo_sBar: bool;
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/mangling-win32.rs b/tests/expectations/tests/mangling-win32.rs
index 87df5e4a..ffaf52cf 100644
--- a/tests/expectations/tests/mangling-win32.rs
+++ b/tests/expectations/tests/mangling-win32.rs
@@ -7,3 +7,22 @@
extern "C" {
pub fn foo();
}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "\u{1}?sBar@Foo@@2_NA"]
+ pub static mut Foo_sBar: bool;
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/expectations/tests/mangling-win64.rs b/tests/expectations/tests/mangling-win64.rs
new file mode 100644
index 00000000..ae5cc9cc
--- /dev/null
+++ b/tests/expectations/tests/mangling-win64.rs
@@ -0,0 +1,28 @@
+/* automatically generated by rust-bindgen */
+
+
+#![allow(dead_code, non_snake_case, non_camel_case_types, non_upper_case_globals)]
+
+
+extern "C" {
+ pub fn foo();
+}
+#[repr(C)]
+#[derive(Debug, Default, Copy)]
+pub struct Foo {
+ pub _address: u8,
+}
+extern "C" {
+ #[link_name = "?sBar@Foo@@2_NA"]
+ pub static mut Foo_sBar: bool;
+}
+#[test]
+fn bindgen_test_layout_Foo() {
+ assert_eq!(::std::mem::size_of::<Foo>() , 1usize , concat ! (
+ "Size of: " , stringify ! ( Foo ) ));
+ assert_eq! (::std::mem::align_of::<Foo>() , 1usize , concat ! (
+ "Alignment of " , stringify ! ( Foo ) ));
+}
+impl Clone for Foo {
+ fn clone(&self) -> Self { *self }
+}
diff --git a/tests/headers/mangling-linux32.hpp b/tests/headers/mangling-linux32.hpp
new file mode 100644
index 00000000..450c91d7
--- /dev/null
+++ b/tests/headers/mangling-linux32.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: -- --target=i586-unknown-linux
+
+extern "C" void foo();
+
+struct Foo {
+ static bool sBar;
+};
diff --git a/tests/headers/mangling-linux64.hpp b/tests/headers/mangling-linux64.hpp
new file mode 100644
index 00000000..36dda913
--- /dev/null
+++ b/tests/headers/mangling-linux64.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: -- --target=x86_64-unknown-linux
+
+extern "C" void foo();
+
+struct Foo {
+ static bool sBar;
+};
diff --git a/tests/headers/mangling-macos.h b/tests/headers/mangling-macos.h
deleted file mode 100644
index 230f938b..00000000
--- a/tests/headers/mangling-macos.h
+++ /dev/null
@@ -1,3 +0,0 @@
-// bindgen-flags: -- --target=x86_64-apple-darwin
-
-void foo();
diff --git a/tests/headers/mangling-macos.hpp b/tests/headers/mangling-macos.hpp
new file mode 100644
index 00000000..94b16202
--- /dev/null
+++ b/tests/headers/mangling-macos.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: -- --target=x86_64-apple-darwin
+
+extern "C" void foo();
+
+struct Foo {
+ static bool sBar;
+};
diff --git a/tests/headers/mangling-win32.h b/tests/headers/mangling-win32.h
deleted file mode 100644
index 897aeb42..00000000
--- a/tests/headers/mangling-win32.h
+++ /dev/null
@@ -1,3 +0,0 @@
-// bindgen-flags: -- --target=i686-pc-win32
-
-void foo();
diff --git a/tests/headers/mangling-win32.hpp b/tests/headers/mangling-win32.hpp
new file mode 100644
index 00000000..50beea5a
--- /dev/null
+++ b/tests/headers/mangling-win32.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: -- --target=i686-pc-win32
+
+extern "C" void foo();
+
+struct Foo {
+ static bool sBar;
+};
diff --git a/tests/headers/mangling-win64.hpp b/tests/headers/mangling-win64.hpp
new file mode 100644
index 00000000..8882d7dd
--- /dev/null
+++ b/tests/headers/mangling-win64.hpp
@@ -0,0 +1,7 @@
+// bindgen-flags: -- --target=x86_64-pc-win32
+
+extern "C" void foo();
+
+struct Foo {
+ static bool sBar;
+};