summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLiran Ringel <liranringel@gmail.com>2017-10-07 12:12:19 +0200
committerLiran Ringel <liranringel@gmail.com>2017-10-07 15:02:08 +0200
commitf2b30c8b07959bf92b161157ba200b7ec301271f (patch)
tree3ce751af7d67a72aafbf680ce9d9f30c108ef835 /src
parentc7fe6b67fa71f7a7a5d8534aa608865a987c1e94 (diff)
Tell LLVM to not mangle names if they're already mangled through link_name attribute
Diffstat (limited to 'src')
-rw-r--r--src/codegen/helpers.rs3
-rw-r--r--src/ir/context.rs18
-rw-r--r--src/ir/function.rs22
3 files changed, 4 insertions, 39 deletions
diff --git a/src/codegen/helpers.rs b/src/codegen/helpers.rs
index 5136d787..9a8b0576 100644
--- a/src/codegen/helpers.rs
+++ b/src/codegen/helpers.rs
@@ -45,6 +45,9 @@ pub mod attributes {
}
pub fn link_name(name: &str) -> quote::Tokens {
+ // LLVM mangles the name by default but it's already mangled.
+ // Prefixing the name with \u{1} should tell LLVM to not mangle it.
+ let name = format!("\u{1}{}", name);
quote! {
#[link_name = #name]
}
diff --git a/src/ir/context.rs b/src/ir/context.rs
index 8f361094..c84e66ca 100644
--- a/src/ir/context.rs
+++ b/src/ir/context.rs
@@ -391,9 +391,6 @@ pub struct BindgenContext {
/// bitfield allocation units computed. Drained in `compute_bitfield_units`.
need_bitfield_allocation: Vec<ItemId>,
- /// Whether we need the mangling hack which removes the prefixing underscore.
- needs_mangling_hack: bool,
-
/// The set of (`ItemId`s of) types that can't derive debug.
///
/// This is populated when we enter codegen by `compute_cannot_derive_debug`
@@ -558,15 +555,6 @@ impl BindgenContext {
).expect("TranslationUnit::parse failed")
};
- // Mac os, iOS and Win32 need __ for mangled symbols but rust will
- // automatically prepend the extra _.
- //
- // We need to make sure that we don't include __ because rust will turn
- // into ___.
- let needs_mangling_hack = effective_target.contains("darwin") ||
- effective_target.contains("ios") ||
- effective_target == "i686-pc-win32";
-
let root_module = Self::build_root_module(ItemId(0));
let root_module_id = root_module.id().as_module_id_unchecked();
@@ -592,7 +580,6 @@ impl BindgenContext {
codegen_items: None,
used_template_parameters: None,
need_bitfield_allocation: Default::default(),
- needs_mangling_hack: needs_mangling_hack,
cannot_derive_debug: None,
cannot_derive_default: None,
cannot_derive_copy: None,
@@ -1415,11 +1402,6 @@ impl BindgenContext {
Item::new(id, None, None, id, ItemKind::Module(module))
}
- /// Returns the target triple bindgen is running over.
- pub fn needs_mangling_hack(&self) -> bool {
- self.needs_mangling_hack
- }
-
/// Get the root module.
pub fn root_module(&self) -> ModuleId {
self.root_module
diff --git a/src/ir/function.rs b/src/ir/function.rs
index 3a9f337c..b637f9f1 100644
--- a/src/ir/function.rs
+++ b/src/ir/function.rs
@@ -206,23 +206,6 @@ fn get_abi(cc: CXCallingConv) -> Abi {
}
}
-fn mangling_hack_if_needed(ctx: &BindgenContext, symbol: &mut String) {
- if ctx.needs_mangling_hack() {
- 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');
- }
- _ => {}
- }
- }
-}
-
/// Get the mangled name for the cursor's referent.
pub fn cursor_mangling(
ctx: &BindgenContext,
@@ -241,8 +224,7 @@ pub fn cursor_mangling(
}
if let Ok(mut manglings) = cursor.cxx_manglings() {
- if let Some(mut m) = manglings.pop() {
- mangling_hack_if_needed(ctx, &mut m);
+ if let Some(m) = manglings.pop() {
return Some(m);
}
}
@@ -252,8 +234,6 @@ pub fn cursor_mangling(
return None;
}
- mangling_hack_if_needed(ctx, &mut mangling);
-
if cursor.kind() == clang_sys::CXCursor_Destructor {
// With old (3.8-) libclang versions, and the Itanium ABI, clang returns
// the "destructor group 0" symbol, which means that it'll try to free