Skip to content

Commit

Permalink
Auto merge of rust-lang#822 - upsuper:mangling-fix, r=emilio
Browse files Browse the repository at this point in the history
Stop Rust from prepending underscore before '?' for win32

This fixes rust-lang#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).
  • Loading branch information
bors-servo authored Jul 18, 2017
2 parents 75c5875 + 4f8de62 commit 63de24e
Show file tree
Hide file tree
Showing 13 changed files with 165 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/ir/function.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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'); }
_ => {}
}
}
}

Expand Down
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-linux32.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-linux64.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
19 changes: 19 additions & 0 deletions tests/expectations/tests/mangling-macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
19 changes: 19 additions & 0 deletions tests/expectations/tests/mangling-win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
}
28 changes: 28 additions & 0 deletions tests/expectations/tests/mangling-win64.rs
Original file line number Diff line number Diff line change
@@ -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 }
}
7 changes: 7 additions & 0 deletions tests/headers/mangling-linux32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=i586-unknown-linux

extern "C" void foo();

struct Foo {
static bool sBar;
};
7 changes: 7 additions & 0 deletions tests/headers/mangling-linux64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-unknown-linux

extern "C" void foo();

struct Foo {
static bool sBar;
};
3 changes: 0 additions & 3 deletions tests/headers/mangling-macos.h

This file was deleted.

7 changes: 7 additions & 0 deletions tests/headers/mangling-macos.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-apple-darwin

extern "C" void foo();

struct Foo {
static bool sBar;
};
3 changes: 0 additions & 3 deletions tests/headers/mangling-win32.h

This file was deleted.

7 changes: 7 additions & 0 deletions tests/headers/mangling-win32.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=i686-pc-win32

extern "C" void foo();

struct Foo {
static bool sBar;
};
7 changes: 7 additions & 0 deletions tests/headers/mangling-win64.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// bindgen-flags: -- --target=x86_64-pc-win32

extern "C" void foo();

struct Foo {
static bool sBar;
};

0 comments on commit 63de24e

Please sign in to comment.