Skip to content

Commit 49fe598

Browse files
committed
do not emit #[no_mangle] on extern functions
1 parent 0df9864 commit 49fe598

File tree

3 files changed

+7
-3
lines changed

3 files changed

+7
-3
lines changed

c2rust-transpile/src/translator/mod.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,11 @@ pub fn stmts_block(mut stmts: Vec<Stmt>) -> P<Block> {
403403
// values.
404404
fn mk_linkage(in_extern_block: bool, new_name: &str, old_name: &str) -> Builder {
405405
if new_name == old_name {
406-
mk() // Don't touch my name Rust!
406+
if in_extern_block {
407+
mk() // There is no mangling by default in extern blocks anymore
408+
} else {
409+
mk().single_attr("no_mangle") // Don't touch my name Rust!
410+
}
407411
} else if in_extern_block {
408412
mk().str_attr("link_name", old_name) // Look for this name
409413
} else {

tests/items/src/test_fn_attrs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,6 @@ pub fn test_fn_attrs() {
5252

5353
if cfg!(not(target_os = "macos")) {
5454
// aliased_fn is aliased to the inline_extern function
55-
assert!(src.contains("#[no_mangle]\n #[link_name = \"inline_extern\"]\n fn aliased_fn();"));
55+
assert!(src.contains("extern \"C\" {\n #[link_name = \"inline_extern\"]\n fn aliased_fn();"));
5656
}
5757
}

tests/statics/src/test_sections.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,6 @@ pub fn test_sectioned_used_static() {
5050

5151
// This static is pub, but we want to ensure it has attributes applied
5252
assert!(src.contains("#[link_section = \"fb\"]\npub static mut rust_initialized_extern: libc::c_int = 1 as libc::c_int;"));
53-
assert!(src.contains("#[no_mangle]\n #[link_name = \"no_attrs\"]\n static mut rust_aliased_static: libc::c_int;"))
53+
assert!(src.contains("extern \"C\" {\n #[link_name = \"no_attrs\"]\n static mut rust_aliased_static: libc::c_int;"))
5454
}
5555
}

0 commit comments

Comments
 (0)